8000 Moosh default-value testing down into 1 test. Polish style. Update re… · pyodide/sphinx-js@344a7e9 · GitHub
[go: up one dir, main page]

8000 Skip to content

Commit 344a7e9

Browse files
committed
Moosh default-value testing down into 1 test. Polish style. Update readme.
1 parent e02aa12 commit 344a7e9

File tree

6 files changed

+24
-43
lines changed

6 files changed

+24
-43
lines changed

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,10 @@ Run ``python setup.py test``. Run ``tox`` to test across Python versions.
279279
Version History
280280
===============
281281

282-
2.4.1
282+
2.5
283283
* Use documented ``@params`` to help fill out the formal param list for a
284284
function. This keeps us from missing params that use destructuring. (flozz)
285+
* Add extracted default values to generated formal param lists. (flozz)
285286

286287
2.4
287288
* Support the ``@example`` tag. (lidavidm)

sphinx_js/renderers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,10 @@ def _formal_params(self, doclet):
119119
params = []
120120
used_names = []
121121

122-
for name, default in [(param['name'].split(".")[0], param.get('defaultvalue')) for param in doclet.get('params', [])]:
122+
for name, default in [(param['name'].split('.')[0], param.get('defaultvalue'))
123+
for param in doclet.get('params', [])]:
123124
if name not in used_names:
124-
params.append("%s=%s" % (name, default) if default is not None else name)
125+
params.append('%s=%s' % (name, default) if default is not None else name)
125126
used_names.append(name)
126127

127128
# Use params from JS code if there are no documented params:

tests/test_build/source/code.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,7 @@ function destructuredParams(p1, {foo, bar}) {}
152152

153153
/**
154154
* @param {number} [p1=42]
155-
* @param {string} [p2="foobar"]
155+
* @param {string} [p2]
156+
* @param {string} [p3="true"]
156157
*/
157-
function defaultValues(p1=42, p2="foobar") {}
158-
159-
/**
160-
* @param {number} [p1=42]
161-
* @param {string} [p2="foobar"]
162-
*/
163-
function defaultValuesOnlyInDoc(p1, p2) {}
164-
165-
/**
166-
* @param {number} p1
167-
* @param {string} p2
168-
*/
169-
function defaultValuesOnlyInJs(p1=42, p2="foobar") {}
158+
function defaultValues(p1, p2="foobar", p3="true") {}

tests/test_build/source/docs/autofunction_default_values_only_in_doc.rst

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/test_build/source/docs/autofunction_default_values_only_in_js.rst

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/test_build/test_build.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,34 +72,26 @@ def test_autofunction_destructured_params(self):
7272
' * **p2.foo** (*String*) --\n\n'
7373
' * **p2.bar** (*String*) --\n')
7474

75-
def test_autofunction_defaut_values(self):
76-
"""Make sure params default values appear in the function definition."""
77-
self._file_contents_eq(
78-
'autofunction_default_values',
79-
u'defaultValues(p1=42, p2="foobar")\n\n'
80-
' Arguments:\n'
81-
' * **p1** (*number*) --\n\n'
82-
' * **p2** (*string*) --\n')
83-
84-
def test_autofunction_defaut_values_only_in_doc(self):
85-
"""Make sure params default values appear in the function definition when
86-
the default values only appears in JSdoc comment."""
87-
self._file_contents_eq(
88-
'autofunction_default_values_only_in_doc',
89-
u'defaultValuesOnlyInDoc(p1=42, p2="foobar")\n\n'
90-
' Arguments:\n'
91-
' * **p1** (*number*) --\n\n'
92-
' * **p2** (*string*) --\n')
75+
def test_autofunction_default_values(self):
76+
"""Make sure params default values appear in the function definition,
77+
whether the defaults are defined in JSDoc or JS.
78+
79+
Unfortunately, there is no way to disambiguate strings from symbolic
80+
values used as default args in JS code: for instance, ``true`` vs.
81+
``"true"``. JSDoc's doclets render them both without quotes. However,
82+
you can work around this by specifying your defaults in the JSDoc
83+
comment rather than the JS code, as we do with p3. It would be lovely
84+
if JSDoc changed its behavior someday so we could know to put quotes
85+
around "foobar" as well.
9386
94-
def test_autofunction_defaut_values_only_in_js(self):
95-
"""Make sure params default values appear in the function definition when
96-
the default values only appears in Javascript Code (ES2015)."""
87+
"""
9788
self._file_contents_eq(
98-
'autofunction_default_values_only_in_js',
99-
u'defaultValuesOnlyInJs(p1=42, p2=foobar)\n\n'
89+
'autofunction_default_values',
90+
u'defaultValues(p1=42, p2=foobar, p3="true")\n\n'
10091
' Arguments:\n'
10192
' * **p1** (*number*) --\n\n'
102-
' * **p2** (*string*) --\n')
93+
' * **p2** (*string*) --\n\n'
94+
' * **p3** (*string*) --\n')
10395

10496
def test_autoclass(self):
10597
"""Make sure classes show their class comment and constructor

0 commit comments

Comments
 (0)
0