Implement slice expression (#1133)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Bart Louwers <bart@emeel.net>
This commit is contained in:
Siarhei Fedartsou
2023-08-26 18:32:45 +02:00
committed by GitHub
parent ecd59d4cc4
commit 09f17c0fc4
15 changed files with 417 additions and 40 deletions

View File

@@ -0,0 +1,19 @@
{
"expression": ["slice", ["array", ["get", "val"]], ["get", "index"]],
"inputs": [
[{}, {"properties": {"val": [1, 2, 3, 4, 5], "index": 2}}],
[{}, {"properties": {"val": [1, 2, 3, 4, 5], "index": 0}}],
[{}, {"properties": {"val": [1, 2, 3, 4, 5], "index": 99}}],
[{}, {"properties": {"val": [1, 2, 3, 4, 5], "index": -2}}]
],
"expected": {
"serialized": ["slice", ["array", ["get", "val"]], ["get", "index"]],
"compiled": {
"result": "success",
"isFeatureConstant": false,
"isZoomConstant": true,
"type": "array"
},
"outputs": [[3, 4, 5], [1, 2, 3, 4, 5], [], [4, 5]]
}
}

View File

@@ -0,0 +1,31 @@
{
"expression": [
"slice",
["array", ["get", "val"]],
["get", "i1"],
["get", "i2"]
],
"inputs": [
[{}, {"properties": {"val": [1, 2, 3, 4, 5], "i1": 2, "i2": 4}}],
[{}, {"properties": {"val": [1, 2, 3, 4, 5], "i1": 1, "i2": 5}}],
[{}, {"properties": {"val": [1, 2, 3, 4, 5], "i1": 1, "i2": 99}}],
[{}, {"properties": {"val": [1, 2, 3, 4, 5], "i1": -4, "i2": -2}}],
[{}, {"properties": {"val": [1, 2, 3, 4, 5], "i1": 0, "i2": -1}}],
[{}, {"properties": {"val": [1, 2, 3, 4, 5], "i1": 0, "i2": 0}}]
],
"expected": {
"serialized": [
"slice",
["array", ["get", "val"]],
["get", "i1"],
["get", "i2"]
],
"compiled": {
"result": "success",
"isFeatureConstant": false,
"isZoomConstant": true,
"type": "array"
},
"outputs": [[3, 4], [2, 3, 4, 5], [2, 3, 4, 5], [2, 3], [1, 2, 3, 4], []]
}
}

View File

@@ -0,0 +1,40 @@
{
"expression": ["slice", ["get", "input"], ["get", "i1"]],
"inputs": [
[{}, {"properties": {"input": false, "i1": 1}}],
[{}, {"properties": {"input": null, "i1": 1}}],
[{}, {"properties": {"input": 12, "i1": 1}}],
[{}, {"properties": {"input": {}, "i1": 1}}],
[{}, {"properties": {"other": 1, "i1": 1}}],
[{}, {"properties": {"input": "correct", "i1": "one"}}]
],
"expected": {
"serialized": ["slice", ["get", "input"], ["get", "i1"]],
"compiled": {
"result": "success",
"isFeatureConstant": false,
"isZoomConstant": true,
"type": "value"
},
"outputs": [
{
"error": "Expected first argument to be of type array or string, but found boolean instead."
},
{
"error": "Expected first argument to be of type array or string, but found null instead."
},
{
"error": "Expected first argument to be of type array or string, but found number instead."
},
{
"error": "Expected first argument to be of type array or string, but found object instead."
},
{
"error": "Expected first argument to be of type array or string, but found null instead."
},
{
"error": "Expected value to be of type number, but found string instead."
}
]
}
}

View File

@@ -0,0 +1,19 @@
{
"expression": ["slice", ["get", "val"], ["get", "index"]],
"inputs": [
[{}, {"properties": {"val": "0123456789", "index": 0}}],
[{}, {"properties": {"val": "0123456789", "index": 4}}],
[{}, {"properties": {"val": "0123456789", "index": 99}}],
[{}, {"properties": {"val": "0123456789", "index": -2}}]
],
"expected": {
"serialized": ["slice", ["get", "val"], ["get", "index"]],
"compiled": {
"result": "success",
"isFeatureConstant": false,
"isZoomConstant": true,
"type": "value"
},
"outputs": ["0123456789", "456789", "", "89"]
}
}

View File

@@ -0,0 +1,20 @@
{
"expression": ["slice", ["get", "val"], ["get", "i1"], ["get", "i2"]],
"inputs": [
[{}, {"properties": {"val": "0123456789", "i1": 1, "i2": 8}}],
[{}, {"properties": {"val": "0123456789", "i1": 4, "i2": -2}}],
[{}, {"properties": {"val": "0123456789", "i1": -3, "i2": -1}}],
[{}, {"properties": {"val": "0123456789", "i1": 0, "i2": -1}}],
[{}, {"properties": {"val": "0123456789", "i1": 0, "i2": 99}}]
],
"expected": {
"serialized": ["slice", ["get", "val"], ["get", "i1"], ["get", "i2"]],
"compiled": {
"result": "success",
"isFeatureConstant": false,
"isZoomConstant": true,
"type": "value"
},
"outputs": ["1234567", "4567", "78", "012345678", "0123456789"]
}
}