mirror of
https://github.com/MorizzG/rlox.git
synced 2025-12-06 04:12:42 +00:00
added tests
This commit is contained in:
parent
1cca1494a4
commit
660464638f
255 changed files with 7220 additions and 3 deletions
2
interpreter/tests/lox/if/class_in_else.lox
Normal file
2
interpreter/tests/lox/if/class_in_else.lox
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// [line 2] Error at 'class': Expect expression.
|
||||
if (true) "ok"; else class Foo {}
|
||||
2
interpreter/tests/lox/if/class_in_then.lox
Normal file
2
interpreter/tests/lox/if/class_in_then.lox
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// [line 2] Error at 'class': Expect expression.
|
||||
if (true) class Foo {}
|
||||
3
interpreter/tests/lox/if/dangling_else.lox
Normal file
3
interpreter/tests/lox/if/dangling_else.lox
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
// A dangling else binds to the right-most if.
|
||||
if (true) if (false) print "bad"; else print "good"; // expect: good
|
||||
if (false) if (true) print "bad"; else print "bad";
|
||||
6
interpreter/tests/lox/if/else.lox
Normal file
6
interpreter/tests/lox/if/else.lox
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// Evaluate the 'else' expression if the condition is false.
|
||||
if (true) print "good"; else print "bad"; // expect: good
|
||||
if (false) print "bad"; else print "good"; // expect: good
|
||||
|
||||
// Allow block body.
|
||||
if (false) nil; else { print "block"; } // expect: block
|
||||
2
interpreter/tests/lox/if/fun_in_else.lox
Normal file
2
interpreter/tests/lox/if/fun_in_else.lox
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// [line 2] Error at 'fun': Expect expression.
|
||||
if (true) "ok"; else fun foo() {}
|
||||
2
interpreter/tests/lox/if/fun_in_then.lox
Normal file
2
interpreter/tests/lox/if/fun_in_then.lox
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// [line 2] Error at 'fun': Expect expression.
|
||||
if (true) fun foo() {}
|
||||
10
interpreter/tests/lox/if/if.lox
Normal file
10
interpreter/tests/lox/if/if.lox
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// Evaluate the 'then' expression if the condition is true.
|
||||
if (true) print "good"; // expect: good
|
||||
if (false) print "bad";
|
||||
|
||||
// Allow block body.
|
||||
if (true) { print "block"; } // expect: block
|
||||
|
||||
// Assignment in if condition.
|
||||
var a = false;
|
||||
if (a = true) print a; // expect: true
|
||||
8
interpreter/tests/lox/if/truth.lox
Normal file
8
interpreter/tests/lox/if/truth.lox
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// False and nil are false.
|
||||
if (false) print "bad"; else print "false"; // expect: false
|
||||
if (nil) print "bad"; else print "nil"; // expect: nil
|
||||
|
||||
// Everything else is true.
|
||||
if (true) print true; // expect: true
|
||||
if (0) print 0; // expect: 0
|
||||
if ("") print "empty"; // expect: empty
|
||||
2
interpreter/tests/lox/if/var_in_else.lox
Normal file
2
interpreter/tests/lox/if/var_in_else.lox
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// [line 2] Error at 'var': Expect expression.
|
||||
if (true) "ok"; else var foo;
|
||||
2
interpreter/tests/lox/if/var_in_then.lox
Normal file
2
interpreter/tests/lox/if/var_in_then.lox
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// [line 2] Error at 'var': Expect expression.
|
||||
if (true) var foo;
|
||||
Loading…
Add table
Add a link
Reference in a new issue