|
|
|
@ -5,7 +5,7 @@ use crate::syntax::{
|
|
|
|
|
|
|
|
|
|
/// Checks `var` declaration parsing.
|
|
|
|
|
#[test] |
|
|
|
|
fn check_var_declaration() { |
|
|
|
|
fn var_declaration() { |
|
|
|
|
check_parser( |
|
|
|
|
"var a = 5;", |
|
|
|
|
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.
|
|
|
|
|
#[test] |
|
|
|
|
fn check_var_declaration_no_spaces() { |
|
|
|
|
fn var_declaration_no_spaces() { |
|
|
|
|
check_parser( |
|
|
|
|
"var a=5;", |
|
|
|
|
vec![Node::var_decl(vec![( |
|
|
|
@ -29,7 +49,7 @@ fn check_var_declaration_no_spaces() {
|
|
|
|
|
|
|
|
|
|
/// Checks empty `var` declaration parsing.
|
|
|
|
|
#[test] |
|
|
|
|
fn check_empty_var_declaration() { |
|
|
|
|
fn empty_var_declaration() { |
|
|
|
|
check_parser( |
|
|
|
|
"var a;", |
|
|
|
|
vec![Node::var_decl(vec![(String::from("a"), None)])], |
|
|
|
@ -38,7 +58,7 @@ fn check_empty_var_declaration() {
|
|
|
|
|
|
|
|
|
|
/// Checks multiple `var` declarations.
|
|
|
|
|
#[test] |
|
|
|
|
fn check_multiple_var_declaration() { |
|
|
|
|
fn multiple_var_declaration() { |
|
|
|
|
check_parser( |
|
|
|
|
"var a = 5, b, c = 6;", |
|
|
|
|
vec![Node::var_decl(vec![ |
|
|
|
@ -51,7 +71,7 @@ fn check_multiple_var_declaration() {
|
|
|
|
|
|
|
|
|
|
/// Checks `let` declaration parsing.
|
|
|
|
|
#[test] |
|
|
|
|
fn check_let_declaration() { |
|
|
|
|
fn let_declaration() { |
|
|
|
|
check_parser( |
|
|
|
|
"let a = 5;", |
|
|
|
|
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.
|
|
|
|
|
#[test] |
|
|
|
|
fn check_let_declaration_no_spaces() { |
|
|
|
|
fn let_declaration_no_spaces() { |
|
|
|
|
check_parser( |
|
|
|
|
"let a=5;", |
|
|
|
|
vec![Node::let_decl(vec![( |
|
|
|
@ -75,7 +115,7 @@ fn check_let_declaration_no_spaces() {
|
|
|
|
|
|
|
|
|
|
/// Checks empty `let` declaration parsing.
|
|
|
|
|
#[test] |
|
|
|
|
fn check_empty_let_declaration() { |
|
|
|
|
fn empty_let_declaration() { |
|
|
|
|
check_parser( |
|
|
|
|
"let a;", |
|
|
|
|
vec![Node::let_decl(vec![(String::from("a"), None)])], |
|
|
|
@ -84,7 +124,7 @@ fn check_empty_let_declaration() {
|
|
|
|
|
|
|
|
|
|
/// Checks multiple `let` declarations.
|
|
|
|
|
#[test] |
|
|
|
|
fn check_multiple_let_declaration() { |
|
|
|
|
fn multiple_let_declaration() { |
|
|
|
|
check_parser( |
|
|
|
|
"let a = 5, b, c = 6;", |
|
|
|
|
vec![Node::let_decl(vec![ |
|
|
|
@ -97,7 +137,7 @@ fn check_multiple_let_declaration() {
|
|
|
|
|
|
|
|
|
|
/// Checks `const` declaration parsing.
|
|
|
|
|
#[test] |
|
|
|
|
fn check_const_declaration() { |
|
|
|
|
fn const_declaration() { |
|
|
|
|
check_parser( |
|
|
|
|
"const a = 5;", |
|
|
|
|
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.
|
|
|
|
|
#[test] |
|
|
|
|
fn check_const_declaration_no_spaces() { |
|
|
|
|
fn const_declaration_no_spaces() { |
|
|
|
|
check_parser( |
|
|
|
|
"const a=5;", |
|
|
|
|
vec![Node::const_decl(vec![( |
|
|
|
@ -121,13 +181,13 @@ fn check_const_declaration_no_spaces() {
|
|
|
|
|
|
|
|
|
|
/// Checks empty `const` declaration parsing.
|
|
|
|
|
#[test] |
|
|
|
|
fn check_empty_const_declaration() { |
|
|
|
|
fn empty_const_declaration() { |
|
|
|
|
check_invalid("const a;"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Checks multiple `const` declarations.
|
|
|
|
|
#[test] |
|
|
|
|
fn check_multiple_const_declaration() { |
|
|
|
|
fn multiple_const_declaration() { |
|
|
|
|
check_parser( |
|
|
|
|
"const a = 5, c = 6;", |
|
|
|
|
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![]), |
|
|
|
|
)], |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|