diff options
author | Chris Loer <chris.loer@gmail.com> | 2018-02-09 17:21:58 -0800 |
---|---|---|
committer | Chris Loer <chris.loer@mapbox.com> | 2018-02-16 14:07:33 -0800 |
commit | e771210d13ab7fe1cf3816b1eeaee18a7bed85bd (patch) | |
tree | 95cb67a9620933a0195de6c8b9742cd48fa48fd5 | |
parent | 8635dab4c38fcd67962819224093d0be95f5ed43 (diff) | |
download | qtlocation-mapboxgl-e771210d13ab7fe1cf3816b1eeaee18a7bed85bd.tar.gz |
[test] Native expression test support for:
- Round-tripping expressions through serialization and checking that outputs don't change
- Checking expression serialization against expected value from fixture
m--------- | mapbox-gl-js | 0 | ||||
-rw-r--r-- | platform/node/test/expression.test.js | 60 |
2 files changed, 36 insertions, 24 deletions
diff --git a/mapbox-gl-js b/mapbox-gl-js -Subproject d61850a6bd84ce6d697be392c7ef6d4b5555c20 +Subproject 8a19f6079933817fd73eed71159130b8ac53a00 diff --git a/platform/node/test/expression.test.js b/platform/node/test/expression.test.js index d7a44abbaa..ffd1c68ff2 100644 --- a/platform/node/test/expression.test.js +++ b/platform/node/test/expression.test.js @@ -32,41 +32,53 @@ function getExpectedType(spec) { suite.run('native', {ignores: ignores, tests: tests}, (fixture) => { const compiled = {}; + const recompiled = {}; const result = { - compiled + compiled, + recompiled }; const spec = fixture.propertySpec || {}; const expression = mbgl.Expression.parse(fixture.expression, getExpectedType(spec)); - if (expression instanceof mbgl.Expression) { - compiled.result = 'success'; - compiled.isFeatureConstant = expression.isFeatureConstant(); - compiled.isZoomConstant = expression.isZoomConstant(); - compiled.type = expression.getType(); + const evaluateExpression = (expression, compilationResult) => { + if (expression instanceof mbgl.Expression) { + compilationResult.result = 'success'; + compilationResult.isFeatureConstant = expression.isFeatureConstant(); + compilationResult.isZoomConstant = expression.isZoomConstant(); + compilationResult.type = expression.getType(); - console.log("input: " + JSON.stringify(fixture.expression)); - console.log("output: " + JSON.stringify(expression.serialize())); + const evaluate = fixture.inputs || []; + const evaluateResults = []; + for (const input of evaluate) { + const feature = Object.assign({ + type: 'Feature', + properties: {}, + geometry: { type: 'Point', coordinates: [0, 0] } + }, input[1]) - const evaluate = fixture.inputs || []; - const evaluateResults = []; - for (const input of evaluate) { - const feature = Object.assign({ - type: 'Feature', - properties: {}, - geometry: { type: 'Point', coordinates: [0, 0] } - }, input[1]) + const output = expression.evaluate(input[0], feature); + evaluateResults.push(output); + } - const output = expression.evaluate(input[0], feature); - evaluateResults.push(output); + if (fixture.inputs) { + return evaluateResults; + } + } else { + compilationResult.result = 'error'; + compilationResult.errors = expression; } + } - if (fixture.inputs) { - result.outputs = evaluateResults; - } - } else { - compiled.result = 'error'; - compiled.errors = expression; + result.outputs = evaluateExpression(expression, compiled); + if (expression instanceof mbgl.Expression) { + result.serialized = expression.serialize(); + const recompiledExpression = mbgl.Expression.parse(result.serialized, getExpectedType(spec)); + result.roundTripOutputs = evaluateExpression(recompiledExpression, recompiled); + // Type is allowed to change through serialization + // (eg "array" -> "array<number, 3>") + // Override the round-tripped type here so that the equality check passes + recompiled.type = compiled.type; } return result; |