added tests

This commit is contained in:
Moritz Gmeiner 2024-09-01 19:15:55 +02:00
commit 660464638f
255 changed files with 7220 additions and 3 deletions

View file

@ -0,0 +1,19 @@
class A {
method(arg) {
print "A.method(" + arg + ")";
}
}
class B < A {
getClosure() {
return super.method;
}
method(arg) {
print "B.method(" + arg + ")";
}
}
var closure = B().getClosure();
closure("arg"); // expect: A.method(arg)

View file

@ -0,0 +1,16 @@
class Base {
foo() {
print "Base.foo()";
}
}
class Derived < Base {
bar() {
print "Derived.bar()";
super.foo();
}
}
Derived().bar();
// expect: Derived.bar()
// expect: Base.foo()

View file

@ -0,0 +1,16 @@
class Base {
foo() {
print "Base.foo()";
}
}
class Derived < Base {
foo() {
print "Derived.foo()";
super.foo();
}
}
Derived().foo();
// expect: Derived.foo()
// expect: Base.foo()

View file

@ -0,0 +1,17 @@
class Base {
toString() { return "Base"; }
}
class Derived < Base {
getClosure() {
fun closure() {
return super.toString();
}
return closure;
}
toString() { return "Derived"; }
}
var closure = Derived().getClosure();
print closure(); // expect: Base

View file

@ -0,0 +1,16 @@
class Base {
init(a, b) {
print "Base.init(" + a + ", " + b + ")";
}
}
class Derived < Base {
init() {
print "Derived.init()";
super.init("a", "b");
}
}
Derived();
// expect: Derived.init()
// expect: Base.init(a, b)

View file

@ -0,0 +1,14 @@
class Base {
foo(a, b) {
print "Base.foo(" + a + ", " + b + ")";
}
}
class Derived < Base {
foo() {
print "Derived.foo()"; // expect: Derived.foo()
super.foo("a", "b", "c", "d"); // expect runtime error: Expected 2 arguments but got 4.
}
}
Derived().foo();

View file

@ -0,0 +1,18 @@
class A {
foo() {
print "A.foo()";
}
}
class B < A {}
class C < B {
foo() {
print "C.foo()";
super.foo();
}
}
C().foo();
// expect: C.foo()
// expect: A.foo()

View file

@ -0,0 +1,13 @@
class Base {
foo(a, b) {
print "Base.foo(" + a + ", " + b + ")";
}
}
class Derived < Base {
foo() {
super.foo(1); // expect runtime error: Expected 2 arguments but got 1.
}
}
Derived().foo();

View file

@ -0,0 +1,7 @@
class Base {
foo() {
super.doesNotExist; // Error at 'super': Can't use 'super' in a class with no superclass.
}
}
Base().foo();

View file

@ -0,0 +1,7 @@
class Base {
foo() {
super.doesNotExist(1); // Error at 'super': Can't use 'super' in a class with no superclass.
}
}
Base().foo();

View file

@ -0,0 +1,9 @@
class Base {}
class Derived < Base {
foo() {
super.doesNotExist(1); // expect runtime error: Undefined property 'doesNotExist'.
}
}
Derived().foo();

View file

@ -0,0 +1,10 @@
class A {
method() {}
}
class B < A {
method() {
// [line 8] Error at ')': Expect '.' after 'super'.
(super).method();
}
}

View file

@ -0,0 +1,22 @@
class Base {
method() {
print "Base.method()";
}
}
class Derived < Base {
method() {
super.method();
}
}
class OtherBase {
method() {
print "OtherBase.method()";
}
}
var derived = Derived();
derived.method(); // expect: Base.method()
Base = OtherBase;
derived.method(); // expect: Base.method()

View file

@ -0,0 +1,2 @@
super.foo("bar"); // Error at 'super': Can't use 'super' outside of a class.
super.foo; // Error at 'super': Can't use 'super' outside of a class.

View file

@ -0,0 +1,26 @@
class A {
say() {
print "A";
}
}
class B < A {
getClosure() {
fun closure() {
super.say();
}
return closure;
}
say() {
print "B";
}
}
class C < B {
say() {
print "C";
}
}
C().getClosure()(); // expect: A

View file

@ -0,0 +1,23 @@
class A {
say() {
print "A";
}
}
class B < A {
test() {
super.say();
}
say() {
print "B";
}
}
class C < B {
say() {
print "C";
}
}
C().test(); // expect: A

View file

@ -0,0 +1,3 @@
super.bar(); // Error at 'super': Can't use 'super' outside of a class.
fun foo() {
}

View file

@ -0,0 +1,8 @@
class A {}
class B < A {
method() {
// [line 6] Error at ';': Expect '.' after 'super'.
super;
}
}

View file

@ -0,0 +1,7 @@
class A {}
class B < A {
method() {
super.; // Error at ';': Expect superclass method name.
}
}

View file

@ -0,0 +1,16 @@
class Base {
init(a) {
this.a = a;
}
}
class Derived < Base {
init(a, b) {
super.init(a);
this.b = b;
}
}
var derived = Derived("a", "b");
print derived.a; // expect: a
print derived.b; // expect: b