|
|
@ -5,7 +5,7 @@ use crate::syntax::{ |
|
|
|
|
|
|
|
|
|
|
|
/// Checks `var` declaration parsing.
|
|
|
|
/// Checks `var` declaration parsing.
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn check_var_declaration() { |
|
|
|
fn var_declaration() { |
|
|
|
check_parser( |
|
|
|
check_parser( |
|
|
|
"var a = 5;", |
|
|
|
"var a = 5;", |
|
|
|
vec![Node::var_decl(vec![( |
|
|
|
vec![Node::var_decl(vec![( |
|
|
@ -15,9 +15,29 @@ fn check_var_declaration() { |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Checks `var` declaration parsing with reserved words.
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn var_declaration_keywords() { |
|
|
|
|
|
|
|
check_parser( |
|
|
|
|
|
|
|
"var yield = 5;", |
|
|
|
|
|
|
|
vec![Node::var_decl(vec![( |
|
|
|
|
|
|
|
String::from("yield"), |
|
|
|
|
|
|
|
Some(Node::const_node(5)), |
|
|
|
|
|
|
|
)])], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
check_parser( |
|
|
|
|
|
|
|
"var await = 5;", |
|
|
|
|
|
|
|
vec![Node::var_decl(vec![( |
|
|
|
|
|
|
|
String::from("await"), |
|
|
|
|
|
|
|
Some(Node::const_node(5)), |
|
|
|
|
|
|
|
)])], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Checks `var` declaration parsing with no spaces.
|
|
|
|
/// Checks `var` declaration parsing with no spaces.
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn check_var_declaration_no_spaces() { |
|
|
|
fn var_declaration_no_spaces() { |
|
|
|
check_parser( |
|
|
|
check_parser( |
|
|
|
"var a=5;", |
|
|
|
"var a=5;", |
|
|
|
vec![Node::var_decl(vec![( |
|
|
|
vec![Node::var_decl(vec![( |
|
|
@ -29,7 +49,7 @@ fn check_var_declaration_no_spaces() { |
|
|
|
|
|
|
|
|
|
|
|
/// Checks empty `var` declaration parsing.
|
|
|
|
/// Checks empty `var` declaration parsing.
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn check_empty_var_declaration() { |
|
|
|
fn empty_var_declaration() { |
|
|
|
check_parser( |
|
|
|
check_parser( |
|
|
|
"var a;", |
|
|
|
"var a;", |
|
|
|
vec![Node::var_decl(vec![(String::from("a"), None)])], |
|
|
|
vec![Node::var_decl(vec![(String::from("a"), None)])], |
|
|
@ -38,7 +58,7 @@ fn check_empty_var_declaration() { |
|
|
|
|
|
|
|
|
|
|
|
/// Checks multiple `var` declarations.
|
|
|
|
/// Checks multiple `var` declarations.
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn check_multiple_var_declaration() { |
|
|
|
fn multiple_var_declaration() { |
|
|
|
check_parser( |
|
|
|
check_parser( |
|
|
|
"var a = 5, b, c = 6;", |
|
|
|
"var a = 5, b, c = 6;", |
|
|
|
vec![Node::var_decl(vec![ |
|
|
|
vec![Node::var_decl(vec![ |
|
|
@ -51,7 +71,7 @@ fn check_multiple_var_declaration() { |
|
|
|
|
|
|
|
|
|
|
|
/// Checks `let` declaration parsing.
|
|
|
|
/// Checks `let` declaration parsing.
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn check_let_declaration() { |
|
|
|
fn let_declaration() { |
|
|
|
check_parser( |
|
|
|
check_parser( |
|
|
|
"let a = 5;", |
|
|
|
"let a = 5;", |
|
|
|
vec![Node::let_decl(vec![( |
|
|
|
vec![Node::let_decl(vec![( |
|
|
@ -61,9 +81,29 @@ fn check_let_declaration() { |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Checks `let` declaration parsing with reserved words.
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn let_declaration_keywords() { |
|
|
|
|
|
|
|
check_parser( |
|
|
|
|
|
|
|
"let yield = 5;", |
|
|
|
|
|
|
|
vec![Node::let_decl(vec![( |
|
|
|
|
|
|
|
String::from("yield"), |
|
|
|
|
|
|
|
Some(Node::const_node(5)), |
|
|
|
|
|
|
|
)])], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
check_parser( |
|
|
|
|
|
|
|
"let await = 5;", |
|
|
|
|
|
|
|
vec![Node::let_decl(vec![( |
|
|
|
|
|
|
|
String::from("await"), |
|
|
|
|
|
|
|
Some(Node::const_node(5)), |
|
|
|
|
|
|
|
)])], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Checks `let` declaration parsing with no spaces.
|
|
|
|
/// Checks `let` declaration parsing with no spaces.
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn check_let_declaration_no_spaces() { |
|
|
|
fn let_declaration_no_spaces() { |
|
|
|
check_parser( |
|
|
|
check_parser( |
|
|
|
"let a=5;", |
|
|
|
"let a=5;", |
|
|
|
vec![Node::let_decl(vec![( |
|
|
|
vec![Node::let_decl(vec![( |
|
|
@ -75,7 +115,7 @@ fn check_let_declaration_no_spaces() { |
|
|
|
|
|
|
|
|
|
|
|
/// Checks empty `let` declaration parsing.
|
|
|
|
/// Checks empty `let` declaration parsing.
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn check_empty_let_declaration() { |
|
|
|
fn empty_let_declaration() { |
|
|
|
check_parser( |
|
|
|
check_parser( |
|
|
|
"let a;", |
|
|
|
"let a;", |
|
|
|
vec![Node::let_decl(vec![(String::from("a"), None)])], |
|
|
|
vec![Node::let_decl(vec![(String::from("a"), None)])], |
|
|
@ -84,7 +124,7 @@ fn check_empty_let_declaration() { |
|
|
|
|
|
|
|
|
|
|
|
/// Checks multiple `let` declarations.
|
|
|
|
/// Checks multiple `let` declarations.
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn check_multiple_let_declaration() { |
|
|
|
fn multiple_let_declaration() { |
|
|
|
check_parser( |
|
|
|
check_parser( |
|
|
|
"let a = 5, b, c = 6;", |
|
|
|
"let a = 5, b, c = 6;", |
|
|
|
vec![Node::let_decl(vec![ |
|
|
|
vec![Node::let_decl(vec![ |
|
|
@ -97,7 +137,7 @@ fn check_multiple_let_declaration() { |
|
|
|
|
|
|
|
|
|
|
|
/// Checks `const` declaration parsing.
|
|
|
|
/// Checks `const` declaration parsing.
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn check_const_declaration() { |
|
|
|
fn const_declaration() { |
|
|
|
check_parser( |
|
|
|
check_parser( |
|
|
|
"const a = 5;", |
|
|
|
"const a = 5;", |
|
|
|
vec![Node::const_decl(vec![( |
|
|
|
vec![Node::const_decl(vec![( |
|
|
@ -107,9 +147,29 @@ fn check_const_declaration() { |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Checks `const` declaration parsing with reserved words.
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn const_declaration_keywords() { |
|
|
|
|
|
|
|
check_parser( |
|
|
|
|
|
|
|
"const yield = 5;", |
|
|
|
|
|
|
|
vec![Node::const_decl(vec![( |
|
|
|
|
|
|
|
String::from("yield"), |
|
|
|
|
|
|
|
Node::const_node(5), |
|
|
|
|
|
|
|
)])], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
check_parser( |
|
|
|
|
|
|
|
"const await = 5;", |
|
|
|
|
|
|
|
vec![Node::const_decl(vec![( |
|
|
|
|
|
|
|
String::from("await"), |
|
|
|
|
|
|
|
Node::const_node(5), |
|
|
|
|
|
|
|
)])], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Checks `const` declaration parsing with no spaces.
|
|
|
|
/// Checks `const` declaration parsing with no spaces.
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn check_const_declaration_no_spaces() { |
|
|
|
fn const_declaration_no_spaces() { |
|
|
|
check_parser( |
|
|
|
check_parser( |
|
|
|
"const a=5;", |
|
|
|
"const a=5;", |
|
|
|
vec![Node::const_decl(vec![( |
|
|
|
vec![Node::const_decl(vec![( |
|
|
@ -121,13 +181,13 @@ fn check_const_declaration_no_spaces() { |
|
|
|
|
|
|
|
|
|
|
|
/// Checks empty `const` declaration parsing.
|
|
|
|
/// Checks empty `const` declaration parsing.
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn check_empty_const_declaration() { |
|
|
|
fn empty_const_declaration() { |
|
|
|
check_invalid("const a;"); |
|
|
|
check_invalid("const a;"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Checks multiple `const` declarations.
|
|
|
|
/// Checks multiple `const` declarations.
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn check_multiple_const_declaration() { |
|
|
|
fn multiple_const_declaration() { |
|
|
|
check_parser( |
|
|
|
check_parser( |
|
|
|
"const a = 5, c = 6;", |
|
|
|
"const a = 5, c = 6;", |
|
|
|
vec![Node::const_decl(vec![ |
|
|
|
vec![Node::const_decl(vec![ |
|
|
@ -136,3 +196,38 @@ fn check_multiple_const_declaration() { |
|
|
|
])], |
|
|
|
])], |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Function declaration parsing.
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn function_declaration() { |
|
|
|
|
|
|
|
check_parser( |
|
|
|
|
|
|
|
"function hello() {}", |
|
|
|
|
|
|
|
vec![Node::function_decl( |
|
|
|
|
|
|
|
"hello", |
|
|
|
|
|
|
|
vec![], |
|
|
|
|
|
|
|
Node::statement_list(vec![]), |
|
|
|
|
|
|
|
)], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Function declaration parsing with keywords.
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn function_declaration_keywords() { |
|
|
|
|
|
|
|
check_parser( |
|
|
|
|
|
|
|
"function yield() {}", |
|
|
|
|
|
|
|
vec![Node::function_decl( |
|
|
|
|
|
|
|
"yield", |
|
|
|
|
|
|
|
vec![], |
|
|
|
|
|
|
|
Node::statement_list(vec![]), |
|
|
|
|
|
|
|
)], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
check_parser( |
|
|
|
|
|
|
|
"function await() {}", |
|
|
|
|
|
|
|
vec![Node::function_decl( |
|
|
|
|
|
|
|
"await", |
|
|
|
|
|
|
|
vec![], |
|
|
|
|
|
|
|
Node::statement_list(vec![]), |
|
|
|
|
|
|
|
)], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|