mirror of
https://github.com/MorizzG/MLox.git
synced 2025-12-06 04:22:41 +00:00
added tests for break and continue
This commit is contained in:
parent
d2077774f7
commit
54dc78f0b8
7 changed files with 123 additions and 2 deletions
11
lox.t/break/for.lox
Normal file
11
lox.t/break/for.lox
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
for (var i = 0; i < 10; i = i + 1) {
|
||||
if (i == 5)
|
||||
break;
|
||||
|
||||
print i;
|
||||
}
|
||||
// expect: 0
|
||||
// expect: 1
|
||||
// expect: 2
|
||||
// expect: 3
|
||||
// expect: 4
|
||||
2
lox.t/break/outside_loop.lox
Normal file
2
lox.t/break/outside_loop.lox
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
break;
|
||||
// expect: error
|
||||
15
lox.t/break/while.lox
Normal file
15
lox.t/break/while.lox
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
var i = 0;
|
||||
|
||||
while (i < 10) {
|
||||
if (i == 5)
|
||||
break;
|
||||
|
||||
print i;
|
||||
|
||||
i = i + 1;
|
||||
}
|
||||
// expect: 0
|
||||
// expect: 1
|
||||
// expect: 2
|
||||
// expect: 3
|
||||
// expect: 4
|
||||
16
lox.t/continue/for.lox
Normal file
16
lox.t/continue/for.lox
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
for (var i = 0; i < 10; i = i + 1) {
|
||||
if (i == 5)
|
||||
continue;
|
||||
|
||||
print i;
|
||||
}
|
||||
// expect: 0
|
||||
// expect: 1
|
||||
// expect: 2
|
||||
// expect: 3
|
||||
// expect: 4
|
||||
// expect: 6
|
||||
// expect: 7
|
||||
// expect: 8
|
||||
// expect: 9
|
||||
|
||||
2
lox.t/continue/outside_loop.lox
Normal file
2
lox.t/continue/outside_loop.lox
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
continue;
|
||||
// expect: error
|
||||
21
lox.t/continue/while.lox
Normal file
21
lox.t/continue/while.lox
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
var i = 0;
|
||||
|
||||
while (i < 10) {
|
||||
if (i == 5) {
|
||||
i = i + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
print i;
|
||||
|
||||
i = i + 1;
|
||||
}
|
||||
// expect: 0
|
||||
// expect: 1
|
||||
// expect: 2
|
||||
// expect: 3
|
||||
// expect: 4
|
||||
// expect: 6
|
||||
// expect: 7
|
||||
// expect: 8
|
||||
// expect: 9
|
||||
58
lox.t/run.t
58
lox.t/run.t
|
|
@ -136,6 +136,31 @@ file bool/not.lox
|
|||
true
|
||||
|
||||
|
||||
file break/for.lox
|
||||
$ mlox break/for.lox
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
|
||||
|
||||
file break/outside_loop.lox
|
||||
$ mlox break/outside_loop.lox
|
||||
found 1 ParserError:
|
||||
ParserError at line 1, column 0: Can use break only in loops
|
||||
[1]
|
||||
|
||||
|
||||
file break/while.lox
|
||||
$ mlox break/while.lox
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
|
||||
|
||||
file call/bool.lox
|
||||
$ mlox call/bool.lox
|
||||
|
||||
|
|
@ -298,8 +323,37 @@ file constructor/return_value.lox
|
|||
$ mlox constructor/return_value.lox
|
||||
|
||||
|
||||
file empty_file.lox
|
||||
$ mlox empty_file.lox
|
||||
file continue/for.lox
|
||||
$ mlox continue/for.lox
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
|
||||
|
||||
file continue/outside_loop.lox
|
||||
$ mlox continue/outside_loop.lox
|
||||
found 1 ParserError:
|
||||
ParserError at line 1, column 0: Can use continue only in loops
|
||||
[1]
|
||||
|
||||
|
||||
file continue/while.lox
|
||||
$ mlox continue/while.lox
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
|
||||
|
||||
file expressions/evaluate.lox
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue