added lox test files

This commit is contained in:
Moritz Gmeiner 2024-08-03 02:44:12 +02:00
commit 0f3d0a15f0
268 changed files with 7497 additions and 3 deletions

2
lox.t/operator/add.lox Normal file
View file

@ -0,0 +1,2 @@
print 123 + 456; // expect: 579
print "str" + "ing"; // expect: string

View file

@ -0,0 +1 @@
true + nil; // expect runtime error: Operands must be two numbers or two strings.

View file

@ -0,0 +1 @@
true + 123; // expect runtime error: Operands must be two numbers or two strings.

View file

@ -0,0 +1 @@
true + "s"; // expect runtime error: Operands must be two numbers or two strings.

View file

@ -0,0 +1 @@
nil + nil; // expect runtime error: Operands must be two numbers or two strings.

View file

@ -0,0 +1 @@
1 + nil; // expect runtime error: Operands must be two numbers or two strings.

View file

@ -0,0 +1 @@
"s" + nil; // expect runtime error: Operands must be two numbers or two strings.

View 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

View file

@ -0,0 +1,2 @@
print 8 / 2; // expect: 4
print 12.34 / 12.34; // expect: 1

View file

@ -0,0 +1 @@
"1" / 1; // expect runtime error: Operands must be numbers.

View file

@ -0,0 +1 @@
1 / "1"; // expect runtime error: Operands must be numbers.

14
lox.t/operator/equals.lox Normal file
View 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

View 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

View 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

View file

@ -0,0 +1 @@
"1" > 1; // expect runtime error: Operands must be numbers.

View file

@ -0,0 +1 @@
1 > "1"; // expect runtime error: Operands must be numbers.

View file

@ -0,0 +1 @@
"1" >= 1; // expect runtime error: Operands must be numbers.

View file

@ -0,0 +1 @@
1 >= "1"; // expect runtime error: Operands must be numbers.

View file

@ -0,0 +1 @@
"1" < 1; // expect runtime error: Operands must be numbers.

View file

@ -0,0 +1 @@
1 < "1"; // expect runtime error: Operands must be numbers.

View file

@ -0,0 +1 @@
"1" <= 1; // expect runtime error: Operands must be numbers.

View file

@ -0,0 +1 @@
1 <= "1"; // expect runtime error: Operands must be numbers.

View file

@ -0,0 +1,2 @@
print 5 * 3; // expect: 15
print 12.34 * 0.3; // expect: 3.702

View file

@ -0,0 +1 @@
"1" * 1; // expect runtime error: Operands must be numbers.

View file

@ -0,0 +1 @@
1 * "1"; // expect runtime error: Operands must be numbers.

View file

@ -0,0 +1,3 @@
print -(3); // expect: -3
print --(3); // expect: 3
print ---(3); // expect: -3

View file

@ -0,0 +1 @@
-"s"; // expect runtime error: Operand must be a number.

13
lox.t/operator/not.lox Normal file
View 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

View file

@ -0,0 +1,3 @@
class Bar {}
print !Bar; // expect: false
print !Bar(); // expect: false

View 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

View file

@ -0,0 +1,2 @@
print 4 - 3; // expect: 1
print 1.2 - 1.2; // expect: 0

View file

@ -0,0 +1 @@
"1" - 1; // expect runtime error: Operands must be numbers.

View file

@ -0,0 +1 @@
1 - "1"; // expect runtime error: Operands must be numbers.