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/operator/add.lox
Normal file
2
interpreter/tests/lox/operator/add.lox
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
print 123 + 456; // expect: 579
|
||||
print "str" + "ing"; // expect: string
|
||||
1
interpreter/tests/lox/operator/add_bool_nil.lox
Normal file
1
interpreter/tests/lox/operator/add_bool_nil.lox
Normal file
|
|
@ -0,0 +1 @@
|
|||
true + nil; // expect runtime error: Operands must be two numbers or two strings.
|
||||
1
interpreter/tests/lox/operator/add_bool_num.lox
Normal file
1
interpreter/tests/lox/operator/add_bool_num.lox
Normal file
|
|
@ -0,0 +1 @@
|
|||
true + 123; // expect runtime error: Operands must be two numbers or two strings.
|
||||
1
interpreter/tests/lox/operator/add_bool_string.lox
Normal file
1
interpreter/tests/lox/operator/add_bool_string.lox
Normal file
|
|
@ -0,0 +1 @@
|
|||
true + "s"; // expect runtime error: Operands must be two numbers or two strings.
|
||||
1
interpreter/tests/lox/operator/add_nil_nil.lox
Normal file
1
interpreter/tests/lox/operator/add_nil_nil.lox
Normal file
|
|
@ -0,0 +1 @@
|
|||
nil + nil; // expect runtime error: Operands must be two numbers or two strings.
|
||||
1
interpreter/tests/lox/operator/add_num_nil.lox
Normal file
1
interpreter/tests/lox/operator/add_num_nil.lox
Normal file
|
|
@ -0,0 +1 @@
|
|||
1 + nil; // expect runtime error: Operands must be two numbers or two strings.
|
||||
1
interpreter/tests/lox/operator/add_string_nil.lox
Normal file
1
interpreter/tests/lox/operator/add_string_nil.lox
Normal file
|
|
@ -0,0 +1 @@
|
|||
"s" + nil; // expect runtime error: Operands must be two numbers or two strings.
|
||||
25
interpreter/tests/lox/operator/comparison.lox
Normal file
25
interpreter/tests/lox/operator/comparison.lox
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
print 1 < 2; // expect: true
|
||||
print 2 < 2; // expect: false
|
||||
print 2 < 1; // expect: false
|
||||
|
||||
print 1 <= 2; // expect: true
|
||||
print 2 <= 2; // expect: true
|
||||
print 2 <= 1; // expect: false
|
||||
|
||||
print 1 > 2; // expect: false
|
||||
print 2 > 2; // expect: false
|
||||
print 2 > 1; // expect: true
|
||||
|
||||
print 1 >= 2; // expect: false
|
||||
print 2 >= 2; // expect: true
|
||||
print 2 >= 1; // expect: true
|
||||
|
||||
// Zero and negative zero compare the same.
|
||||
print 0 < -0; // expect: false
|
||||
print -0 < 0; // expect: false
|
||||
print 0 > -0; // expect: false
|
||||
print -0 > 0; // expect: false
|
||||
print 0 <= -0; // expect: true
|
||||
print -0 <= 0; // expect: true
|
||||
print 0 >= -0; // expect: true
|
||||
print -0 >= 0; // expect: true
|
||||
2
interpreter/tests/lox/operator/divide.lox
Normal file
2
interpreter/tests/lox/operator/divide.lox
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
print 8 / 2; // expect: 4
|
||||
print 12.34 / 12.34; // expect: 1
|
||||
1
interpreter/tests/lox/operator/divide_nonnum_num.lox
Normal file
1
interpreter/tests/lox/operator/divide_nonnum_num.lox
Normal file
|
|
@ -0,0 +1 @@
|
|||
"1" / 1; // expect runtime error: Operands must be numbers.
|
||||
1
interpreter/tests/lox/operator/divide_num_nonnum.lox
Normal file
1
interpreter/tests/lox/operator/divide_num_nonnum.lox
Normal file
|
|
@ -0,0 +1 @@
|
|||
1 / "1"; // expect runtime error: Operands must be numbers.
|
||||
14
interpreter/tests/lox/operator/equals.lox
Normal file
14
interpreter/tests/lox/operator/equals.lox
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
print nil == nil; // expect: true
|
||||
|
||||
print true == true; // expect: true
|
||||
print true == false; // expect: false
|
||||
|
||||
print 1 == 1; // expect: true
|
||||
print 1 == 2; // expect: false
|
||||
|
||||
print "str" == "str"; // expect: true
|
||||
print "str" == "ing"; // expect: false
|
||||
|
||||
print nil == false; // expect: false
|
||||
print false == 0; // expect: false
|
||||
print 0 == "0"; // expect: false
|
||||
13
interpreter/tests/lox/operator/equals_class.lox
Normal file
13
interpreter/tests/lox/operator/equals_class.lox
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// Bound methods have identity equality.
|
||||
class Foo {}
|
||||
class Bar {}
|
||||
|
||||
print Foo == Foo; // expect: true
|
||||
print Foo == Bar; // expect: false
|
||||
print Bar == Foo; // expect: false
|
||||
print Bar == Bar; // expect: true
|
||||
|
||||
print Foo == "Foo"; // expect: false
|
||||
print Foo == nil; // expect: false
|
||||
print Foo == 123; // expect: false
|
||||
print Foo == true; // expect: false
|
||||
13
interpreter/tests/lox/operator/equals_method.lox
Normal file
13
interpreter/tests/lox/operator/equals_method.lox
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// Bound methods have identity equality.
|
||||
class Foo {
|
||||
method() {}
|
||||
}
|
||||
|
||||
var foo = Foo();
|
||||
var fooMethod = foo.method;
|
||||
|
||||
// Same bound method.
|
||||
print fooMethod == fooMethod; // expect: true
|
||||
|
||||
// Different closurizations.
|
||||
print foo.method == foo.method; // expect: false
|
||||
1
interpreter/tests/lox/operator/greater_nonnum_num.lox
Normal file
1
interpreter/tests/lox/operator/greater_nonnum_num.lox
Normal file
|
|
@ -0,0 +1 @@
|
|||
"1" > 1; // expect runtime error: Operands must be numbers.
|
||||
1
interpreter/tests/lox/operator/greater_num_nonnum.lox
Normal file
1
interpreter/tests/lox/operator/greater_num_nonnum.lox
Normal file
|
|
@ -0,0 +1 @@
|
|||
1 > "1"; // expect runtime error: Operands must be numbers.
|
||||
|
|
@ -0,0 +1 @@
|
|||
"1" >= 1; // expect runtime error: Operands must be numbers.
|
||||
|
|
@ -0,0 +1 @@
|
|||
1 >= "1"; // expect runtime error: Operands must be numbers.
|
||||
1
interpreter/tests/lox/operator/less_nonnum_num.lox
Normal file
1
interpreter/tests/lox/operator/less_nonnum_num.lox
Normal file
|
|
@ -0,0 +1 @@
|
|||
"1" < 1; // expect runtime error: Operands must be numbers.
|
||||
1
interpreter/tests/lox/operator/less_num_nonnum.lox
Normal file
1
interpreter/tests/lox/operator/less_num_nonnum.lox
Normal file
|
|
@ -0,0 +1 @@
|
|||
1 < "1"; // expect runtime error: Operands must be numbers.
|
||||
|
|
@ -0,0 +1 @@
|
|||
"1" <= 1; // expect runtime error: Operands must be numbers.
|
||||
|
|
@ -0,0 +1 @@
|
|||
1 <= "1"; // expect runtime error: Operands must be numbers.
|
||||
2
interpreter/tests/lox/operator/multiply.lox
Normal file
2
interpreter/tests/lox/operator/multiply.lox
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
print 5 * 3; // expect: 15
|
||||
print 12.34 * 0.3; // expect: 3.702
|
||||
1
interpreter/tests/lox/operator/multiply_nonnum_num.lox
Normal file
1
interpreter/tests/lox/operator/multiply_nonnum_num.lox
Normal file
|
|
@ -0,0 +1 @@
|
|||
"1" * 1; // expect runtime error: Operands must be numbers.
|
||||
1
interpreter/tests/lox/operator/multiply_num_nonnum.lox
Normal file
1
interpreter/tests/lox/operator/multiply_num_nonnum.lox
Normal file
|
|
@ -0,0 +1 @@
|
|||
1 * "1"; // expect runtime error: Operands must be numbers.
|
||||
3
interpreter/tests/lox/operator/negate.lox
Normal file
3
interpreter/tests/lox/operator/negate.lox
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
print -(3); // expect: -3
|
||||
print --(3); // expect: 3
|
||||
print ---(3); // expect: -3
|
||||
1
interpreter/tests/lox/operator/negate_nonnum.lox
Normal file
1
interpreter/tests/lox/operator/negate_nonnum.lox
Normal file
|
|
@ -0,0 +1 @@
|
|||
-"s"; // expect runtime error: Operand must be a number.
|
||||
13
interpreter/tests/lox/operator/not.lox
Normal file
13
interpreter/tests/lox/operator/not.lox
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
print !true; // expect: false
|
||||
print !false; // expect: true
|
||||
print !!true; // expect: true
|
||||
|
||||
print !123; // expect: false
|
||||
print !0; // expect: false
|
||||
|
||||
print !nil; // expect: true
|
||||
|
||||
print !""; // expect: false
|
||||
|
||||
fun foo() {}
|
||||
print !foo; // expect: false
|
||||
3
interpreter/tests/lox/operator/not_class.lox
Normal file
3
interpreter/tests/lox/operator/not_class.lox
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
class Bar {}
|
||||
print !Bar; // expect: false
|
||||
print !Bar(); // expect: false
|
||||
14
interpreter/tests/lox/operator/not_equals.lox
Normal file
14
interpreter/tests/lox/operator/not_equals.lox
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
print nil != nil; // expect: false
|
||||
|
||||
print true != true; // expect: false
|
||||
print true != false; // expect: true
|
||||
|
||||
print 1 != 1; // expect: false
|
||||
print 1 != 2; // expect: true
|
||||
|
||||
print "str" != "str"; // expect: false
|
||||
print "str" != "ing"; // expect: true
|
||||
|
||||
print nil != false; // expect: true
|
||||
print false != 0; // expect: true
|
||||
print 0 != "0"; // expect: true
|
||||
2
interpreter/tests/lox/operator/subtract.lox
Normal file
2
interpreter/tests/lox/operator/subtract.lox
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
print 4 - 3; // expect: 1
|
||||
print 1.2 - 1.2; // expect: 0
|
||||
1
interpreter/tests/lox/operator/subtract_nonnum_num.lox
Normal file
1
interpreter/tests/lox/operator/subtract_nonnum_num.lox
Normal file
|
|
@ -0,0 +1 @@
|
|||
"1" - 1; // expect runtime error: Operands must be numbers.
|
||||
1
interpreter/tests/lox/operator/subtract_num_nonnum.lox
Normal file
1
interpreter/tests/lox/operator/subtract_num_nonnum.lox
Normal file
|
|
@ -0,0 +1 @@
|
|||
1 - "1"; // expect runtime error: Operands must be numbers.
|
||||
Loading…
Add table
Add a link
Reference in a new issue