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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#!../../liquidsoap ../test.liq
count = ref(1)
fail = ref(false)
def echo(s) =
print(s)
if s != string(count()) then fail := true end
count := count() + 1
()
end
def t(lbl, f) =
if
f()
then
echo(lbl)
else
echo(
"fail #{lbl}"
)
end
end
def f() =
t("1", {1 == 1})
t("2", {1 + 1 == 2})
t("3", {(-1) + 2 == 1})
t("4", {(-1) + 2 <= 3 * 2})
t("5", {true})
t("6", {true and true})
t("7", {1 == 1 and 1 == 1})
t("8", {(1 == 1) and (1 == 1)})
t("9", {true and (-1) + 2 <= 3 * 2})
l = [("bla", ""), ("bli", "x"), ("blo", "xx"), ("blu", "xxx"), ("dix", "10")]
echo(l["dix"])
t("11", {2 == list.length(r//.split(l["blo"]))})
echo("1#{1 + 1}")
echo(string(int_of_float(float_of_string(default=13., "blah"))))
f = fun (x) -> x
# Checking that the following is not recursive:
f = fun (x) -> f(x)
echo(string(f(14)))
t("15", {list.remove(2, [2]) == []})
t("16", {"bla" == (true ? "bla" : "foo" )})
t("17", {"foo" == (false ? "bla" : "foo" )})
# Generic eval
let eval x =
"{foo = 123, gni = \"aabbcc\"}"
t("18", {x.foo == 123})
t("19", {x.gni == "aabbcc"})
# Eval with sources!
let eval x =
"output.dummy(id='bla', blank())"
t("20", {x.id() == "bla"})
# Eval with patterns
let eval {foo, gni, gni = [x, y]} =
"{foo = 123, gni = [1,2]}"
t("21", {foo == 123})
t("22", {gni == [1, 2]})
t("23", {x == 1})
t("24", {y == 2})
# Eval with type cast
let eval ([x, y] : [int]) = "[123,456]"
t("25", {(x, y) == (123, 456)})
# @ infix notation
def f(x) =
2 * x
end
t("26", {2 @ f == 4})
if fail() then test.fail() else test.pass() end
end
test.check(f)
|