-
Notifications
You must be signed in to change notification settings - Fork 8
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
test: add test for unnamed returns #22
Changes from 5 commits
d917f1e
f22f77f
5b95b7e
eedd649
9131c4a
63b27fc
beeacd7
776362c
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 |
---|---|---|
|
@@ -95,7 +95,7 @@ export function parseNodeNatspec(node: NodeToProcess): Natspec { | |
result.inheritdoc = { content: tagMatch[2] }; | ||
} | ||
} else if (tagName === 'param' || tagName === 'return') { | ||
const tagMatch = line.match(/^\s*@(\w+) *(\w+) (.*)$/); | ||
const tagMatch = line.match(/^\s*@(\w+) *(\w*) *(.*)$/); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good job catching this 👍🏻 |
||
if (tagMatch) { | ||
currentTag = { name: tagMatch[2], content: tagMatch[3].trim() }; | ||
result[tagName === 'param' ? 'params' : 'returns'].push(currentTag); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,7 +153,172 @@ describe('Validator', () => { | |
}; | ||
|
||
const result = validator.validate(node, natspec); | ||
expect(result).toContainEqual(`@return missing for unnamed return`); | ||
expect(result).toContainEqual(`@return missing for unnamed return №2`); | ||
}); | ||
|
||
it('should warn of missed unnamed return', () => { | ||
dristpunk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
node = contract.vFunctions.find(({ name }) => name === 'externalSimpleMultipleUnnamedReturn')!; | ||
let natspec = { | ||
tags: [ | ||
{ | ||
name: 'notice', | ||
content: 'External function that returns a bool', | ||
}, | ||
{ | ||
name: 'dev', | ||
content: 'A dev comment', | ||
}, | ||
], | ||
params: [], | ||
returns: [ | ||
{ | ||
name: 'Some', | ||
content: 'return data', | ||
}, | ||
], | ||
}; | ||
|
||
const result = validator.validate(node, natspec); | ||
expect(result).toEqual([`@return missing for unnamed return №2`]); // only 1 warning | ||
}); | ||
|
||
it('should not warn of extra natspec tags', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code for this case won't compile, right? If so we can delete the test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
right, and a couple of more tests |
||
node = contract.vFunctions.find(({ name }) => name === 'externalSimpleMultipleUnnamedReturn')!; | ||
let natspec = { | ||
tags: [ | ||
{ | ||
name: 'notice', | ||
content: 'External function that returns a bool', | ||
}, | ||
{ | ||
name: 'dev', | ||
content: 'A dev comment', | ||
}, | ||
], | ||
params: [], | ||
returns: [ | ||
{ | ||
name: 'Some', | ||
content: 'return data', | ||
}, | ||
{ | ||
name: 'Some', | ||
content: 'return data', | ||
}, | ||
], | ||
}; | ||
|
||
const result = validator.validate(node, natspec); | ||
expect(result).toEqual([]); // no warnings | ||
}); | ||
|
||
it('should warn if tags are in a wrong order', () => { | ||
node = contract.vFunctions.find(({ name }) => name === 'externalSimpleMultipleReturn')!; | ||
let natspec = { | ||
tags: [ | ||
{ | ||
name: 'notice', | ||
content: 'External function that returns a bool', | ||
}, | ||
{ | ||
name: 'dev', | ||
content: 'A dev comment', | ||
}, | ||
], | ||
params: [ | ||
{ | ||
name: '_magicNumber', | ||
content: 'A parameter description', | ||
}, | ||
{ | ||
name: '_name', | ||
content: 'Another parameter description', | ||
}, | ||
], | ||
returns: [ | ||
{ | ||
name: 'Some', | ||
content: 'return data', | ||
}, | ||
{ | ||
name: '_isMagic', | ||
content: 'Some return data', | ||
}, | ||
], | ||
}; | ||
|
||
const result = validator.validate(node, natspec); | ||
expect(result).toEqual(['@return _isMagic is missing']); // 1 warning | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The warning is misleading here. As a user, I will check that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
this won't compile as well so I'll delete it |
||
}); | ||
|
||
it('should warn all returns if the first natspec tag is missing', () => { | ||
node = contract.vFunctions.find(({ name }) => name === 'externalSimpleMultipleReturn')!; | ||
let natspec = { | ||
tags: [ | ||
{ | ||
name: 'notice', | ||
content: 'External function that returns a bool', | ||
}, | ||
{ | ||
name: 'dev', | ||
content: 'A dev comment', | ||
}, | ||
], | ||
params: [ | ||
{ | ||
name: '_magicNumber', | ||
content: 'A parameter description', | ||
}, | ||
{ | ||
name: '_name', | ||
content: 'Another parameter description', | ||
}, | ||
], | ||
returns: [ | ||
{ | ||
name: 'Some', | ||
content: 'return data', | ||
}, | ||
], | ||
}; | ||
|
||
const result = validator.validate(node, natspec); | ||
expect(result).toEqual(['@return _isMagic is missing', '@return missing for unnamed return №2']); // 2 warnings | ||
}); | ||
|
||
it('should warn if the last natspec tag is missing', () => { | ||
node = contract.vFunctions.find(({ name }) => name === 'externalSimpleMultipleReturn')!; | ||
let natspec = { | ||
tags: [ | ||
{ | ||
name: 'notice', | ||
content: 'External function that returns a bool', | ||
}, | ||
{ | ||
name: 'dev', | ||
content: 'A dev comment', | ||
}, | ||
], | ||
params: [ | ||
{ | ||
name: '_magicNumber', | ||
content: 'A parameter description', | ||
}, | ||
{ | ||
name: '_name', | ||
content: 'Another parameter description', | ||
}, | ||
], | ||
returns: [ | ||
{ | ||
name: '_isMagic', | ||
content: 'Some return data', | ||
}, | ||
], | ||
}; | ||
|
||
const result = validator.validate(node, natspec); | ||
expect(result).toEqual(['@return missing for unnamed return №2']); // 1 warnings | ||
}); | ||
|
||
// TODO: Check overridden functions, virtual, etc? | ||
|
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.
Could you move this function to
ParserTestFunny
? It's the contract that acts as a collection of weird natspec.