"IO" -> "System".
Get rid of the separate opt-in IO class and replace it with a core System class. - Remove wren_io.c, wren_io.h, and io.wren. - Remove the flags that disable it. - Remove the overloads for print() with different arity. (It was an experiment, but I don't think it's that useful.) - Remove IO.read(). That will reappear using libuv in the CLI at some point. - Remove IO.time. Doesn't seem to have been used. - Update all of the tests, docs, etc. I'm sorry for all the breakage this causes, but I think "System" is a better name for this class (it makes it natural to add things like "System.gc()") and frees up "IO" for referring to the CLI's IO module.
This commit is contained in:
@@ -1,23 +1,23 @@
|
||||
IO.print(true == true) // expect: true
|
||||
IO.print(true == false) // expect: false
|
||||
IO.print(false == true) // expect: false
|
||||
IO.print(false == false) // expect: true
|
||||
System.print(true == true) // expect: true
|
||||
System.print(true == false) // expect: false
|
||||
System.print(false == true) // expect: false
|
||||
System.print(false == false) // expect: true
|
||||
|
||||
// Not equal to other types.
|
||||
IO.print(true == 1) // expect: false
|
||||
IO.print(false == 0) // expect: false
|
||||
IO.print(true == "true") // expect: false
|
||||
IO.print(false == "false") // expect: false
|
||||
IO.print(false == "") // expect: false
|
||||
System.print(true == 1) // expect: false
|
||||
System.print(false == 0) // expect: false
|
||||
System.print(true == "true") // expect: false
|
||||
System.print(false == "false") // expect: false
|
||||
System.print(false == "") // expect: false
|
||||
|
||||
IO.print(true != true) // expect: false
|
||||
IO.print(true != false) // expect: true
|
||||
IO.print(false != true) // expect: true
|
||||
IO.print(false != false) // expect: false
|
||||
System.print(true != true) // expect: false
|
||||
System.print(true != false) // expect: true
|
||||
System.print(false != true) // expect: true
|
||||
System.print(false != false) // expect: false
|
||||
|
||||
// Not equal to other types.
|
||||
IO.print(true != 1) // expect: true
|
||||
IO.print(false != 0) // expect: true
|
||||
IO.print(true != "true") // expect: true
|
||||
IO.print(false != "false") // expect: true
|
||||
IO.print(false != "") // expect: true
|
||||
System.print(true != 1) // expect: true
|
||||
System.print(false != 0) // expect: true
|
||||
System.print(true != "true") // expect: true
|
||||
System.print(false != "false") // expect: true
|
||||
System.print(false != "") // expect: true
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
IO.print(!true) // expect: false
|
||||
IO.print(!false) // expect: true
|
||||
IO.print(!!true) // expect: true
|
||||
System.print(!true) // expect: false
|
||||
System.print(!false) // expect: true
|
||||
System.print(!!true) // expect: true
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
IO.print(true.toString) // expect: true
|
||||
IO.print(false.toString) // expect: false
|
||||
System.print(true.toString) // expect: true
|
||||
System.print(false.toString) // expect: false
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
IO.print(true is Bool) // expect: true
|
||||
IO.print(true is Object) // expect: true
|
||||
IO.print(true is Num) // expect: false
|
||||
IO.print(true.type == Bool) // expect: true
|
||||
System.print(true is Bool) // expect: true
|
||||
System.print(true is Object) // expect: true
|
||||
System.print(true is Num) // expect: false
|
||||
System.print(true.type == Bool) // expect: true
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
IO.print(Num == Num) // expect: true
|
||||
IO.print(Num == Bool) // expect: false
|
||||
System.print(Num == Num) // expect: true
|
||||
System.print(Num == Bool) // expect: false
|
||||
|
||||
// Not equal to other types.
|
||||
IO.print(Num == 123) // expect: false
|
||||
IO.print(Num == true) // expect: false
|
||||
System.print(Num == 123) // expect: false
|
||||
System.print(Num == true) // expect: false
|
||||
|
||||
IO.print(Num != Num) // expect: false
|
||||
IO.print(Num != Bool) // expect: true
|
||||
System.print(Num != Num) // expect: false
|
||||
System.print(Num != Bool) // expect: true
|
||||
|
||||
// Not equal to other types.
|
||||
IO.print(Num != 123) // expect: true
|
||||
IO.print(Num != true) // expect: true
|
||||
System.print(Num != 123) // expect: true
|
||||
System.print(Num != true) // expect: true
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
class Foo {}
|
||||
|
||||
IO.print(Foo.name) // expect: Foo
|
||||
IO.print(Foo.type.name) // expect: Foo metaclass
|
||||
System.print(Foo.name) // expect: Foo
|
||||
System.print(Foo.type.name) // expect: Foo metaclass
|
||||
|
||||
// Make sure the built-in classes have proper names too.
|
||||
IO.print(Object.name) // expect: Object
|
||||
IO.print(Bool.name) // expect: Bool
|
||||
IO.print(Class.name) // expect: Class
|
||||
System.print(Object.name) // expect: Object
|
||||
System.print(Bool.name) // expect: Bool
|
||||
System.print(Class.name) // expect: Class
|
||||
|
||||
// And metaclass names.
|
||||
IO.print(Object.type.name) // expect: Object metaclass
|
||||
IO.print(Bool.type.name) // expect: Bool metaclass
|
||||
System.print(Object.type.name) // expect: Object metaclass
|
||||
System.print(Bool.type.name) // expect: Bool metaclass
|
||||
|
||||
@@ -5,11 +5,11 @@ class Bar is Foo {}
|
||||
class Baz is Bar {}
|
||||
|
||||
// A class with no explicit superclass inherits Object.
|
||||
IO.print(Foo.supertype == Object) // expect: true
|
||||
System.print(Foo.supertype == Object) // expect: true
|
||||
|
||||
// Otherwise, it's the superclass.
|
||||
IO.print(Bar.supertype == Foo) // expect: true
|
||||
IO.print(Baz.supertype == Bar) // expect: true
|
||||
System.print(Bar.supertype == Foo) // expect: true
|
||||
System.print(Baz.supertype == Bar) // expect: true
|
||||
|
||||
// Object has no supertype.
|
||||
IO.print(Object.supertype) // expect: null
|
||||
System.print(Object.supertype) // expect: null
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
class Foo {}
|
||||
|
||||
// A class is a class.
|
||||
IO.print(Foo is Class) // expect: true
|
||||
System.print(Foo is Class) // expect: true
|
||||
|
||||
// Its metatype is also a class.
|
||||
IO.print(Foo.type is Class) // expect: true
|
||||
System.print(Foo.type is Class) // expect: true
|
||||
|
||||
// The metatype's metatype is Class.
|
||||
IO.print(Foo.type.type == Class) // expect: true
|
||||
System.print(Foo.type.type == Class) // expect: true
|
||||
|
||||
// And Class's metatype circles back onto itself.
|
||||
IO.print(Foo.type.type.type == Class) // expect: true
|
||||
IO.print(Foo.type.type.type.type == Class) // expect: true
|
||||
IO.print(Foo.type.type.type.type.type == Class) // expect: true
|
||||
System.print(Foo.type.type.type == Class) // expect: true
|
||||
System.print(Foo.type.type.type.type == Class) // expect: true
|
||||
System.print(Foo.type.type.type.type.type == Class) // expect: true
|
||||
|
||||
@@ -2,6 +2,6 @@ var fiber = Fiber.new {
|
||||
Fiber.abort("Error message.")
|
||||
}
|
||||
|
||||
IO.print(fiber.try()) // expect: Error message.
|
||||
IO.print(fiber.isDone) // expect: true
|
||||
IO.print(fiber.error) // expect: Error message.
|
||||
System.print(fiber.try()) // expect: Error message.
|
||||
System.print(fiber.isDone) // expect: true
|
||||
System.print(fiber.error) // expect: Error message.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var fiber = Fiber.new {
|
||||
IO.print("fiber")
|
||||
System.print("fiber")
|
||||
}
|
||||
|
||||
IO.print("before") // expect: before
|
||||
System.print("before") // expect: before
|
||||
fiber.call() // expect: fiber
|
||||
IO.print("after") // expect: after
|
||||
System.print("after") // expect: after
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var fiber = Fiber.new {
|
||||
IO.print("call")
|
||||
System.print("call")
|
||||
}
|
||||
|
||||
fiber.call() // expect: call
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var fiber = Fiber.new {
|
||||
Fiber.abort("Error!")
|
||||
IO.print("should not get here")
|
||||
System.print("should not get here")
|
||||
}
|
||||
|
||||
fiber.try()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var fiber = Fiber.new {
|
||||
IO.print("fiber") // expect: fiber
|
||||
System.print("fiber") // expect: fiber
|
||||
}
|
||||
|
||||
IO.print(fiber.call()) // expect: null
|
||||
System.print(fiber.call()) // expect: null
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var fiber = Fiber.new {
|
||||
IO.print("fiber")
|
||||
System.print("fiber")
|
||||
return "result" // expect: fiber
|
||||
}
|
||||
|
||||
IO.print(fiber.call()) // expect: result
|
||||
System.print(fiber.call()) // expect: result
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
var main = Fiber.current
|
||||
|
||||
var fiber = Fiber.new {
|
||||
IO.print("transferred")
|
||||
IO.print(main.transfer())
|
||||
IO.print("called")
|
||||
System.print("transferred")
|
||||
System.print(main.transfer())
|
||||
System.print("called")
|
||||
}
|
||||
|
||||
fiber.transfer() // expect: transferred
|
||||
IO.print("main") // expect: main
|
||||
System.print("main") // expect: main
|
||||
fiber.call() // expect: null
|
||||
// expect: called
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
var fiber = Fiber.new {
|
||||
IO.print("fiber")
|
||||
System.print("fiber")
|
||||
}
|
||||
|
||||
// The first value passed to the fiber is ignored, since there's no yield call
|
||||
// to return it.
|
||||
IO.print("before") // expect: before
|
||||
System.print("before") // expect: before
|
||||
fiber.call("ignored") // expect: fiber
|
||||
IO.print("after") // expect: after
|
||||
System.print("after") // expect: after
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var fiber = Fiber.new {
|
||||
IO.print("call")
|
||||
System.print("call")
|
||||
}
|
||||
|
||||
fiber.call(1) // expect: call
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var fiber = Fiber.new {
|
||||
Fiber.abort("Error!")
|
||||
IO.print("should not get here")
|
||||
System.print("should not get here")
|
||||
}
|
||||
|
||||
fiber.try()
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
var main = Fiber.current
|
||||
|
||||
var fiber = Fiber.new {
|
||||
IO.print("transferred")
|
||||
IO.print(main.transfer())
|
||||
IO.print("called")
|
||||
System.print("transferred")
|
||||
System.print(main.transfer())
|
||||
System.print("called")
|
||||
}
|
||||
|
||||
fiber.transfer() // expect: transferred
|
||||
IO.print("main") // expect: main
|
||||
System.print("main") // expect: main
|
||||
fiber.call("value") // expect: value
|
||||
// expect: called
|
||||
|
||||
@@ -2,6 +2,6 @@ var fiber = Fiber.new {
|
||||
"s".unknown
|
||||
}
|
||||
|
||||
IO.print(fiber.error) // expect: null
|
||||
IO.print(fiber.try()) // expect: String does not implement 'unknown'.
|
||||
IO.print(fiber.error) // expect: String does not implement 'unknown'.
|
||||
System.print(fiber.error) // expect: null
|
||||
System.print(fiber.try()) // expect: String does not implement 'unknown'.
|
||||
System.print(fiber.error) // expect: String does not implement 'unknown'.
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
var fiber = Fiber.new {
|
||||
IO.print("1")
|
||||
System.print("1")
|
||||
Fiber.yield()
|
||||
IO.print("2")
|
||||
System.print("2")
|
||||
}
|
||||
|
||||
IO.print(fiber.isDone) // expect: false
|
||||
System.print(fiber.isDone) // expect: false
|
||||
fiber.call() // expect: 1
|
||||
IO.print(fiber.isDone) // expect: false
|
||||
System.print(fiber.isDone) // expect: false
|
||||
fiber.call() // expect: 2
|
||||
IO.print(fiber.isDone) // expect: true
|
||||
System.print(fiber.isDone) // expect: true
|
||||
|
||||
@@ -3,4 +3,4 @@ var fiber = Fiber.new {
|
||||
}
|
||||
|
||||
fiber.try()
|
||||
IO.print(fiber.isDone) // expect: true
|
||||
System.print(fiber.isDone) // expect: true
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
var b = Fiber.new {
|
||||
IO.print("fiber b")
|
||||
System.print("fiber b")
|
||||
}
|
||||
|
||||
var a = Fiber.new {
|
||||
IO.print("begin fiber a")
|
||||
System.print("begin fiber a")
|
||||
b.call()
|
||||
IO.print("end fiber a")
|
||||
System.print("end fiber a")
|
||||
}
|
||||
|
||||
IO.print("begin main")
|
||||
System.print("begin main")
|
||||
a.call()
|
||||
IO.print("end main")
|
||||
System.print("end main")
|
||||
|
||||
// expect: begin main
|
||||
// expect: begin fiber a
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
var a = Fiber.new {
|
||||
IO.print("a")
|
||||
System.print("a")
|
||||
}
|
||||
|
||||
var b = Fiber.new {
|
||||
IO.print("b before")
|
||||
System.print("b before")
|
||||
a.transfer()
|
||||
IO.print("b after")
|
||||
System.print("b after")
|
||||
}
|
||||
|
||||
var c = Fiber.new {
|
||||
IO.print("c before")
|
||||
System.print("c before")
|
||||
b.transfer()
|
||||
IO.print("c after")
|
||||
System.print("c after")
|
||||
}
|
||||
|
||||
IO.print("start") // expect: start
|
||||
System.print("start") // expect: start
|
||||
|
||||
c.transfer()
|
||||
// expect: c before
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
var F = Fiber.new {
|
||||
IO.print(1) // expect: 1
|
||||
IO.print(F.transfer()) // expect: null
|
||||
IO.print(2) // expect: 2
|
||||
System.print(1) // expect: 1
|
||||
System.print(F.transfer()) // expect: null
|
||||
System.print(2) // expect: 2
|
||||
}
|
||||
|
||||
F.call()
|
||||
// F remembers its original caller so transfers back to main.
|
||||
IO.print(3) // expect: 3
|
||||
System.print(3) // expect: 3
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
var A = Fiber.new {
|
||||
IO.print(2)
|
||||
System.print(2)
|
||||
B.transfer()
|
||||
IO.print("nope")
|
||||
System.print("nope")
|
||||
}
|
||||
|
||||
var B = Fiber.new {
|
||||
IO.print(1)
|
||||
System.print(1)
|
||||
A.transfer()
|
||||
IO.print(3)
|
||||
System.print(3)
|
||||
}
|
||||
|
||||
B.call()
|
||||
@@ -15,4 +15,4 @@ B.call()
|
||||
// expect: 2
|
||||
// expect: 3
|
||||
// B remembers its original caller so returns to main.
|
||||
IO.print(4) // expect: 4
|
||||
System.print(4) // expect: 4
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
var main = Fiber.current
|
||||
|
||||
var fiber = Fiber.new {
|
||||
IO.print("fiber 1")
|
||||
IO.print(main.transfer())
|
||||
System.print("fiber 1")
|
||||
System.print(main.transfer())
|
||||
|
||||
// Yield to bounce back to main and clear the caller so we don't get a
|
||||
// double call() error below.
|
||||
Fiber.yield()
|
||||
|
||||
IO.print(main.transfer())
|
||||
System.print(main.transfer())
|
||||
}
|
||||
|
||||
fiber.transfer() // expect: fiber 1
|
||||
IO.print("main 1") // expect: main 1
|
||||
System.print("main 1") // expect: main 1
|
||||
fiber.call("call 1") // expect: call 1
|
||||
|
||||
IO.print("main 2") // expect: main 2
|
||||
System.print("main 2") // expect: main 2
|
||||
// Transfer back into the fiber so it has a NULL caller.
|
||||
fiber.transfer()
|
||||
|
||||
fiber.call() // expect: null
|
||||
IO.print("main 3") // expect: main 3
|
||||
System.print("main 3") // expect: main 3
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
var main = Fiber.current
|
||||
|
||||
var fiber = Fiber.new {
|
||||
IO.print("fiber")
|
||||
IO.print(main.transfer())
|
||||
System.print("fiber")
|
||||
System.print(main.transfer())
|
||||
}
|
||||
|
||||
fiber.transfer() // expect: fiber
|
||||
IO.print("main") // expect: main
|
||||
System.print("main") // expect: main
|
||||
fiber.transfer("transfer") // expect: transfer
|
||||
|
||||
// This does not get run since we exit when the transferred fiber completes.
|
||||
IO.print("nope")
|
||||
System.print("nope")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var a = Fiber.new {
|
||||
IO.print("run")
|
||||
System.print("run")
|
||||
}
|
||||
|
||||
a.call() // expect: run
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var a = Fiber.new {
|
||||
Fiber.abort("Error!")
|
||||
IO.print("should not get here")
|
||||
System.print("should not get here")
|
||||
}
|
||||
|
||||
a.try()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var fiber = Fiber.new {
|
||||
IO.print("called")
|
||||
IO.print(Fiber.yield())
|
||||
IO.print("transferred")
|
||||
System.print("called")
|
||||
System.print(Fiber.yield())
|
||||
System.print("transferred")
|
||||
}
|
||||
|
||||
fiber.call() // expect: called
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
var a = Fiber.new {
|
||||
IO.print("a")
|
||||
System.print("a")
|
||||
}
|
||||
|
||||
var b = Fiber.new {
|
||||
IO.print("b before")
|
||||
System.print("b before")
|
||||
a.transfer("ignored")
|
||||
IO.print("b after")
|
||||
System.print("b after")
|
||||
}
|
||||
|
||||
var c = Fiber.new {
|
||||
IO.print("c before")
|
||||
System.print("c before")
|
||||
b.transfer("ignored")
|
||||
IO.print("c after")
|
||||
System.print("c after")
|
||||
}
|
||||
|
||||
IO.print("start") // expect: start
|
||||
System.print("start") // expect: start
|
||||
|
||||
c.transfer("ignored")
|
||||
// expect: c before
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
var F = Fiber.new {
|
||||
IO.print(1) // expect: 1
|
||||
IO.print(F.transfer("value")) // expect: value
|
||||
IO.print(2) // expect: 2
|
||||
System.print(1) // expect: 1
|
||||
System.print(F.transfer("value")) // expect: value
|
||||
System.print(2) // expect: 2
|
||||
}
|
||||
|
||||
F.call()
|
||||
IO.print(3) // expect: 3
|
||||
System.print(3) // expect: 3
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
var A = Fiber.new {
|
||||
IO.print(2)
|
||||
System.print(2)
|
||||
B.transfer("ignored")
|
||||
IO.print("nope")
|
||||
System.print("nope")
|
||||
}
|
||||
|
||||
var B = Fiber.new {
|
||||
IO.print(1)
|
||||
System.print(1)
|
||||
A.transfer("ignored")
|
||||
IO.print(3)
|
||||
System.print(3)
|
||||
}
|
||||
|
||||
B.call()
|
||||
// expect: 1
|
||||
// expect: 2
|
||||
// expect: 3
|
||||
IO.print(4) // expect: 4
|
||||
System.print(4) // expect: 4
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var a = Fiber.new {
|
||||
IO.print("run")
|
||||
System.print("run")
|
||||
}
|
||||
|
||||
a.call() // expect: run
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var a = Fiber.new {
|
||||
Fiber.abort("Error!")
|
||||
IO.print("should not get here")
|
||||
System.print("should not get here")
|
||||
}
|
||||
|
||||
a.try()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var fiber = Fiber.new {
|
||||
IO.print("called")
|
||||
IO.print(Fiber.yield())
|
||||
IO.print("transferred")
|
||||
System.print("called")
|
||||
System.print(Fiber.yield())
|
||||
System.print("transferred")
|
||||
}
|
||||
|
||||
fiber.call() // expect: called
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
var fiber = Fiber.new {
|
||||
IO.print("before")
|
||||
System.print("before")
|
||||
true.unknownMethod
|
||||
IO.print("after")
|
||||
System.print("after")
|
||||
}
|
||||
|
||||
IO.print(fiber.try())
|
||||
System.print(fiber.try())
|
||||
// expect: before
|
||||
// expect: Bool does not implement 'unknownMethod'.
|
||||
IO.print("after try") // expect: after try
|
||||
System.print("after try") // expect: after try
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var fiber = Fiber.new {
|
||||
IO.print("try")
|
||||
System.print("try")
|
||||
}
|
||||
|
||||
fiber.try() // expect: try
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
var fiber = Fiber.new {
|
||||
IO.print("fiber")
|
||||
System.print("fiber")
|
||||
}
|
||||
|
||||
IO.print("before") // expect: before
|
||||
IO.print(fiber.try()) // expect: fiber
|
||||
System.print("before") // expect: before
|
||||
System.print(fiber.try()) // expect: fiber
|
||||
// expect: null
|
||||
IO.print("after") // expect: after
|
||||
System.print("after") // expect: after
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var fiber = Fiber.new {}
|
||||
IO.print(fiber is Fiber) // expect: true
|
||||
IO.print(fiber is Object) // expect: true
|
||||
IO.print(fiber is Bool) // expect: false
|
||||
IO.print(fiber.type == Fiber) // expect: true
|
||||
System.print(fiber is Fiber) // expect: true
|
||||
System.print(fiber is Object) // expect: true
|
||||
System.print(fiber is Bool) // expect: false
|
||||
System.print(fiber.type == Fiber) // expect: true
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
var fiber = Fiber.new {
|
||||
IO.print("fiber 1")
|
||||
System.print("fiber 1")
|
||||
Fiber.yield()
|
||||
IO.print("fiber 2")
|
||||
System.print("fiber 2")
|
||||
Fiber.yield()
|
||||
IO.print("fiber 3")
|
||||
System.print("fiber 3")
|
||||
}
|
||||
|
||||
fiber.call() // expect: fiber 1
|
||||
IO.print("main 1") // expect: main 1
|
||||
System.print("main 1") // expect: main 1
|
||||
fiber.call() // expect: fiber 2
|
||||
IO.print("main 2") // expect: main 2
|
||||
System.print("main 2") // expect: main 2
|
||||
fiber.call() // expect: fiber 3
|
||||
IO.print("main 3") // expect: main 3
|
||||
System.print("main 3") // expect: main 3
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
IO.print("before") // expect: before
|
||||
System.print("before") // expect: before
|
||||
Fiber.yield()
|
||||
IO.print("not reached")
|
||||
System.print("not reached")
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
var fiber = Fiber.new {
|
||||
IO.print("fiber 1")
|
||||
IO.print(Fiber.yield())
|
||||
IO.print(Fiber.yield())
|
||||
System.print("fiber 1")
|
||||
System.print(Fiber.yield())
|
||||
System.print(Fiber.yield())
|
||||
}
|
||||
|
||||
fiber.call() // expect: fiber 1
|
||||
IO.print("main 1") // expect: main 1
|
||||
System.print("main 1") // expect: main 1
|
||||
fiber.call("call 1") // expect: call 1
|
||||
IO.print("main 2") // expect: main 2
|
||||
System.print("main 2") // expect: main 2
|
||||
fiber.call() // expect: null
|
||||
IO.print("main 3") // expect: main 3
|
||||
System.print("main 3") // expect: main 3
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
var main = Fiber.current
|
||||
|
||||
var a = Fiber.new {
|
||||
IO.print("a")
|
||||
IO.print(Fiber.yield())
|
||||
System.print("a")
|
||||
System.print(Fiber.yield())
|
||||
}
|
||||
|
||||
var b = Fiber.new {
|
||||
IO.print("b")
|
||||
IO.print(Fiber.yield())
|
||||
System.print("b")
|
||||
System.print(Fiber.yield())
|
||||
|
||||
a.call()
|
||||
a.transfer("value")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var a = Fiber.new {
|
||||
IO.print("before") // expect: before
|
||||
System.print("before") // expect: before
|
||||
Fiber.yield()
|
||||
IO.print("not reached")
|
||||
System.print("not reached")
|
||||
}
|
||||
|
||||
// Transfer through a chain of fibers. Since none of them are called, they all
|
||||
@@ -9,4 +9,4 @@ var a = Fiber.new {
|
||||
var b = Fiber.new { a.transfer() }
|
||||
var c = Fiber.new { b.transfer() }
|
||||
c.transfer()
|
||||
IO.print("not reached")
|
||||
System.print("not reached")
|
||||
@@ -1,14 +1,14 @@
|
||||
var fiber = Fiber.new {
|
||||
IO.print("fiber 1")
|
||||
System.print("fiber 1")
|
||||
Fiber.yield("yield 1")
|
||||
IO.print("fiber 2")
|
||||
System.print("fiber 2")
|
||||
Fiber.yield("yield 2")
|
||||
IO.print("fiber 3")
|
||||
System.print("fiber 3")
|
||||
}
|
||||
|
||||
IO.print(fiber.call()) // expect: fiber 1
|
||||
System.print(fiber.call()) // expect: fiber 1
|
||||
// expect: yield 1
|
||||
IO.print(fiber.call()) // expect: fiber 2
|
||||
System.print(fiber.call()) // expect: fiber 2
|
||||
// expect: yield 2
|
||||
IO.print(fiber.call()) // expect: fiber 3
|
||||
System.print(fiber.call()) // expect: fiber 3
|
||||
// expect: null
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
IO.print("before") // expect: before
|
||||
System.print("before") // expect: before
|
||||
Fiber.yield(1)
|
||||
IO.print("not reached")
|
||||
System.print("not reached")
|
||||
@@ -1,7 +1,7 @@
|
||||
var a = Fiber.new {
|
||||
IO.print("before") // expect: before
|
||||
System.print("before") // expect: before
|
||||
Fiber.yield(1)
|
||||
IO.print("not reached")
|
||||
System.print("not reached")
|
||||
}
|
||||
|
||||
// Transfer through a chain of fibers. Since none of them are called, they all
|
||||
@@ -9,4 +9,4 @@ var a = Fiber.new {
|
||||
var b = Fiber.new { a.transfer() }
|
||||
var c = Fiber.new { b.transfer() }
|
||||
c.transfer()
|
||||
IO.print("not reached")
|
||||
System.print("not reached")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
IO.print(Fn.new {}.arity) // expect: 0
|
||||
IO.print(Fn.new {|a| a}.arity) // expect: 1
|
||||
IO.print(Fn.new {|a, b| a}.arity) // expect: 2
|
||||
IO.print(Fn.new {|a, b, c| a}.arity) // expect: 3
|
||||
IO.print(Fn.new {|a, b, c, d| a}.arity) // expect: 4
|
||||
System.print(Fn.new {}.arity) // expect: 0
|
||||
System.print(Fn.new {|a| a}.arity) // expect: 1
|
||||
System.print(Fn.new {|a, b| a}.arity) // expect: 2
|
||||
System.print(Fn.new {|a, b, c| a}.arity) // expect: 3
|
||||
System.print(Fn.new {|a, b, c, d| a}.arity) // expect: 4
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var f0 = Fn.new { IO.print("zero") }
|
||||
var f1 = Fn.new {|a| IO.print("one ", a) }
|
||||
var f2 = Fn.new {|a, b| IO.print("two ", a, " ", b) }
|
||||
var f3 = Fn.new {|a, b, c| IO.print("three ", a, " ", b, " ", c) }
|
||||
var f0 = Fn.new { System.print("zero") }
|
||||
var f1 = Fn.new {|a| System.print("one " + a) }
|
||||
var f2 = Fn.new {|a, b| System.print("two " + a + " " + b) }
|
||||
var f3 = Fn.new {|a, b, c| System.print("three " + a + " " + b + " " + c) }
|
||||
|
||||
f0.call("a") // expect: zero
|
||||
f0.call("a", "b") // expect: zero
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
var f2 = Fn.new {|a, b| IO.print(a, b) }
|
||||
var f2 = Fn.new {|a, b| System.print(a, b) }
|
||||
f2.call("a") // expect runtime error: Function expects more arguments.
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
// Not structurally equal.
|
||||
IO.print(Fn.new { 123 } == Fn.new { 123 }) // expect: false
|
||||
IO.print(Fn.new { 123 } != Fn.new { 123 }) // expect: true
|
||||
System.print(Fn.new { 123 } == Fn.new { 123 }) // expect: false
|
||||
System.print(Fn.new { 123 } != Fn.new { 123 }) // expect: true
|
||||
|
||||
// Not equal to other types.
|
||||
IO.print(Fn.new { 123 } == 1) // expect: false
|
||||
IO.print(Fn.new { 123 } == false) // expect: false
|
||||
IO.print(Fn.new { 123 } == "fn 123") // expect: false
|
||||
IO.print(Fn.new { 123 } != 1) // expect: true
|
||||
IO.print(Fn.new { 123 } != false) // expect: true
|
||||
IO.print(Fn.new { 123 } != "fn 123") // expect: true
|
||||
System.print(Fn.new { 123 } == 1) // expect: false
|
||||
System.print(Fn.new { 123 } == false) // expect: false
|
||||
System.print(Fn.new { 123 } == "fn 123") // expect: false
|
||||
System.print(Fn.new { 123 } != 1) // expect: true
|
||||
System.print(Fn.new { 123 } != false) // expect: true
|
||||
System.print(Fn.new { 123 } != "fn 123") // expect: true
|
||||
|
||||
// Equal by identity.
|
||||
var f = Fn.new { 123 }
|
||||
IO.print(f == f) // expect: true
|
||||
IO.print(f != f) // expect: false
|
||||
System.print(f == f) // expect: true
|
||||
System.print(f != f) // expect: false
|
||||
|
||||
@@ -1 +1 @@
|
||||
IO.print(Fn.new {}) // expect: <fn>
|
||||
System.print(Fn.new {}) // expect: <fn>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
IO.print(Fn.new { 0 } is Fn) // expect: true
|
||||
IO.print(Fn.new { 0 } is Object) // expect: true
|
||||
IO.print(Fn.new { 0 } is String) // expect: false
|
||||
IO.print(Fn.new { 0 }.type == Fn) // expect: true
|
||||
System.print(Fn.new { 0 } is Fn) // expect: true
|
||||
System.print(Fn.new { 0 } is Object) // expect: true
|
||||
System.print(Fn.new { 0 } is String) // expect: false
|
||||
System.print(Fn.new { 0 }.type == Fn) // expect: true
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
var a = [1]
|
||||
a.add(2)
|
||||
IO.print(a) // expect: [1, 2]
|
||||
System.print(a) // expect: [1, 2]
|
||||
a.add(3)
|
||||
IO.print(a) // expect: [1, 2, 3]
|
||||
System.print(a) // expect: [1, 2, 3]
|
||||
|
||||
// Returns added element.
|
||||
IO.print(a.add(4)) // expect: 4
|
||||
System.print(a.add(4)) // expect: 4
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
var a = [1]
|
||||
a.addAll([2, 3])
|
||||
IO.print(a) // expect: [1, 2, 3]
|
||||
System.print(a) // expect: [1, 2, 3]
|
||||
a.addAll([])
|
||||
IO.print(a) // expect: [1, 2, 3]
|
||||
System.print(a) // expect: [1, 2, 3]
|
||||
a.addAll(4..6)
|
||||
IO.print(a) // expect: [1, 2, 3, 4, 5, 6]
|
||||
System.print(a) // expect: [1, 2, 3, 4, 5, 6]
|
||||
|
||||
// Returns argument.
|
||||
var range = 7..9
|
||||
IO.print(a.addAll(range) == range) // expect: true
|
||||
System.print(a.addAll(range) == range) // expect: true
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var a = [1, 2, 3]
|
||||
a.clear()
|
||||
IO.print(a) // expect: []
|
||||
IO.print(a.count) // expect: 0
|
||||
System.print(a) // expect: []
|
||||
System.print(a.count) // expect: 0
|
||||
|
||||
// Returns null.
|
||||
IO.print([1, 2].clear()) // expect: null
|
||||
System.print([1, 2].clear()) // expect: null
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var list = [1, 2, 3, 4, "foo"]
|
||||
|
||||
IO.print(list.contains(2)) // expect: true
|
||||
IO.print(list.contains(5)) // expect: false
|
||||
IO.print(list.contains("foo")) // expect: true
|
||||
IO.print(list.contains("bar")) // expect: false
|
||||
System.print(list.contains(2)) // expect: true
|
||||
System.print(list.contains(5)) // expect: false
|
||||
System.print(list.contains("foo")) // expect: true
|
||||
System.print(list.contains("bar")) // expect: false
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
IO.print([].count) // expect: 0
|
||||
IO.print([1].count) // expect: 1
|
||||
IO.print([1, 2, 3, 4].count) // expect: 4
|
||||
System.print([].count) // expect: 0
|
||||
System.print([1].count) // expect: 1
|
||||
System.print([1, 2, 3, 4].count) // expect: 4
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var a = [1, 2, 3]
|
||||
|
||||
IO.print(a.count {|x| x > 3 }) // expect: 0
|
||||
IO.print(a.count {|x| x > 1 }) // expect: 2
|
||||
System.print(a.count {|x| x > 3 }) // expect: 0
|
||||
System.print(a.count {|x| x > 1 }) // expect: 2
|
||||
|
||||
IO.print([].count {|x| true }) // expect: 0
|
||||
System.print([].count {|x| true }) // expect: 0
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
var a = [1, 2, 3]
|
||||
|
||||
IO.print(a.count {|x| "truthy" }) // expect: 3
|
||||
System.print(a.count {|x| "truthy" }) // expect: 3
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
var words = ""
|
||||
["One", "Two", "Three"].each {|word| words = words + word }
|
||||
IO.print(words) // expect: OneTwoThree
|
||||
System.print(words) // expect: OneTwoThree
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
var i = 0
|
||||
[].each {|item| i = i + 1 }
|
||||
IO.print(i) // expect: 0
|
||||
System.print(i) // expect: 0
|
||||
|
||||
+10
-10
@@ -1,41 +1,41 @@
|
||||
// Add to empty list.
|
||||
var a = []
|
||||
a.insert(0, 1)
|
||||
IO.print(a) // expect: [1]
|
||||
System.print(a) // expect: [1]
|
||||
|
||||
// Normal indices.
|
||||
var b = [1, 2, 3]
|
||||
b.insert(0, 4)
|
||||
IO.print(b) // expect: [4, 1, 2, 3]
|
||||
System.print(b) // expect: [4, 1, 2, 3]
|
||||
|
||||
var c = [1, 2, 3]
|
||||
c.insert(1, 4)
|
||||
IO.print(c) // expect: [1, 4, 2, 3]
|
||||
System.print(c) // expect: [1, 4, 2, 3]
|
||||
|
||||
var d = [1, 2, 3]
|
||||
d.insert(2, 4)
|
||||
IO.print(d) // expect: [1, 2, 4, 3]
|
||||
System.print(d) // expect: [1, 2, 4, 3]
|
||||
|
||||
var e = [1, 2, 3]
|
||||
e.insert(3, 4)
|
||||
IO.print(e) // expect: [1, 2, 3, 4]
|
||||
System.print(e) // expect: [1, 2, 3, 4]
|
||||
|
||||
// Negative indices.
|
||||
var f = [1, 2, 3]
|
||||
f.insert(-4, 4)
|
||||
IO.print(f) // expect: [4, 1, 2, 3]
|
||||
System.print(f) // expect: [4, 1, 2, 3]
|
||||
|
||||
var g = [1, 2, 3]
|
||||
g.insert(-3, 4)
|
||||
IO.print(g) // expect: [1, 4, 2, 3]
|
||||
System.print(g) // expect: [1, 4, 2, 3]
|
||||
|
||||
var h = [1, 2, 3]
|
||||
h.insert(-2, 4)
|
||||
IO.print(h) // expect: [1, 2, 4, 3]
|
||||
System.print(h) // expect: [1, 2, 4, 3]
|
||||
|
||||
var i = [1, 2, 3]
|
||||
i.insert(-1, 4)
|
||||
IO.print(i) // expect: [1, 2, 3, 4]
|
||||
System.print(i) // expect: [1, 2, 3, 4]
|
||||
|
||||
// Returns.inserted value.
|
||||
IO.print([1, 2].insert(0, 3)) // expect: 3
|
||||
System.print([1, 2].insert(0, 3)) // expect: 3
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
var a = ["one", "two", "three", "four"]
|
||||
IO.print(a.iterate(null)) // expect: 0
|
||||
IO.print(a.iterate(0)) // expect: 1
|
||||
IO.print(a.iterate(1)) // expect: 2
|
||||
IO.print(a.iterate(2)) // expect: 3
|
||||
IO.print(a.iterate(3)) // expect: false
|
||||
System.print(a.iterate(null)) // expect: 0
|
||||
System.print(a.iterate(0)) // expect: 1
|
||||
System.print(a.iterate(1)) // expect: 2
|
||||
System.print(a.iterate(2)) // expect: 3
|
||||
System.print(a.iterate(3)) // expect: false
|
||||
|
||||
// Out of bounds.
|
||||
IO.print(a.iterate(123)) // expect: false
|
||||
IO.print(a.iterate(-1)) // expect: false
|
||||
System.print(a.iterate(123)) // expect: false
|
||||
System.print(a.iterate(-1)) // expect: false
|
||||
|
||||
// Nothing to iterate in an empty list.
|
||||
IO.print([].iterate(null)) // expect: false
|
||||
System.print([].iterate(null)) // expect: false
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var a = ["one", "two", "three", "four"]
|
||||
IO.print(a.iteratorValue(0)) // expect: one
|
||||
IO.print(a.iteratorValue(1)) // expect: two
|
||||
IO.print(a.iteratorValue(2)) // expect: three
|
||||
IO.print(a.iteratorValue(3)) // expect: four
|
||||
System.print(a.iteratorValue(0)) // expect: one
|
||||
System.print(a.iteratorValue(1)) // expect: two
|
||||
System.print(a.iteratorValue(2)) // expect: three
|
||||
System.print(a.iteratorValue(3)) // expect: four
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
// Handle empty list.
|
||||
IO.print([].join(",") == "") // expect: true
|
||||
System.print([].join(",") == "") // expect: true
|
||||
|
||||
// Handle a simple list with an empty delimeter.
|
||||
IO.print([1, 2, 3].join("")) // expect: 123
|
||||
System.print([1, 2, 3].join("")) // expect: 123
|
||||
|
||||
// Handle a simple list with no separator.
|
||||
IO.print([1, 2, 3].join) // expect: 123
|
||||
System.print([1, 2, 3].join) // expect: 123
|
||||
|
||||
// Does not quote strings.
|
||||
IO.print([1, "2", true].join(",")) // expect: 1,2,true
|
||||
System.print([1, "2", true].join(",")) // expect: 1,2,true
|
||||
|
||||
// Nested lists.
|
||||
IO.print([1, [2, [3], 4], 5].join(",")) // expect: 1,[2, [3], 4],5
|
||||
System.print([1, [2, [3], 4], 5].join(",")) // expect: 1,[2, [3], 4],5
|
||||
|
||||
// Calls toString on elements.
|
||||
class Foo {
|
||||
@@ -19,6 +19,6 @@ class Foo {
|
||||
toString { "Foo.toString" }
|
||||
}
|
||||
|
||||
IO.print([1, Foo.new(), 2].join(", ")) // expect: 1, Foo.toString, 2
|
||||
System.print([1, Foo.new(), 2].join(", ")) // expect: 1, Foo.toString, 2
|
||||
|
||||
// TODO: Handle lists that contain themselves.
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
var a = [1, 2, 3]
|
||||
var b = a.map {|x| x + 1 }.toList
|
||||
IO.print(b) // expect: [2, 3, 4]
|
||||
System.print(b) // expect: [2, 3, 4]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var list = List.new()
|
||||
|
||||
IO.print(list.count) // expect: 0
|
||||
IO.print(list) // expect: []
|
||||
System.print(list.count) // expect: 0
|
||||
System.print(list) // expect: []
|
||||
list.add(1)
|
||||
IO.print(list) // expect: [1]
|
||||
System.print(list) // expect: [1]
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
IO.print(![1, 2]) // expect: false
|
||||
IO.print(![]) // expect: false
|
||||
System.print(![1, 2]) // expect: false
|
||||
System.print(![]) // expect: false
|
||||
|
||||
@@ -6,13 +6,13 @@ var e = a + []
|
||||
var f = [] + a
|
||||
var g = [] + []
|
||||
|
||||
IO.print(a) // expect: [1, 2, 3]
|
||||
IO.print(b) // expect: [4, 5, 6]
|
||||
IO.print(c) // expect: [1, 2, 3, 4, 5, 6]
|
||||
IO.print(d) // expect: [1, 2, 3, 4, 5, 6]
|
||||
IO.print(e) // expect: [1, 2, 3]
|
||||
IO.print(f) // expect: [1, 2, 3]
|
||||
IO.print(g) // expect: []
|
||||
System.print(a) // expect: [1, 2, 3]
|
||||
System.print(b) // expect: [4, 5, 6]
|
||||
System.print(c) // expect: [1, 2, 3, 4, 5, 6]
|
||||
System.print(d) // expect: [1, 2, 3, 4, 5, 6]
|
||||
System.print(e) // expect: [1, 2, 3]
|
||||
System.print(f) // expect: [1, 2, 3]
|
||||
System.print(g) // expect: []
|
||||
|
||||
// Doesn't modify original list.
|
||||
IO.print(a) // expect: [1, 2, 3]
|
||||
System.print(a) // expect: [1, 2, 3]
|
||||
|
||||
@@ -3,12 +3,12 @@ var b = ["W", "o", "r", "l", "d"]
|
||||
var max = Fn.new {|a, b| a > b ? a : b }
|
||||
var sum = Fn.new {|a, b| a + b }
|
||||
|
||||
IO.print(a.reduce(max)) // expect: 5
|
||||
IO.print(a.reduce(10, max)) // expect: 10
|
||||
System.print(a.reduce(max)) // expect: 5
|
||||
System.print(a.reduce(10, max)) // expect: 10
|
||||
|
||||
IO.print(a.reduce(sum)) // expect: 13
|
||||
IO.print(a.reduce(-1, sum)) // expect: 12
|
||||
System.print(a.reduce(sum)) // expect: 13
|
||||
System.print(a.reduce(-1, sum)) // expect: 12
|
||||
|
||||
// sum also concatenates strings
|
||||
IO.print(b.reduce("Hello ", sum)) // expect: Hello World
|
||||
IO.print(b.reduce(sum)) // expect: World
|
||||
System.print(b.reduce("Hello ", sum)) // expect: Hello World
|
||||
System.print(b.reduce(sum)) // expect: World
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
IO.print([1].reduce {|a, b| 42 }) // expect: 1
|
||||
IO.print([].reduce(1) {|a, b| 42 }) // expect: 1
|
||||
System.print([1].reduce {|a, b| 42 }) // expect: 1
|
||||
System.print([].reduce(1) {|a, b| 42 }) // expect: 1
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
var a = [1, 2, 3]
|
||||
a.removeAt(0)
|
||||
IO.print(a) // expect: [2, 3]
|
||||
System.print(a) // expect: [2, 3]
|
||||
|
||||
var b = [1, 2, 3]
|
||||
b.removeAt(1)
|
||||
IO.print(b) // expect: [1, 3]
|
||||
System.print(b) // expect: [1, 3]
|
||||
|
||||
var c = [1, 2, 3]
|
||||
c.removeAt(2)
|
||||
IO.print(c) // expect: [1, 2]
|
||||
System.print(c) // expect: [1, 2]
|
||||
|
||||
// Index backwards from end.
|
||||
var d = [1, 2, 3]
|
||||
d.removeAt(-3)
|
||||
IO.print(d) // expect: [2, 3]
|
||||
System.print(d) // expect: [2, 3]
|
||||
|
||||
var e = [1, 2, 3]
|
||||
e.removeAt(-2)
|
||||
IO.print(e) // expect: [1, 3]
|
||||
System.print(e) // expect: [1, 3]
|
||||
|
||||
var f = [1, 2, 3]
|
||||
f.removeAt(-1)
|
||||
IO.print(f) // expect: [1, 2]
|
||||
System.print(f) // expect: [1, 2]
|
||||
|
||||
// Return the removed value.
|
||||
IO.print([3, 4, 5].removeAt(1)) // expect: 4
|
||||
System.print([3, 4, 5].removeAt(1)) // expect: 4
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// Returns elements.
|
||||
var list = ["a", "b", "c", "d"]
|
||||
IO.print(list[0]) // expect: a
|
||||
IO.print(list[1]) // expect: b
|
||||
IO.print(list[2]) // expect: c
|
||||
IO.print(list[3]) // expect: d
|
||||
System.print(list[0]) // expect: a
|
||||
System.print(list[1]) // expect: b
|
||||
System.print(list[2]) // expect: c
|
||||
System.print(list[3]) // expect: d
|
||||
|
||||
// Allows indexing backwards from the end.
|
||||
IO.print(list[-4]) // expect: a
|
||||
IO.print(list[-3]) // expect: b
|
||||
IO.print(list[-2]) // expect: c
|
||||
IO.print(list[-1]) // expect: d
|
||||
System.print(list[-4]) // expect: a
|
||||
System.print(list[-3]) // expect: b
|
||||
System.print(list[-2]) // expect: c
|
||||
System.print(list[-1]) // expect: d
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
// Returns lists.
|
||||
var list = ["a", "b", "c", "d", "e"]
|
||||
IO.print(list[0..0]) // expect: [a]
|
||||
IO.print(list[1...1]) // expect: []
|
||||
IO.print(list[1..2]) // expect: [b, c]
|
||||
IO.print(list[1...2]) // expect: [b]
|
||||
IO.print(list[2..4]) // expect: [c, d, e]
|
||||
IO.print(list[2...5]) // expect: [c, d, e]
|
||||
System.print(list[0..0]) // expect: [a]
|
||||
System.print(list[1...1]) // expect: []
|
||||
System.print(list[1..2]) // expect: [b, c]
|
||||
System.print(list[1...2]) // expect: [b]
|
||||
System.print(list[2..4]) // expect: [c, d, e]
|
||||
System.print(list[2...5]) // expect: [c, d, e]
|
||||
|
||||
// A backwards range reverses.
|
||||
IO.print(list[3..1]) // expect: [d, c, b]
|
||||
IO.print(list[3...1]) // expect: [d, c]
|
||||
IO.print(list[3...3]) // expect: []
|
||||
System.print(list[3..1]) // expect: [d, c, b]
|
||||
System.print(list[3...1]) // expect: [d, c]
|
||||
System.print(list[3...3]) // expect: []
|
||||
|
||||
// Negative ranges index from the end.
|
||||
IO.print(list[-5..-2]) // expect: [a, b, c, d]
|
||||
IO.print(list[-5...-2]) // expect: [a, b, c]
|
||||
IO.print(list[-3..-5]) // expect: [c, b, a]
|
||||
IO.print(list[-3...-6]) // expect: [c, b, a]
|
||||
System.print(list[-5..-2]) // expect: [a, b, c, d]
|
||||
System.print(list[-5...-2]) // expect: [a, b, c]
|
||||
System.print(list[-3..-5]) // expect: [c, b, a]
|
||||
System.print(list[-3...-6]) // expect: [c, b, a]
|
||||
|
||||
// Half-negative ranges are treated like the negative value is fixed before
|
||||
// walking the range.
|
||||
IO.print(list[-5..3]) // expect: [a, b, c, d]
|
||||
IO.print(list[-3...5]) // expect: [c, d, e]
|
||||
IO.print(list[-2..1]) // expect: [d, c, b]
|
||||
IO.print(list[-2...0]) // expect: [d, c, b]
|
||||
System.print(list[-5..3]) // expect: [a, b, c, d]
|
||||
System.print(list[-3...5]) // expect: [c, d, e]
|
||||
System.print(list[-2..1]) // expect: [d, c, b]
|
||||
System.print(list[-2...0]) // expect: [d, c, b]
|
||||
|
||||
IO.print(list[1..-2]) // expect: [b, c, d]
|
||||
IO.print(list[2...-1]) // expect: [c, d]
|
||||
IO.print(list[4..-5]) // expect: [e, d, c, b, a]
|
||||
IO.print(list[3...-6]) // expect: [d, c, b, a]
|
||||
System.print(list[1..-2]) // expect: [b, c, d]
|
||||
System.print(list[2...-1]) // expect: [c, d]
|
||||
System.print(list[4..-5]) // expect: [e, d, c, b, a]
|
||||
System.print(list[3...-6]) // expect: [d, c, b, a]
|
||||
|
||||
// An empty range at zero is allowed on an empty list.
|
||||
IO.print([][0...0]) // expect: []
|
||||
IO.print([][0..-1]) // expect: []
|
||||
System.print([][0...0]) // expect: []
|
||||
System.print([][0..-1]) // expect: []
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
list[0] = 5
|
||||
list[1] = 6
|
||||
list[2] = 7
|
||||
IO.print(list) // expect: [5, 6, 7]
|
||||
System.print(list) // expect: [5, 6, 7]
|
||||
}
|
||||
|
||||
// Returns right-hand side.
|
||||
{
|
||||
var list = [1, 2, 3]
|
||||
IO.print(list[1] = 5) // expect: 5
|
||||
System.print(list[1] = 5) // expect: 5
|
||||
}
|
||||
|
||||
// Negative indices.
|
||||
@@ -19,5 +19,5 @@
|
||||
list[-1] = 5
|
||||
list[-2] = 6
|
||||
list[-3] = 7
|
||||
IO.print(list) // expect: [7, 6, 5]
|
||||
System.print(list) // expect: [7, 6, 5]
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// Handle empty list.
|
||||
IO.print([].toString) // expect: []
|
||||
System.print([].toString) // expect: []
|
||||
|
||||
// Does not quote strings.
|
||||
IO.print([1, "2", true].toString) // expect: [1, 2, true]
|
||||
System.print([1, "2", true].toString) // expect: [1, 2, true]
|
||||
|
||||
// Nested lists.
|
||||
IO.print([1, [2, [3], 4], 5]) // expect: [1, [2, [3], 4], 5]
|
||||
System.print([1, [2, [3], 4], 5]) // expect: [1, [2, [3], 4], 5]
|
||||
|
||||
// Calls toString on elements.
|
||||
class Foo {
|
||||
@@ -13,6 +13,6 @@ class Foo {
|
||||
toString { "Foo.toString" }
|
||||
}
|
||||
|
||||
IO.print([1, Foo.new(), 2]) // expect: [1, Foo.toString, 2]
|
||||
System.print([1, Foo.new(), 2]) // expect: [1, Foo.toString, 2]
|
||||
|
||||
// TODO: Handle lists that contain themselves.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
IO.print([] is List) // expect: true
|
||||
IO.print([] is Sequence) // expect: true
|
||||
IO.print([] is Object) // expect: true
|
||||
IO.print([] is Bool) // expect: false
|
||||
IO.print([].type == List) // expect: true
|
||||
System.print([] is List) // expect: true
|
||||
System.print([] is Sequence) // expect: true
|
||||
System.print([] is Object) // expect: true
|
||||
System.print([] is Bool) // expect: false
|
||||
System.print([].type == List) // expect: true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var a = [1, 2, 3]
|
||||
var b = a.where {|x| x > 1 }.toList
|
||||
IO.print(b) // expect: [2, 3]
|
||||
System.print(b) // expect: [2, 3]
|
||||
|
||||
var c = a.where {|x| x > 10 }.toList
|
||||
IO.print(c) // expect: []
|
||||
System.print(c) // expect: []
|
||||
|
||||
@@ -8,4 +8,4 @@ for (i in 0...100) {
|
||||
if (i >= 10) map.remove(i - 10)
|
||||
}
|
||||
|
||||
IO.print(map.count) // expect: 10
|
||||
System.print(map.count) // expect: 10
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var a = {1: 1, 2: 2, 3: 3}
|
||||
a.clear()
|
||||
IO.print(a) // expect: {}
|
||||
IO.print(a.count) // expect: 0
|
||||
System.print(a) // expect: {}
|
||||
System.print(a.count) // expect: 0
|
||||
|
||||
// Returns null.
|
||||
IO.print({1: 2}.clear()) // expect: null
|
||||
System.print({1: 2}.clear()) // expect: null
|
||||
|
||||
@@ -4,8 +4,8 @@ var map = {
|
||||
"three": 3
|
||||
}
|
||||
|
||||
IO.print(map.containsKey("one")) // expect: true
|
||||
IO.print(map.containsKey("two")) // expect: true
|
||||
IO.print(map.containsKey("three")) // expect: true
|
||||
IO.print(map.containsKey("four")) // expect: false
|
||||
IO.print(map.containsKey("five")) // expect: false
|
||||
System.print(map.containsKey("one")) // expect: true
|
||||
System.print(map.containsKey("two")) // expect: true
|
||||
System.print(map.containsKey("three")) // expect: true
|
||||
System.print(map.containsKey("four")) // expect: false
|
||||
System.print(map.containsKey("five")) // expect: false
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
var map = {}
|
||||
IO.print(map.count) // expect: 0
|
||||
System.print(map.count) // expect: 0
|
||||
map["one"] = "value"
|
||||
IO.print(map.count) // expect: 1
|
||||
System.print(map.count) // expect: 1
|
||||
map["two"] = "value"
|
||||
IO.print(map.count) // expect: 2
|
||||
System.print(map.count) // expect: 2
|
||||
map["three"] = "value"
|
||||
IO.print(map.count) // expect: 3
|
||||
System.print(map.count) // expect: 3
|
||||
|
||||
// Adding existing key does not increase count.
|
||||
map["two"] = "new value"
|
||||
IO.print(map.count) // expect: 3
|
||||
System.print(map.count) // expect: 3
|
||||
|
||||
@@ -2,4 +2,4 @@ var map = {
|
||||
"": "empty string"
|
||||
}
|
||||
|
||||
IO.print(map[""]) // expect: empty string
|
||||
System.print(map[""]) // expect: empty string
|
||||
|
||||
@@ -4,23 +4,23 @@ var a = {"one": 1, "two": 2, "three": 3, "four": 4}.keys
|
||||
// entry table and the hashing process isn't specified. So we just validate
|
||||
// what we can assume about them.
|
||||
|
||||
IO.print(a.iterate(null) is Num) // expect: true
|
||||
IO.print(a.iterate(null) >= 0) // expect: true
|
||||
System.print(a.iterate(null) is Num) // expect: true
|
||||
System.print(a.iterate(null) >= 0) // expect: true
|
||||
|
||||
IO.print(a.iterate(0) is Num) // expect: true
|
||||
IO.print(a.iterate(0) > 0) // expect: true
|
||||
IO.print(a.iterate(1) is Num) // expect: true
|
||||
IO.print(a.iterate(1) > 0) // expect: true
|
||||
IO.print(a.iterate(2) is Num) // expect: true
|
||||
IO.print(a.iterate(2) > 0) // expect: true
|
||||
IO.print(a.iterate(3) is Num) // expect: true
|
||||
IO.print(a.iterate(3) > 0) // expect: true
|
||||
System.print(a.iterate(0) is Num) // expect: true
|
||||
System.print(a.iterate(0) > 0) // expect: true
|
||||
System.print(a.iterate(1) is Num) // expect: true
|
||||
System.print(a.iterate(1) > 0) // expect: true
|
||||
System.print(a.iterate(2) is Num) // expect: true
|
||||
System.print(a.iterate(2) > 0) // expect: true
|
||||
System.print(a.iterate(3) is Num) // expect: true
|
||||
System.print(a.iterate(3) > 0) // expect: true
|
||||
|
||||
var previous = -1
|
||||
var iterator = a.iterate(null)
|
||||
while (iterator) {
|
||||
IO.print(iterator > previous)
|
||||
IO.print(iterator is Num)
|
||||
System.print(iterator > previous)
|
||||
System.print(iterator is Num)
|
||||
previous = iterator
|
||||
iterator = a.iterate(iterator)
|
||||
}
|
||||
@@ -38,8 +38,8 @@ while (iterator) {
|
||||
// expect: true
|
||||
|
||||
// Out of bounds.
|
||||
IO.print(a.iterate(16)) // expect: false
|
||||
IO.print(a.iterate(-1)) // expect: false
|
||||
System.print(a.iterate(16)) // expect: false
|
||||
System.print(a.iterate(-1)) // expect: false
|
||||
|
||||
// Nothing to iterate in an empty map.
|
||||
IO.print({}.keys.iterate(null)) // expect: false
|
||||
System.print({}.keys.iterate(null)) // expect: false
|
||||
|
||||
@@ -12,17 +12,17 @@ var map = {
|
||||
fiber: "fiber"
|
||||
}
|
||||
|
||||
IO.print(map[null]) // expect: null value
|
||||
IO.print(map[true]) // expect: true value
|
||||
IO.print(map[false]) // expect: false value
|
||||
IO.print(map[0]) // expect: zero
|
||||
IO.print(map[1.2]) // expect: 1 point 2
|
||||
IO.print(map[List]) // expect: list class
|
||||
IO.print(map["null"]) // expect: string value
|
||||
IO.print(map[1..3]) // expect: 1 to 3
|
||||
IO.print(map[fiber]) // expect: fiber
|
||||
System.print(map[null]) // expect: null value
|
||||
System.print(map[true]) // expect: true value
|
||||
System.print(map[false]) // expect: false value
|
||||
System.print(map[0]) // expect: zero
|
||||
System.print(map[1.2]) // expect: 1 point 2
|
||||
System.print(map[List]) // expect: list class
|
||||
System.print(map["null"]) // expect: string value
|
||||
System.print(map[1..3]) // expect: 1 to 3
|
||||
System.print(map[fiber]) // expect: fiber
|
||||
|
||||
IO.print(map.count) // expect: 9
|
||||
System.print(map.count) // expect: 9
|
||||
|
||||
// Use the same keys (but sometimes different objects) to ensure keys have the
|
||||
// right equality semantics.
|
||||
@@ -35,13 +35,13 @@ map[[].type] = "new list class"
|
||||
map["nu" + "ll"] = "new string value"
|
||||
map[(3 - 2)..(1 + 2)] = "new 1 to 3"
|
||||
|
||||
IO.print(map[null]) // expect: new null value
|
||||
IO.print(map[true]) // expect: new true value
|
||||
IO.print(map[false]) // expect: new false value
|
||||
IO.print(map[0]) // expect: new zero
|
||||
IO.print(map[1.2]) // expect: new 1 point 2
|
||||
IO.print(map[List]) // expect: new list class
|
||||
IO.print(map["null"]) // expect: new string value
|
||||
IO.print(map[1..3]) // expect: new 1 to 3
|
||||
System.print(map[null]) // expect: new null value
|
||||
System.print(map[true]) // expect: new true value
|
||||
System.print(map[false]) // expect: new false value
|
||||
System.print(map[0]) // expect: new zero
|
||||
System.print(map[1.2]) // expect: new 1 point 2
|
||||
System.print(map[List]) // expect: new list class
|
||||
System.print(map["null"]) // expect: new string value
|
||||
System.print(map[1..3]) // expect: new 1 to 3
|
||||
|
||||
IO.print(map.count) // expect: 9
|
||||
System.print(map.count) // expect: 9
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var map = Map.new()
|
||||
|
||||
IO.print(map.count) // expect: 0
|
||||
IO.print(map) // expect: {}
|
||||
System.print(map.count) // expect: 0
|
||||
System.print(map) // expect: {}
|
||||
|
||||
@@ -4,15 +4,15 @@ var map = {
|
||||
"three": 3
|
||||
}
|
||||
|
||||
IO.print(map.count) // expect: 3
|
||||
IO.print(map.remove("two")) // expect: 2
|
||||
IO.print(map.count) // expect: 2
|
||||
IO.print(map.remove("three")) // expect: 3
|
||||
IO.print(map.count) // expect: 1
|
||||
System.print(map.count) // expect: 3
|
||||
System.print(map.remove("two")) // expect: 2
|
||||
System.print(map.count) // expect: 2
|
||||
System.print(map.remove("three")) // expect: 3
|
||||
System.print(map.count) // expect: 1
|
||||
|
||||
// Remove an already removed entry.
|
||||
IO.print(map.remove("two")) // expect: null
|
||||
IO.print(map.count) // expect: 1
|
||||
System.print(map.remove("two")) // expect: null
|
||||
System.print(map.count) // expect: 1
|
||||
|
||||
IO.print(map.remove("one")) // expect: 1
|
||||
IO.print(map.count) // expect: 0
|
||||
System.print(map.remove("one")) // expect: 1
|
||||
System.print(map.count) // expect: 0
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// This is a regression test to ensure map handles a null entry array.
|
||||
|
||||
var map = {}
|
||||
IO.print(map["key"]) // expect: null
|
||||
System.print(map["key"]) // expect: null
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// Handle empty map.
|
||||
IO.print({}.toString) // expect: {}
|
||||
System.print({}.toString) // expect: {}
|
||||
|
||||
// Does not quote strings.
|
||||
IO.print({"1": "2"}.toString) // expect: {1: 2}
|
||||
System.print({"1": "2"}.toString) // expect: {1: 2}
|
||||
|
||||
// Nested maps.
|
||||
IO.print({1: {2: {}}}) // expect: {1: {2: {}}}
|
||||
System.print({1: {2: {}}}) // expect: {1: {2: {}}}
|
||||
|
||||
// Calls toString on elements.
|
||||
class Foo {
|
||||
@@ -13,12 +13,12 @@ class Foo {
|
||||
toString { "Foo.toString" }
|
||||
}
|
||||
|
||||
IO.print({1: Foo.new()}) // expect: {1: Foo.toString}
|
||||
System.print({1: Foo.new()}) // expect: {1: Foo.toString}
|
||||
|
||||
// Since iteration order is unspecified, we don't know what order the results
|
||||
// will be.
|
||||
var s = {1: 2, 3: 4, 5: 6}.toString
|
||||
IO.print(s == "{1: 2, 3: 4, 5: 6}" ||
|
||||
System.print(s == "{1: 2, 3: 4, 5: 6}" ||
|
||||
s == "{1: 2, 5: 6, 3: 4}" ||
|
||||
s == "{3: 4, 1: 2, 5: 6}" ||
|
||||
s == "{3: 4, 5: 6, 1: 2}" ||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
IO.print({} is Map) // expect: true
|
||||
System.print({} is Map) // expect: true
|
||||
// TODO: Abstract base class for associations.
|
||||
IO.print({} is Object) // expect: true
|
||||
IO.print({} is Bool) // expect: false
|
||||
IO.print({}.type == Map) // expect: true
|
||||
System.print({} is Object) // expect: true
|
||||
System.print({} is Bool) // expect: false
|
||||
System.print({}.type == Map) // expect: true
|
||||
|
||||
@@ -4,23 +4,23 @@ var a = {"one": 1, "two": 2, "three": 3, "four": 4}.values
|
||||
// entry table and the hashing process isn't specified. So we just validate
|
||||
// what we can assume about them.
|
||||
|
||||
IO.print(a.iterate(null) is Num) // expect: true
|
||||
IO.print(a.iterate(null) >= 0) // expect: true
|
||||
System.print(a.iterate(null) is Num) // expect: true
|
||||
System.print(a.iterate(null) >= 0) // expect: true
|
||||
|
||||
IO.print(a.iterate(0) is Num) // expect: true
|
||||
IO.print(a.iterate(0) > 0) // expect: true
|
||||
IO.print(a.iterate(1) is Num) // expect: true
|
||||
IO.print(a.iterate(1) > 0) // expect: true
|
||||
IO.print(a.iterate(2) is Num) // expect: true
|
||||
IO.print(a.iterate(2) > 0) // expect: true
|
||||
IO.print(a.iterate(3) is Num) // expect: true
|
||||
IO.print(a.iterate(3) > 0) // expect: true
|
||||
System.print(a.iterate(0) is Num) // expect: true
|
||||
System.print(a.iterate(0) > 0) // expect: true
|
||||
System.print(a.iterate(1) is Num) // expect: true
|
||||
System.print(a.iterate(1) > 0) // expect: true
|
||||
System.print(a.iterate(2) is Num) // expect: true
|
||||
System.print(a.iterate(2) > 0) // expect: true
|
||||
System.print(a.iterate(3) is Num) // expect: true
|
||||
System.print(a.iterate(3) > 0) // expect: true
|
||||
|
||||
var previous = -1
|
||||
var iterator = a.iterate(null)
|
||||
while (iterator) {
|
||||
IO.print(iterator > previous)
|
||||
IO.print(iterator is Num)
|
||||
System.print(iterator > previous)
|
||||
System.print(iterator is Num)
|
||||
previous = iterator
|
||||
iterator = a.iterate(iterator)
|
||||
}
|
||||
@@ -38,8 +38,8 @@ while (iterator) {
|
||||
// expect: true
|
||||
|
||||
// Out of bounds.
|
||||
IO.print(a.iterate(16)) // expect: false
|
||||
IO.print(a.iterate(-1)) // expect: false
|
||||
System.print(a.iterate(16)) // expect: false
|
||||
System.print(a.iterate(-1)) // expect: false
|
||||
|
||||
// Nothing to iterate in an empty map.
|
||||
IO.print({}.values.iterate(null)) // expect: false
|
||||
System.print({}.values.iterate(null)) // expect: false
|
||||
|
||||
@@ -1 +1 @@
|
||||
IO.print(!null) // expect: true
|
||||
System.print(!null) // expect: true
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
IO.print(null is Null) // expect: true
|
||||
IO.print(null is Object) // expect: true
|
||||
IO.print(null is Bool) // expect: false
|
||||
IO.print(null.type == Null) // expect: true
|
||||
System.print(null is Null) // expect: true
|
||||
System.print(null is Object) // expect: true
|
||||
System.print(null is Bool) // expect: false
|
||||
System.print(null.type == Null) // expect: true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
IO.print(123.abs) // expect: 123
|
||||
IO.print((-123).abs) // expect: 123
|
||||
IO.print(0.abs) // expect: 0
|
||||
IO.print((-0).abs) // expect: 0
|
||||
IO.print((-0.12).abs) // expect: 0.12
|
||||
IO.print(12.34.abs) // expect: 12.34
|
||||
System.print(123.abs) // expect: 123
|
||||
System.print((-123).abs) // expect: 123
|
||||
System.print(0.abs) // expect: 0
|
||||
System.print((-0).abs) // expect: 0
|
||||
System.print((-0.12).abs) // expect: 0.12
|
||||
System.print(12.34.abs) // expect: 12.34
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
IO.print(0.acos) // expect: 1.5707963267949
|
||||
IO.print(1.acos) // expect: 0
|
||||
IO.print((-1).acos) // expect: 3.1415926535898
|
||||
System.print(0.acos) // expect: 1.5707963267949
|
||||
System.print(1.acos) // expect: 0
|
||||
System.print((-1).acos) // expect: 3.1415926535898
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
IO.print(0.asin) // expect: 0
|
||||
IO.print(1.asin) // expect: 1.5707963267949
|
||||
IO.print((-1).asin) // expect: -1.5707963267949
|
||||
System.print(0.asin) // expect: 0
|
||||
System.print(1.asin) // expect: 1.5707963267949
|
||||
System.print((-1).asin) // expect: -1.5707963267949
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
IO.print(0.atan) // expect: 0
|
||||
IO.print(1.atan) // expect: 0.78539816339745
|
||||
System.print(0.atan) // expect: 0
|
||||
System.print(1.atan) // expect: 0.78539816339745
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user