mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 22:28:45 +01:00
Handle extra and missing arguments to fn.call.
This commit is contained in:
16
test/function/call_extra_arguments.wren
Normal file
16
test/function/call_extra_arguments.wren
Normal file
@ -0,0 +1,16 @@
|
||||
var f0 = fn IO.print("zero")
|
||||
var f1 = fn(a) IO.print("one " + a)
|
||||
var f2 = fn(a, b) IO.print("two " + a + " " + b)
|
||||
var f3 = fn(a, b, c) IO.print("three " + a + " " + b + " " + c)
|
||||
|
||||
f0.call("a") // expect: zero
|
||||
f0.call("a", "b") // expect: zero
|
||||
|
||||
f1.call("a", "b") // expect: one a
|
||||
f1.call("a", "b", "c") // expect: one a
|
||||
|
||||
f2.call("a", "b", "c") // expect: two a b
|
||||
f2.call("a", "b", "c", "d") // expect: two a b
|
||||
|
||||
f3.call("a", "b", "c", "d") // expect: three a b c
|
||||
f3.call("a", "b", "c", "d", "e") // expect: three a b c
|
||||
2
test/function/call_missing_arguments.wren
Normal file
2
test/function/call_missing_arguments.wren
Normal file
@ -0,0 +1,2 @@
|
||||
var f2 = fn(a, b) IO.print(a + b)
|
||||
f2.call("a") // expect runtime error: Function expects more arguments.
|
||||
Reference in New Issue
Block a user