Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[test] Native expression test support for:
Browse files Browse the repository at this point in the history
 - Round-tripping expressions through serialization and checking that outputs don't change
 - Checking expression serialization against expected value from fixture
  • Loading branch information
ChrisLoer authored and tobrun committed Feb 26, 2018
1 parent fa49e21 commit 8a45887
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
2 changes: 1 addition & 1 deletion mapbox-gl-js
Submodule mapbox-gl-js updated 164 files
60 changes: 36 additions & 24 deletions platform/node/test/expression.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8a45887

Please sign in to comment.