added tests

This commit is contained in:
Moritz Gmeiner 2024-09-01 19:15:55 +02:00
commit 660464638f
255 changed files with 7220 additions and 3 deletions

View file

@ -0,0 +1,2 @@
// [line 2] Error at 'class': Expect expression.
if (true) "ok"; else class Foo {}

View file

@ -0,0 +1,2 @@
// [line 2] Error at 'class': Expect expression.
if (true) class Foo {}

View 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";

View 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

View file

@ -0,0 +1,2 @@
// [line 2] Error at 'fun': Expect expression.
if (true) "ok"; else fun foo() {}

View file

@ -0,0 +1,2 @@
// [line 2] Error at 'fun': Expect expression.
if (true) fun foo() {}

View 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

View 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

View file

@ -0,0 +1,2 @@
// [line 2] Error at 'var': Expect expression.
if (true) "ok"; else var foo;

View file

@ -0,0 +1,2 @@
// [line 2] Error at 'var': Expect expression.
if (true) var foo;