From 37de50c54d251e9bf1fa01a043f69e013f36950d Mon Sep 17 00:00:00 2001 From: Anand Thakker Date: Wed, 25 Oct 2017 09:39:49 -0400 Subject: [PATCH] Add separate unit test for piecewise-constant check The previous commit causes the 'curve' parsing validation to preempt createExpression()'s check for piecewise-constant zoom function using 'step' interpolation, because `line-dasharray`'s style spec type, `array`, already isn't interpolatable. Adding this unit test to make sure we always enforce step curves, even for a theoretical style property whose base type is interpolatable. --- debug/index.html | 4 ++++ test/unit/style-spec/expression.test.js | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 test/unit/style-spec/expression.test.js diff --git a/debug/index.html b/debug/index.html index 9c7f3bb641c..1fc7ff37026 100644 --- a/debug/index.html +++ b/debug/index.html @@ -26,6 +26,10 @@ hash: true }); +map.on('load', function () { + map.setPaintProperty('road-path', 'line-dasharray', ["curve", ["linear"], ["zoom"], 0, ["literal", [1, 2]], 1, ["literal", [3, 4]]]) +}) + diff --git a/test/unit/style-spec/expression.test.js b/test/unit/style-spec/expression.test.js new file mode 100644 index 00000000000..5e5afafe84a --- /dev/null +++ b/test/unit/style-spec/expression.test.js @@ -0,0 +1,21 @@ +'use strict'; + +const test = require('mapbox-gl-js-test').test; +const {createExpression} = require('../../../src/style-spec/expression'); + +test('createExpression', (t) => { + test('require piecewise-constant zoom curves to use "step" interpolation', (t) => { + const expression = createExpression([ + 'curve', ['linear'], ['zoom'], 0, 0, 10, 10 + ], { + type: 'number', + function: 'piecewise-constant' + }); + t.equal(expression.result, 'error'); + t.equal(expression.errors.length, 1); + t.equal(expression.errors[0].message, 'interpolation type must be "step" for this property'); + t.end(); + }); + + t.end(); +});