From 34cb223411aa36e313bdc1061c0f39a9f12797a9 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 2 Feb 2017 17:26:35 -0800 Subject: [PATCH] Allow boolean stop domain values for categorical functions --- js/style-spec/validate/validate_function.js | 4 ++-- test/js/style-spec/fixture/functions.input.json | 2 +- test/js/style-spec/fixture/functions.output.json | 14 +++++--------- test/js/style-spec/function.test.js | 15 +++++++++++++++ 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/js/style-spec/validate/validate_function.js b/js/style-spec/validate/validate_function.js index 56256c8cbd7..db26da6467f 100644 --- a/js/style-spec/validate/validate_function.js +++ b/js/style-spec/validate/validate_function.js @@ -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') { diff --git a/test/js/style-spec/fixture/functions.input.json b/test/js/style-spec/fixture/functions.input.json index 45f7bfb53c0..6412a5ed695 100644 --- a/test/js/style-spec/fixture/functions.input.json +++ b/test/js/style-spec/fixture/functions.input.json @@ -520,7 +520,7 @@ } }, { - "id": "invalid boolean domain type", + "id": "valid boolean domain type", "type": "fill", "source": "source", "source-layer": "layer", diff --git a/test/js/style-spec/fixture/functions.output.json b/test/js/style-spec/fixture/functions.output.json index 0dd064a3bc3..e97ddc07501 100644 --- a/test/js/style-spec/fixture/functions.output.json +++ b/test/js/style-spec/fixture/functions.output.json @@ -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 }, { @@ -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", @@ -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 }, { diff --git a/test/js/style-spec/function.test.js b/test/js/style-spec/function.test.js index e33ec84e011..344d7dfdf3d 100644 --- a/test/js/style-spec/function.test.js +++ b/test/js/style-spec/function.test.js @@ -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(); });