luau-syntax 0.732.0

Luau lexer, parser, AST, CST, and source utilities
Documentation
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};

// PrettyPrinter.test.cpp: prettyPrint_error_expr
#[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)"
        );
    });
}

// PrettyPrinter.test.cpp: prettyPrint_error_stat
#[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))"
        );
    });
}

// PrettyPrinter.test.cpp: prettyPrint_error_type
#[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%"
        );
    });
}

// PrettyPrinter.test.cpp: prettyPrint_parse_error
#[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>"
    );
}

// PrettyPrinter.test.cpp: fuzzer_prettyPrint_with_zero_location
#[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);
        },
    );
}