test: add forall test for empty list and non-bool/non-function args
Add test case verifying that `forall` returns true for an empty list regardless of predicate, and add two new test files covering runtime errors when `forall` receives a non-boolean-returning function or a non-function argument. Also refactor the `forall` implementation to use logical negation (`!`) instead of explicit `!= true` comparison.
This commit is contained in:
@@ -2,8 +2,8 @@ var a = [1, 2, 3]
|
||||
var b = a.forall {|x| x > 1 }
|
||||
IO.print(b) // expect: false
|
||||
|
||||
var c = a.forall {|x| x.toString }
|
||||
IO.print(c) // expect: false
|
||||
|
||||
var d = a.forall {|x| x > 0 }
|
||||
IO.print(d) // expect: true
|
||||
|
||||
var e = [].forall {|x| false }
|
||||
IO.print(e) // expect: true
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
[1, 2, 3].forall {|x| "string" } // expect runtime error: String does not implement method '!' with 0 arguments.
|
||||
@@ -0,0 +1 @@
|
||||
[1, 2, 3].forall("string") // expect runtime error: String does not implement method 'call' with 1 argument.
|
||||
Reference in New Issue
Block a user