Skip to content

Commit 4c3d2df

Browse files
committed
wip more tests
1 parent a4f700c commit 4c3d2df

File tree

4 files changed

+47
-19
lines changed

4 files changed

+47
-19
lines changed
Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
match x:
2-
| 1: "lt one"
3-
| "hi": "eq zero"
4-
| `there ${1 + 1}`: "eq two"
5-
| ~f(): "f(x) truthy"
6-
| .prop: "has prop"
7-
| .0: "has first child"
2+
| 1 or 0.1 or 0x11 or +1 or -1:
3+
it
4+
| "hi":
5+
it
6+
| `there ${1 + 1}`:
7+
it
8+
| /\s+/:
9+
it
10+
| Number or Boolean or String:
11+
it
12+
| Array or Object or Map or Foo:
13+
it
14+
| null or undefined:
15+
it
16+
| x or +x:
17+
it
18+
| not 1 or not x:
19+
it
Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
if (x === 1) {
2-
"lt one";
3-
} else if (x === "hi") {
4-
"eq zero";
5-
} else if (x === `there ${ 1 + 1 }`) {
6-
"eq two";
7-
} else if (f(x)) {
8-
"f(x) truthy";
9-
} else if (x.prop) {
10-
"has prop";
11-
} else if (x[0]) {
12-
"has first child";
13-
}
1+
if (x === 1 || x === 0.1 || x === 0x11 || x === +1 || x === -1) {
2+
it;
3+
} else if (x === "hi") {
4+
it;
5+
} else if (x === `there ${ 1 + 1 }`) {
6+
it;
7+
} else if (/\s+/.test(x)) {
8+
it;
9+
} else if (typeof x === "number" || typeof x === "boolean" || typeof x === "string") {
10+
it;
11+
} else if (x instanceof Array || x instanceof Object || x instanceof Map || x instanceof Foo) {
12+
it;
13+
} else if (x === null || x === undefined) {
14+
it;
15+
} else if (x || +x) {
16+
it;
17+
} else if (!(x === 1) || !x) {
18+
it;
19+
}

test/fixtures/match/not/actual.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
match x:
2+
| not 1 or not Number or not "hi":
3+
it
4+
| not x or not 1 + 1 or not foo(bar):
5+
it

test/fixtures/match/not/expected.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
if (!(x === 1) || !(typeof x === "number") || !(x === "hi")) {
2+
it;
3+
} else if (!x || !1 + 1 || !foo(bar)) {
4+
it;
5+
}

0 commit comments

Comments
 (0)