mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 14:18:42 +01:00
Make IO.write() call toString on its argument.
This commit is contained in:
12
test/io/write.wren
Normal file
12
test/io/write.wren
Normal file
@ -0,0 +1,12 @@
|
||||
class Foo {
|
||||
toString { return "Foo.toString" }
|
||||
}
|
||||
|
||||
// Calls toString on argument.
|
||||
IO.write(new Foo) // expect: Foo.toString
|
||||
|
||||
// Returns argument.
|
||||
var result = IO.write(123) // expect: 123
|
||||
IO.write(result == 123) // expect: true
|
||||
|
||||
// TODO: What if toString on argument doesn't return a string?
|
||||
17
test/list/to_string.wren
Normal file
17
test/list/to_string.wren
Normal file
@ -0,0 +1,17 @@
|
||||
// Handle empty list.
|
||||
IO.write([].toString) // expect: []
|
||||
|
||||
// Does not quote strings.
|
||||
IO.write([1, "2", true].toString) // expect: [1, 2, true]
|
||||
|
||||
// Nested lists.
|
||||
IO.write([1, [2, [3], 4], 5]) // expect: [1, [2, [3], 4], 5]
|
||||
|
||||
// Calls toString on elements.
|
||||
class Foo {
|
||||
toString { return "Foo.toString" }
|
||||
}
|
||||
|
||||
IO.write([1, new Foo, 2]) // expect: [1, Foo.toString, 2]
|
||||
|
||||
// TODO: Handle lists that contain themselves.
|
||||
2
test/object/to_string.wren
Normal file
2
test/object/to_string.wren
Normal file
@ -0,0 +1,2 @@
|
||||
class Foo {}
|
||||
IO.write((new Foo).toString) // expect: <object>
|
||||
Reference in New Issue
Block a user