-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow interpolation for variable-length numeric arrays (#5519)
* Disallow interpolation for variable-length numeric arrays * Add separate unit test for piecewise-constant check This fix 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
1 parent
4c7d0d7
commit 3eced30
Showing
5 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
23 changes: 23 additions & 0 deletions
23
test/integration/expression-tests/curve/exponential-uninterpolatable-numeric-array/test.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"expression": [ | ||
"curve", | ||
["exponential", 2], | ||
["number", ["get", "x"]], | ||
1, | ||
["array", "number", ["get", "array"]], | ||
3, | ||
["array", "number", ["get", "array_two"]] | ||
], | ||
"inputs": [], | ||
"expected": { | ||
"compiled": { | ||
"result": "error", | ||
"errors": [ | ||
{ | ||
"key": "", | ||
"error": "Type array<number> is not interpolatable, and thus cannot be used as a exponential curve's output type." | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters