mirror of
https://github.com/gorules/zen.git
synced 2026-12-03 16:10:41 +00:00
484 lines
9.6 KiB
TOML
484 lines
9.6 KiB
TOML
# Built-in function type inference and dependency tracking
|
|
|
|
[[test]]
|
|
name = "sum function"
|
|
expression = "sum([a, b, c])"
|
|
input = '{"a": 1, "b": 2, "c": 3}'
|
|
reads = [
|
|
{ type = "direct", path = ["a"] },
|
|
{ type = "direct", path = ["b"] },
|
|
{ type = "direct", path = ["c"] },
|
|
]
|
|
|
|
[test.loose]
|
|
return_type = '"Number"'
|
|
|
|
[test.strict]
|
|
return_type = '"Number"'
|
|
|
|
[[test]]
|
|
name = "len function"
|
|
expression = "len(items)"
|
|
input = '{"items": [1, 2, 3]}'
|
|
reads = [
|
|
{ type = "direct", path = ["items"] },
|
|
]
|
|
|
|
[test.loose]
|
|
return_type = '"Number"'
|
|
|
|
[test.strict]
|
|
return_type = '"Number"'
|
|
|
|
[[test]]
|
|
name = "max function"
|
|
expression = "max([a, b])"
|
|
input = '{"a": 10, "b": 20}'
|
|
reads = [
|
|
{ type = "direct", path = ["a"] },
|
|
{ type = "direct", path = ["b"] },
|
|
]
|
|
|
|
[test.loose]
|
|
return_type = '"Number"'
|
|
|
|
[test.strict]
|
|
return_type = '"Number"'
|
|
|
|
[[test]]
|
|
name = "min function"
|
|
expression = "min([a, b])"
|
|
input = '{"a": 10, "b": 20}'
|
|
reads = [
|
|
{ type = "direct", path = ["a"] },
|
|
{ type = "direct", path = ["b"] },
|
|
]
|
|
|
|
[test.loose]
|
|
return_type = '"Number"'
|
|
|
|
[test.strict]
|
|
return_type = '"Number"'
|
|
|
|
[[test]]
|
|
name = "floor function"
|
|
expression = "floor(x)"
|
|
input = '{"x": 5.7}'
|
|
reads = [
|
|
{ type = "direct", path = ["x"] },
|
|
]
|
|
|
|
[test.loose]
|
|
return_type = '"Number"'
|
|
|
|
[test.strict]
|
|
return_type = '"Number"'
|
|
|
|
[[test]]
|
|
name = "ceil function"
|
|
expression = "ceil(x)"
|
|
input = '{"x": 5.2}'
|
|
reads = [
|
|
{ type = "direct", path = ["x"] },
|
|
]
|
|
|
|
[test.loose]
|
|
return_type = '"Number"'
|
|
|
|
[test.strict]
|
|
return_type = '"Number"'
|
|
|
|
[[test]]
|
|
name = "abs function"
|
|
expression = "abs(x)"
|
|
input = '{"x": -5}'
|
|
reads = [
|
|
{ type = "direct", path = ["x"] },
|
|
]
|
|
|
|
[test.loose]
|
|
return_type = '"Number"'
|
|
|
|
[test.strict]
|
|
return_type = '"Number"'
|
|
|
|
[[test]]
|
|
name = "upper function"
|
|
expression = "upper(name)"
|
|
input = '{"name": "hello"}'
|
|
reads = [
|
|
{ type = "direct", path = ["name"] },
|
|
]
|
|
|
|
[test.loose]
|
|
return_type = '"String"'
|
|
|
|
[test.strict]
|
|
return_type = '"String"'
|
|
|
|
[[test]]
|
|
name = "lower function"
|
|
expression = "lower(name)"
|
|
input = '{"name": "HELLO"}'
|
|
reads = [
|
|
{ type = "direct", path = ["name"] },
|
|
]
|
|
|
|
[test.loose]
|
|
return_type = '"String"'
|
|
|
|
[test.strict]
|
|
return_type = '"String"'
|
|
|
|
[[test]]
|
|
name = "contains function"
|
|
expression = "contains(text, 'world')"
|
|
input = '{"text": "hello world"}'
|
|
reads = [
|
|
{ type = "direct", path = ["text"] },
|
|
]
|
|
|
|
[test.loose]
|
|
return_type = '"Bool"'
|
|
|
|
[test.strict]
|
|
return_type = '"Bool"'
|
|
|
|
[[test]]
|
|
name = "startsWith function"
|
|
expression = "startsWith(text, 'hello')"
|
|
input = '{"text": "hello world"}'
|
|
reads = [
|
|
{ type = "direct", path = ["text"] },
|
|
]
|
|
|
|
[test.loose]
|
|
return_type = '"Bool"'
|
|
|
|
[test.strict]
|
|
return_type = '"Bool"'
|
|
|
|
[[test]]
|
|
name = "endsWith function"
|
|
expression = "endsWith(text, 'world')"
|
|
input = '{"text": "hello world"}'
|
|
reads = [
|
|
{ type = "direct", path = ["text"] },
|
|
]
|
|
|
|
[test.loose]
|
|
return_type = '"Bool"'
|
|
|
|
[test.strict]
|
|
return_type = '"Bool"'
|
|
|
|
[[test]]
|
|
name = "merge of an any-typed array"
|
|
expression = "merge([a, b])"
|
|
input = '{"Object":{"a":"Any","b":"Any"}}'
|
|
|
|
[test.loose]
|
|
return_type = '"Any"'
|
|
|
|
[test.strict]
|
|
return_type = '"Any"'
|
|
|
|
[[test]]
|
|
name = "merge of empty array literal"
|
|
expression = "merge([])"
|
|
|
|
[test.loose]
|
|
return_type = '"Any"'
|
|
|
|
[test.strict]
|
|
return_type = '"Any"'
|
|
|
|
[[test]]
|
|
name = "merge of scalar array errors"
|
|
expression = "merge([1, 2])"
|
|
|
|
[test.loose]
|
|
diagnostics = [
|
|
{ source = "type_check", severity = "error" },
|
|
]
|
|
|
|
[test.strict]
|
|
diagnostics = [
|
|
{ source = "type_check", severity = "error" },
|
|
]
|
|
|
|
[[test]]
|
|
name = "merge nullable object with object"
|
|
expression = "merge([a, {y: 1}])"
|
|
input = '{"Object": {"a": {"Nullable": {"Object": {"x": "Number"}}}}}'
|
|
|
|
[test.loose]
|
|
return_type = '{"Object": {"x": "Number", "y": "Number"}}'
|
|
|
|
[test.strict]
|
|
return_type = '{"Object": {"x": "Number", "y": "Number"}}'
|
|
|
|
[[test]]
|
|
name = "merge null literal with object"
|
|
expression = "merge([null, {y: 1}])"
|
|
|
|
[test.loose]
|
|
return_type = '{"Object": {"y": "Number"}}'
|
|
|
|
[test.strict]
|
|
return_type = '{"Object": {"y": "Number"}}'
|
|
|
|
[[test]]
|
|
name = "mergeDeep nullable object with object"
|
|
expression = "mergeDeep([a, {y: 1}])"
|
|
input = '{"Object": {"a": {"Nullable": {"Object": {"x": "Number"}}}}}'
|
|
|
|
[test.loose]
|
|
return_type = '{"Object": {"x": "Number", "y": "Number"}}'
|
|
|
|
[test.strict]
|
|
return_type = '{"Object": {"x": "Number", "y": "Number"}}'
|
|
|
|
[[test]]
|
|
name = "merge of non-array argument errors"
|
|
expression = "merge(a)"
|
|
input = '{"Object": {"a": {"Object": {"x": "Number"}}}}'
|
|
|
|
[test.loose]
|
|
diagnostics = [{ source = "type_check", severity = "error" }]
|
|
|
|
[test.strict]
|
|
diagnostics = [{ source = "type_check", severity = "error" }]
|
|
|
|
[[test]]
|
|
name = "mergeDeep of scalar array errors"
|
|
expression = "mergeDeep([1, 2])"
|
|
|
|
[test.loose]
|
|
diagnostics = [{ source = "type_check", severity = "error" }]
|
|
|
|
[test.strict]
|
|
diagnostics = [{ source = "type_check", severity = "error" }]
|
|
|
|
[[test]]
|
|
name = "date comparison methods return bool"
|
|
expression = "d(a).isSameOrAfter(d(b))"
|
|
input = '{"a": "2023-10-15", "b": "2023-10-14"}'
|
|
reads = [
|
|
{ type = "direct", path = ["a"] },
|
|
{ type = "direct", path = ["b"] },
|
|
]
|
|
|
|
[test.loose]
|
|
return_type = '"Bool"'
|
|
|
|
[test.strict]
|
|
return_type = '"Bool"'
|
|
|
|
[[test]]
|
|
name = "date comparison with unit returns bool"
|
|
expression = "d(a).isBefore(d(b), 'day')"
|
|
input = '{"a": "2023-10-15", "b": "2023-10-14"}'
|
|
reads = [
|
|
{ type = "direct", path = ["a"] },
|
|
{ type = "direct", path = ["b"] },
|
|
]
|
|
|
|
[test.loose]
|
|
return_type = '"Bool"'
|
|
|
|
[test.strict]
|
|
return_type = '"Bool"'
|
|
|
|
[[test]]
|
|
name = "failed overload keeps its return type"
|
|
expression = "len(tags)"
|
|
input = '{"Object": {"tags": {"Nullable": {"Array": "String"}}}}'
|
|
|
|
[test.loose]
|
|
return_type = '"Number"'
|
|
diagnostics = [
|
|
{ source = "type_check", severity = "error" },
|
|
{ source = "type_check", severity = "error" },
|
|
]
|
|
|
|
[test.strict]
|
|
return_type = '"Number"'
|
|
diagnostics = [
|
|
{ source = "type_check", severity = "error" },
|
|
{ source = "type_check", severity = "error" },
|
|
]
|
|
|
|
# ── join: the inverse of split ───────────────────────────────────────────────
|
|
|
|
[[test]]
|
|
name = "join strings with a separator"
|
|
expression = "join(tags, ', ')"
|
|
input = '{"tags": ["a", "b"]}'
|
|
reads = [
|
|
{ type = "direct", path = ["tags"] },
|
|
]
|
|
|
|
[test.loose]
|
|
return_type = '"String"'
|
|
|
|
[test.strict]
|
|
return_type = '"String"'
|
|
|
|
[[test]]
|
|
name = "join without a separator"
|
|
expression = "join(tags)"
|
|
input = '{"tags": ["a", "b"]}'
|
|
|
|
[test.loose]
|
|
return_type = '"String"'
|
|
|
|
[test.strict]
|
|
return_type = '"String"'
|
|
|
|
[[test]]
|
|
name = "join numbers, bools and dates"
|
|
expression = "join(ns, '-') + join(bs) + join([d('2024-01-01')])"
|
|
input = '{"ns": [1, 2], "bs": [true]}'
|
|
|
|
[test.loose]
|
|
return_type = '"String"'
|
|
|
|
[test.strict]
|
|
return_type = '"String"'
|
|
|
|
[[test]]
|
|
name = "join nullable items"
|
|
expression = "join(tags, '|')"
|
|
input = '{"Object": {"tags": {"Array": {"Nullable": "String"}}}}'
|
|
|
|
[test.loose]
|
|
return_type = '"String"'
|
|
|
|
[test.strict]
|
|
return_type = '"String"'
|
|
|
|
[[test]]
|
|
name = "join of unknown items"
|
|
expression = "join(x, sep)"
|
|
input = '{"Object": {"x": "Any", "sep": "Any"}}'
|
|
|
|
[test.loose]
|
|
return_type = '"String"'
|
|
|
|
[test.strict]
|
|
return_type = '"String"'
|
|
|
|
[[test]]
|
|
name = "join of a projection"
|
|
expression = "join(map(items as t, t.name), ', ')"
|
|
input = '{"items": [{"name": "a"}]}'
|
|
reads = [
|
|
{ type = "iteration", collection = ["items"], alias = "t", reads = [
|
|
{ type = "direct", path = ["t", "name"] },
|
|
] },
|
|
]
|
|
|
|
[test.loose]
|
|
return_type = '"String"'
|
|
|
|
[test.strict]
|
|
return_type = '"String"'
|
|
|
|
[[test]]
|
|
name = "join of objects is a type error"
|
|
expression = "join(items, ', ')"
|
|
input = '{"items": [{"name": "a"}]}'
|
|
|
|
[test.loose]
|
|
return_type = '"String"'
|
|
diagnostics = [{ source = "type_check", severity = "error" }]
|
|
|
|
[test.strict]
|
|
return_type = '"String"'
|
|
diagnostics = [{ source = "type_check", severity = "error" }]
|
|
|
|
[[test]]
|
|
name = "join of lists is a type error"
|
|
expression = "join([[1], [2]])"
|
|
|
|
[test.loose]
|
|
diagnostics = [{ source = "type_check", severity = "error" }]
|
|
|
|
[test.strict]
|
|
diagnostics = [{ source = "type_check", severity = "error" }]
|
|
|
|
[[test]]
|
|
name = "join separator must be a string"
|
|
expression = "join(tags, 1)"
|
|
input = '{"tags": ["a"]}'
|
|
|
|
[test.loose]
|
|
diagnostics = [{ source = "type_check", severity = "error" }]
|
|
|
|
[test.strict]
|
|
diagnostics = [{ source = "type_check", severity = "error" }]
|
|
|
|
[[test]]
|
|
name = "join of a string is a type error"
|
|
expression = "join(name)"
|
|
input = '{"name": "a"}'
|
|
|
|
[test.loose]
|
|
diagnostics = [{ source = "type_check", severity = "error" }]
|
|
|
|
[test.strict]
|
|
diagnostics = [{ source = "type_check", severity = "error" }]
|
|
|
|
# ── Bare-array aggregates ────────────────────────────────────────────────────
|
|
|
|
[[test]]
|
|
name = "percentileApprox of a number list"
|
|
expression = "percentileApprox(ns, 0.5)"
|
|
input = '{"ns": [1, 2]}'
|
|
reads = [
|
|
{ type = "direct", path = ["ns"] },
|
|
]
|
|
|
|
[test.loose]
|
|
return_type = '"Number"'
|
|
|
|
[test.strict]
|
|
return_type = '{"Nullable":"Number"}'
|
|
|
|
[[test]]
|
|
name = "percentileApprox of a string list is a type error"
|
|
expression = "percentileApprox(tags, 0.5)"
|
|
input = '{"tags": ["a"]}'
|
|
|
|
[test.loose]
|
|
diagnostics = [{ source = "type_check", severity = "error" }]
|
|
|
|
[test.strict]
|
|
diagnostics = [{ source = "type_check", severity = "error" }]
|
|
|
|
[[test]]
|
|
name = "mode of a string list"
|
|
expression = "mode(tags)"
|
|
input = '{"tags": ["a", "b"]}'
|
|
|
|
[test.loose]
|
|
return_type = '"String"'
|
|
|
|
[test.strict]
|
|
return_type = '"String"'
|
|
|
|
[[test]]
|
|
name = "lastN with an alias and no callback is the built-in"
|
|
expression = "lastN(items as t, 2)"
|
|
input = '{"items": [1, 2, 3]}'
|
|
reads = [
|
|
{ type = "direct", path = ["items"] },
|
|
]
|
|
|
|
[test.loose]
|
|
return_type = '{"Array":"Any"}'
|
|
|
|
[test.strict]
|
|
return_type = '{"Array":"Any"}'
|