erg/tests/should_ok/default_param.er
2024-09-15 12:48:33 +09:00

28 lines
664 B
Python

f x: Int, y: Int := 1, z: Nat := 2 = x + y + z
assert f(1) == 4
assert f(1, 2) == 5
assert f(1, 2, 3) == 6
id_or_int x := 1 = x
i = id_or_int()
s = id_or_int "a"
assert i + 1 + 1 == 3
assert s + "b" == "ab"
_: (Int, y := Int, z := Nat) -> Int = f
_: (Int, y := Int) -> Int = f
_: Int -> Int = f
_: (Int, Int) -> Int = f
_: (Int, Int, Nat) -> Int = f
_: (Int, Int, _: {1}) -> Int = f
_: Int -> Int = id_or_int
_: Str -> Str = id_or_int
check f: (Int, n := Int) -> Int = f(1)
check2 f: (m := Int, n := Int) -> Int = f(m:=1, n:=2)
f2(m: Int := 1, n := 1, l := 1) = m + n + l
f3(*x: Int, **y: Int) = len(x) + y.get("n", 0)
_ = check2 f2
_ = check f3
_ = check2 f3