Skip to content

Commit 65b838d

Browse files
author
Maarten Staa
committed
Add a few more tests, to bring the coverage back to the expected level.
1 parent 71c5acd commit 65b838d

File tree

4 files changed

+300
-0
lines changed

4 files changed

+300
-0
lines changed

test/snapshot/__snapshots__/interface.test.js.snap

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,55 @@ Program {
4444
}
4545
`;
4646

47+
exports[`interface invalid private flag 1`] = `
48+
Program {
49+
"children": Array [
50+
Interface {
51+
"attrGroups": Array [],
52+
"body": Array [
53+
ClassConstant {
54+
"attrGroups": Array [],
55+
"constants": Array [
56+
Constant {
57+
"kind": "constant",
58+
"name": Identifier {
59+
"kind": "identifier",
60+
"name": "B",
61+
},
62+
"value": Number {
63+
"kind": "number",
64+
"value": "1",
65+
},
66+
},
67+
],
68+
"kind": "classconstant",
69+
"visibility": "",
70+
},
71+
],
72+
"extends": null,
73+
"kind": "interface",
74+
"name": Identifier {
75+
"kind": "identifier",
76+
"name": "A",
77+
},
78+
},
79+
],
80+
"errors": Array [
81+
Error {
82+
"expected": Array [
83+
195,
84+
196,
85+
],
86+
"kind": "error",
87+
"line": 1,
88+
"message": "Parse Error : syntax error, unexpected 'private' (T_PRIVATE) on line 1",
89+
"token": "'private' (T_PRIVATE)",
90+
},
91+
],
92+
"kind": "program",
93+
}
94+
`;
95+
4796
exports[`interface multiple extends 1`] = `
4897
Program {
4998
"children": Array [

test/snapshot/__snapshots__/useitem.test.js.snap

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,231 @@ Program {
141141
}
142142
`;
143143

144+
exports[`useitem invalid use 1`] = `
145+
Program {
146+
"children": Array [
147+
UseGroup {
148+
"items": Array [
149+
UseItem {
150+
"alias": null,
151+
"kind": "useitem",
152+
"name": "",
153+
"type": null,
154+
},
155+
],
156+
"kind": "usegroup",
157+
"name": null,
158+
"type": "function",
159+
},
160+
ExpressionStatement {
161+
"expression": Variable {
162+
"curly": false,
163+
"kind": "variable",
164+
"name": "foo",
165+
},
166+
"kind": "expressionstatement",
167+
},
168+
UseGroup {
169+
"items": Array [
170+
UseItem {
171+
"alias": null,
172+
"kind": "useitem",
173+
"name": "FOO",
174+
"type": null,
175+
},
176+
UseItem {
177+
"alias": null,
178+
"kind": "useitem",
179+
"name": "BAR",
180+
"type": null,
181+
},
182+
],
183+
"kind": "usegroup",
184+
"name": "",
185+
"type": "const",
186+
},
187+
UseGroup {
188+
"items": Array [
189+
UseItem {
190+
"alias": null,
191+
"kind": "useitem",
192+
"name": "foo",
193+
"type": null,
194+
},
195+
],
196+
"kind": "usegroup",
197+
"name": "some",
198+
"type": null,
199+
},
200+
ExpressionStatement {
201+
"expression": Variable {
202+
"curly": false,
203+
"kind": "variable",
204+
"name": "error",
205+
},
206+
"kind": "expressionstatement",
207+
},
208+
ExpressionStatement {
209+
"expression": undefined,
210+
"kind": "expressionstatement",
211+
},
212+
_Function {
213+
"arguments": Array [
214+
Parameter {
215+
"attrGroups": Array [],
216+
"byref": false,
217+
"flags": 0,
218+
"kind": "parameter",
219+
"name": null,
220+
"nullable": false,
221+
"readonly": false,
222+
"type": null,
223+
"value": null,
224+
"variadic": false,
225+
},
226+
Parameter {
227+
"attrGroups": Array [],
228+
"byref": false,
229+
"flags": 0,
230+
"kind": "parameter",
231+
"name": null,
232+
"nullable": false,
233+
"readonly": false,
234+
"type": null,
235+
"value": null,
236+
"variadic": false,
237+
},
238+
],
239+
"attrGroups": Array [],
240+
"body": null,
241+
"byref": false,
242+
"kind": "function",
243+
"name": Identifier {
244+
"kind": "identifier",
245+
"name": false,
246+
},
247+
"nullable": false,
248+
"type": null,
249+
},
250+
ExpressionStatement {
251+
"expression": undefined,
252+
"kind": "expressionstatement",
253+
},
254+
],
255+
"errors": Array [
256+
Error {
257+
"expected": 105,
258+
"kind": "error",
259+
"line": 1,
260+
"message": "Parse Error : syntax error, unexpected '$foo' (T_VARIABLE), expecting T_STRING on line 1",
261+
"token": "'$foo' (T_VARIABLE)",
262+
},
263+
Error {
264+
"expected": ";",
265+
"kind": "error",
266+
"line": 1,
267+
"message": "Parse Error : syntax error, unexpected '$foo' (T_VARIABLE), expecting ';' on line 1",
268+
"token": "'$foo' (T_VARIABLE)",
269+
},
270+
Error {
271+
"expected": "}",
272+
"kind": "error",
273+
"line": 8,
274+
"message": "Parse Error : syntax error, unexpected '$error' (T_VARIABLE), expecting '}' on line 8",
275+
"token": "'$error' (T_VARIABLE)",
276+
},
277+
Error {
278+
"expected": ";",
279+
"kind": "error",
280+
"line": 8,
281+
"message": "Parse Error : syntax error, unexpected '$error' (T_VARIABLE), expecting ';' on line 8",
282+
"token": "'$error' (T_VARIABLE)",
283+
},
284+
Error {
285+
"expected": ";",
286+
"kind": "error",
287+
"line": 8,
288+
"message": "Parse Error : syntax error, unexpected ',', expecting ';' on line 8",
289+
"token": "','",
290+
},
291+
Error {
292+
"expected": "EXPR",
293+
"kind": "error",
294+
"line": 8,
295+
"message": "Parse Error : syntax error, unexpected ',' on line 8",
296+
"token": "','",
297+
},
298+
Error {
299+
"expected": ";",
300+
"kind": "error",
301+
"line": 9,
302+
"message": "Parse Error : syntax error, unexpected 'function' (T_FUNCTION), expecting ';' on line 9",
303+
"token": "'function' (T_FUNCTION)",
304+
},
305+
Error {
306+
"expected": "(",
307+
"kind": "error",
308+
"line": 9,
309+
"message": "Parse Error : syntax error, unexpected '$bar' (T_VARIABLE), expecting '(' on line 9",
310+
"token": "'$bar' (T_VARIABLE)",
311+
},
312+
Error {
313+
"expected": "(",
314+
"kind": "error",
315+
"line": 9,
316+
"message": "Parse Error : syntax error, unexpected ',', expecting '(' on line 9",
317+
"token": "','",
318+
},
319+
Error {
320+
"expected": 222,
321+
"kind": "error",
322+
"line": 9,
323+
"message": "Parse Error : syntax error, unexpected ',', expecting T_VARIABLE on line 9",
324+
"token": "','",
325+
},
326+
Error {
327+
"expected": 222,
328+
"kind": "error",
329+
"line": 10,
330+
"message": "Parse Error : syntax error, unexpected '}', expecting T_VARIABLE on line 10",
331+
"token": "'}'",
332+
},
333+
Error {
334+
"expected": Array [
335+
",",
336+
")",
337+
],
338+
"kind": "error",
339+
"line": 10,
340+
"message": "Parse Error : syntax error, unexpected '}' on line 10",
341+
"token": "'}'",
342+
},
343+
Error {
344+
"expected": ")",
345+
"kind": "error",
346+
"line": 10,
347+
"message": "Parse Error : syntax error, unexpected '}', expecting ')' on line 10",
348+
"token": "'}'",
349+
},
350+
Error {
351+
"expected": "{",
352+
"kind": "error",
353+
"line": 10,
354+
"message": "Parse Error : syntax error, unexpected '}', expecting '{' on line 10",
355+
"token": "'}'",
356+
},
357+
Error {
358+
"expected": "EXPR",
359+
"kind": "error",
360+
"line": 10,
361+
"message": "Parse Error : syntax error, unexpected '}' on line 10",
362+
"token": "'}'",
363+
},
364+
],
365+
"kind": "program",
366+
}
367+
`;
368+
144369
exports[`useitem simple 1`] = `
145370
Program {
146371
"children": Array [

test/snapshot/interface.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,11 @@ describe("interface", function () {
1010
it("multiple extends", function () {
1111
expect(parser.parseEval("interface A extends B, C {}")).toMatchSnapshot();
1212
});
13+
it("invalid private flag", function () {
14+
expect(
15+
parser.parseEval("interface A { private const B = 1; }", {
16+
parser: { suppressErrors: true },
17+
})
18+
).toMatchSnapshot();
19+
});
1320
});

test/snapshot/useitem.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,23 @@ describe("useitem", () => {
4040
parser.parseEval("use const My\\Full\\CONSTANT as MY_CONST;")
4141
).toMatchSnapshot();
4242
});
43+
it("invalid use", () => {
44+
expect(
45+
parser.parseEval(
46+
`use function $foo;
47+
use const namespace\\{
48+
FOO,
49+
BAR,
50+
};
51+
use some\\{
52+
namespace\\foo,
53+
$error,
54+
function $bar,
55+
};`,
56+
{
57+
parser: { suppressErrors: true },
58+
}
59+
)
60+
).toMatchSnapshot();
61+
});
4362
});

0 commit comments

Comments
 (0)