Skip to content

Commit

Permalink
feat: add tests for col_num
Browse files Browse the repository at this point in the history
  • Loading branch information
hsiaosiyuan0 committed Feb 15, 2023
1 parent 5d53366 commit 30d190f
Show file tree
Hide file tree
Showing 20 changed files with 316 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[*]
indent_style = tab
indent_style = space
indent_size = 2
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"DECREF",
"divrem",
"dlimb",
"dowhile",
"DYNBUF",
"ediv",
"edivrem",
Expand All @@ -55,6 +56,7 @@
"fdivrem",
"fdopen",
"finalizers",
"forof",
"FPROUND",
"ftoa",
"getset",
Expand Down
11 changes: 11 additions & 0 deletions tests/test-col/cases/break.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var a = 1;

outer: while (a > 1) {
while (a < 1) {
break outer;
}
}

/* EXPECT(outer):
ident: 'outer' 5:11
*/
11 changes: 11 additions & 0 deletions tests/test-col/cases/continue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var a = 1;

outer: while (a > 1) {
while (a < 1) {
continue outer;
}
}

/* EXPECT(outer):
ident: 'outer' 5:14
*/
21 changes: 21 additions & 0 deletions tests/test-col/cases/dowhile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var a = 1;

do {
print(a);
} while (a < 0);

/* EXPECT(a):
token: '{' 3:4
*/

/* EXPECT(a):
ident: 'a' 4:9
*/

/* EXPECT(a <):
ident: 'a' 5:10
*/

/* EXPECT(0):
number: 0 5:14
*/
28 changes: 28 additions & 0 deletions tests/test-col/cases/expr_basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var a;

function b() {}

var c = { ["👌"]: () => {} };

a = new b();
a = a + b() + c["👌"]();

/* EXPECT(b after new):
ident: 'b' 7:9
*/

/* EXPECT(( after new b):
token: '(' 7:10
*/

/* EXPECT(( after b):
token: '(' 8:10
*/

/* EXPECT([ after c):
token: '[' 8:16
*/

/* EXPECT() after ]):
token: '(' 8:21
*/
22 changes: 22 additions & 0 deletions tests/test-col/cases/for_basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
for (let a = 1, b, c; a < 10; a++, b++) {
c += 1;
}

/* EXPECT(let a = 1):
ident: 'let' 1:6
ident: 'a' 1:10
token: '=' 1:12
number: 1 1:14
*/

/* EXPECT(b):
ident: 'b' 1:17
*/

/* EXPECT(c in c += 1):
ident: 'c' 2:3
*/

/* EXPECT(1 in c += 1):
number: 1 2:8
*/
11 changes: 11 additions & 0 deletions tests/test-col/cases/forin_basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var b;
for (const a in b) {
}

/* EXPECT(a):
ident: 'a' 2:12
*/

/* EXPECT(b):
ident: 'b' 2:17
*/
15 changes: 15 additions & 0 deletions tests/test-col/cases/forin_destruct.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var b;
for (const { a, b: c } in b) {
}

/* EXPECT(a):
ident: 'a' 2:14
*/

/* EXPECT(b):
ident: 'b' 2:17
*/

/* EXPECT(c):
ident: 'c' 2:20
*/
15 changes: 15 additions & 0 deletions tests/test-col/cases/forof_basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var b = [];
for (const a of b) {
}

/* EXPECT(]):
token: ']' 1:10
*/

/* EXPECT(a):
ident: 'a' 2:12
*/

/* EXPECT(b):
ident: 'b' 2:17
*/
23 changes: 23 additions & 0 deletions tests/test-col/cases/forof_destruct.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var b = [];
for (const [a, { b: c = 1 }] of b) {
}

/* EXPECT(]):
token: ']' 1:10
*/

/* EXPECT(a):
ident: 'a' 2:13
*/

/* EXPECT(b):
ident: 'b' 2:18
*/

/* EXPECT(c):
ident: 'c' 2:21
*/

/* EXPECT(1):
number: 1 2:25
*/
13 changes: 13 additions & 0 deletions tests/test-col/cases/if_basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var a = 1;

if (print(a)) {
} else if ("😀" === a) {
}

/* EXPECT(a after emoji):
ident: 'a' 4:20
*/

/* EXPECT(a):
ident: 'a' 3:11
*/
7 changes: 7 additions & 0 deletions tests/test-col/cases/return.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function f() {
return 1;
}

/* EXPECT(1):
number: 1 2:10
*/
20 changes: 20 additions & 0 deletions tests/test-col/cases/switch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var a = 1;

switch (a) {
case "a":
break;
default:
print(a);
}

/* EXPECT(a):
ident: 'a' 3:9
*/

/* EXPECT(:):
token: ':' 6:10
*/

/* EXPECT(a in print):
ident: 'a' 7:11
*/
15 changes: 15 additions & 0 deletions tests/test-col/cases/throw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
try {
throw "test😀";
} catch (error) {}

/* EXPECT({ after try):
token: '{' 1:5
*/

/* EXPECT(; term throw):
token: ';' 2:16
*/

/* EXPECT(error):
ident: 'error' 3:10
*/
5 changes: 5 additions & 0 deletions tests/test-col/cases/unicode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let a = "😀" + 1;

/* EXPECT(1):
number: 1 1:15
*/
File renamed without changes.
34 changes: 34 additions & 0 deletions tests/test-col/cases/vardec_destruct.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const [d, { e: f } = { e: 1 }] = [];
const { h: { i = 1 } = {} } = {};

/* EXPECT(d):
ident: 'd' 1:8
*/

/* EXPECT(e-alias):
ident: 'e' 1:13
*/

/* EXPECT(e-default):
ident: 'e' 1:24
*/

/* EXPECT(f):
ident: 'f' 1:16
*/

/* EXPECT(h):
ident: 'h' 2:9
*/

/* EXPECT(i):
ident: 'i' 2:14
*/

/* EXPECT([-rhs):
token: '[' 1:34
*/

/* EXPECT((-rhs):
token: '{' 2:31
*/
12 changes: 12 additions & 0 deletions tests/test-col/cases/while_basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var a = 0,
b = 10;

while (a > b) {}

/* EXPECT(a):
ident: 'a' 4:8
*/

/* EXPECT(b):
ident: 'b' 4:12
*/
Loading

0 comments on commit 30d190f

Please sign in to comment.