|
|
@ -1,6 +1,7 @@ |
|
|
|
use crate::syntax::{ |
|
|
|
use crate::syntax::{ |
|
|
|
ast::node::{ |
|
|
|
ast::node::{ |
|
|
|
ArrowFunctionDecl, BinOp, FormalParameter, FunctionDecl, Identifier, Node, Return, |
|
|
|
ArrowFunctionDecl, BinOp, FormalParameter, FunctionDecl, Identifier, LetDecl, LetDeclList, |
|
|
|
|
|
|
|
Node, Return, |
|
|
|
}, |
|
|
|
}, |
|
|
|
ast::op::NumOp, |
|
|
|
ast::op::NumOp, |
|
|
|
parser::tests::check_parser, |
|
|
|
parser::tests::check_parser, |
|
|
@ -176,3 +177,193 @@ fn check_arrow_empty_return_semicolon_insertion() { |
|
|
|
.into()], |
|
|
|
.into()], |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn check_arrow_assignment() { |
|
|
|
|
|
|
|
check_parser( |
|
|
|
|
|
|
|
"let foo = (a) => { return a };", |
|
|
|
|
|
|
|
vec![LetDeclList::from(vec![LetDecl::new::<_, Option<Node>>( |
|
|
|
|
|
|
|
Identifier::from("foo"), |
|
|
|
|
|
|
|
Some( |
|
|
|
|
|
|
|
ArrowFunctionDecl::new( |
|
|
|
|
|
|
|
vec![FormalParameter::new("a", None, false)], |
|
|
|
|
|
|
|
vec![Return::new::<Node, Option<_>, Option<_>>( |
|
|
|
|
|
|
|
Some(Identifier::from("a").into()), |
|
|
|
|
|
|
|
None, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.into()], |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.into(), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
)]) |
|
|
|
|
|
|
|
.into()], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn check_arrow_assignment_nobrackets() { |
|
|
|
|
|
|
|
check_parser( |
|
|
|
|
|
|
|
"let foo = (a) => a;", |
|
|
|
|
|
|
|
vec![LetDeclList::from(vec![LetDecl::new::<_, Option<Node>>( |
|
|
|
|
|
|
|
Identifier::from("foo"), |
|
|
|
|
|
|
|
Some( |
|
|
|
|
|
|
|
ArrowFunctionDecl::new( |
|
|
|
|
|
|
|
vec![FormalParameter::new("a", None, false)], |
|
|
|
|
|
|
|
vec![Return::new::<Node, Option<_>, Option<_>>( |
|
|
|
|
|
|
|
Some(Identifier::from("a").into()), |
|
|
|
|
|
|
|
None, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.into()], |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.into(), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
)]) |
|
|
|
|
|
|
|
.into()], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn check_arrow_assignment_noparenthesis() { |
|
|
|
|
|
|
|
check_parser( |
|
|
|
|
|
|
|
"let foo = a => { return a };", |
|
|
|
|
|
|
|
vec![LetDeclList::from(vec![LetDecl::new::<_, Option<Node>>( |
|
|
|
|
|
|
|
Identifier::from("foo"), |
|
|
|
|
|
|
|
Some( |
|
|
|
|
|
|
|
ArrowFunctionDecl::new( |
|
|
|
|
|
|
|
vec![FormalParameter::new("a", None, false)], |
|
|
|
|
|
|
|
vec![Return::new::<Node, Option<_>, Option<_>>( |
|
|
|
|
|
|
|
Some(Identifier::from("a").into()), |
|
|
|
|
|
|
|
None, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.into()], |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.into(), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
)]) |
|
|
|
|
|
|
|
.into()], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn check_arrow_assignment_noparenthesis_nobrackets() { |
|
|
|
|
|
|
|
check_parser( |
|
|
|
|
|
|
|
"let foo = a => a;", |
|
|
|
|
|
|
|
vec![LetDeclList::from(vec![LetDecl::new::<_, Option<Node>>( |
|
|
|
|
|
|
|
Identifier::from("foo"), |
|
|
|
|
|
|
|
Some( |
|
|
|
|
|
|
|
ArrowFunctionDecl::new( |
|
|
|
|
|
|
|
vec![FormalParameter::new("a", None, false)], |
|
|
|
|
|
|
|
vec![Return::new::<Node, Option<_>, Option<_>>( |
|
|
|
|
|
|
|
Some(Identifier::from("a").into()), |
|
|
|
|
|
|
|
None, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.into()], |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.into(), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
)]) |
|
|
|
|
|
|
|
.into()], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn check_arrow_assignment_2arg() { |
|
|
|
|
|
|
|
check_parser( |
|
|
|
|
|
|
|
"let foo = (a, b) => { return a };", |
|
|
|
|
|
|
|
vec![LetDeclList::from(vec![LetDecl::new::<_, Option<Node>>( |
|
|
|
|
|
|
|
Identifier::from("foo"), |
|
|
|
|
|
|
|
Some( |
|
|
|
|
|
|
|
ArrowFunctionDecl::new( |
|
|
|
|
|
|
|
vec![ |
|
|
|
|
|
|
|
FormalParameter::new("a", None, false), |
|
|
|
|
|
|
|
FormalParameter::new("b", None, false), |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
vec![Return::new::<Node, Option<_>, Option<_>>( |
|
|
|
|
|
|
|
Some(Identifier::from("a").into()), |
|
|
|
|
|
|
|
None, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.into()], |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.into(), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
)]) |
|
|
|
|
|
|
|
.into()], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn check_arrow_assignment_2arg_nobrackets() { |
|
|
|
|
|
|
|
check_parser( |
|
|
|
|
|
|
|
"let foo = (a, b) => a;", |
|
|
|
|
|
|
|
vec![LetDeclList::from(vec![LetDecl::new::<_, Option<Node>>( |
|
|
|
|
|
|
|
Identifier::from("foo"), |
|
|
|
|
|
|
|
Some( |
|
|
|
|
|
|
|
ArrowFunctionDecl::new( |
|
|
|
|
|
|
|
vec![ |
|
|
|
|
|
|
|
FormalParameter::new("a", None, false), |
|
|
|
|
|
|
|
FormalParameter::new("b", None, false), |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
vec![Return::new::<Node, Option<_>, Option<_>>( |
|
|
|
|
|
|
|
Some(Identifier::from("a").into()), |
|
|
|
|
|
|
|
None, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.into()], |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.into(), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
)]) |
|
|
|
|
|
|
|
.into()], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn check_arrow_assignment_3arg() { |
|
|
|
|
|
|
|
check_parser( |
|
|
|
|
|
|
|
"let foo = (a, b, c) => { return a };", |
|
|
|
|
|
|
|
vec![LetDeclList::from(vec![LetDecl::new::<_, Option<Node>>( |
|
|
|
|
|
|
|
Identifier::from("foo"), |
|
|
|
|
|
|
|
Some( |
|
|
|
|
|
|
|
ArrowFunctionDecl::new( |
|
|
|
|
|
|
|
vec![ |
|
|
|
|
|
|
|
FormalParameter::new("a", None, false), |
|
|
|
|
|
|
|
FormalParameter::new("b", None, false), |
|
|
|
|
|
|
|
FormalParameter::new("c", None, false), |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
vec![Return::new::<Node, Option<_>, Option<_>>( |
|
|
|
|
|
|
|
Some(Identifier::from("a").into()), |
|
|
|
|
|
|
|
None, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.into()], |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.into(), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
)]) |
|
|
|
|
|
|
|
.into()], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn check_arrow_assignment_3arg_nobrackets() { |
|
|
|
|
|
|
|
check_parser( |
|
|
|
|
|
|
|
"let foo = (a, b, c) => a;", |
|
|
|
|
|
|
|
vec![LetDeclList::from(vec![LetDecl::new::<_, Option<Node>>( |
|
|
|
|
|
|
|
Identifier::from("foo"), |
|
|
|
|
|
|
|
Some( |
|
|
|
|
|
|
|
ArrowFunctionDecl::new( |
|
|
|
|
|
|
|
vec![ |
|
|
|
|
|
|
|
FormalParameter::new("a", None, false), |
|
|
|
|
|
|
|
FormalParameter::new("b", None, false), |
|
|
|
|
|
|
|
FormalParameter::new("c", None, false), |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
vec![Return::new::<Node, Option<_>, Option<_>>( |
|
|
|
|
|
|
|
Some(Identifier::from("a").into()), |
|
|
|
|
|
|
|
None, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.into()], |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.into(), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
)]) |
|
|
|
|
|
|
|
.into()], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|