lang: funcs: Add lookup default func for list or map
This version requires you specify the default value.
This commit is contained in:
40
lang/interpret_test/TestAstFunc2/lookup0.txtar
Normal file
40
lang/interpret_test/TestAstFunc2/lookup0.txtar
Normal file
@@ -0,0 +1,40 @@
|
||||
-- main.mcl --
|
||||
$l1 = ["a", "b", "c",]
|
||||
|
||||
$l2 = [$l1, ["hello", "world",],]
|
||||
|
||||
test $l1[0] || "fail" {}
|
||||
test $l1[2] || "fail" {}
|
||||
test $l1[3] || "pass" {}
|
||||
test $l2[1] || ["fail",] {}
|
||||
|
||||
$map1 map{int: str} = {42 => "hello1",}
|
||||
test $map1[42] || "not found" {}
|
||||
|
||||
$map2 map{int: str} = {42 => "hello2",}
|
||||
test $map2[13] || "world2" {}
|
||||
|
||||
$map3 = {42 => "hello3",}
|
||||
test $map3[42] || "not found" {}
|
||||
|
||||
$map4 = {42 => "hello4",}
|
||||
test $map4[13] || "world4" {}
|
||||
|
||||
$map5 = {"wow" => "pass1",}
|
||||
test $map5["wow"] || "fail" {}
|
||||
|
||||
$map6 = {"wow" => "fail",}
|
||||
test $map6["mom"] || "pass2" {}
|
||||
|
||||
-- OUTPUT --
|
||||
Vertex: test[a]
|
||||
Vertex: test[c]
|
||||
Vertex: test[hello1]
|
||||
Vertex: test[hello3]
|
||||
Vertex: test[hello]
|
||||
Vertex: test[pass1]
|
||||
Vertex: test[pass2]
|
||||
Vertex: test[pass]
|
||||
Vertex: test[world2]
|
||||
Vertex: test[world4]
|
||||
Vertex: test[world]
|
||||
Reference in New Issue
Block a user