use super::*;
#[test]
fn parse_error_function_call() {
let errors = parse_errors(
r#"
function stringifyTable(t)
local foo = t:Parse 2
return foo
end
"#,
);
assert_eq!(errors[0].location.begin.line, 2);
assert_eq!(
errors[0].message,
"Expected '(', '{' or <string> when parsing function call, got '2'"
);
}
#[test]
fn parse_error_function_call_newline() {
let errors = parse_errors(
r#"
function stringifyTable(t)
local foo = t:Parse
return foo
end
"#,
);
assert_eq!(errors[0].location.begin.line, 2);
assert_eq!(
errors[0].message,
"Expected function call arguments after '('"
);
}
#[test]
fn parse_error_confusing_function_call() {
for source in [
r#"
function add(x, y) return x + y end
add
(4, 7)
"#,
r#"
function add(x, y) return x + y end
local f = add
(f :: any)['x'] = 2
"#,
r#"
local x = {}
function x:add(a, b) return a + b end
x:add
(1, 2)
"#,
r#"
local t = {}
function f() return t end
t.x, (f)
().y = 5, 6
"#,
] {
let errors = parse_errors(source);
assert_eq!(errors.len(), 1);
errors.assert_first_message(
"Ambiguous syntax: this looks like an argument list for a function call, but could also be a start of new statement; use ';' to separate statements",
);
}
}
#[test]
fn get_a_nice_error_when_there_is_an_extra_comma_at_the_end_of_a_function_argument_list() {
let errors = parse_errors(
r#"
foo(a, b, c,)
"#,
);
assert_eq!(errors.len(), 1);
assert_eq!(errors[0].location, loc!(pos!(1, 20), pos!(1, 21)));
assert_eq!(
errors[0].message,
"Expected expression after ',' but got ')' instead"
);
}