-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
set up cross-platform testing for expressions
- Loading branch information
Anand Thakker
committed
Jun 19, 2017
1 parent
04dbb97
commit 0a272d4
Showing
68 changed files
with
3,193 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
|
||
require('flow-remove-types/register'); | ||
const util = require('../src/util/util'); | ||
const expressionSuite = require('./integration').expression; | ||
const compileExpression = require('../src/style-spec/function/compile'); | ||
|
||
let tests; | ||
|
||
if (process.argv[1] === __filename && process.argv.length > 2) { | ||
tests = process.argv.slice(2); | ||
} | ||
|
||
expressionSuite.run('js', {tests: tests}, (fixture) => { | ||
const compiled = compileExpression(fixture.expression); | ||
|
||
const testResult = { | ||
compileResult: util.pick(compiled, ['result', 'js', 'isFeatureConstant', 'isZoomConstant', 'errors']) | ||
}; | ||
if (compiled.result === 'success') testResult.compileResult.type = compiled.type.name; | ||
|
||
if (compiled.result === 'success' && fixture.evaluate) { | ||
const evaluateResults = []; | ||
for (const input of fixture.evaluate) { | ||
try { | ||
const output = compiled.function.apply(null, input); | ||
evaluateResults.push(output); | ||
} catch (error) { | ||
if (error.name === 'ExpressionEvaluationError') { | ||
evaluateResults.push({ error: error.toJSON() }); | ||
} else { | ||
evaluateResults.push({ error: error.message }); | ||
} | ||
} | ||
} | ||
if (evaluateResults.length) { | ||
testResult.evaluateResults = evaluateResults; | ||
} | ||
} | ||
|
||
return testResult; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"expression": [ | ||
"acos", | ||
0.5 | ||
], | ||
"evaluate": [ | ||
[ | ||
{}, | ||
{} | ||
] | ||
], | ||
"expected": { | ||
"compileResult": { | ||
"result": "success", | ||
"isFeatureConstant": true, | ||
"isZoomConstant": true, | ||
"type": "number" | ||
}, | ||
"evaluateResults": [ | ||
1.0471975511965976 | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"expression": [ | ||
"&&", | ||
[ | ||
"boolean", | ||
[ | ||
"get", | ||
[ | ||
"properties" | ||
], | ||
"x" | ||
] | ||
], | ||
[ | ||
"boolean", | ||
[ | ||
"get", | ||
[ | ||
"properties" | ||
], | ||
"y" | ||
] | ||
] | ||
], | ||
"evaluate": [ | ||
[ | ||
{}, | ||
{ | ||
"properties": { | ||
"x": true, | ||
"y": false | ||
} | ||
} | ||
], | ||
[ | ||
{}, | ||
{ | ||
"properties": { | ||
"x": true, | ||
"y": true | ||
} | ||
} | ||
] | ||
], | ||
"expected": { | ||
"compileResult": { | ||
"result": "success", | ||
"isFeatureConstant": false, | ||
"isZoomConstant": true, | ||
"type": "boolean" | ||
}, | ||
"evaluateResults": [ | ||
false, | ||
true | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"expression": [ | ||
"asin", | ||
0.5 | ||
], | ||
"evaluate": [ | ||
[ | ||
{}, | ||
{} | ||
] | ||
], | ||
"expected": { | ||
"compileResult": { | ||
"result": "success", | ||
"isFeatureConstant": true, | ||
"isZoomConstant": true, | ||
"type": "number" | ||
}, | ||
"evaluateResults": [ | ||
0.5235987755982988 | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"expression": [ | ||
"number", | ||
[ | ||
"at", | ||
[ | ||
"json_array", | ||
[ | ||
"get", | ||
[ | ||
"properties" | ||
], | ||
"arr" | ||
] | ||
], | ||
1 | ||
] | ||
], | ||
"evaluate": [ | ||
[ | ||
{}, | ||
{ | ||
"properties": { | ||
"arr": [ | ||
9, | ||
8, | ||
7 | ||
] | ||
} | ||
} | ||
] | ||
], | ||
"expected": { | ||
"compileResult": { | ||
"result": "success", | ||
"isFeatureConstant": false, | ||
"isZoomConstant": true, | ||
"type": "number" | ||
}, | ||
"evaluateResults": [ | ||
8 | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"expression": [ | ||
"atan", | ||
1 | ||
], | ||
"evaluate": [ | ||
[ | ||
{}, | ||
{} | ||
] | ||
], | ||
"expected": { | ||
"compileResult": { | ||
"result": "success", | ||
"isFeatureConstant": true, | ||
"isZoomConstant": true, | ||
"type": "number" | ||
}, | ||
"evaluateResults": [ | ||
0.7853981633974483 | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
{ | ||
"expression": [ | ||
"boolean", | ||
[ | ||
"get", | ||
[ | ||
"properties" | ||
], | ||
"x" | ||
] | ||
], | ||
"evaluate": [ | ||
[ | ||
{}, | ||
{} | ||
], | ||
[ | ||
{}, | ||
{ | ||
"properties": { | ||
"x": true | ||
} | ||
} | ||
], | ||
[ | ||
{}, | ||
{ | ||
"properties": { | ||
"x": false | ||
} | ||
} | ||
], | ||
[ | ||
{}, | ||
{ | ||
"properties": { | ||
"x": "" | ||
} | ||
} | ||
], | ||
[ | ||
{}, | ||
{ | ||
"properties": { | ||
"x": "false" | ||
} | ||
} | ||
], | ||
[ | ||
{}, | ||
{ | ||
"properties": { | ||
"x": 0 | ||
} | ||
} | ||
], | ||
[ | ||
{}, | ||
{ | ||
"properties": { | ||
"x": 1 | ||
} | ||
} | ||
], | ||
[ | ||
{}, | ||
{ | ||
"properties": { | ||
"x": null | ||
} | ||
} | ||
] | ||
], | ||
"expected": { | ||
"compileResult": { | ||
"result": "success", | ||
"isFeatureConstant": false, | ||
"isZoomConstant": true, | ||
"type": "boolean" | ||
}, | ||
"evaluateResults": [ | ||
{ | ||
"error": "ExpressionEvaluationError: Property x not found in object with keys: []" | ||
}, | ||
true, | ||
false, | ||
false, | ||
true, | ||
false, | ||
true, | ||
false | ||
] | ||
} | ||
} |
Oops, something went wrong.