use crate::pretty_printer::with_parse;
use luau_common::ByteSlice;
use luau_syntax::parser::ParseOptions;
use luau_syntax::pretty_printer::{pretty_print, pretty_print_with_types};
#[test]
fn pretty_print_error_expr() {
with_parse("local a = f:-", ParseOptions::default(), |result| {
assert_eq!(
pretty_print_with_types(result.root).as_bytes(),
b"local a = (error-expr: f:%error-id%)-(error-expr)"
);
});
}
#[test]
fn pretty_print_error_stat() {
with_parse("-", ParseOptions::default(), |result| {
assert_eq!(
pretty_print_with_types(result.root).as_bytes(),
b"(error-stat: (error-expr))"
);
});
}
#[test]
fn pretty_print_error_type() {
with_parse("local a: ", ParseOptions::default(), |result| {
assert_eq!(
pretty_print_with_types(result.root).as_bytes(),
b"local a:%error-type%"
);
});
}
#[test]
fn pretty_print_parse_error() {
let result = pretty_print("local a = -", ParseOptions::default(), false, false);
assert_eq!(result.code.as_bytes(), b"");
assert_eq!(
result.parse_error,
"Expected identifier when parsing expression, got <eof>"
);
}
#[test]
fn fuzzer_pretty_print_with_zero_location() {
let source = r#"
if _ then
elseif _ then
elseif l0 then
else
local function l0<t0>(...):(t0<t0...>,(any)|(<t0>((any)|(<t0>(""[[[[[[[[[[[[[[[[[[[[[[[[!*t")->()))->()))
end
end
"#;
with_parse(
source,
ParseOptions::default().with_comment_capture(true),
|result| {
pretty_print_with_types(result.root);
},
);
}