mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
json.filter, object.filter, object.get, object.keys, object.remove
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
committed by
Anand Krishnamoorthi
parent
6b637e9151
commit
cba0af0d3f
39
tests/interpreter/cases/builtins/objects/filter.yaml
Normal file
39
tests/interpreter/cases/builtins/objects/filter.yaml
Normal file
@@ -0,0 +1,39 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: all
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
obj = {
|
||||
"a": 5,
|
||||
"b": 6,
|
||||
"c": 7,
|
||||
{1}: 8,
|
||||
{"a":5}: 9,
|
||||
}
|
||||
|
||||
results = {
|
||||
"o1": object.filter(obj, ["a", {1}]),
|
||||
"o2": object.filter(obj, {"a":1, "c": 0}),
|
||||
"o3": object.filter(obj, {"a", "c"}),
|
||||
}
|
||||
query: data.test.results
|
||||
want_result:
|
||||
o1:
|
||||
object!:
|
||||
- key: a
|
||||
value: 5
|
||||
- key:
|
||||
set!: [1]
|
||||
value: 8
|
||||
o2:
|
||||
a: 5
|
||||
c: 7
|
||||
o3:
|
||||
a: 5
|
||||
c: 7
|
||||
|
||||
30
tests/interpreter/cases/builtins/objects/get.yaml
Normal file
30
tests/interpreter/cases/builtins/objects/get.yaml
Normal file
@@ -0,0 +1,30 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: all
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
obj = {
|
||||
"a": 5,
|
||||
"b": {"c":8},
|
||||
"c": 7,
|
||||
{1}: 8,
|
||||
{"a":5}: 9,
|
||||
}
|
||||
|
||||
results = {
|
||||
"v1": object.get(obj, "a", "default"),
|
||||
"v2": object.get(obj, ["b", "c"], "default"),
|
||||
"v3": object.get(obj, ["a", "b"], "default"),
|
||||
"v4": object.get(obj, {"a":5}, "default"),
|
||||
}
|
||||
query: data.test.results
|
||||
want_result:
|
||||
v1: 5
|
||||
v2: 8
|
||||
v3: "default"
|
||||
v4: 9
|
||||
60
tests/interpreter/cases/builtins/objects/json.filter.yaml
Normal file
60
tests/interpreter/cases/builtins/objects/json.filter.yaml
Normal file
@@ -0,0 +1,60 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: all
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
obj = {
|
||||
"a" : 5,
|
||||
"b" : {
|
||||
"c" : {
|
||||
"d" : 6
|
||||
},
|
||||
"d" : 7
|
||||
},
|
||||
"c" : 8
|
||||
}
|
||||
s = { "a": [[1, [7,8,9], 2], {"a":1, "b":2, "c":3}]}
|
||||
t = { "a": { 1, 2, {"x"}, {8, 9, 10} }}
|
||||
results = {
|
||||
"o1": json.filter(obj, ["a", "b/c"]),
|
||||
"o2": json.filter(obj, {"c", ["b", "d"]}),
|
||||
"o3": json.filter(s, [["a", 1]]),
|
||||
"o4": json.filter(s, ["a/0/1/2", ["a", "0", "2"], "a/0/1/1"]),
|
||||
"o5": json.filter(t, [["a", 1]]),
|
||||
"o6": json.filter(t, [["a", {"x"}]]),
|
||||
"o7": json.filter(t, [["a", {8, 9, 10}, 9]]),
|
||||
}
|
||||
|
||||
#TODO: more filters
|
||||
query: data.test.results
|
||||
want_result:
|
||||
o1:
|
||||
a: 5
|
||||
b:
|
||||
c:
|
||||
d: 6
|
||||
o2:
|
||||
b:
|
||||
d: 7
|
||||
c: 8
|
||||
o3:
|
||||
a: []
|
||||
o4:
|
||||
a: [[[8, 9], 2]]
|
||||
o5:
|
||||
a:
|
||||
set!: [1]
|
||||
o6:
|
||||
a:
|
||||
set!:
|
||||
- set!: ["x"]
|
||||
o7:
|
||||
a:
|
||||
set!:
|
||||
- set!: [9]
|
||||
#TODO: Extensive tests
|
||||
37
tests/interpreter/cases/builtins/objects/keys.yaml
Normal file
37
tests/interpreter/cases/builtins/objects/keys.yaml
Normal file
@@ -0,0 +1,37 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: all
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
obj = {
|
||||
"a": 5,
|
||||
"b": 6,
|
||||
"c": 7,
|
||||
{1}: 8,
|
||||
{"a":5}: 9,
|
||||
true: false,
|
||||
5 : 10,
|
||||
null: 5,
|
||||
}
|
||||
|
||||
results = {
|
||||
"v1": object.keys(obj),
|
||||
}
|
||||
query: data.test.results
|
||||
want_result:
|
||||
v1:
|
||||
set!:
|
||||
- "a"
|
||||
- "b"
|
||||
- "c"
|
||||
- set!: [1]
|
||||
- a: 5
|
||||
- true
|
||||
- 5
|
||||
- null
|
||||
|
||||
45
tests/interpreter/cases/builtins/objects/remove.yaml
Normal file
45
tests/interpreter/cases/builtins/objects/remove.yaml
Normal file
@@ -0,0 +1,45 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: all
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
obj = {
|
||||
"a": 5,
|
||||
"b": 6,
|
||||
"c": 7,
|
||||
{1}: 8,
|
||||
{"a":5}: 9,
|
||||
true: false,
|
||||
5 : 10,
|
||||
null: 5,
|
||||
}
|
||||
|
||||
r1 = object.remove(obj, ["a", "b", {1}])
|
||||
|
||||
results = {
|
||||
"v1": r1,
|
||||
"v2": r1 == object.remove(obj, {"a", "b", {1}}),
|
||||
"v3": r1 == object.remove(obj, {"a":1, "b":1, {1}:1}),
|
||||
}
|
||||
query: data.test.results
|
||||
want_result:
|
||||
v1:
|
||||
object!:
|
||||
- key: c
|
||||
value: 7
|
||||
- key:
|
||||
a: 5
|
||||
value: 9
|
||||
- key: true
|
||||
value: false
|
||||
- key: 5
|
||||
value: 10
|
||||
- key: null
|
||||
value: 5
|
||||
v2: true
|
||||
v3: true
|
||||
Reference in New Issue
Block a user