diff --git a/src/style-spec/expression/parsing_context.js b/src/style-spec/expression/parsing_context.js index 92802626026..25e42df7ea2 100644 --- a/src/style-spec/expression/parsing_context.js +++ b/src/style-spec/expression/parsing_context.js @@ -4,6 +4,9 @@ const Scope = require('./scope'); const {checkSubtype} = require('./types'); const ParsingError = require('./parsing_error'); const Literal = require('./definitions/literal'); +const Assertion = require('./definitions/assertion'); +const ArrayAssertion = require('./definitions/array'); +const Coercion = require('./definitions/coercion'); import type {Expression} from './expression'; import type {Type} from './types'; @@ -77,10 +80,10 @@ class ParsingContext { expected.kind === 'boolean'; if (canAssert && actual.kind === 'value') { - const Assertion = require('./definitions/assertion'); parsed = new Assertion(expected, [parsed]); + } else if (expected.kind === 'array' && actual.kind === 'value') { + parsed = new ArrayAssertion(expected, parsed); } else if (expected.kind === 'color' && (actual.kind === 'value' || actual.kind === 'string')) { - const Coercion = require('./definitions/coercion'); parsed = new Coercion(expected, [parsed]); } diff --git a/test/integration/expression-tests/array/implicit-1/test.json b/test/integration/expression-tests/array/implicit-1/test.json new file mode 100644 index 00000000000..15ba27a79ef --- /dev/null +++ b/test/integration/expression-tests/array/implicit-1/test.json @@ -0,0 +1,21 @@ +{ + "expression": ["at", 0, ["get", "array"]], + "inputs": [ + [{}, {"properties": {"array": [0, 1, 2]}}], + [{}, {"properties": {"array": "not"}}] + ], + "expected": { + "compiled": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "value" + }, + "outputs": [ + 0, + { + "error": "Expected value to be of type array, but found string instead." + } + ] + } +} diff --git a/test/integration/expression-tests/array/implicit-2/test.json b/test/integration/expression-tests/array/implicit-2/test.json new file mode 100644 index 00000000000..1ed42745f96 --- /dev/null +++ b/test/integration/expression-tests/array/implicit-2/test.json @@ -0,0 +1,26 @@ +{ + "propertySpec": {"type": "array", "value": "string"}, + "expression": ["get", "array"], + "inputs": [ + [{}, {"properties": {"array": ["a", "b"]}}], + [{}, {"properties": {"array": [1, 2]}}], + [{}, {"properties": {"array": "not"}}] + ], + "expected": { + "compiled": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "array" + }, + "outputs": [ + ["a", "b"], + { + "error": "Expected value to be of type array, but found array instead." + }, + { + "error": "Expected value to be of type array, but found string instead." + } + ] + } +} diff --git a/test/integration/expression-tests/array/implicit-3/test.json b/test/integration/expression-tests/array/implicit-3/test.json new file mode 100644 index 00000000000..0ce449c41e4 --- /dev/null +++ b/test/integration/expression-tests/array/implicit-3/test.json @@ -0,0 +1,26 @@ +{ + "propertySpec": {"type": "array", "value": "number", "length": 2}, + "expression": ["get", "array"], + "inputs": [ + [{}, {"properties": {"array": [1, 2]}}], + [{}, {"properties": {"array": [1, 2, 3]}}], + [{}, {"properties": {"array": "not"}}] + ], + "expected": { + "compiled": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "array" + }, + "outputs": [ + [1, 2], + { + "error": "Expected value to be of type array, but found array instead." + }, + { + "error": "Expected value to be of type array, but found string instead." + } + ] + } +}