use crate::syntax::{
ast::{
node::{
ConstDecl, ConstDeclList, FunctionDecl, LetDecl, LetDeclList, Node, VarDecl,
VarDeclList,
},
Const,
},
parser::tests::{check_invalid, check_parser},
};
#[test]
fn var_declaration() {
check_parser(
"var a = 5;",
vec![VarDeclList::from(vec![VarDecl::new("a", Some(Const::from(5).into()))]).into()],
);
}
#[test]
fn var_declaration_keywords() {
check_parser(
"var yield = 5;",
vec![VarDeclList::from(vec![VarDecl::new("yield", Some(Const::from(5).into()))]).into()],
);
check_parser(
"var await = 5;",
vec![VarDeclList::from(vec![VarDecl::new("await", Some(Const::from(5).into()))]).into()],
);
}
#[test]
fn var_declaration_no_spaces() {
check_parser(
"var a=5;",
vec![VarDeclList::from(vec![VarDecl::new("a", Some(Const::from(5).into()))]).into()],
);
}
#[test]
fn empty_var_declaration() {
check_parser(
"var a;",
vec![VarDeclList::from(vec![VarDecl::new("a", None)]).into()],
);
}
#[test]
fn multiple_var_declaration() {
check_parser(
"var a = 5, b, c = 6;",
vec![VarDeclList::from(vec![
VarDecl::new("a", Some(Const::from(5).into())),
VarDecl::new("b", None),
VarDecl::new("c", Some(Const::from(6).into())),
])
.into()],
);
}
#[test]
fn let_declaration() {
check_parser(
"let a = 5;",
vec![LetDeclList::from(vec![LetDecl::new("a", Node::from(Const::from(5)))]).into()],
);
}
#[test]
fn let_declaration_keywords() {
check_parser(
"let yield = 5;",
vec![LetDeclList::from(vec![LetDecl::new("yield", Node::from(Const::from(5)))]).into()],
);
check_parser(
"let await = 5;",
vec![LetDeclList::from(vec![LetDecl::new("await", Node::from(Const::from(5)))]).into()],
);
}
#[test]
fn let_declaration_no_spaces() {
check_parser(
"let a=5;",
vec![LetDeclList::from(vec![LetDecl::new("a", Node::from(Const::from(5)))]).into()],
);
}
#[test]
fn empty_let_declaration() {
check_parser(
"let a;",
vec![LetDeclList::from(vec![LetDecl::new("a", None)]).into()],
);
}
#[test]
fn multiple_let_declaration() {
check_parser(
"let a = 5, b, c = 6;",
vec![LetDeclList::from(vec![
LetDecl::new("a", Node::from(Const::from(5))),
LetDecl::new("b", None),
LetDecl::new("c", Node::from(Const::from(6))),
])
.into()],
);
}
#[test]
fn const_declaration() {
check_parser(
"const a = 5;",
vec![ConstDeclList::from(ConstDecl::new("a", Const::from(5))).into()],
);
}
#[test]
fn const_declaration_keywords() {
check_parser(
"const yield = 5;",
vec![ConstDeclList::from(ConstDecl::new("yield", Const::from(5))).into()],
);
check_parser(
"const await = 5;",
vec![ConstDeclList::from(ConstDecl::new("await", Const::from(5))).into()],
);
}
#[test]
fn const_declaration_no_spaces() {
check_parser(
"const a=5;",
vec![ConstDeclList::from(ConstDecl::new("a", Const::from(5))).into()],
);
}
#[test]
fn empty_const_declaration() {
check_invalid("const a;");
}
#[test]
fn multiple_const_declaration() {
check_parser(
"const a = 5, c = 6;",
vec![ConstDeclList::from(vec![
ConstDecl::new("a", Const::from(5)),
ConstDecl::new("c", Const::from(6)),
])
.into()],
);
}
#[test]
fn function_declaration() {
check_parser(
"function hello() {}",
vec![FunctionDecl::new(Box::from("hello"), vec![], vec![]).into()],
);
}
#[test]
fn function_declaration_keywords() {
check_parser(
"function yield() {}",
vec![FunctionDecl::new(Box::from("yield"), vec![], vec![]).into()],
);
check_parser(
"function await() {}",
vec![FunctionDecl::new(Box::from("await"), vec![], vec![]).into()],
);
}