mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
Tests for aggregates builtins
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
committed by
Anand Krishnamoorthi
parent
6b87e99fb9
commit
31e1c63281
@@ -100,7 +100,8 @@ fn sort(span: &Span, params: &[Expr], args: &[Value]) -> Result<Value> {
|
||||
ac.sort();
|
||||
Value::from_array(ac)
|
||||
}
|
||||
Value::Set(a) => Value::from_set(a.iter().cloned().collect()),
|
||||
// Sorting a set produces array.
|
||||
Value::Set(a) => Value::from_array(a.iter().cloned().collect()),
|
||||
a => {
|
||||
let span = params[0].span();
|
||||
bail!(span.error(format!("`sort` requires array/set argument. Got `{a}`.").as_str()))
|
||||
|
||||
58
tests/interpreter/cases/builtins/aggregates/count.yaml
Normal file
58
tests/interpreter/cases/builtins/aggregates/count.yaml
Normal file
@@ -0,0 +1,58 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: all
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = [
|
||||
count([]),
|
||||
count([1]),
|
||||
count([1, 2, 3]),
|
||||
|
||||
count({}),
|
||||
count({"a":1}),
|
||||
count({"a":1, "b":2}),
|
||||
|
||||
count(set()),
|
||||
count({1}),
|
||||
count({1,1}),
|
||||
count({1,2}),
|
||||
|
||||
count(""),
|
||||
count("abc")
|
||||
]
|
||||
|
||||
# Undefined
|
||||
r { false }
|
||||
z = count(r)
|
||||
query: data.test
|
||||
want_result:
|
||||
x: [
|
||||
0, 1, 3,
|
||||
0, 1, 2,
|
||||
0, 1, 1, 2,
|
||||
0, 3
|
||||
]
|
||||
|
||||
- note: invalid-null
|
||||
data: {}
|
||||
modules: ["package test\n x= count(null)"]
|
||||
query: data.test
|
||||
error: "`count` requires array/object/set/string argument."
|
||||
|
||||
- note: invalid-bool
|
||||
data: {}
|
||||
modules: ["package test\n x= count(true)"]
|
||||
query: data.test
|
||||
error: "`count` requires array/object/set/string argument."
|
||||
|
||||
- note: invalid-number
|
||||
data: {}
|
||||
modules: ["package test\n x= count(5)"]
|
||||
query: data.test
|
||||
error: "`count` requires array/object/set/string argument."
|
||||
|
||||
52
tests/interpreter/cases/builtins/aggregates/max.yaml
Normal file
52
tests/interpreter/cases/builtins/aggregates/max.yaml
Normal file
@@ -0,0 +1,52 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: all
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = [
|
||||
max([-1, 3, 2]),
|
||||
max({1, 2, -1}),
|
||||
]
|
||||
|
||||
r {false}
|
||||
u1 = max(r)
|
||||
u2 = max([])
|
||||
u3 = max(set())
|
||||
query: data.test
|
||||
want_result:
|
||||
x: [ 3, 2 ]
|
||||
|
||||
- note: invalid-null
|
||||
data: {}
|
||||
modules: ["package test\n x= max(null)"]
|
||||
query: data.test
|
||||
error: "`max` requires array/set argument."
|
||||
|
||||
- note: invalid-bool
|
||||
data: {}
|
||||
modules: ["package test\n x= max(true)"]
|
||||
query: data.test
|
||||
error: "`max` requires array/set argument."
|
||||
|
||||
- note: invalid-number
|
||||
data: {}
|
||||
modules: ["package test\n x= max(5)"]
|
||||
query: data.test
|
||||
error: "`max` requires array/set argument."
|
||||
|
||||
- note: invalid-string
|
||||
data: {}
|
||||
modules: ["package test\n x= max(`abc`)"]
|
||||
query: data.test
|
||||
error: "`max` requires array/set argument."
|
||||
|
||||
- note: invalid-object
|
||||
data: {}
|
||||
modules: ["package test\n x= max({})"]
|
||||
query: data.test
|
||||
error: "`max` requires array/set argument."
|
||||
53
tests/interpreter/cases/builtins/aggregates/min.yaml
Normal file
53
tests/interpreter/cases/builtins/aggregates/min.yaml
Normal file
@@ -0,0 +1,53 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: all
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = [
|
||||
min([-1, 3, 2]),
|
||||
min({1, 2, -1}),
|
||||
]
|
||||
|
||||
r {false}
|
||||
u1 = min(r)
|
||||
u2 = min([])
|
||||
u3 = min(set())
|
||||
query: data.test
|
||||
want_result:
|
||||
x: [ 3, 2 ]
|
||||
|
||||
- note: invalid-null
|
||||
data: {}
|
||||
modules: ["package test\n x= min(null)"]
|
||||
query: data.test
|
||||
error: "`min` requires array/set argument."
|
||||
|
||||
- note: invalid-bool
|
||||
data: {}
|
||||
modules: ["package test\n x= min(true)"]
|
||||
query: data.test
|
||||
error: "`min` requires array/set argument."
|
||||
|
||||
- note: invalid-number
|
||||
data: {}
|
||||
modules: ["package test\n x= min(5)"]
|
||||
query: data.test
|
||||
error: "`min` requires array/set argument."
|
||||
|
||||
- note: invalid-string
|
||||
data: {}
|
||||
modules: ["package test\n x= min(`abc`)"]
|
||||
query: data.test
|
||||
error: "`min` requires array/set argument."
|
||||
|
||||
- note: invalid-object
|
||||
data: {}
|
||||
modules: ["package test\n x= min({})"]
|
||||
query: data.test
|
||||
error: "`min` requires array/set argument."
|
||||
|
||||
56
tests/interpreter/cases/builtins/aggregates/product.yaml
Normal file
56
tests/interpreter/cases/builtins/aggregates/product.yaml
Normal file
@@ -0,0 +1,56 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: all
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = [
|
||||
product([-1, 3, 2]),
|
||||
product([1, 2, -1]),
|
||||
product([1, -1, 2, -1]),
|
||||
product([]),
|
||||
product([0]),
|
||||
product({3, 2, 1}),
|
||||
product(set()),
|
||||
product({0}),
|
||||
]
|
||||
|
||||
r {false}
|
||||
u1 = product(r)
|
||||
query: data.test
|
||||
want_result:
|
||||
x: [-6, -2, 2, 1, 0, 6, 1, 0]
|
||||
|
||||
- note: invalid-null
|
||||
data: {}
|
||||
modules: ["package test\n x= product(null)"]
|
||||
query: data.test
|
||||
error: "`product` requires array/set argument."
|
||||
|
||||
- note: invalid-bool
|
||||
data: {}
|
||||
modules: ["package test\n x= product(true)"]
|
||||
query: data.test
|
||||
error: "`product` requires array/set argument."
|
||||
|
||||
- note: invalid-number
|
||||
data: {}
|
||||
modules: ["package test\n x= product(5)"]
|
||||
query: data.test
|
||||
error: "`product` requires array/set argument."
|
||||
|
||||
- note: invalid-string
|
||||
data: {}
|
||||
modules: ["package test\n x= product(`abc`)"]
|
||||
query: data.test
|
||||
error: "`product` requires array/set argument."
|
||||
|
||||
- note: invalid-object
|
||||
data: {}
|
||||
modules: ["package test\n x= product({})"]
|
||||
query: data.test
|
||||
error: "`product` requires array/set argument."
|
||||
60
tests/interpreter/cases/builtins/aggregates/sort.yaml
Normal file
60
tests/interpreter/cases/builtins/aggregates/sort.yaml
Normal file
@@ -0,0 +1,60 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: all
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = [
|
||||
sort([-1, 3, 2]),
|
||||
sort([1, 2, -1]),
|
||||
sort([1, -1, 2, -1]),
|
||||
sort([]),
|
||||
sort({3, 2, 1}),
|
||||
sort(set())
|
||||
]
|
||||
|
||||
r {false}
|
||||
u1 = sort(r)
|
||||
query: data.test
|
||||
want_result:
|
||||
x:
|
||||
- [-1, 2, 3]
|
||||
- [-1, 1, 2]
|
||||
- [-1, -1, 1, 2]
|
||||
- []
|
||||
- [1, 2, 3]
|
||||
- []
|
||||
|
||||
- note: invalid-null
|
||||
data: {}
|
||||
modules: ["package test\n x= sort(null)"]
|
||||
query: data.test
|
||||
error: "`sort` requires array/set argument."
|
||||
|
||||
- note: invalid-bool
|
||||
data: {}
|
||||
modules: ["package test\n x= sort(true)"]
|
||||
query: data.test
|
||||
error: "`sort` requires array/set argument."
|
||||
|
||||
- note: invalid-number
|
||||
data: {}
|
||||
modules: ["package test\n x= sort(5)"]
|
||||
query: data.test
|
||||
error: "`sort` requires array/set argument."
|
||||
|
||||
- note: invalid-string
|
||||
data: {}
|
||||
modules: ["package test\n x= sort(`abc`)"]
|
||||
query: data.test
|
||||
error: "`sort` requires array/set argument."
|
||||
|
||||
- note: invalid-object
|
||||
data: {}
|
||||
modules: ["package test\n x= sort({})"]
|
||||
query: data.test
|
||||
error: "`sort` requires array/set argument."
|
||||
56
tests/interpreter/cases/builtins/aggregates/sum.yaml
Normal file
56
tests/interpreter/cases/builtins/aggregates/sum.yaml
Normal file
@@ -0,0 +1,56 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: all
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = [
|
||||
sum([-1, 3, 2]),
|
||||
sum([1, 2, -1]),
|
||||
sum([1, -1, 2, -1]),
|
||||
sum([]),
|
||||
sum([0]),
|
||||
sum({3, 2, 1}),
|
||||
sum(set()),
|
||||
sum({0}),
|
||||
]
|
||||
|
||||
r {false}
|
||||
u1 = sum(r)
|
||||
query: data.test
|
||||
want_result:
|
||||
x: [4, 2, 1, 0, 0, 6, 0, 0]
|
||||
|
||||
- note: invalid-null
|
||||
data: {}
|
||||
modules: ["package test\n x= sum(null)"]
|
||||
query: data.test
|
||||
error: "`sum` requires array/set argument."
|
||||
|
||||
- note: invalid-bool
|
||||
data: {}
|
||||
modules: ["package test\n x= sum(true)"]
|
||||
query: data.test
|
||||
error: "`sum` requires array/set argument."
|
||||
|
||||
- note: invalid-number
|
||||
data: {}
|
||||
modules: ["package test\n x= sum(5)"]
|
||||
query: data.test
|
||||
error: "`sum` requires array/set argument."
|
||||
|
||||
- note: invalid-string
|
||||
data: {}
|
||||
modules: ["package test\n x= sum(`abc`)"]
|
||||
query: data.test
|
||||
error: "`sum` requires array/set argument."
|
||||
|
||||
- note: invalid-object
|
||||
data: {}
|
||||
modules: ["package test\n x= sum({})"]
|
||||
query: data.test
|
||||
error: "`sum` requires array/set argument."
|
||||
Reference in New Issue
Block a user