Skip to content
This repository was archived by the owner on Mar 29, 2023. It is now read-only.

Commit 7b4c599

Browse files
test: new
1 parent ea69b15 commit 7b4c599

File tree

2 files changed

+292
-0
lines changed

2 files changed

+292
-0
lines changed
Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`new anonymous 1`] = `
4+
Program {
5+
"children": Array [
6+
ExpressionStatement {
7+
"expression": New {
8+
"arguments": Array [],
9+
"kind": "new",
10+
"what": Class {
11+
"body": Array [],
12+
"extends": null,
13+
"implements": null,
14+
"isAbstract": false,
15+
"isAnonymous": true,
16+
"isFinal": false,
17+
"kind": "class",
18+
"name": null,
19+
},
20+
},
21+
"kind": "expressionstatement",
22+
},
23+
],
24+
"errors": Array [],
25+
"kind": "program",
26+
}
27+
`;
28+
29+
exports[`new anonymous no parens 1`] = `
30+
Program {
31+
"children": Array [
32+
ExpressionStatement {
33+
"expression": New {
34+
"arguments": Array [],
35+
"kind": "new",
36+
"what": Class {
37+
"body": Array [],
38+
"extends": null,
39+
"implements": null,
40+
"isAbstract": false,
41+
"isAnonymous": true,
42+
"isFinal": false,
43+
"kind": "class",
44+
"name": null,
45+
},
46+
},
47+
"kind": "expressionstatement",
48+
},
49+
],
50+
"errors": Array [],
51+
"kind": "program",
52+
}
53+
`;
54+
55+
exports[`new anonymous with argument 1`] = `
56+
Program {
57+
"children": Array [
58+
ExpressionStatement {
59+
"expression": New {
60+
"arguments": Array [
61+
Variable {
62+
"byref": false,
63+
"curly": false,
64+
"kind": "variable",
65+
"name": "var",
66+
},
67+
],
68+
"kind": "new",
69+
"what": Class {
70+
"body": Array [],
71+
"extends": null,
72+
"implements": null,
73+
"isAbstract": false,
74+
"isAnonymous": true,
75+
"isFinal": false,
76+
"kind": "class",
77+
"name": null,
78+
},
79+
},
80+
"kind": "expressionstatement",
81+
},
82+
],
83+
"errors": Array [],
84+
"kind": "program",
85+
}
86+
`;
87+
88+
exports[`new anonymous with multiple argument 1`] = `
89+
Program {
90+
"children": Array [
91+
ExpressionStatement {
92+
"expression": New {
93+
"arguments": Array [
94+
Variable {
95+
"byref": false,
96+
"curly": false,
97+
"kind": "variable",
98+
"name": "one",
99+
},
100+
Variable {
101+
"byref": false,
102+
"curly": false,
103+
"kind": "variable",
104+
"name": "two",
105+
},
106+
Variable {
107+
"byref": false,
108+
"curly": false,
109+
"kind": "variable",
110+
"name": "three",
111+
},
112+
],
113+
"kind": "new",
114+
"what": Class {
115+
"body": Array [],
116+
"extends": null,
117+
"implements": null,
118+
"isAbstract": false,
119+
"isAnonymous": true,
120+
"isFinal": false,
121+
"kind": "class",
122+
"name": null,
123+
},
124+
},
125+
"kind": "expressionstatement",
126+
},
127+
],
128+
"errors": Array [],
129+
"kind": "program",
130+
}
131+
`;
132+
133+
exports[`new no parens 1`] = `
134+
Program {
135+
"children": Array [
136+
ExpressionStatement {
137+
"expression": New {
138+
"arguments": Array [],
139+
"kind": "new",
140+
"what": ClassReference {
141+
"kind": "classreference",
142+
"name": "Foo",
143+
"resolution": "uqn",
144+
},
145+
},
146+
"kind": "expressionstatement",
147+
},
148+
],
149+
"errors": Array [],
150+
"kind": "program",
151+
}
152+
`;
153+
154+
exports[`new simple (2) 1`] = `
155+
Program {
156+
"children": Array [
157+
ExpressionStatement {
158+
"expression": New {
159+
"arguments": Array [],
160+
"kind": "new",
161+
"what": ClassReference {
162+
"kind": "classreference",
163+
"name": "\\\\Foo",
164+
"resolution": "qn",
165+
},
166+
},
167+
"kind": "expressionstatement",
168+
},
169+
],
170+
"errors": Array [],
171+
"kind": "program",
172+
}
173+
`;
174+
175+
exports[`new simple (3) 1`] = `
176+
Program {
177+
"children": Array [
178+
ExpressionStatement {
179+
"expression": New {
180+
"arguments": Array [],
181+
"kind": "new",
182+
"what": ClassReference {
183+
"kind": "classreference",
184+
"name": "Foo\\\\Foo",
185+
"resolution": "qn",
186+
},
187+
},
188+
"kind": "expressionstatement",
189+
},
190+
],
191+
"errors": Array [],
192+
"kind": "program",
193+
}
194+
`;
195+
196+
exports[`new simple (4) 1`] = `
197+
Program {
198+
"children": Array [
199+
ExpressionStatement {
200+
"expression": New {
201+
"arguments": Array [],
202+
"kind": "new",
203+
"what": ClassReference {
204+
"kind": "classreference",
205+
"name": "\\\\Foo\\\\Foo",
206+
"resolution": "qn",
207+
},
208+
},
209+
"kind": "expressionstatement",
210+
},
211+
],
212+
"errors": Array [],
213+
"kind": "program",
214+
}
215+
`;
216+
217+
exports[`new simple 1`] = `
218+
Program {
219+
"children": Array [
220+
ExpressionStatement {
221+
"expression": New {
222+
"arguments": Array [],
223+
"kind": "new",
224+
"what": ClassReference {
225+
"kind": "classreference",
226+
"name": "Foo",
227+
"resolution": "uqn",
228+
},
229+
},
230+
"kind": "expressionstatement",
231+
},
232+
],
233+
"errors": Array [],
234+
"kind": "program",
235+
}
236+
`;
237+
238+
exports[`new variable 1`] = `
239+
Program {
240+
"children": Array [
241+
ExpressionStatement {
242+
"expression": New {
243+
"arguments": Array [],
244+
"kind": "new",
245+
"what": Variable {
246+
"byref": false,
247+
"curly": false,
248+
"kind": "variable",
249+
"name": "var",
250+
},
251+
},
252+
"kind": "expressionstatement",
253+
},
254+
],
255+
"errors": Array [],
256+
"kind": "program",
257+
}
258+
`;

test/snapshot/new.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const parser = require('../main');
2+
3+
describe("new", function() {
4+
it("simple", function() {
5+
expect(parser.parseEval('new Foo();')).toMatchSnapshot();
6+
});
7+
it("variable", function() {
8+
expect(parser.parseEval('new $var;')).toMatchSnapshot();
9+
});
10+
it("simple (2)", function() {
11+
expect(parser.parseEval('new \\Foo();')).toMatchSnapshot();
12+
});
13+
it("simple (3)", function() {
14+
expect(parser.parseEval('new Foo\\Foo();')).toMatchSnapshot();
15+
});
16+
it("simple (4)", function() {
17+
expect(parser.parseEval('new \\Foo\\Foo();')).toMatchSnapshot();
18+
});
19+
it("no parens", function() {
20+
expect(parser.parseEval('new Foo;')).toMatchSnapshot();
21+
});
22+
it("anonymous", function() {
23+
expect(parser.parseEval('new class() {};')).toMatchSnapshot();
24+
});
25+
it("anonymous no parens", function() {
26+
expect(parser.parseEval('new class {};')).toMatchSnapshot();
27+
});
28+
it("anonymous with argument", function() {
29+
expect(parser.parseEval('new class($var) {};')).toMatchSnapshot();
30+
});
31+
it("anonymous with multiple argument", function() {
32+
expect(parser.parseEval('new class($one, $two, $three) {};')).toMatchSnapshot();
33+
});
34+
});

0 commit comments

Comments
 (0)