Skip to content

Commit

Permalink
Allow boolean stop domain values for categorical functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Feb 3, 2017
1 parent e328b80 commit 34cb223
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
4 changes: 2 additions & 2 deletions js/style-spec/validate/validate_function.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ module.exports = function validateFunction(options) {
return [new ValidationError(options.key, options.value, '%s stop domain type must match previous stop domain type %s', type, stopKeyType)];
}

if (type !== 'number' && type !== 'string') {
return [new ValidationError(options.key, options.value, 'property value must be a number or string')];
if (type !== 'number' && type !== 'string' && type !== 'boolean') {
return [new ValidationError(options.key, options.value, 'stop domain value must be a number, string, or boolean')];
}

if (type !== 'number' && functionType !== 'categorical') {
Expand Down
2 changes: 1 addition & 1 deletion test/js/style-spec/fixture/functions.input.json
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@
}
},
{
"id": "invalid boolean domain type",
"id": "valid boolean domain type",
"type": "fill",
"source": "source",
"source-layer": "layer",
Expand Down
14 changes: 5 additions & 9 deletions test/js/style-spec/fixture/functions.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"line": 284
},
{
"message": "layers[16].paint.fill-color.stops[0][0].value: property value must be a number or string",
"message": "layers[16].paint.fill-color.stops[0][0].value: stop domain value must be a number, string, or boolean",
"line": 305
},
{
Expand All @@ -80,11 +80,11 @@
"line": 341
},
{
"message": "layers[19].paint.fill-color: \"property\" property is required",
"line": 354
"message": "layers[31].paint.fill-color.stops[0][0]: stop domain value must be a number, string, or boolean"
},
{
"message": "layers[31].paint.fill-color.stops[0][0]: property value must be a number or string"
"message": "layers[19].paint.fill-color: \"property\" property is required",
"line": 354
},
{
"message": "layers[22].paint.background-color.stops: identity function may not have a \"stops\" property",
Expand Down Expand Up @@ -115,11 +115,7 @@
"line": 515
},
{
"message": "layers[29].paint.fill-color.stops[0][0]: property value must be a number or string",
"line": 533
},
{
"message": "layers[30].paint.fill-color.stops[0][0]: property value must be a number or string",
"message": "layers[30].paint.fill-color.stops[0][0]: stop domain value must be a number, string, or boolean",
"line": 551
},
{
Expand Down
15 changes: 15 additions & 0 deletions test/js/style-spec/function.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,21 @@ test('categorical function', (t) => {
t.end();
});

t.test('boolean', (t) => {
const f = createFunction({
property: 'foo',
type: 'categorical',
stops: [[true, 'true'], [false, 'false']]
}, {
type: 'string'
});

t.equal(f(0, {foo: true}), 'true');
t.equal(f(0, {foo: false}), 'false');

t.end();
});

t.end();
});

Expand Down

0 comments on commit 34cb223

Please sign in to comment.