Skip to content

Commit ad0d03b

Browse files
committed
Fix and expand function parsing Rust tests
1 parent 67b7cc2 commit ad0d03b

File tree

1 file changed

+53
-9
lines changed

1 file changed

+53
-9
lines changed

parser/src/parser.rs

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,12 @@ mod tests {
9595
function: Box::new(ast::Expression::Identifier {
9696
name: String::from("print"),
9797
}),
98-
args: vec![ast::Expression::String {
99-
value: String::from("Hello world"),
100-
},],
98+
args: vec![(
99+
None,
100+
ast::Expression::String {
101+
value: String::from("Hello world"),
102+
}
103+
),],
101104
},
102105
},
103106
},],
@@ -120,12 +123,53 @@ mod tests {
120123
name: String::from("print"),
121124
}),
122125
args: vec![
123-
ast::Expression::String {
124-
value: String::from("Hello world"),
125-
},
126-
ast::Expression::Number {
127-
value: ast::Number::Integer { value: 2 },
128-
},
126+
(
127+
None,
128+
ast::Expression::String {
129+
value: String::from("Hello world"),
130+
}
131+
),
132+
(
133+
None,
134+
ast::Expression::Number {
135+
value: ast::Number::Integer { value: 2 },
136+
}
137+
),
138+
],
139+
},
140+
},
141+
},],
142+
}
143+
);
144+
}
145+
146+
#[test]
147+
fn test_parse_kwargs() {
148+
let source = String::from("my_func('positional', keyword=2)\n");
149+
let parse_ast = parse_program(&source).unwrap();
150+
assert_eq!(
151+
parse_ast,
152+
ast::Program {
153+
statements: vec![ast::LocatedStatement {
154+
location: ast::Location::new(1, 1),
155+
node: ast::Statement::Expression {
156+
expression: ast::Expression::Call {
157+
function: Box::new(ast::Expression::Identifier {
158+
name: String::from("my_func"),
159+
}),
160+
args: vec![
161+
(
162+
None,
163+
ast::Expression::String {
164+
value: String::from("positional"),
165+
}
166+
),
167+
(
168+
Some("keyword".to_string()),
169+
ast::Expression::Number {
170+
value: ast::Number::Integer { value: 2 },
171+
}
172+
),
129173
],
130174
},
131175
},

0 commit comments

Comments
 (0)