Skip to content

Commit c65f7b2

Browse files
committed
improved test coverage
1 parent 3c92a4d commit c65f7b2

File tree

3 files changed

+88
-4
lines changed

3 files changed

+88
-4
lines changed

src/parser/expr.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ module.exports = {
609609
const node = this.node("match");
610610
this.expect(this.tok.T_MATCH) && this.next();
611611
if (this.version < 800) {
612-
this.reaseError("Match statements are not allowed before PHP 8");
612+
this.raiseError("Match statements are not allowed before PHP 8");
613613
}
614614
let cond = null;
615615
let arms = [];

test/snapshot/__snapshots__/match.test.js.snap

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,71 @@ Program {
7373
}
7474
`;
7575

76+
exports[`match can have hanging comma 1`] = `
77+
Program {
78+
"children": Array [
79+
ExpressionStatement {
80+
"expression": Assign {
81+
"kind": "assign",
82+
"left": Variable {
83+
"curly": false,
84+
"kind": "variable",
85+
"name": "test",
86+
},
87+
"operator": "=",
88+
"right": Match {
89+
"arms": Array [
90+
MatchArm {
91+
"body": String {
92+
"isDoubleQuote": false,
93+
"kind": "string",
94+
"raw": "'ok'",
95+
"unicode": false,
96+
"value": "ok",
97+
},
98+
"conds": Array [
99+
Boolean {
100+
"kind": "boolean",
101+
"raw": "true",
102+
"value": true,
103+
},
104+
],
105+
"kind": "matcharm",
106+
},
107+
MatchArm {
108+
"body": String {
109+
"isDoubleQuote": false,
110+
"kind": "string",
111+
"raw": "'Nope!'",
112+
"unicode": false,
113+
"value": "Nope!",
114+
},
115+
"conds": Array [
116+
Boolean {
117+
"kind": "boolean",
118+
"raw": "false",
119+
"value": false,
120+
},
121+
],
122+
"kind": "matcharm",
123+
},
124+
],
125+
"cond": Variable {
126+
"curly": false,
127+
"kind": "variable",
128+
"name": "test",
129+
},
130+
"kind": "match",
131+
},
132+
},
133+
"kind": "expressionstatement",
134+
},
135+
],
136+
"errors": Array [],
137+
"kind": "program",
138+
}
139+
`;
140+
76141
exports[`match can have lhs, functions 1`] = `
77142
Program {
78143
"children": Array [

test/snapshot/match.test.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe("match", () => {
66
$test = match($a) {
77
true => 'yes',
88
false => 'no',
9-
default => null,
9+
default => null
1010
};
1111
`);
1212
expect(ast).toMatchSnapshot();
@@ -16,7 +16,7 @@ describe("match", () => {
1616
const ast = parser.parseEval(`
1717
$test = match(true) {
1818
test($a), abc($b) => 'yes',
19-
default => null,
19+
default => null
2020
};
2121
`);
2222
expect(ast).toMatchSnapshot();
@@ -26,9 +26,28 @@ describe("match", () => {
2626
const ast = parser.parseEval(`
2727
$test = match(trye) {
2828
0,1,2,3 => run(),
29-
default => null,
29+
default => null
3030
};
3131
`);
3232
expect(ast).toMatchSnapshot();
3333
});
34+
it("can have hanging comma", () => {
35+
const ast = parser.parseEval(`
36+
$test = match($test) {
37+
true => 'ok',
38+
false => 'Nope!',
39+
};
40+
`);
41+
expect(ast).toMatchSnapshot();
42+
});
43+
it("does not support older php than 8", () => {
44+
expect(() => {
45+
new parser({ parser: { version: 704 } }).parseEval(`
46+
$test = match($test) {
47+
true => 'ok',
48+
false => 'Nope!',
49+
};
50+
`);
51+
}).toThrow(SyntaxError);
52+
});
3453
});

0 commit comments

Comments
 (0)