ucg/integration_tests/functional_processing_test.ucg

78 lines
1.5 KiB
Plaintext
Raw Normal View History

let list1 = [1, 2, 3, 4];
let list2 = ["foo", "bar", "foo", "bar"];
let mapper = macro(item) => { result = item + 1 };
let filtrator = macro(item) => {
result = select item, NULL, {
foo = item,
},
};
let boolfiltrator = macro(item) => {
result = item < 5,
};
assert |
map mapper.result list1 == [2, 3, 4, 5];
|;
assert |
(map mapper.result [1, 2, 3, 4]) == [2, 3, 4, 5];
|;
assert |
map mapper.result [1, 2, 3, 4] == [2, 3, 4, 5];
|;
assert |
filter filtrator.result list2 == ["foo", "foo"];
|;
assert |
(filter filtrator.result ["foo", "bar", "foo", "bar"]) == ["foo", "foo"];
|;
assert |
filter filtrator.result ["foo", "bar", "foo", "bar"] == ["foo", "foo"];
|;
assert |
filter boolfiltrator.result [1, 2, 3, 4, 5, 6, 7] == [1, 2, 3, 4];
|;
// Tuple processing
let test_tpl = {
foo = "bar",
quux = "baz",
};
let identity_tpl_mapper = macro(name, val) => {
result = [name, val],
};
assert |
map identity_tpl_mapper.result test_tpl == test_tpl;
|;
let tpl_mapper = macro(name, val) => {
result = select name, [name, val], {
"foo" = ["foo", "barbar"],
quux = ["cute", "pygmy"],
},
};
assert |
map tpl_mapper.result test_tpl == {foo = "barbar", cute = "pygmy"};
|;
let identity_tpl_filter = macro(name, val) => {
result = true,
};
// strip out foo field
let tpl_filter = macro(name, val) => {
result = name != "foo",
};
assert |
filter identity_tpl_filter.result test_tpl == test_tpl;
|;
assert |
filter tpl_filter.result test_tpl == { quux = "baz" };
|;