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:
@ -0,0 +1,7 @@
|
||||
class Foo {
|
||||
static methodOnFoo { IO.print("foo") }
|
||||
}
|
||||
|
||||
class Bar is Foo {}
|
||||
|
||||
Bar.methodOnFoo // expect runtime error: Bar metaclass does not implement 'methodOnFoo'.
|
||||
35
test/language/inheritance/inherit_fields.wren
Normal file
35
test/language/inheritance/inherit_fields.wren
Normal file
@ -0,0 +1,35 @@
|
||||
class Foo {
|
||||
foo(a, b) {
|
||||
_field1 = a
|
||||
_field2 = b
|
||||
}
|
||||
|
||||
fooPrint {
|
||||
IO.print(_field1)
|
||||
IO.print(_field2)
|
||||
}
|
||||
}
|
||||
|
||||
class Bar is Foo {
|
||||
bar(a, b) {
|
||||
_field1 = a
|
||||
_field2 = b
|
||||
}
|
||||
|
||||
barPrint {
|
||||
IO.print(_field1)
|
||||
IO.print(_field2)
|
||||
}
|
||||
}
|
||||
|
||||
var bar = new Bar
|
||||
bar.foo("foo 1", "foo 2")
|
||||
bar.bar("bar 1", "bar 2")
|
||||
|
||||
bar.fooPrint
|
||||
// expect: foo 1
|
||||
// expect: foo 2
|
||||
|
||||
bar.barPrint
|
||||
// expect: bar 1
|
||||
// expect: bar 2
|
||||
1
test/language/inheritance/inherit_from_class.wren
Normal file
1
test/language/inheritance/inherit_from_class.wren
Normal file
@ -0,0 +1 @@
|
||||
class Subclass is Class {} // expect runtime error: Subclass cannot inherit from Class.
|
||||
8
test/language/inheritance/inherit_from_closure.wren
Normal file
8
test/language/inheritance/inherit_from_closure.wren
Normal file
@ -0,0 +1,8 @@
|
||||
var ClosureType
|
||||
|
||||
{
|
||||
var a = "a"
|
||||
ClosureType = new Fn { IO.print(a) }.type
|
||||
}
|
||||
|
||||
class Subclass is ClosureType {} // expect runtime error: Subclass cannot inherit from Fn.
|
||||
1
test/language/inheritance/inherit_from_fiber.wren
Normal file
1
test/language/inheritance/inherit_from_fiber.wren
Normal file
@ -0,0 +1 @@
|
||||
class Subclass is Fiber {} // expect runtime error: Subclass cannot inherit from Fiber.
|
||||
1
test/language/inheritance/inherit_from_fn.wren
Normal file
1
test/language/inheritance/inherit_from_fn.wren
Normal file
@ -0,0 +1 @@
|
||||
class Subclass is Fn {} // expect runtime error: Subclass cannot inherit from Fn.
|
||||
1
test/language/inheritance/inherit_from_list.wren
Normal file
1
test/language/inheritance/inherit_from_list.wren
Normal file
@ -0,0 +1 @@
|
||||
class Subclass is List {} // expect runtime error: Subclass cannot inherit from List.
|
||||
1
test/language/inheritance/inherit_from_map.wren
Normal file
1
test/language/inheritance/inherit_from_map.wren
Normal file
@ -0,0 +1 @@
|
||||
class Subclass is Map {} // expect runtime error: Subclass cannot inherit from Map.
|
||||
1
test/language/inheritance/inherit_from_nonclass.wren
Normal file
1
test/language/inheritance/inherit_from_nonclass.wren
Normal file
@ -0,0 +1 @@
|
||||
class Foo is 123 {} // expect runtime error: Must inherit from a class.
|
||||
1
test/language/inheritance/inherit_from_range.wren
Normal file
1
test/language/inheritance/inherit_from_range.wren
Normal file
@ -0,0 +1 @@
|
||||
class Subclass is Range {} // expect runtime error: Subclass cannot inherit from Range.
|
||||
1
test/language/inheritance/inherit_from_string.wren
Normal file
1
test/language/inheritance/inherit_from_string.wren
Normal file
@ -0,0 +1 @@
|
||||
class Subclass is String {} // expect runtime error: Subclass cannot inherit from String.
|
||||
26
test/language/inheritance/inherit_methods.wren
Normal file
26
test/language/inheritance/inherit_methods.wren
Normal file
@ -0,0 +1,26 @@
|
||||
class Foo {
|
||||
methodOnFoo { IO.print("foo") }
|
||||
method(a) { IO.print("foo") }
|
||||
method(a, b, c) { IO.print("foo") }
|
||||
override { IO.print("foo") }
|
||||
}
|
||||
|
||||
class Bar is Foo {
|
||||
methodOnBar { IO.print("bar") }
|
||||
method(a, b) { IO.print("bar") }
|
||||
method(a, b, c, d) { IO.print("bar") }
|
||||
override { IO.print("bar") }
|
||||
}
|
||||
|
||||
var bar = new Bar
|
||||
bar.methodOnFoo // expect: foo
|
||||
bar.methodOnBar // expect: bar
|
||||
|
||||
// Methods with different arity do not shadow each other.
|
||||
bar.method(1) // expect: foo
|
||||
bar.method(1, 2) // expect: bar
|
||||
bar.method(1, 2, 3) // expect: foo
|
||||
bar.method(1, 2, 3, 4) // expect: bar
|
||||
bar.override // expect: bar
|
||||
|
||||
// TODO: Prevent extending built-in types.
|
||||
36
test/language/inheritance/inherited_fields_in_closure.wren
Normal file
36
test/language/inheritance/inherited_fields_in_closure.wren
Normal file
@ -0,0 +1,36 @@
|
||||
class Foo {
|
||||
new { _field = "Foo field" }
|
||||
|
||||
closeOverFooGet {
|
||||
return new Fn { new Fn { _field } }
|
||||
}
|
||||
|
||||
closeOverFooSet {
|
||||
return new Fn { new Fn { _field = "new foo value" } }
|
||||
}
|
||||
}
|
||||
|
||||
class Bar is Foo {
|
||||
new {
|
||||
super
|
||||
_field = "Bar field"
|
||||
}
|
||||
|
||||
closeOverBarGet {
|
||||
return new Fn { new Fn { _field } }
|
||||
}
|
||||
|
||||
closeOverBarSet {
|
||||
return new Fn { new Fn { _field = "new bar value" } }
|
||||
}
|
||||
}
|
||||
|
||||
var bar = new Bar
|
||||
IO.print(bar.closeOverFooGet.call().call()) // expect: Foo field
|
||||
IO.print(bar.closeOverBarGet.call().call()) // expect: Bar field
|
||||
bar.closeOverFooSet.call().call()
|
||||
IO.print(bar.closeOverFooGet.call().call()) // expect: new foo value
|
||||
IO.print(bar.closeOverBarGet.call().call()) // expect: Bar field
|
||||
bar.closeOverBarSet.call().call()
|
||||
IO.print(bar.closeOverFooGet.call().call()) // expect: new foo value
|
||||
IO.print(bar.closeOverBarGet.call().call()) // expect: new bar value
|
||||
16
test/language/inheritance/is.wren
Normal file
16
test/language/inheritance/is.wren
Normal file
@ -0,0 +1,16 @@
|
||||
class A {}
|
||||
class B is A {}
|
||||
class C is B {}
|
||||
var a = new A
|
||||
var b = new B
|
||||
var c = new C
|
||||
|
||||
IO.print(a is A) // expect: true
|
||||
IO.print(a is B) // expect: false
|
||||
IO.print(a is C) // expect: false
|
||||
IO.print(b is A) // expect: true
|
||||
IO.print(b is B) // expect: true
|
||||
IO.print(b is C) // expect: false
|
||||
IO.print(c is A) // expect: true
|
||||
IO.print(c is B) // expect: true
|
||||
IO.print(c is C) // expect: true
|
||||
Reference in New Issue
Block a user