Skip to content

Commit d567958

Browse files
committed
Add function expression test
1 parent 2616c22 commit d567958

3 files changed

Lines changed: 160 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
f = function add( x, y ) {
2+
return x + y;
3+
};
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
{
2+
"length": 45,
3+
"lines": 4,
4+
"empty": 1,
5+
"sloc": 2,
6+
"lloc": 2,
7+
"scope": 0,
8+
"comments": {
9+
"count": 0,
10+
"length": 0,
11+
"lines": 0,
12+
"inline": 0,
13+
"block": {
14+
"count": 0,
15+
"length": 0,
16+
"lines": 0,
17+
"inline": 0,
18+
"jsdoc": {
19+
"count": 0,
20+
"length": 0,
21+
"lines": 0,
22+
"inline": 0
23+
}
24+
},
25+
"line": {
26+
"count": 0,
27+
"length": 0,
28+
"lines": 0,
29+
"inline": 0
30+
}
31+
},
32+
"statements": 2,
33+
"branches": 0,
34+
"if": {
35+
"count": 0,
36+
"data": []
37+
},
38+
"switch": {
39+
"count": 0,
40+
"data": []
41+
},
42+
"throw": 0,
43+
"try": {
44+
"count": 0,
45+
"data": []
46+
},
47+
"while": {
48+
"count": 0,
49+
"data": []
50+
},
51+
"dowhile": {
52+
"count": 0,
53+
"data": []
54+
},
55+
"for": {
56+
"count": 0,
57+
"data": []
58+
},
59+
"forin": {
60+
"count": 0,
61+
"data": []
62+
},
63+
"var": 0,
64+
"function": {
65+
"count": 1,
66+
"data": [
67+
{
68+
"length": 38,
69+
"lines": 3,
70+
"empty": 0,
71+
"sloc": 1,
72+
"lloc": 1,
73+
"scope": 0,
74+
"comments": {
75+
"count": 0,
76+
"length": 0,
77+
"lines": 0,
78+
"inline": 0,
79+
"block": {
80+
"count": 0,
81+
"length": 0,
82+
"lines": 0,
83+
"inline": 0,
84+
"jsdoc": {
85+
"count": 0,
86+
"length": 0,
87+
"lines": 0,
88+
"inline": 0
89+
}
90+
},
91+
"line": {
92+
"count": 0,
93+
"length": 0,
94+
"lines": 0,
95+
"inline": 0
96+
}
97+
},
98+
"statements": 1,
99+
"branches": 0,
100+
"if": {
101+
"count": 0,
102+
"data": []
103+
},
104+
"switch": {
105+
"count": 0,
106+
"data": []
107+
},
108+
"throw": 0,
109+
"try": {
110+
"count": 0,
111+
"data": []
112+
},
113+
"while": {
114+
"count": 0,
115+
"data": []
116+
},
117+
"dowhile": {
118+
"count": 0,
119+
"data": []
120+
},
121+
"for": {
122+
"count": 0,
123+
"data": []
124+
},
125+
"forin": {
126+
"count": 0,
127+
"data": []
128+
},
129+
"var": 0,
130+
"function": {
131+
"count": 0,
132+
"data": []
133+
},
134+
"type": "expression",
135+
"name": "add",
136+
"params": 2
137+
}
138+
]
139+
}
140+
}

lib/node_modules/@stdlib/_tools/js/program-summary/test/test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,23 @@ tape( 'the function analyzes a JavaScript program (empty function)', opts, funct
440440
t.end();
441441
});
442442

443+
tape( 'the function analyzes a JavaScript program (function expression)', opts, function test( t ) {
444+
var expected;
445+
var fpath;
446+
var prog;
447+
var o;
448+
449+
fpath = join( __dirname, 'fixtures', 'function_expression.js.txt' );
450+
prog = readFileSync( fpath );
451+
452+
expected = require( './fixtures/function_expression.json' );
453+
454+
o = analyze( prog );
455+
t.deepEqual( o, expected, 'returns expected value' );
456+
457+
t.end();
458+
});
459+
443460
tape( 'the function analyzes a JavaScript program (nested function expressions)', opts, function test( t ) {
444461
var expected;
445462
var fpath;

0 commit comments

Comments
 (0)