Skip to content

Commit

Permalink
Add separate unit test for piecewise-constant check
Browse files Browse the repository at this point in the history
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<number>`, 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.
  • Loading branch information
Anand Thakker committed Oct 25, 2017
1 parent 353c5dd commit 37de50c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions debug/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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]]])
})

</script>
</body>
</html>
21 changes: 21 additions & 0 deletions test/unit/style-spec/expression.test.js
Original file line number Diff line number Diff line change
@@ -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();
});

0 comments on commit 37de50c

Please sign in to comment.