-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_lambda.t
34 lines (29 loc) · 906 Bytes
/
test_lambda.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
-- SPDX-FileCopyrightText: 2024 René Hiemstra <[email protected]>
-- SPDX-FileCopyrightText: 2024 Torsten Keßler <[email protected]>
--
-- SPDX-License-Identifier: MIT
import "terratest/terratest"
local lambda = require("lambda")
testenv "lambda's" do
testset "no captures" do
terracode
var p = lambda.new([terra(i : int) return i * i end])
end
test p(1) == 1
test p(2) == 4
end
testset "with captured vars" do
--the capture is an anonymous struct. the order of the variables needs
--to match the function signature.
terracode
var x, y = 2, 3
var p = lambda.new(
[terra(i : int, x : int, y : int) return i * i * x * y end]
, {x = 2, y = 3}
)
end
test p(1) == 6
test p(2) == 24
test p.x == 2 and p.y == 3
end
end