[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
This commit is contained in:
Submodule mapbox-gl-js updated: d61850a6bd...8a19f60799
@@ -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));
|
||||
|
||||
const evaluateExpression = (expression, compilationResult) => {
|
||||
if (expression instanceof mbgl.Expression) {
|
||||
compilationResult.result = 'success';
|
||||
compilationResult.isFeatureConstant = expression.isFeatureConstant();
|
||||
compilationResult.isZoomConstant = expression.isZoomConstant();
|
||||
compilationResult.type = expression.getType();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (fixture.inputs) {
|
||||
return evaluateResults;
|
||||
}
|
||||
} else {
|
||||
compilationResult.result = 'error';
|
||||
compilationResult.errors = expression;
|
||||
}
|
||||
}
|
||||
|
||||
result.outputs = evaluateExpression(expression, compiled);
|
||||
if (expression instanceof mbgl.Expression) {
|
||||
compiled.result = 'success';
|
||||
compiled.isFeatureConstant = expression.isFeatureConstant();
|
||||
compiled.isZoomConstant = expression.isZoomConstant();
|
||||
compiled.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 output = expression.evaluate(input[0], feature);
|
||||
evaluateResults.push(output);
|
||||
}
|
||||
|
||||
if (fixture.inputs) {
|
||||
result.outputs = evaluateResults;
|
||||
}
|
||||
} else {
|
||||
compiled.result = 'error';
|
||||
compiled.errors = 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;
|
||||
|
||||
Reference in New Issue
Block a user