test: add constructor overload tests for Foo class with arity dispatch
Add test file for Foo class constructors covering zero, one, and two argument overloads by arity. Verify each overload produces correct output and that new instances return proper type and toString behavior.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
class Foo {
|
||||
this bar { io.write("this bar") }
|
||||
this baz { io.write("this baz") }
|
||||
this bar(arg) { io.write("this bar " + arg) }
|
||||
|
||||
toString { "Foo" }
|
||||
}
|
||||
|
||||
// Different names.
|
||||
Foo.bar // expect: this bar
|
||||
Foo.baz // expect: this baz
|
||||
|
||||
// Can overload by arity.
|
||||
Foo.bar // expect: this bar
|
||||
Foo.bar("one") // expect: this bar one
|
||||
|
||||
// Returns the new instance.
|
||||
var foo = Foo.bar // expect: this bar
|
||||
io.write(foo is Foo) // expect: true
|
||||
io.write(foo.toString) // expect: Foo
|
||||
@@ -0,0 +1,18 @@
|
||||
class Foo {
|
||||
// TODO(bob): Do we want to require an explicit "new" here?
|
||||
this new { io.write("zero") }
|
||||
this new(a) { io.write(a) }
|
||||
this new(a, b) { io.write(a + b) }
|
||||
|
||||
toString { "Foo" }
|
||||
}
|
||||
|
||||
// Can overload by arity.
|
||||
Foo.new // expect: zero
|
||||
Foo.new("one") // expect: one
|
||||
Foo.new("one", "two") // expect: onetwo
|
||||
|
||||
// Returns the new instance.
|
||||
var foo = Foo.new // expect: zero
|
||||
io.write(foo is Foo) // expect: true
|
||||
io.write(foo.toString) // expect: Foo
|
||||
Reference in New Issue
Block a user