2019-01-13 20:33:38 -06:00
|
|
|
let tpl = import "std/tuples.ucg";
|
2019-04-09 20:43:42 -05:00
|
|
|
let t = (import "std/testing.ucg");
|
2019-01-09 22:25:11 -06:00
|
|
|
|
2019-01-13 09:37:44 -06:00
|
|
|
assert t.equal{
|
2019-02-24 08:16:07 -06:00
|
|
|
left = tpl.fields{tpl={foo=1, bar=2}},
|
2019-01-09 22:25:11 -06:00
|
|
|
right = ["foo", "bar"],
|
|
|
|
};
|
|
|
|
|
2019-04-15 22:14:18 -05:00
|
|
|
assert t.equal{
|
|
|
|
left = tpl.ops{tpl={foo=1, bar=2}}.fields(),
|
|
|
|
right = ["foo", "bar"],
|
|
|
|
};
|
|
|
|
|
2019-01-13 09:37:44 -06:00
|
|
|
assert t.equal{
|
2019-02-24 08:16:07 -06:00
|
|
|
left = tpl.values{tpl={foo=1, bar=2}},
|
2019-01-09 22:25:11 -06:00
|
|
|
right = [1, 2],
|
2019-01-09 22:33:03 -06:00
|
|
|
};
|
|
|
|
|
2019-04-15 22:14:18 -05:00
|
|
|
assert t.equal{
|
|
|
|
left = tpl.ops{tpl={foo=1, bar=2}}.values(),
|
|
|
|
right = [1, 2],
|
|
|
|
};
|
|
|
|
|
2019-01-13 09:37:44 -06:00
|
|
|
assert t.equal{
|
2019-02-24 08:16:07 -06:00
|
|
|
left = tpl.iter{tpl={foo=1, bar=2}},
|
2019-01-09 22:33:03 -06:00
|
|
|
right = [["foo", 1], ["bar", 2]],
|
2019-01-15 19:31:55 -06:00
|
|
|
};
|
|
|
|
|
2019-04-15 22:14:18 -05:00
|
|
|
assert t.equal{
|
|
|
|
left = tpl.ops{tpl={foo=1, bar=2}}.iter(),
|
|
|
|
right = [["foo", 1], ["bar", 2]],
|
|
|
|
};
|
|
|
|
|
2019-01-15 19:31:55 -06:00
|
|
|
assert t.equal{
|
2019-02-24 08:16:07 -06:00
|
|
|
left = tpl.strip_nulls{tpl={foo="bar", bar=NULL}},
|
2019-01-15 19:31:55 -06:00
|
|
|
right = {foo="bar"},
|
2019-01-19 13:06:43 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
assert t.ok{
|
2019-02-24 08:16:07 -06:00
|
|
|
test = tpl.has_fields{tpl={foo=1, bar=2}, fields=["foo", "bar"]},
|
2019-01-19 13:06:43 -06:00
|
|
|
desc = "tuple has fields has foo and bar fields",
|
|
|
|
};
|
|
|
|
|
|
|
|
assert t.not_ok{
|
2019-02-24 08:16:07 -06:00
|
|
|
test = tpl.has_fields{tpl={blah=1, bar=2}, fields=["foo", "bar"]},
|
2019-01-19 13:06:43 -06:00
|
|
|
desc = "tuple does not have fields foo and bar",
|
|
|
|
};
|
|
|
|
|
|
|
|
assert t.ok{
|
|
|
|
test = tpl.field_type{
|
|
|
|
tpl={foo=1},
|
|
|
|
field="foo",
|
|
|
|
type="int",
|
2019-02-24 08:16:07 -06:00
|
|
|
},
|
2019-01-19 13:06:43 -06:00
|
|
|
desc = "tuple has field of type int",
|
2019-01-09 22:25:11 -06:00
|
|
|
};
|