1
1
import { ContractDefinition } from 'solc-typed-ast' ;
2
- import { Parser } from '../src/parser' ;
3
2
import { getFileCompiledSource } from './utils' ;
3
+ import { parseNodeNatspec } from '../src/utils' ;
4
4
import { mockNatspec } from './mocks' ;
5
5
6
6
describe ( 'Parser' , ( ) => {
7
- const parser : Parser = new Parser ( ) ;
8
7
let contract : ContractDefinition ;
9
8
10
9
describe ( 'Contract' , ( ) => {
@@ -15,7 +14,7 @@ describe('Parser', () => {
15
14
16
15
it ( 'should parse the inheritdoc tag' , async ( ) => {
17
16
const node = contract . vFunctions . find ( ( { name } ) => name === 'viewFunctionNoParams' ) ! ;
18
- const result = parser . parseNodeNatspec ( node ) ;
17
+ const result = parseNodeNatspec ( node ) ;
19
18
20
19
expect ( result ) . toEqual (
21
20
mockNatspec ( {
@@ -32,7 +31,7 @@ describe('Parser', () => {
32
31
33
32
it ( 'should parse constant' , async ( ) => {
34
33
const node = contract . vStateVariables . find ( ( { name } ) => name === 'SOME_CONSTANT' ) ! ;
35
- const result = parser . parseNodeNatspec ( node ) ;
34
+ const result = parseNodeNatspec ( node ) ;
36
35
37
36
expect ( result ) . toEqual (
38
37
mockNatspec ( {
@@ -45,7 +44,7 @@ describe('Parser', () => {
45
44
46
45
it ( 'should parse variable' , async ( ) => {
47
46
const node = contract . vStateVariables . find ( ( { name } ) => name === 'someVariable' ) ! ;
48
- const result = parser . parseNodeNatspec ( node ) ;
47
+ const result = parseNodeNatspec ( node ) ;
49
48
50
49
expect ( result ) . toEqual (
51
50
mockNatspec ( {
@@ -58,7 +57,7 @@ describe('Parser', () => {
58
57
59
58
it ( 'should parse modifier' , async ( ) => {
60
59
const node = contract . vModifiers . find ( ( { name } ) => name === 'someModifier' ) ! ;
61
- const result = parser . parseNodeNatspec ( node ) ;
60
+ const result = parseNodeNatspec ( node ) ;
62
61
63
62
expect ( result ) . toEqual (
64
63
mockNatspec ( {
@@ -80,7 +79,7 @@ describe('Parser', () => {
80
79
81
80
it ( 'should parse external function' , async ( ) => {
82
81
const node = contract . vFunctions . find ( ( { name } ) => name === 'viewFunctionNoParams' ) ! ;
83
- const result = parser . parseNodeNatspec ( node ) ;
82
+ const result = parseNodeNatspec ( node ) ;
84
83
85
84
expect ( result ) . toEqual (
86
85
mockNatspec ( {
@@ -99,7 +98,7 @@ describe('Parser', () => {
99
98
100
99
it ( 'should parse private function' , async ( ) => {
101
100
const node = contract . vFunctions . find ( ( { name } ) => name === '_viewPrivate' ) ! ;
102
- const result = parser . parseNodeNatspec ( node ) ;
101
+ const result = parseNodeNatspec ( node ) ;
103
102
104
103
expect ( result ) . toEqual (
105
104
mockNatspec ( {
@@ -131,7 +130,7 @@ describe('Parser', () => {
131
130
132
131
it ( 'should parse multiline descriptions' , async ( ) => {
133
132
const node = contract . vFunctions . find ( ( { name } ) => name === '_viewMultiline' ) ! ;
134
- const result = parser . parseNodeNatspec ( node ) ;
133
+ const result = parseNodeNatspec ( node ) ;
135
134
136
135
expect ( result ) . toEqual (
137
136
mockNatspec ( {
@@ -147,7 +146,7 @@ describe('Parser', () => {
147
146
148
147
it ( 'should parse multiple of the same tag' , async ( ) => {
149
148
const node = contract . vFunctions . find ( ( { name } ) => name === '_viewDuplicateTag' ) ! ;
150
- const result = parser . parseNodeNatspec ( node ) ;
149
+ const result = parseNodeNatspec ( node ) ;
151
150
152
151
expect ( result ) . toEqual (
153
152
mockNatspec ( {
@@ -174,7 +173,7 @@ describe('Parser', () => {
174
173
175
174
it ( 'should parse error' , async ( ) => {
176
175
const node = contract . vErrors . find ( ( { name } ) => name === 'SimpleError' ) ! ;
177
- const result = parser . parseNodeNatspec ( node ) ;
176
+ const result = parseNodeNatspec ( node ) ;
178
177
179
178
expect ( result ) . toEqual (
180
179
mockNatspec ( {
@@ -190,7 +189,7 @@ describe('Parser', () => {
190
189
191
190
it ( 'should parse event' , async ( ) => {
192
191
const node = contract . vEvents . find ( ( { name } ) => name === 'SimpleEvent' ) ! ;
193
- const result = parser . parseNodeNatspec ( node ) ;
192
+ const result = parseNodeNatspec ( node ) ;
194
193
195
194
expect ( result ) . toEqual (
196
195
mockNatspec ( {
@@ -206,7 +205,7 @@ describe('Parser', () => {
206
205
207
206
it ( 'should parse struct' , async ( ) => {
208
207
const node = contract . vStructs . find ( ( { name } ) => name === 'SimplestStruct' ) ! ;
209
- const result = parser . parseNodeNatspec ( node ) ;
208
+ const result = parseNodeNatspec ( node ) ;
210
209
211
210
expect ( result ) . toEqual (
212
211
mockNatspec ( {
@@ -235,7 +234,7 @@ describe('Parser', () => {
235
234
// TODO: Parse natspec for enums
236
235
// it('should parse enum', async () => {
237
236
// const node = contract.vEnums.find(({ name }) => name === 'SimpleEnum')!;
238
- // const result = parser. parseNodeNatspec(node);
237
+ // const result = parseNodeNatspec(node);
239
238
240
239
// expect(result).toEqual(mockNatspec({
241
240
// tags: [],
@@ -244,7 +243,7 @@ describe('Parser', () => {
244
243
245
244
it ( 'should parse external function without parameters' , async ( ) => {
246
245
const node = contract . vFunctions . find ( ( { name } ) => name === 'viewFunctionNoParams' ) ! ;
247
- const result = parser . parseNodeNatspec ( node ) ;
246
+ const result = parseNodeNatspec ( node ) ;
248
247
249
248
expect ( result ) . toEqual (
250
249
mockNatspec ( {
@@ -270,7 +269,7 @@ describe('Parser', () => {
270
269
271
270
it ( 'should parse external function with parameters' , async ( ) => {
272
271
const node = contract . vFunctions . find ( ( { name } ) => name === 'viewFunctionWithParams' ) ! ;
273
- const result = parser . parseNodeNatspec ( node ) ;
272
+ const result = parseNodeNatspec ( node ) ;
274
273
275
274
expect ( result ) . toEqual (
276
275
mockNatspec ( {
@@ -309,7 +308,7 @@ describe('Parser', () => {
309
308
310
309
it ( 'should parse struct' , async ( ) => {
311
310
const node = contract . vStructs . find ( ( { name } ) => name === 'SimpleStruct' ) ! ;
312
- const result = parser . parseNodeNatspec ( node ) ;
311
+ const result = parseNodeNatspec ( node ) ;
313
312
314
313
expect ( result ) . toEqual (
315
314
mockNatspec ( {
@@ -320,7 +319,7 @@ describe('Parser', () => {
320
319
321
320
it ( 'should parse inheritdoc + natspec' , async ( ) => {
322
321
const node = contract . vStateVariables . find ( ( { name } ) => name === 'someVariable' ) ! ;
323
- const result = parser . parseNodeNatspec ( node ) ;
322
+ const result = parseNodeNatspec ( node ) ;
324
323
325
324
expect ( result ) . toEqual (
326
325
mockNatspec ( {
@@ -339,21 +338,21 @@ describe('Parser', () => {
339
338
340
339
it ( 'should not parse the inheritdoc tag with just 2 slashes' , async ( ) => {
341
340
const node = contract . vStateVariables . find ( ( { name } ) => name === 'SOME_CONSTANT' ) ! ;
342
- const result = parser . parseNodeNatspec ( node ) ;
341
+ const result = parseNodeNatspec ( node ) ;
343
342
344
343
expect ( result ) . toEqual ( mockNatspec ( { } ) ) ;
345
344
} ) ;
346
345
347
346
it ( 'should not parse regular comments as natspec' , async ( ) => {
348
347
const node = contract . vFunctions . find ( ( { name } ) => name === 'viewFunctionWithParams' ) ! ;
349
- const result = parser . parseNodeNatspec ( node ) ;
348
+ const result = parseNodeNatspec ( node ) ;
350
349
351
350
expect ( result ) . toEqual ( mockNatspec ( { } ) ) ;
352
351
} ) ;
353
352
354
353
it ( 'should parse natspec with multiple spaces' , async ( ) => {
355
354
const node = contract . vFunctions . find ( ( { name } ) => name === '_viewPrivate' ) ! ;
356
- const result = parser . parseNodeNatspec ( node ) ;
355
+ const result = parseNodeNatspec ( node ) ;
357
356
358
357
expect ( result ) . toEqual (
359
358
mockNatspec ( {
@@ -381,14 +380,14 @@ describe('Parser', () => {
381
380
382
381
it ( 'should not parse natspec with invalid number of slashes' , async ( ) => {
383
382
const node = contract . vFunctions . find ( ( { name } ) => name === '_viewInternal' ) ! ;
384
- const result = parser . parseNodeNatspec ( node ) ;
383
+ const result = parseNodeNatspec ( node ) ;
385
384
386
385
expect ( result ) . toEqual ( mockNatspec ( { } ) ) ;
387
386
} ) ;
388
387
389
388
it ( 'should parse block natspec with invalid formatting' , async ( ) => {
390
389
const node = contract . vFunctions . find ( ( { name } ) => name === '_viewBlockLinterFail' ) ! ;
391
- const result = parser . parseNodeNatspec ( node ) ;
390
+ const result = parseNodeNatspec ( node ) ;
392
391
393
392
expect ( result ) . toEqual (
394
393
mockNatspec ( {
@@ -404,7 +403,7 @@ describe('Parser', () => {
404
403
405
404
it ( 'should parse block natspec with invalid formatting' , async ( ) => {
406
405
const node = contract . vFunctions . find ( ( { name } ) => name === '_viewLinterFail' ) ! ;
407
- const result = parser . parseNodeNatspec ( node ) ;
406
+ const result = parseNodeNatspec ( node ) ;
408
407
409
408
expect ( result ) . toEqual (
410
409
mockNatspec ( {
0 commit comments