-
Notifications
You must be signed in to change notification settings - Fork 24
Support default values for non-optional properties (name=value syntax) #187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| const { parse } = require('../../lib/index.cjs'); | ||
|
|
||
| test('non-optional property with default value', () => { | ||
| const parsed = parse(` | ||
| /** | ||
| * Some annoying set of bitmasks or something. | ||
| * | ||
| * @property {number} BITMASK_VALUE_A=16 - blah blah | ||
| * @property {number} BITMASK_VALUE_B=32 - the other thing | ||
| */`); | ||
|
|
||
| expect(parsed[0].tags).toMatchObject([ | ||
| { | ||
| tag: 'property', | ||
| type: 'number', | ||
| name: 'BITMASK_VALUE_A', | ||
| optional: false, | ||
| default: '16', | ||
| description: '- blah blah', | ||
| }, | ||
| { | ||
| tag: 'property', | ||
| type: 'number', | ||
| name: 'BITMASK_VALUE_B', | ||
| optional: false, | ||
| default: '32', | ||
| description: '- the other thing', | ||
| }, | ||
| ]); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -620,6 +620,152 @@ test('empty', () => { | |
| ); | ||
| }); | ||
|
|
||
| test('non-optional with default', () => { | ||
| expect( | ||
| tokenize( | ||
| seedSpec({ | ||
| source: [ | ||
| { | ||
| number: 1, | ||
| source: '...', | ||
| tokens: seedTokens({ | ||
| description: 'param=value param description', | ||
| }), | ||
| }, | ||
| ], | ||
| }) | ||
| ) | ||
| ).toEqual( | ||
| seedSpec({ | ||
| name: 'param', | ||
| optional: false, | ||
| default: 'value', | ||
| source: [ | ||
| { | ||
| number: 1, | ||
| source: '...', | ||
| tokens: seedTokens({ | ||
| name: 'param=value', | ||
| postName: ' ', | ||
| description: 'param description', | ||
| }), | ||
| }, | ||
| ], | ||
| }) | ||
| ); | ||
| }); | ||
|
|
||
| test('non-optional with numeric default', () => { | ||
| expect( | ||
| tokenize( | ||
| seedSpec({ | ||
| source: [ | ||
| { | ||
| number: 1, | ||
| source: '...', | ||
| tokens: seedTokens({ | ||
| description: 'BITMASK_VALUE_A=16 blah blah', | ||
| }), | ||
| }, | ||
| ], | ||
| }) | ||
| ) | ||
| ).toEqual( | ||
| seedSpec({ | ||
| name: 'BITMASK_VALUE_A', | ||
| optional: false, | ||
| default: '16', | ||
| source: [ | ||
| { | ||
| number: 1, | ||
| source: '...', | ||
| tokens: seedTokens({ | ||
| name: 'BITMASK_VALUE_A=16', | ||
| postName: ' ', | ||
| description: 'blah blah', | ||
| }), | ||
| }, | ||
| ], | ||
| }) | ||
| ); | ||
| }); | ||
|
Comment on lines
+623
to
+691
|
||
|
|
||
| test('non-optional with empty default', () => { | ||
| expect( | ||
| tokenize( | ||
| seedSpec({ | ||
| source: [ | ||
| { | ||
| number: 1, | ||
| source: '...', | ||
| tokens: seedTokens({ | ||
| description: 'param= param description', | ||
| }), | ||
| }, | ||
| ], | ||
| }) | ||
| ) | ||
| ).toEqual( | ||
| seedSpec({ | ||
| problems: [ | ||
| { | ||
| code: 'spec:name:empty-default', | ||
| line: 1, | ||
| critical: true, | ||
| message: 'empty default value', | ||
| }, | ||
| ], | ||
| source: [ | ||
| { | ||
| number: 1, | ||
| source: '...', | ||
| tokens: seedTokens({ | ||
| description: 'param= param description', | ||
| }), | ||
| }, | ||
| ], | ||
| }) | ||
| ); | ||
| }); | ||
|
|
||
| test('non-optional with invalid default syntax', () => { | ||
| expect( | ||
| tokenize( | ||
| seedSpec({ | ||
| source: [ | ||
| { | ||
| number: 1, | ||
| source: '...', | ||
| tokens: seedTokens({ | ||
| description: 'param=value=value param description', | ||
| }), | ||
| }, | ||
| ], | ||
| }) | ||
| ) | ||
| ).toEqual( | ||
| seedSpec({ | ||
| problems: [ | ||
| { | ||
| code: 'spec:name:invalid-default', | ||
| line: 1, | ||
| critical: true, | ||
| message: 'invalid default value syntax', | ||
| }, | ||
| ], | ||
| source: [ | ||
| { | ||
| number: 1, | ||
| source: '...', | ||
| tokens: seedTokens({ | ||
| description: 'param=value=value param description', | ||
| }), | ||
| }, | ||
| ], | ||
| }) | ||
| ); | ||
| }); | ||
|
|
||
| test('default value syntax', () => { | ||
| expect( | ||
| tokenize( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-optional default parsing diverges from the optional
[name=value]path: it doesn’t trim around=and it skips thespec:name:invalid-defaultvalidation (e.g.name=value=valuewould now be accepted unbracketed but rejected when bracketed). Consider reusing the same split/join/trim + invalid-default check logic for both branches so defaults behave consistently.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already addressed in 786bf5f — the non-optional path now uses the same
split/join/trimapproach andspec:name:invalid-defaultcheck as the optional path.