| 724 | |
| 725 | #[test] |
| 726 | fn test_define_function_with_args() { |
| 727 | let input = "function foo(a, b) { return a+b; }".to_string(); |
| 728 | let lexer = JsLexer::new(input); |
| 729 | let mut parser = JsParser::new(lexer); |
| 730 | let mut expected = Program::new(); |
| 731 | let mut body = Vec::new(); |
| 732 | body.push(Rc::new(Node::FunctionDeclaration { |
| 733 | id: Some(Rc::new(Node::Identifier("foo".to_string()))), |
| 734 | params: [ |
| 735 | Some(Rc::new(Node::Identifier("a".to_string()))), |
| 736 | Some(Rc::new(Node::Identifier("b".to_string()))), |
| 737 | ] |
| 738 | .to_vec(), |
| 739 | body: Some(Rc::new(Node::BlockStatement { |
| 740 | body: [Some(Rc::new(Node::ReturnStatement { |
| 741 | argument: Some(Rc::new(Node::BinaryExpression { |
| 742 | operator: '+', |
| 743 | left: Some(Rc::new(Node::Identifier("a".to_string()))), |
| 744 | right: Some(Rc::new(Node::Identifier("b".to_string()))), |
| 745 | })), |
| 746 | }))] |
| 747 | .to_vec(), |
| 748 | })), |
| 749 | })); |
| 750 | expected.set_body(body); |
| 751 | assert_eq!(expected, parser.parse_ast()); |
| 752 | } |
| 753 | |
| 754 | #[test] |
| 755 | fn test_add_function_add_num() { |