Skip to content

Commit 215b767

Browse files
author
Maarten Staa
committed
Add a few more test cases.
1 parent 16b707a commit 215b767

File tree

5 files changed

+121
-1
lines changed

5 files changed

+121
-1
lines changed

src/parser.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ const Parser = function (lexer, ast) {
130130
this.tok.T_VARIABLE,
131131
"$",
132132
"&",
133-
this.tok.T_NS_SEPARATOR,
134133
this.tok.T_STRING,
135134
this.tok.T_NAME_RELATIVE,
136135
this.tok.T_NAME_QUALIFIED,

test/snapshot/__snapshots__/ast.test.js.snap

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,62 @@ Program {
529529
}
530530
`;
531531

532+
exports[`Test AST structure test invalid namespace separator 1`] = `
533+
Program {
534+
"children": Array [
535+
ExpressionStatement {
536+
"expression": Error {
537+
"expected": "SCALAR",
538+
"kind": "error",
539+
"line": 1,
540+
"message": "Parse Error : syntax error, unexpected '\\\\' (T_NS_SEPARATOR) on line 1",
541+
"token": "'\\\\' (T_NS_SEPARATOR)",
542+
},
543+
"kind": "expressionstatement",
544+
},
545+
ExpressionStatement {
546+
"expression": Assign {
547+
"kind": "assign",
548+
"left": Variable {
549+
"curly": false,
550+
"kind": "variable",
551+
"name": "var",
552+
},
553+
"operator": "=",
554+
"right": Number {
555+
"kind": "number",
556+
"value": "1",
557+
},
558+
},
559+
"kind": "expressionstatement",
560+
},
561+
Inline {
562+
"kind": "inline",
563+
"raw": "
564+
!",
565+
"value": " !",
566+
},
567+
],
568+
"errors": Array [
569+
Error {
570+
"expected": "SCALAR",
571+
"kind": "error",
572+
"line": 1,
573+
"message": "Parse Error : syntax error, unexpected '\\\\' (T_NS_SEPARATOR) on line 1",
574+
"token": "'\\\\' (T_NS_SEPARATOR)",
575+
},
576+
Error {
577+
"expected": ";",
578+
"kind": "error",
579+
"line": 1,
580+
"message": "Parse Error : syntax error, unexpected '$var' (T_VARIABLE), expecting ';' on line 1",
581+
"token": "'$var' (T_VARIABLE)",
582+
},
583+
],
584+
"kind": "program",
585+
}
586+
`;
587+
532588
exports[`Test AST structure test magics 1`] = `
533589
Program {
534590
"children": Array [

test/snapshot/__snapshots__/namespace.test.js.snap

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,33 @@ Program {
11431143
}
11441144
`;
11451145

1146+
exports[`Test namespace statements test bare namespace separator 1`] = `
1147+
Program {
1148+
"children": Array [
1149+
ExpressionStatement {
1150+
"expression": Error {
1151+
"expected": "SCALAR",
1152+
"kind": "error",
1153+
"line": 1,
1154+
"message": "Parse Error : syntax error, unexpected '\\\\' (T_NS_SEPARATOR) on line 1",
1155+
"token": "'\\\\' (T_NS_SEPARATOR)",
1156+
},
1157+
"kind": "expressionstatement",
1158+
},
1159+
],
1160+
"errors": Array [
1161+
Error {
1162+
"expected": "SCALAR",
1163+
"kind": "error",
1164+
"line": 1,
1165+
"message": "Parse Error : syntax error, unexpected '\\\\' (T_NS_SEPARATOR) on line 1",
1166+
"token": "'\\\\' (T_NS_SEPARATOR)",
1167+
},
1168+
],
1169+
"kind": "program",
1170+
}
1171+
`;
1172+
11461173
exports[`Test namespace statements test keywords 1`] = `
11471174
Program {
11481175
"children": Array [
@@ -1170,6 +1197,25 @@ Program {
11701197
},
11711198
"kind": "expressionstatement",
11721199
},
1200+
UseGroup {
1201+
"items": Array [
1202+
UseItem {
1203+
"alias": null,
1204+
"kind": "useitem",
1205+
"name": "a",
1206+
"type": null,
1207+
},
1208+
UseItem {
1209+
"alias": null,
1210+
"kind": "useitem",
1211+
"name": "b",
1212+
"type": null,
1213+
},
1214+
],
1215+
"kind": "usegroup",
1216+
"name": "\\\\foo\\\\bar",
1217+
"type": null,
1218+
},
11731219
ExpressionStatement {
11741220
"expression": Assign {
11751221
"kind": "assign",

test/snapshot/ast.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ describe("Test AST structure", function () {
5656
expect(parser.parseCode("<?php echo 'World'; ?>\r\n !")).toMatchSnapshot();
5757
});
5858

59+
it("test invalid namespace separator", function () {
60+
expect(
61+
parser.parseCode("<?php \\$var = 1; ?>\r\n !", {
62+
parser: { suppressErrors: true },
63+
})
64+
).toMatchSnapshot();
65+
});
66+
5967
it("test magics", function () {
6068
expect(parser.parseEval("echo __FILE__, __DIR__;")).toMatchSnapshot();
6169
});

test/snapshot/namespace.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ describe("Test namespace statements", function () {
9090
`
9191
namespace\\enum();
9292
\\foo\\trait\\class();
93+
use \\foo\\bar\\{ a, b };
9394
$var = namespace\\bar;
9495
`,
9596
{
@@ -101,6 +102,16 @@ describe("Test namespace statements", function () {
101102
).toMatchSnapshot();
102103
});
103104

105+
it("test bare namespace separator", function () {
106+
expect(
107+
parser.parseEval(`\\`, {
108+
parser: {
109+
suppressErrors: true,
110+
},
111+
})
112+
).toMatchSnapshot();
113+
});
114+
104115
it("test namespace error", function () {
105116
expect(
106117
parser.parseEval(

0 commit comments

Comments
 (0)