use super::*;
#[test]
fn error_on_unicode() {
parse_errors(
r#"
local ☃ = 10
"#,
)
.assert_first_message(
"Expected identifier when parsing variable name, got Unicode character U+2603",
);
}
#[test]
fn allow_unicode_in_string() {
with_parse(
r#"local snowman = "☃""#,
ParseOptions::default(),
|result| {
let result = result.unwrap();
assert!(result.metadata.errors.is_empty());
},
);
}
#[test]
fn error_on_confusable() {
parse_errors(r#"
local pi = 3․13
"#)
.assert_first_message(
"Expected identifier when parsing expression, got Unicode character U+2024 (did you mean '.'?)",
);
}
#[test]
fn parse_error_broken_comment() {
for source in [
"--[[unfinished work",
"--!strict\n--[[unfinished work",
"local x = 1 --[[unfinished work",
] {
parse_errors(source).assert_first_message(
"Expected identifier when parsing expression, got unfinished comment",
);
}
}
#[test]
fn string_literals_broken() {
for source in ["return \"", "return \"\\", "return \"\r\r"] {
parse_errors(source).assert_first_message("Malformed string; did you forget to finish it?");
}
}
#[test]
fn string_literals_escapes_broken() {
for source in [
"return \"\\u{\"",
"return \"\\u{FO}\"",
"return \"\\u{123456789}\"",
"return \"\\359\"",
"return \"\\xFO\"",
"return \"\\xF\"",
"return \"\\x\"",
] {
parse_errors(source)
.assert_first_message("String literal contains malformed escape sequence");
}
}