From 61cbba9c1e7c6a22f207bd31d1a5cd7fe04eee33 Mon Sep 17 00:00:00 2001 From: ryanhamley Date: Fri, 1 Nov 2019 11:16:17 -0700 Subject: [PATCH 1/4] Remove hardcoded image list in expression test harness --- test/expression.test.js | 5 ++++- .../integration/expression-tests/image/basic/test.json | 5 +++-- .../expression-tests/image/coalesce/test.json | 6 +++++- .../expression-tests/image/compound/test.json | 10 +++++++++- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/test/expression.test.js b/test/expression.test.js index 883ea54c213..0003c0bf973 100644 --- a/test/expression.test.js +++ b/test/expression.test.js @@ -6,7 +6,6 @@ import {toString} from '../src/style-spec/expression/types'; import ignores from './ignores.json'; let tests; -const availableImages = ['monument-15']; if (process.argv[1] === __filename && process.argv.length > 2) { tests = process.argv.slice(2); @@ -14,6 +13,7 @@ if (process.argv[1] === __filename && process.argv.length > 2) { run('js', {ignores, tests}, (fixture) => { const spec = Object.assign({}, fixture.propertySpec); + let availableImages = []; if (!spec['property-type']) { spec['property-type'] = 'data-driven'; @@ -49,6 +49,9 @@ run('js', {ignores, tests}, (fixture) => { for (const input of fixture.inputs || []) { try { const feature = {properties: input[1].properties || {}}; + if (input[2]) { + availableImages = input[2]; + } if ('id' in input[1]) { feature.id = input[1].id; } diff --git a/test/integration/expression-tests/image/basic/test.json b/test/integration/expression-tests/image/basic/test.json index 4a08789305b..31538316e96 100644 --- a/test/integration/expression-tests/image/basic/test.json +++ b/test/integration/expression-tests/image/basic/test.json @@ -5,8 +5,9 @@ ], "inputs": [ [ - {}, - {} + {}, + {}, + ["monument-15"] ] ], "expected": { diff --git a/test/integration/expression-tests/image/coalesce/test.json b/test/integration/expression-tests/image/coalesce/test.json index a2d2284c24c..3959032dd5c 100644 --- a/test/integration/expression-tests/image/coalesce/test.json +++ b/test/integration/expression-tests/image/coalesce/test.json @@ -4,7 +4,11 @@ "type": "resolvedImage" }, "inputs": [ - [{}, {}] + [ + {}, + {}, + ["monument-15"] + ] ], "expected": { "compiled": { diff --git a/test/integration/expression-tests/image/compound/test.json b/test/integration/expression-tests/image/compound/test.json index 31491640dae..765c8d395eb 100644 --- a/test/integration/expression-tests/image/compound/test.json +++ b/test/integration/expression-tests/image/compound/test.json @@ -3,7 +3,15 @@ "image", ["get", "icon"] ], - "inputs": [[{}, {"properties": {"icon": "monument-15"}}]], + "inputs": [ + [ + {}, + { + "properties": {"icon": "monument-15"} + }, + ["monument-15"] + ] + ], "expected": { "compiled": { "result": "success", From 8192ed2c294e8bf261e63da6f3e68ef3ed15c95d Mon Sep 17 00:00:00 2001 From: ryanhamley Date: Fri, 1 Nov 2019 11:18:49 -0700 Subject: [PATCH 2/4] Dont initialize availableImages as array --- test/expression.test.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/expression.test.js b/test/expression.test.js index 0003c0bf973..ce0527a6a3d 100644 --- a/test/expression.test.js +++ b/test/expression.test.js @@ -13,7 +13,7 @@ if (process.argv[1] === __filename && process.argv.length > 2) { run('js', {ignores, tests}, (fixture) => { const spec = Object.assign({}, fixture.propertySpec); - let availableImages = []; + let availableImages; if (!spec['property-type']) { spec['property-type'] = 'data-driven'; @@ -49,9 +49,8 @@ run('js', {ignores, tests}, (fixture) => { for (const input of fixture.inputs || []) { try { const feature = {properties: input[1].properties || {}}; - if (input[2]) { - availableImages = input[2]; - } + availableImages = input[2] || []; + if ('id' in input[1]) { feature.id = input[1].id; } From 62d4aa6999d7f82074d8b3526d15bdcaaf6866b5 Mon Sep 17 00:00:00 2001 From: ryanhamley Date: Fri, 1 Nov 2019 13:40:18 -0700 Subject: [PATCH 3/4] Use evaluation context input object --- test/expression.test.js | 2 +- test/integration/expression-tests/image/basic/test.json | 5 ++--- test/integration/expression-tests/image/coalesce/test.json | 5 ++--- test/integration/expression-tests/image/compound/test.json | 5 ++--- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/test/expression.test.js b/test/expression.test.js index ce0527a6a3d..bddd175b932 100644 --- a/test/expression.test.js +++ b/test/expression.test.js @@ -49,7 +49,7 @@ run('js', {ignores, tests}, (fixture) => { for (const input of fixture.inputs || []) { try { const feature = {properties: input[1].properties || {}}; - availableImages = input[2] || []; + availableImages = input[0].availableImages; if ('id' in input[1]) { feature.id = input[1].id; diff --git a/test/integration/expression-tests/image/basic/test.json b/test/integration/expression-tests/image/basic/test.json index 31538316e96..797966e7e7f 100644 --- a/test/integration/expression-tests/image/basic/test.json +++ b/test/integration/expression-tests/image/basic/test.json @@ -5,9 +5,8 @@ ], "inputs": [ [ - {}, - {}, - ["monument-15"] + {"availableImages": ["monument-15"]}, + {} ] ], "expected": { diff --git a/test/integration/expression-tests/image/coalesce/test.json b/test/integration/expression-tests/image/coalesce/test.json index 3959032dd5c..75f168207eb 100644 --- a/test/integration/expression-tests/image/coalesce/test.json +++ b/test/integration/expression-tests/image/coalesce/test.json @@ -5,9 +5,8 @@ }, "inputs": [ [ - {}, - {}, - ["monument-15"] + {"availableImages": ["monument-15"]}, + {} ] ], "expected": { diff --git a/test/integration/expression-tests/image/compound/test.json b/test/integration/expression-tests/image/compound/test.json index 765c8d395eb..0b2b8bbcf28 100644 --- a/test/integration/expression-tests/image/compound/test.json +++ b/test/integration/expression-tests/image/compound/test.json @@ -5,11 +5,10 @@ ], "inputs": [ [ - {}, + {"availableImages": ["monument-15"]}, { "properties": {"icon": "monument-15"} - }, - ["monument-15"] + } ] ], "expected": { From 9d15b67d822e26dbcf7d85f7ebc48f796172b1da Mon Sep 17 00:00:00 2001 From: ryanhamley Date: Fri, 1 Nov 2019 14:28:23 -0700 Subject: [PATCH 4/4] Guard against null/undefined availableImages --- test/expression.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/expression.test.js b/test/expression.test.js index bddd175b932..ad46463f72a 100644 --- a/test/expression.test.js +++ b/test/expression.test.js @@ -49,7 +49,7 @@ run('js', {ignores, tests}, (fixture) => { for (const input of fixture.inputs || []) { try { const feature = {properties: input[1].properties || {}}; - availableImages = input[0].availableImages; + availableImages = input[0].availableImages || []; if ('id' in input[1]) { feature.id = input[1].id;