From a1233cb33e3b55cde90b52b908cb4d8f4b6864e6 Mon Sep 17 00:00:00 2001 From: Chris Loer Date: Mon, 17 Sep 2018 14:57:08 -0700 Subject: [PATCH] Add expression test cases for implicit format type annotations. --- .../format/implicit-assert/test.json | 14 +++++ .../format/implicit-coerce/test.json | 53 +++++++++++++++++++ .../format/implicit-omit/test.json | 53 +++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 test/integration/expression-tests/format/implicit-assert/test.json create mode 100644 test/integration/expression-tests/format/implicit-coerce/test.json create mode 100644 test/integration/expression-tests/format/implicit-omit/test.json diff --git a/test/integration/expression-tests/format/implicit-assert/test.json b/test/integration/expression-tests/format/implicit-assert/test.json new file mode 100644 index 00000000000..ee26d2f0b43 --- /dev/null +++ b/test/integration/expression-tests/format/implicit-assert/test.json @@ -0,0 +1,14 @@ +{ + "expression": ["number", ["get", "p"]], + "propertySpec": { + "type": "formatted" + }, + "expected": { + "compiled": { + "result": "error", + "errors": [ + {"key": "", "error": "Expected formatted but found number instead."} + ] + } + } +} diff --git a/test/integration/expression-tests/format/implicit-coerce/test.json b/test/integration/expression-tests/format/implicit-coerce/test.json new file mode 100644 index 00000000000..dabce92bb5f --- /dev/null +++ b/test/integration/expression-tests/format/implicit-coerce/test.json @@ -0,0 +1,53 @@ +{ + "expression": ["to-string", ["get", "p"]], + "propertySpec": { + "type": "formatted" + }, + "inputs": [ + [{}, {"properties": {}}], + [{}, {"properties": {"p": 0}}], + [{}, {"properties": {"p": "a"}}] + ], + "expected": { + "compiled": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "formatted" + }, + "outputs": [ + { + "sections": [ + { + "text": "", + "scale": null, + "fontStack": null + } + ] + }, + { + "sections": [ + { + "text": "0", + "scale": null, + "fontStack": null + } + ] + }, + { + "sections": [ + { + "text": "a", + "scale": null, + "fontStack": null + } + ] + } + ], + "serialized": [ + "format", + ["to-string", ["get", "p"]], + {} + ] + } +} diff --git a/test/integration/expression-tests/format/implicit-omit/test.json b/test/integration/expression-tests/format/implicit-omit/test.json new file mode 100644 index 00000000000..44405f7fdd4 --- /dev/null +++ b/test/integration/expression-tests/format/implicit-omit/test.json @@ -0,0 +1,53 @@ +{ + "expression": ["coalesce", ["get", "q"], ["get", "p"]], + "propertySpec": { + "type": "formatted" + }, + "inputs": [ + [{}, {"properties": {}}], + [{}, {"properties": {"p": 0}}], + [{}, {"properties": {"p": "a"}}] + ], + "expected": { + "compiled": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "formatted" + }, + "outputs": [ + { + "sections": [ + { + "text": "", + "scale": null, + "fontStack": null + } + ] + }, + { + "sections": [ + { + "text": "0", + "scale": null, + "fontStack": null + } + ] + }, + { + "sections": [ + { + "text": "a", + "scale": null, + "fontStack": null + } + ] + } + ], + "serialized": [ + "format", + ["coalesce", ["get", "q"], ["get", "p"]], + {} + ] + } +}