@@ -84,6 +84,7 @@ describe('AST', () => {
8484 var ast = parseContract ( "contract test {}" )
8585 assert . deepEqual ( ast , {
8686 "type" : "ContractDefinition" ,
87+ "natspec" : null ,
8788 "name" : "test" ,
8889 "baseContracts" : [ ] ,
8990 "subNodes" : [ ] ,
@@ -94,6 +95,7 @@ describe('AST', () => {
9495 ast = parseContract ( "contract test is foo, bar {}" )
9596 assert . deepEqual ( ast , {
9697 "type" : "ContractDefinition" ,
98+ "natspec" : null ,
9799 "name" : "test" ,
98100 "baseContracts" : [
99101 {
@@ -121,6 +123,7 @@ describe('AST', () => {
121123 ast = parseContract ( "library test {}" )
122124 assert . deepEqual ( ast , {
123125 "type" : "ContractDefinition" ,
126+ "natspec" : null ,
124127 "name" : "test" ,
125128 "baseContracts" : [ ] ,
126129 "subNodes" : [ ] ,
@@ -131,6 +134,7 @@ describe('AST', () => {
131134 ast = parseContract ( "interface test {}" )
132135 assert . deepEqual ( ast , {
133136 "type" : "ContractDefinition" ,
137+ "natspec" : null ,
134138 "name" : "test" ,
135139 "baseContracts" : [ ] ,
136140 "subNodes" : [ ] ,
@@ -171,6 +175,7 @@ describe('AST', () => {
171175 var ast = parseNode ( "function foo(uint a) pure {}" )
172176 assert . deepEqual ( ast , {
173177 "type" : "FunctionDefinition" ,
178+ "natspec" : null ,
174179 "name" : "foo" ,
175180 "parameters" : [
176181 {
@@ -200,6 +205,7 @@ describe('AST', () => {
200205 ast = parseNode ( "function foo(uint a) pure returns (uint256) {}" )
201206 assert . deepEqual ( ast , {
202207 "type" : "FunctionDefinition" ,
208+ "natspec" : null ,
203209 "name" : "foo" ,
204210 "parameters" : [
205211 {
@@ -1091,6 +1097,7 @@ describe('AST', () => {
10911097 assert . deepEqual ( ast , {
10921098 "type" : "EventDefinition" ,
10931099 "name" : "Foo" ,
1100+ "natspec" : null ,
10941101 "parameters" : [
10951102 {
10961103 "type" : "VariableDeclaration" ,
@@ -1490,4 +1497,121 @@ describe('AST', () => {
14901497 "type" : "AssemblyIf"
14911498 } )
14921499 } )
1500+
1501+ it ( "NatSpec multi line" , function ( ) {
1502+ const ast = parser . parse (
1503+ `/**
1504+ * @dev This is the Sum contract.
1505+ * @title Sum Contract
1506+ * @author username
1507+ */
1508+ contract Sum { }`
1509+ ) ;
1510+ assert . deepEqual ( ast . children [ 0 ] , {
1511+ type : "ContractDefinition" ,
1512+ natspec : {
1513+ dev : "This is the Sum contract." ,
1514+ title : "Sum Contract" ,
1515+ author : "username" ,
1516+ } ,
1517+ name : "Sum" ,
1518+ baseContracts : [ ] ,
1519+ subNodes : [ ] ,
1520+ kind : "contract" ,
1521+ } )
1522+ } )
1523+
1524+ it ( "NatSpec single line" , function ( ) {
1525+ const ast = parser . parse (
1526+ `/// @dev This is the Sum contract.
1527+ /// @title Sum Contract
1528+ /// @author username
1529+ contract Sum { }`
1530+ ) ;
1531+ assert . deepEqual ( ast . children [ 0 ] , {
1532+ type : "ContractDefinition" ,
1533+ natspec : {
1534+ dev : "This is the Sum contract." ,
1535+ title : "Sum Contract" ,
1536+ author : "username" ,
1537+ } ,
1538+ name : "Sum" ,
1539+ baseContracts : [ ] ,
1540+ subNodes : [ ] ,
1541+ kind : "contract" ,
1542+ } )
1543+ } )
1544+
1545+ it ( "NatSpec multi line event" , function ( ) {
1546+ const ast = parseNode (
1547+ `/**
1548+ * @dev This method says hello
1549+ * @param user the user address
1550+ */
1551+ event sayHello(address user);`
1552+ ) ;
1553+ assert . deepEqual ( ast . natspec , {
1554+ dev : "This method says hello" ,
1555+ params : {
1556+ user : "the user address"
1557+ } ,
1558+ } )
1559+ } )
1560+
1561+ it ( "NatSpec multi line function" , function ( ) {
1562+ const ast = parseNode (
1563+ `/**
1564+ * @dev This method transfer fund to other user
1565+ * @param from the address extract funds
1566+ * @param to the user address to give funds
1567+ * @param amount the amount to transfer
1568+ */
1569+ function transfer(address from, address to, uint256 amount) public {}` ) ;
1570+
1571+ assert . deepEqual ( ast . natspec , {
1572+ dev : "This method transfer fund to other user" ,
1573+ params : {
1574+ from : "the address extract funds" ,
1575+ to : "the user address to give funds" ,
1576+ amount : "the amount to transfer" ,
1577+ } ,
1578+ } )
1579+ } )
1580+ it ( "NatSpec multi line multiple functions in contract" , function ( ) {
1581+ const ast = parser . parse (
1582+ `/**
1583+ * @dev The ERC20 contract
1584+ */
1585+ contract ERC20 {
1586+ /**
1587+ * @dev This method transfer fund to other user
1588+ * @param from the address extract funds
1589+ * @param to the user address to give funds
1590+ * @param amount the amount to transfer
1591+ */
1592+ function transfer(address from, address to, uint256 amount) public {}
1593+ /**
1594+ * @dev This method gets the approved amount
1595+ * @param user the user address to verify
1596+ * @return the approved amount
1597+ */
1598+ function approved(address user) public view returns(uint256) {}
1599+ }` ) ;
1600+ const methods = ast . children [ 0 ] . subNodes ;
1601+ assert . deepEqual ( methods [ 0 ] . natspec , {
1602+ dev : 'This method transfer fund to other user' ,
1603+ params : {
1604+ from : 'the address extract funds' ,
1605+ to : 'the user address to give funds' ,
1606+ amount : 'the amount to transfer' ,
1607+ } ,
1608+ } ) ;
1609+ assert . deepEqual ( methods [ 1 ] . natspec , {
1610+ dev : 'This method gets the approved amount' ,
1611+ params : {
1612+ user : 'the user address to verify' ,
1613+ } ,
1614+ return : 'the approved amount' ,
1615+ } ) ;
1616+ } )
14931617} )
0 commit comments