Skip to content

Commit

Permalink
enable esprima tests for iterators
Browse files Browse the repository at this point in the history
Summary: flow supports for-of but the esprima tests were disabled.

one of the cases (`for (var x = 42 of list)`) fails in flow but passes in esprima-fb 15001.1.0-dev-harmony-fb. afaict, it's fixed in upstream esprima so we can delete the expected difference once we merge/upgrade.

also, turns out that the esprima test runner doesn't handle the case where we error but esprima doesn't. fixed that by making it generate diffs for the errors so that we can expect them.

Reviewed By: @gabelevi

Differential Revision: D2193570
  • Loading branch information
mroch authored and facebook-github-bot-4 committed Jun 29, 2015
1 parent 151759d commit d8961c0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
23 changes: 14 additions & 9 deletions src/parser/test/esprima_test_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ function new_env() {

function diff_to_string(diff) {
var expected_str = "";
if (typeof diff.expected !== "undefined") {
if (typeof diff.expected !== "undefined" ||
typeof diff.actual !== "undefined") {
expected_str =
". Expected " + diff.expected + ", got " + diff.actual;
}
Expand Down Expand Up @@ -393,17 +394,21 @@ function runTest(test, esprima_opts) {
compare(esprima_ast, flow_ast, env);

if (flow_errors.length !== 0) {
result.passed = false;
output("****Unexpected Errors****");
env.push_path('errors');
for (var i = 0; i < flow_errors.length; i++) {
var e = flow_errors[i];
output(
"(#" + i + ")",
"(line " + e.loc.start.line + ", col " + e.loc.start.column + ") - " +
"(line " + e.loc.end.line + ", col " + e.loc.end.column + "): ",
e.message
);
env.push_path(i);
env.push_path('column');
env.diff("Wrong error column", undefined, e.loc.start.column + 1);
env.pop_path();
env.push_path('line');
env.diff("Wrong error line", undefined, e.loc.start.line);
env.pop_path();
env.push_path('message');
env.diff("Wrong error message", undefined, e.message);
env.pop_path();
}
env.pop_path();
}

var ast_types_errors = env.get_ast_types_errors();
Expand Down
24 changes: 22 additions & 2 deletions src/parser/test/esprima_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4154,8 +4154,28 @@ module.exports = {
'Harmony: Iterators': [
'for(x of list) process(x);',
'for (var x of list) process(x);',
'for (var x = 42 of list) process(x);',
'for (let x of list) process(x);'
'for (let x of list) process(x);',
{
content: 'for (var x = 42 of list) process(x);',
explanation: "Esprima thinks this is valid, it isn't",
expected_differences : {
'root.errors.0.column': {
type: 'Wrong error column',
expected: undefined,
actual: 6,
},
'root.errors.0.line': {
type: 'Wrong error line',
expected: undefined,
actual: 1,
},
'root.errors.0.message': {
type: 'Wrong error message',
expected: undefined,
actual: 'Invalid left-hand side in for-of',
}
}
}
],


Expand Down
1 change: 0 additions & 1 deletion src/parser/test/run_esprima_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ var todo = {
'Invalid Type Annotations': true,
'Array Comprehension': true,
'Harmony: Modules': true,
'Harmony: Iterators': true,
'Harmony: Invalid Class (strawman)': true,
'ES6: Destructured Parameters': true,
'ES7 Proposal: Rest Properties' : true,
Expand Down

0 comments on commit d8961c0

Please sign in to comment.