forked from Mirror/wren
Reorganize tests and benchmark scripts.
Mainly to get rid of one top level directory. But this will also be useful when there are tests of the embedding API.
This commit is contained in:
8
test/language/constructor/default.wren
Normal file
8
test/language/constructor/default.wren
Normal file
@ -0,0 +1,8 @@
|
||||
class Foo {
|
||||
toString { "Foo" }
|
||||
}
|
||||
|
||||
// Classes inherit the argument-less "new" one by default.
|
||||
var foo = new Foo
|
||||
IO.print(foo is Foo) // expect: true
|
||||
IO.print(foo.toString) // expect: Foo
|
||||
7
test/language/constructor/infix_class_expression.wren
Normal file
7
test/language/constructor/infix_class_expression.wren
Normal file
@ -0,0 +1,7 @@
|
||||
class Foo {
|
||||
+(other) { "Foo " + other }
|
||||
}
|
||||
|
||||
IO.print(new Foo + "value") // expect: Foo value
|
||||
|
||||
// TODO: Other expressions following a constructor, like new Foo.bar("arg").
|
||||
19
test/language/constructor/new.wren
Normal file
19
test/language/constructor/new.wren
Normal file
@ -0,0 +1,19 @@
|
||||
class Foo {
|
||||
new { IO.print("none") }
|
||||
new() { IO.print("zero") }
|
||||
new(a) { IO.print(a) }
|
||||
new(a, b) { IO.print(a + b) }
|
||||
|
||||
toString { "Foo" }
|
||||
}
|
||||
|
||||
// Can overload by arity.
|
||||
new Foo // expect: none
|
||||
new Foo() // expect: zero
|
||||
new Foo("one") // expect: one
|
||||
new Foo("one", "two") // expect: onetwo
|
||||
|
||||
// Returns the new instance.
|
||||
var foo = new Foo // expect: none
|
||||
IO.print(foo is Foo) // expect: true
|
||||
IO.print(foo.toString) // expect: Foo
|
||||
40
test/language/constructor/superclass.wren
Normal file
40
test/language/constructor/superclass.wren
Normal file
@ -0,0 +1,40 @@
|
||||
class A {
|
||||
new(arg) {
|
||||
IO.print("new A ", arg)
|
||||
_field = arg
|
||||
}
|
||||
|
||||
aField { _field }
|
||||
}
|
||||
|
||||
class B is A {
|
||||
new(arg1, arg2) {
|
||||
super(arg2)
|
||||
IO.print("new B ", arg1)
|
||||
_field = arg1
|
||||
}
|
||||
|
||||
bField { _field }
|
||||
}
|
||||
|
||||
class C is B {
|
||||
new {
|
||||
super("one", "two")
|
||||
IO.print("new C")
|
||||
_field = "c"
|
||||
}
|
||||
|
||||
cField { _field }
|
||||
}
|
||||
|
||||
var c = new C
|
||||
// expect: new A two
|
||||
// expect: new B one
|
||||
// expect: new C
|
||||
IO.print(c is A) // expect: true
|
||||
IO.print(c is B) // expect: true
|
||||
IO.print(c is C) // expect: true
|
||||
|
||||
IO.print(c.aField) // expect: two
|
||||
IO.print(c.bField) // expect: one
|
||||
IO.print(c.cField) // expect: c
|
||||
Reference in New Issue
Block a user