diff options
author | Chris Loer <chris.loer@gmail.com> | 2018-02-09 17:21:58 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2018-02-28 16:09:09 -0800 |
commit | 3d591ae2a26be3041647a4b01e29c453aa8066c1 (patch) | |
tree | 024463d13f47b6e8072973891a60c0fd6825abcd /platform/node | |
parent | 75feda12f17dececadf72986c45af78fe18afc56 (diff) | |
download | qtlocation-mapboxgl-3d591ae2a26be3041647a4b01e29c453aa8066c1.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
Diffstat (limited to 'platform/node')
-rw-r--r-- | platform/node/test/expression.test.js | 60 |
1 files changed, 36 insertions, 24 deletions
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; |