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
13
interpreter/tests/lox/this/closure.lox
Normal file
13
interpreter/tests/lox/this/closure.lox
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
class Foo {
|
||||
getClosure() {
|
||||
fun closure() {
|
||||
return this.toString();
|
||||
}
|
||||
return closure;
|
||||
}
|
||||
|
||||
toString() { return "Foo"; }
|
||||
}
|
||||
|
||||
var closure = Foo().getClosure();
|
||||
print closure(); // expect: Foo
|
||||
20
interpreter/tests/lox/this/nested_class.lox
Normal file
20
interpreter/tests/lox/this/nested_class.lox
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
class Outer {
|
||||
method() {
|
||||
print this; // expect: Outer instance
|
||||
|
||||
fun f() {
|
||||
print this; // expect: Outer instance
|
||||
|
||||
class Inner {
|
||||
method() {
|
||||
print this; // expect: Inner instance
|
||||
}
|
||||
}
|
||||
|
||||
Inner().method();
|
||||
}
|
||||
f();
|
||||
}
|
||||
}
|
||||
|
||||
Outer().method();
|
||||
19
interpreter/tests/lox/this/nested_closure.lox
Normal file
19
interpreter/tests/lox/this/nested_closure.lox
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
class Foo {
|
||||
getClosure() {
|
||||
fun f() {
|
||||
fun g() {
|
||||
fun h() {
|
||||
return this.toString();
|
||||
}
|
||||
return h;
|
||||
}
|
||||
return g;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
toString() { return "Foo"; }
|
||||
}
|
||||
|
||||
var closure = Foo().getClosure();
|
||||
print closure()()(); // expect: Foo
|
||||
1
interpreter/tests/lox/this/this_at_top_level.lox
Normal file
1
interpreter/tests/lox/this/this_at_top_level.lox
Normal file
|
|
@ -0,0 +1 @@
|
|||
this; // Error at 'this': Can't use 'this' outside of a class.
|
||||
6
interpreter/tests/lox/this/this_in_method.lox
Normal file
6
interpreter/tests/lox/this/this_in_method.lox
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
class Foo {
|
||||
bar() { return this; }
|
||||
baz() { return "baz"; }
|
||||
}
|
||||
|
||||
print Foo().bar().baz(); // expect: baz
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fun foo() {
|
||||
this; // Error at 'this': Can't use 'this' outside of a class.
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue