use super::super::common::*;
#[test]
fn parse_continue() {
with_parse(
r#"
while true do
continue()
continue = 5
continue, continue = continue
continue
end
"#,
ParseOptions::default(),
|result| {
let result = result.unwrap();
let [statement] = statement_kinds(result.root.as_slice()).exact();
let while_statement = statement.as_while().expect("expected while statement");
let body = while_statement.body;
let body_statements = block_statement_kinds(body);
assert_eq!(body.len(), 4);
assert_eq!(body_statements[0].tag, StatementTag::Expression);
assert_eq!(body_statements[1].tag, StatementTag::Assign);
assert_eq!(body_statements[2].tag, StatementTag::Assign);
assert_eq!(body_statements[3].tag, StatementTag::Continue);
},
);
}
#[test]
fn break_return_not_last_error() {
parse_errors("return 0 print(5)").assert_first_message("Expected <eof>, got 'print'");
parse_errors("while true do break print(5) end")
.assert_first_message("Expected 'end' (to close 'do' at column 12), got 'print'");
}
#[test]
fn continue_not_last_error() {
parse_errors("while true do continue print(5) end")
.assert_first_message("Expected 'end' (to close 'do' at column 12), got 'print'");
}
#[test]
fn parse_compound_assignment() {
with_parse("a += 5", ParseOptions::default(), |result| {
let result = result.unwrap();
let [statement] = statement_kinds(result.root.as_slice()).exact();
let assign = statement
.as_compound_assign()
.expect("expected compound assignment");
let ExpressionKind::Global(name) = assign.var.kind() else {
panic!("expected variable assignment target");
};
assert_eq!(name, "a");
assert_eq!(assign.op, BinaryOp::Add);
assert!(matches!(
assign.value.kind(),
ExpressionKind::Number { value: 5.0, .. }
));
});
}