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

View file

@ -0,0 +1,11 @@
class Foo {
init(a, b) {
print "init"; // expect: init
this.a = a;
this.b = b;
}
}
var foo = Foo(1, 2);
print foo.a; // expect: 1
print foo.b; // expect: 2

View file

@ -0,0 +1,11 @@
class Foo {
init() {
print "init";
return;
print "nope";
}
}
var foo = Foo(); // expect: init
print foo.init(); // expect: init
// expect: Foo instance

View file

@ -0,0 +1,15 @@
class Foo {
init(arg) {
print "Foo.init(" + arg + ")";
this.field = "init";
}
}
var foo = Foo("one"); // expect: Foo.init(one)
foo.field = "field";
var foo2 = foo.init("two"); // expect: Foo.init(two)
print foo2; // expect: Foo instance
// Make sure init() doesn't create a fresh instance.
print foo.field; // expect: init

View file

@ -0,0 +1,4 @@
class Foo {}
var foo = Foo();
print foo; // expect: Foo instance

View file

@ -0,0 +1,3 @@
class Foo {}
var foo = Foo(1, 2, 3); // expect runtime error: Expected 0 arguments but got 3.

View file

@ -0,0 +1,10 @@
class Foo {
init() {
print "init";
return;
print "nope";
}
}
var foo = Foo(); // expect: init
print foo; // expect: Foo instance

View file

@ -0,0 +1,8 @@
class Foo {
init(a, b) {
this.a = a;
this.b = b;
}
}
var foo = Foo(1, 2, 3, 4); // expect runtime error: Expected 2 arguments but got 4.

View file

@ -0,0 +1,12 @@
class Foo {
init(arg) {
print "Foo.init(" + arg + ")";
this.field = "init";
}
}
fun init() {
print "not initializer";
}
init(); // expect: not initializer

View file

@ -0,0 +1,5 @@
class Foo {
init(a, b) {}
}
var foo = Foo(1); // expect runtime error: Expected 2 arguments but got 1.

View file

@ -0,0 +1,10 @@
class Foo {
init() {
fun init() {
return "bar";
}
print init(); // expect: bar
}
}
print Foo(); // expect: Foo instance

View file

@ -0,0 +1,5 @@
class Foo {
init() {
return "result"; // Error at 'return': Can't return a value from an initializer.
}
}