mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 22:28:45 +01:00
Add more forall test cases.
This commit is contained in:
@ -17,7 +17,7 @@ class Sequence {
|
||||
|
||||
forall(f) {
|
||||
for (element in this) {
|
||||
if (f.call(element) != true) return false
|
||||
if (!f.call(element)) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ static const char* libSource =
|
||||
"\n"
|
||||
" forall(f) {\n"
|
||||
" for (element in this) {\n"
|
||||
" if (f.call(element) != true) return false\n"
|
||||
" if (!f.call(element)) return false\n"
|
||||
" }\n"
|
||||
" return true\n"
|
||||
" }\n"
|
||||
|
||||
@ -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
|
||||
|
||||
1
test/list/forall_non_bool_returning_fn.wren
Normal file
1
test/list/forall_non_bool_returning_fn.wren
Normal file
@ -0,0 +1 @@
|
||||
[1, 2, 3].forall {|x| "string" } // expect runtime error: String does not implement method '!' with 0 arguments.
|
||||
1
test/list/forall_non_function_arg.wren
Normal file
1
test/list/forall_non_function_arg.wren
Normal file
@ -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