Leave newlines in javascript test programs
This commit is contained in:
parent
21258e6a9e
commit
14d7ebb7da
5 changed files with 166 additions and 160 deletions
|
|
@ -9,138 +9,140 @@ secondFunction(x);
|
|||
---
|
||||
|
||||
(program
|
||||
(var_declaration
|
||||
(var_assignment (identifier) (object))
|
||||
(identifier)
|
||||
(var_assignment (identifier) (number)))
|
||||
(expression_statement (function_call (identifier) (identifier)))
|
||||
(expression_statement (function_call (identifier) (identifier))))
|
||||
(var_declaration
|
||||
(var_assignment (identifier) (object))
|
||||
(identifier)
|
||||
(var_assignment (identifier) (number)))
|
||||
(expression_statement (function_call (identifier) (identifier)))
|
||||
(expression_statement (function_call (identifier) (identifier))))
|
||||
|
||||
==========================================
|
||||
if statements
|
||||
==========================================
|
||||
|
||||
if (isReady()) {
|
||||
console.log(theData)
|
||||
console.log(theData)
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(if_statement (function_call (identifier))
|
||||
(statement_block (expression_statement (function_call (member_access (identifier) (identifier)) (identifier)))))
|
||||
(program (if_statement (function_call (identifier))
|
||||
(statement_block (expression_statement
|
||||
(function_call (member_access (identifier) (identifier)) (identifier))))))
|
||||
|
||||
==========================================
|
||||
if-else statements
|
||||
==========================================
|
||||
|
||||
if (theCondition) {
|
||||
firstFunction();
|
||||
firstFunction();
|
||||
} else {
|
||||
secondFunction();
|
||||
secondFunction();
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(if_statement
|
||||
(identifier)
|
||||
(statement_block (expression_statement (function_call (identifier))))
|
||||
(statement_block (expression_statement (function_call (identifier)))))
|
||||
(program (if_statement
|
||||
(identifier)
|
||||
(statement_block (expression_statement (function_call (identifier))))
|
||||
(statement_block (expression_statement (function_call (identifier))))))
|
||||
|
||||
==================================================
|
||||
if-else statements with multiple conditions
|
||||
==================================================
|
||||
|
||||
if (firstValue) {
|
||||
firstFunction();
|
||||
firstFunction();
|
||||
} else if (secondValue)
|
||||
secondFunction();
|
||||
secondFunction();
|
||||
else {
|
||||
thirdFunction();
|
||||
thirdFunction();
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(if_statement (identifier)
|
||||
(statement_block (expression_statement (function_call (identifier))))
|
||||
(if_statement (identifier)
|
||||
(expression_statement (function_call (identifier)))
|
||||
(statement_block (expression_statement (function_call (identifier))))))
|
||||
(program (if_statement (identifier)
|
||||
(statement_block (expression_statement (function_call (identifier))))
|
||||
(if_statement (identifier)
|
||||
(expression_statement (function_call (identifier)))
|
||||
(statement_block (expression_statement (function_call (identifier)))))))
|
||||
|
||||
==========================================
|
||||
for loops
|
||||
==========================================
|
||||
|
||||
for (var i = 1; someCondition(i); i = next()) {
|
||||
doSomething();
|
||||
doSomething();
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(for_statement
|
||||
(var_declaration (var_assignment (identifier) (number)))
|
||||
(function_call (identifier) (identifier))
|
||||
(assignment (identifier) (function_call (identifier)))
|
||||
(statement_block (expression_statement (function_call (identifier)))))
|
||||
(program (for_statement
|
||||
(var_declaration (var_assignment (identifier) (number)))
|
||||
(function_call (identifier) (identifier))
|
||||
(assignment (identifier) (function_call (identifier)))
|
||||
(statement_block (expression_statement (function_call (identifier))))))
|
||||
|
||||
==========================================
|
||||
for-in loops
|
||||
==========================================
|
||||
|
||||
for (var key in someObject)
|
||||
doSomething();
|
||||
doSomething();
|
||||
for (key in someObject)
|
||||
doSomethingElse();
|
||||
doSomethingElse();
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(for_in_statement
|
||||
(identifier) (identifier)
|
||||
(expression_statement (function_call (identifier))))
|
||||
(for_in_statement
|
||||
(identifier) (identifier)
|
||||
(expression_statement (function_call (identifier)))))
|
||||
(for_in_statement
|
||||
(identifier) (identifier)
|
||||
(expression_statement (function_call (identifier))))
|
||||
(for_in_statement
|
||||
(identifier) (identifier)
|
||||
(expression_statement (function_call (identifier)))))
|
||||
|
||||
==========================================
|
||||
while loops
|
||||
==========================================
|
||||
|
||||
while (someCondition(i)) {
|
||||
doSomething();
|
||||
doSomething();
|
||||
}
|
||||
|
||||
---
|
||||
(while_statement
|
||||
(function_call (identifier) (identifier))
|
||||
(statement_block (expression_statement (function_call (identifier)))))
|
||||
|
||||
(program (while_statement
|
||||
(function_call (identifier) (identifier))
|
||||
(statement_block (expression_statement (function_call (identifier))))))
|
||||
|
||||
==========================================
|
||||
try/catch statements
|
||||
==========================================
|
||||
|
||||
try {
|
||||
doSomething();
|
||||
doSomething();
|
||||
} catch (e) {
|
||||
logError(e);
|
||||
logError(e);
|
||||
}
|
||||
|
||||
try {
|
||||
doSomething();
|
||||
doSomething();
|
||||
} finally {
|
||||
logError();
|
||||
logError();
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(try_statement
|
||||
(statement_block (expression_statement (function_call (identifier))))
|
||||
(catch (identifier)
|
||||
(statement_block (expression_statement (function_call (identifier) (identifier))))))
|
||||
(try_statement
|
||||
(statement_block (expression_statement (function_call (identifier))))
|
||||
(finally
|
||||
(statement_block (expression_statement (function_call (identifier)))))))
|
||||
(try_statement
|
||||
(statement_block (expression_statement (function_call (identifier))))
|
||||
(catch (identifier)
|
||||
(statement_block (expression_statement (function_call (identifier) (identifier))))))
|
||||
(try_statement
|
||||
(statement_block (expression_statement (function_call (identifier))))
|
||||
(finally
|
||||
(statement_block (expression_statement (function_call (identifier)))))))
|
||||
|
||||
===========================================
|
||||
throw statements
|
||||
|
|
@ -150,7 +152,8 @@ throw new Error("wtf");
|
|||
|
||||
---
|
||||
|
||||
(throw_statement (constructor_call (identifier) (string)))
|
||||
(program
|
||||
(throw_statement (constructor_call (identifier) (string))))
|
||||
|
||||
===========================================
|
||||
indented code after blocks
|
||||
|
|
@ -162,35 +165,35 @@ indented code after blocks
|
|||
---
|
||||
|
||||
(program
|
||||
(expression_statement
|
||||
(function_expression (identifier) (statement_block)))
|
||||
(return_statement (identifier)))
|
||||
(expression_statement
|
||||
(function_expression (identifier) (statement_block)))
|
||||
(return_statement (identifier)))
|
||||
|
||||
===========================================
|
||||
switch statements
|
||||
===========================================
|
||||
|
||||
switch(x) {
|
||||
case "hello":
|
||||
print("one");
|
||||
break;
|
||||
case z():
|
||||
print("two");
|
||||
break;
|
||||
default:
|
||||
print("three");
|
||||
case "hello":
|
||||
print("one");
|
||||
break;
|
||||
case z():
|
||||
print("two");
|
||||
break;
|
||||
default:
|
||||
print("three");
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(switch_statement (identifier)
|
||||
(case
|
||||
(string)
|
||||
(expression_statement (function_call (identifier) (string)))
|
||||
(break_statement))
|
||||
(case
|
||||
(function_call (identifier))
|
||||
(expression_statement (function_call (identifier) (string)))
|
||||
(break_statement))
|
||||
(default
|
||||
(expression_statement (function_call (identifier) (string)))))
|
||||
(program (switch_statement (identifier)
|
||||
(case
|
||||
(string)
|
||||
(expression_statement (function_call (identifier) (string)))
|
||||
(break_statement))
|
||||
(case
|
||||
(function_call (identifier))
|
||||
(expression_statement (function_call (identifier) (string)))
|
||||
(break_statement))
|
||||
(default
|
||||
(expression_statement (function_call (identifier) (string))))))
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ stuff(|||);
|
|||
|
||||
---
|
||||
|
||||
(expression_statement (function_call (identifier) (ERROR (UNEXPECTED '|'))))
|
||||
(program
|
||||
(expression_statement (function_call (identifier) (ERROR (UNEXPECTED '|')))))
|
||||
|
||||
==========================================
|
||||
errors in if statements
|
||||
|
|
@ -14,7 +15,7 @@ errors in if statements
|
|||
|
||||
stuff();
|
||||
if (*nonsense*) {
|
||||
*more-nonsense*;
|
||||
*more-nonsense*;
|
||||
}
|
||||
moreStuff();
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ theFunction(/regex1/, /regex2/g);
|
|||
|
||||
---
|
||||
|
||||
(expression_statement (function_call (identifier)
|
||||
(arguments (regex) (regex))))
|
||||
(program (expression_statement
|
||||
(function_call (identifier) (arguments (regex) (regex)))))
|
||||
|
||||
==========================================
|
||||
numbers
|
||||
|
|
@ -17,8 +17,8 @@ theFunction(100.0, 200);
|
|||
|
||||
---
|
||||
|
||||
(expression_statement (function_call (identifier)
|
||||
(arguments (number) (number))))
|
||||
(program (expression_statement
|
||||
(function_call (identifier) (arguments (number) (number)))))
|
||||
|
||||
==========================================
|
||||
strings
|
||||
|
|
@ -28,27 +28,29 @@ theFunction('', "", 'single-quoted-string', "double-quoted-string");
|
|||
|
||||
---
|
||||
|
||||
(expression_statement (function_call (identifier)
|
||||
(arguments (string) (string) (string) (string))))
|
||||
(program (expression_statement
|
||||
(function_call (identifier)
|
||||
(arguments (string) (string) (string) (string)))))
|
||||
|
||||
==========================================
|
||||
function expressions
|
||||
==========================================
|
||||
|
||||
var x = {
|
||||
theMethod: function(argA, argB) {
|
||||
var x = argA;
|
||||
}
|
||||
theMethod: function(argA, argB) {
|
||||
var x = argA;
|
||||
}
|
||||
};
|
||||
|
||||
---
|
||||
|
||||
(var_declaration (var_assignment
|
||||
(program
|
||||
(var_declaration (var_assignment
|
||||
(identifier)
|
||||
(object (pair (identifier) (function_expression
|
||||
(formal_parameters (identifier) (identifier))
|
||||
(statement_block
|
||||
(var_declaration (var_assignment (identifier) (identifier)))))))))
|
||||
(formal_parameters (identifier) (identifier))
|
||||
(statement_block
|
||||
(var_declaration (var_assignment (identifier) (identifier))))))))))
|
||||
|
||||
==========================================
|
||||
comments
|
||||
|
|
@ -58,13 +60,13 @@ comments
|
|||
// here we go.
|
||||
var thing = {
|
||||
|
||||
// this is a property.
|
||||
// its value is a function.
|
||||
key: function(x /* this is a parameter */) {
|
||||
// this is a property.
|
||||
// its value is a function.
|
||||
key: function(x /* this is a parameter */) {
|
||||
|
||||
// this is a statement
|
||||
doStuff();
|
||||
}
|
||||
// this is a statement
|
||||
doStuff();
|
||||
}
|
||||
};
|
||||
|
||||
---
|
||||
|
|
@ -73,15 +75,15 @@ var thing = {
|
|||
(comment)
|
||||
(comment)
|
||||
(var_declaration (var_assignment
|
||||
(identifier)
|
||||
(object
|
||||
(identifier)
|
||||
(object
|
||||
(comment)
|
||||
(comment)
|
||||
(pair (identifier) (function_expression
|
||||
(formal_parameters (identifier) (comment))
|
||||
(statement_block
|
||||
(comment)
|
||||
(comment)
|
||||
(pair (identifier) (function_expression
|
||||
(formal_parameters (identifier) (comment))
|
||||
(statement_block
|
||||
(comment)
|
||||
(expression_statement (function_call (identifier))))))))))
|
||||
(expression_statement (function_call (identifier))))))))))
|
||||
|
||||
==========================================
|
||||
comments within expressions
|
||||
|
|
@ -92,4 +94,5 @@ y // comment
|
|||
|
||||
---
|
||||
|
||||
(expression_statement (math_op (expression (identifier) (comment)) (identifier)))
|
||||
(program (expression_statement
|
||||
(math_op (expression (identifier) (comment)) (identifier))))
|
||||
|
|
|
|||
|
|
@ -6,9 +6,10 @@ x.theMethod(5, 6);
|
|||
|
||||
---
|
||||
|
||||
(expression_statement (function_call
|
||||
(program (expression_statement
|
||||
(function_call
|
||||
(member_access (identifier) (identifier))
|
||||
(arguments (number) (number))))
|
||||
(arguments (number) (number)))))
|
||||
|
||||
==========================================
|
||||
constructor calls
|
||||
|
|
@ -18,13 +19,13 @@ var x = new Node(5, new Node(3, null));
|
|||
|
||||
---
|
||||
|
||||
(var_declaration (var_assignment
|
||||
(identifier)
|
||||
(program (var_declaration (var_assignment
|
||||
(identifier)
|
||||
(constructor_call (identifier) (arguments
|
||||
(number)
|
||||
(constructor_call (identifier) (arguments
|
||||
(number)
|
||||
(constructor_call (identifier) (arguments
|
||||
(number)
|
||||
(null)))))))
|
||||
(number)
|
||||
(null))))))))
|
||||
|
||||
==========================================
|
||||
property access with dot notation
|
||||
|
|
@ -36,12 +37,12 @@ print(object.property);
|
|||
---
|
||||
|
||||
(program
|
||||
(expression_statement (assignment
|
||||
(member_access (identifier) (identifier))
|
||||
(string)))
|
||||
(expression_statement (function_call
|
||||
(identifier)
|
||||
(member_access (identifier) (identifier)))))
|
||||
(expression_statement (assignment
|
||||
(member_access (identifier) (identifier))
|
||||
(string)))
|
||||
(expression_statement (function_call
|
||||
(identifier)
|
||||
(member_access (identifier) (identifier)))))
|
||||
|
||||
==========================================
|
||||
property access across lines
|
||||
|
|
@ -53,10 +54,10 @@ object
|
|||
|
||||
---
|
||||
|
||||
(expression_statement
|
||||
(member_access
|
||||
(member_access (identifier) (identifier))
|
||||
(identifier)))
|
||||
(program (expression_statement
|
||||
(member_access
|
||||
(member_access (identifier) (identifier))
|
||||
(identifier))))
|
||||
|
||||
===========================================
|
||||
dynamic property access
|
||||
|
|
@ -66,13 +67,14 @@ object[propertName()] = propertyValue();
|
|||
print(object[propertyName()]);
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(expression_statement (assignment
|
||||
(subscript_access (identifier) (function_call (identifier)))
|
||||
(function_call (identifier))))
|
||||
(expression_statement (function_call
|
||||
(identifier)
|
||||
(subscript_access (identifier) (function_call (identifier))))))
|
||||
(expression_statement (assignment
|
||||
(subscript_access (identifier) (function_call (identifier)))
|
||||
(function_call (identifier))))
|
||||
(expression_statement (function_call
|
||||
(identifier)
|
||||
(subscript_access (identifier) (function_call (identifier))))))
|
||||
|
||||
==========================================
|
||||
ternary expressions
|
||||
|
|
@ -82,10 +84,10 @@ print(isDone() ? stuff : otherStuff);
|
|||
|
||||
---
|
||||
|
||||
(expression_statement
|
||||
(function_call
|
||||
(identifier)
|
||||
(ternary (function_call (identifier)) (identifier) (identifier))))
|
||||
(program (expression_statement
|
||||
(function_call
|
||||
(identifier)
|
||||
(ternary (function_call (identifier)) (identifier) (identifier)))))
|
||||
|
||||
==========================================
|
||||
mathematical operators
|
||||
|
|
@ -94,14 +96,15 @@ mathematical operators
|
|||
a++ + b * c - d / e--
|
||||
|
||||
---
|
||||
(expression_statement
|
||||
|
||||
(program (expression_statement
|
||||
(math_op
|
||||
(math_op
|
||||
(math_op (identifier))
|
||||
(math_op (identifier) (identifier)))
|
||||
(math_op
|
||||
(identifier)
|
||||
(math_op (identifier)))))
|
||||
(math_op (identifier))))))
|
||||
|
||||
==========================================
|
||||
boolean operators
|
||||
|
|
@ -111,11 +114,11 @@ boolean operators
|
|||
|
||||
---
|
||||
|
||||
(expression_statement
|
||||
(program (expression_statement
|
||||
(bool_op
|
||||
(bool_op (identifier))
|
||||
(bool_op
|
||||
(bool_op (identifier))
|
||||
(bool_op
|
||||
(expression (bool_op (identifier) (identifier))))))
|
||||
(expression (bool_op (identifier) (identifier)))))))
|
||||
|
||||
===========================================
|
||||
type operators
|
||||
|
|
@ -125,10 +128,11 @@ print((x instanceof Array) || (typeof x === "string"))
|
|||
|
||||
---
|
||||
|
||||
(expression_statement (function_call (identifier)
|
||||
(program (expression_statement
|
||||
(function_call (identifier)
|
||||
(bool_op
|
||||
(expression (type_op (identifier) (identifier)))
|
||||
(expression (rel_op (type_op (identifier)) (string))))))
|
||||
(expression (type_op (identifier) (identifier)))
|
||||
(expression (rel_op (type_op (identifier)) (string)))))))
|
||||
|
||||
============================================
|
||||
the 'in' operator
|
||||
|
|
@ -137,9 +141,11 @@ the 'in' operator
|
|||
print(x in y)
|
||||
|
||||
---
|
||||
(expression_statement (function_call
|
||||
|
||||
(program (expression_statement
|
||||
(function_call
|
||||
(identifier)
|
||||
(type_op (identifier) (identifier))))
|
||||
(type_op (identifier) (identifier)))))
|
||||
|
||||
============================================
|
||||
assignment operators
|
||||
|
|
@ -153,10 +159,10 @@ x /= 2;
|
|||
---
|
||||
|
||||
(program
|
||||
(expression_statement (math_assignment (identifier) (number)))
|
||||
(expression_statement (math_assignment (identifier) (number)))
|
||||
(expression_statement (math_assignment (identifier) (number)))
|
||||
(expression_statement (math_assignment (identifier) (number))))
|
||||
(expression_statement (math_assignment (identifier) (number)))
|
||||
(expression_statement (math_assignment (identifier) (number)))
|
||||
(expression_statement (math_assignment (identifier) (number)))
|
||||
(expression_statement (math_assignment (identifier) (number))))
|
||||
|
||||
============================================
|
||||
property access and operators
|
||||
|
|
@ -166,7 +172,8 @@ print(x.y.z && a.b.c)
|
|||
|
||||
---
|
||||
|
||||
(expression_statement (function_call (identifier)
|
||||
(program (expression_statement
|
||||
(function_call (identifier)
|
||||
(bool_op
|
||||
(member_access (member_access (identifier) (identifier)) (identifier))
|
||||
(member_access (member_access (identifier) (identifier)) (identifier)))))
|
||||
(member_access (member_access (identifier) (identifier)) (identifier))
|
||||
(member_access (member_access (identifier) (identifier)) (identifier))))))
|
||||
|
|
|
|||
|
|
@ -10,12 +10,6 @@ extern "C" const TSLanguage *ts_language_arithmetic();
|
|||
extern "C" const TSLanguage *ts_language_golang();
|
||||
extern "C" const TSLanguage *ts_language_c();
|
||||
|
||||
static string trim_newlines(const string &input) {
|
||||
size_t start = input.find_first_not_of("\n");
|
||||
size_t last = input.find_last_not_of("\n");
|
||||
return input.substr(start, last + 1);
|
||||
}
|
||||
|
||||
START_TEST
|
||||
|
||||
describe("Languages", [&]() {
|
||||
|
|
@ -37,8 +31,6 @@ describe("Languages", [&]() {
|
|||
});
|
||||
|
||||
for (auto &entry : test_entries_for_language(language_name)) {
|
||||
entry.input = trim_newlines(entry.input);
|
||||
|
||||
auto expect_the_correct_tree = [&]() {
|
||||
const char *node_string = ts_node_string(ts_document_root_node(doc), doc);
|
||||
AssertThat(node_string, Equals(entry.tree_string.c_str()));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue