| 703 | |
| 704 | #[test] |
| 705 | fn test_define_function() { |
| 706 | let input = "function foo() { return 42; }".to_string(); |
| 707 | let lexer = JsLexer::new(input); |
| 708 | let mut parser = JsParser::new(lexer); |
| 709 | let mut expected = Program::new(); |
| 710 | let mut body = Vec::new(); |
| 711 | body.push(Rc::new(Node::FunctionDeclaration { |
| 712 | id: Some(Rc::new(Node::Identifier("foo".to_string()))), |
| 713 | params: [].to_vec(), |
| 714 | body: Some(Rc::new(Node::BlockStatement { |
| 715 | body: [Some(Rc::new(Node::ReturnStatement { |
| 716 | argument: Some(Rc::new(Node::NumericLiteral(42))), |
| 717 | }))] |
| 718 | .to_vec(), |
| 719 | })), |
| 720 | })); |
| 721 | expected.set_body(body); |
| 722 | assert_eq!(expected, parser.parse_ast()); |
| 723 | } |
| 724 | |
| 725 | #[test] |
| 726 | fn test_define_function_with_args() { |