mirror of
https://github.com/MorizzG/MLox.git
synced 2025-12-06 04:22:41 +00:00
added lox test files
This commit is contained in:
parent
821f5c62bc
commit
0f3d0a15f0
268 changed files with 7497 additions and 3 deletions
14
lox.t/inheritance/constructor.lox
Normal file
14
lox.t/inheritance/constructor.lox
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
class A {
|
||||
init(param) {
|
||||
this.field = param;
|
||||
}
|
||||
|
||||
test() {
|
||||
print this.field;
|
||||
}
|
||||
}
|
||||
|
||||
class B < A {}
|
||||
|
||||
var b = B("value");
|
||||
b.test(); // expect: value
|
||||
3
lox.t/inheritance/inherit_from_function.lox
Normal file
3
lox.t/inheritance/inherit_from_function.lox
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fun foo() {}
|
||||
|
||||
class Subclass < foo {} // expect runtime error: Superclass must be a class.
|
||||
2
lox.t/inheritance/inherit_from_nil.lox
Normal file
2
lox.t/inheritance/inherit_from_nil.lox
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
var Nil = nil;
|
||||
class Foo < Nil {} // expect runtime error: Superclass must be a class.
|
||||
2
lox.t/inheritance/inherit_from_number.lox
Normal file
2
lox.t/inheritance/inherit_from_number.lox
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
var Number = 123;
|
||||
class Foo < Number {} // expect runtime error: Superclass must be a class.
|
||||
14
lox.t/inheritance/inherit_methods.lox
Normal file
14
lox.t/inheritance/inherit_methods.lox
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
class Foo {
|
||||
methodOnFoo() { print "foo"; }
|
||||
override() { print "foo"; }
|
||||
}
|
||||
|
||||
class Bar < Foo {
|
||||
methodOnBar() { print "bar"; }
|
||||
override() { print "bar"; }
|
||||
}
|
||||
|
||||
var bar = Bar();
|
||||
bar.methodOnFoo(); // expect: foo
|
||||
bar.methodOnBar(); // expect: bar
|
||||
bar.override(); // expect: bar
|
||||
4
lox.t/inheritance/parenthesized_superclass.lox
Normal file
4
lox.t/inheritance/parenthesized_superclass.lox
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
class Foo {}
|
||||
|
||||
// [line 4] Error at '(': Expect superclass name.
|
||||
class Bar < (Foo) {}
|
||||
38
lox.t/inheritance/set_fields_from_base_class.lox
Normal file
38
lox.t/inheritance/set_fields_from_base_class.lox
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
class Foo {
|
||||
foo(a, b) {
|
||||
this.field1 = a;
|
||||
this.field2 = b;
|
||||
}
|
||||
|
||||
fooPrint() {
|
||||
print this.field1;
|
||||
print this.field2;
|
||||
}
|
||||
}
|
||||
|
||||
class Bar < Foo {
|
||||
bar(a, b) {
|
||||
this.field1 = a;
|
||||
this.field2 = b;
|
||||
}
|
||||
|
||||
barPrint() {
|
||||
print this.field1;
|
||||
print this.field2;
|
||||
}
|
||||
}
|
||||
|
||||
var bar = Bar();
|
||||
bar.foo("foo 1", "foo 2");
|
||||
bar.fooPrint();
|
||||
// expect: foo 1
|
||||
// expect: foo 2
|
||||
|
||||
bar.bar("bar 1", "bar 2");
|
||||
bar.barPrint();
|
||||
// expect: bar 1
|
||||
// expect: bar 2
|
||||
|
||||
bar.fooPrint();
|
||||
// expect: bar 1
|
||||
// expect: bar 2
|
||||
Loading…
Add table
Add a link
Reference in a new issue