Skip to content

Commit

Permalink
Fix validation error on categorical zoom-and-property functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Feb 7, 2017
1 parent 10cf38d commit 677ce98
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/style-spec/validate/validate_function.js
Expand Up @@ -12,7 +12,7 @@ module.exports = function validateFunction(options) {
const functionValueSpec = options.valueSpec;
const functionType = unbundle(options.value.type);
let stopKeyType;
const stopDomainValues = {};
let stopDomainValues = {};
let previousStopDomainValue;
let previousStopDomainZoom;

Expand Down Expand Up @@ -114,6 +114,7 @@ module.exports = function validateFunction(options) {
if (unbundle(value[0].zoom) !== previousStopDomainZoom) {
previousStopDomainZoom = unbundle(value[0].zoom);
previousStopDomainValue = undefined;
stopDomainValues = {};
}
errors = errors.concat(validateObject({
key: `${key}[0]`,
Expand Down
77 changes: 77 additions & 0 deletions test/unit/style-spec/fixture/functions.input.json
Expand Up @@ -724,6 +724,83 @@
}
}
},
{
"id": "invalid categorical zoom-and-property function - repeated stop",
"type": "fill",
"source": "source",
"source-layer": "layer",
"paint": {
"fill-opacity": {
"property": "mapbox",
"type": "categorical",
"stops": [
[
{
"zoom": 0,
"value": "0"
},
0
],
[
{
"zoom": 0,
"value": "1"
},
0
],
[
{
"zoom": 0,
"value": "0"
},
0
]
]
}
}
},
{
"id": "valid categorical zoom-and-property function",
"type": "fill",
"source": "source",
"source-layer": "layer",
"paint": {
"fill-opacity": {
"property": "mapbox",
"type": "categorical",
"stops": [
[
{
"zoom": 0,
"value": "0"
},
0
],
[
{
"zoom": 0,
"value": "1"
},
1
],
[
{
"zoom": 1,
"value": "0"
},
0
],
[
{
"zoom": 1,
"value": "1"
},
1
]
]
}
}
},
{
"id": "valid default",
"type": "fill",
Expand Down
18 changes: 11 additions & 7 deletions test/unit/style-spec/fixture/functions.output.json
Expand Up @@ -79,13 +79,13 @@
"message": "layers[19].paint.fill-color: \"property\" property is required",
"line": 354
},
{
"message": "layers[32].paint.fill-color.stops[0][0]: stop domain value must be a number, string, or boolean"
},
{
"message": "layers[22].paint.fill-color: missing required property \"property\"",
"line": 401
},
{
"message": "layers[32].paint.fill-color.stops[0][0]: stop domain value must be a number, string, or boolean"
},
{
"message": "layers[23].paint.fill-color.stops: identity function may not have a \"stops\" property",
"line": 415
Expand Down Expand Up @@ -147,11 +147,15 @@
"line": 718
},
{
"message": "layers[40].paint.fill-opacity.default: number expected, string found",
"line": 749
"message": "layers[39].paint.fill-opacity.stops[2][0].value: stop domain values must be unique",
"line": 754
},
{
"message": "layers[42].paint.fill-opacity.default: number expected, string found",
"line": 826
},
{
"message": "layers[41].paint.fill-color.default: color expected, \"invalid\" found",
"line": 762
"message": "layers[43].paint.fill-color.default: color expected, \"invalid\" found",
"line": 839
}
]

0 comments on commit 677ce98

Please sign in to comment.