luau-syntax 0.732.0

Luau lexer, parser, AST, CST, and source utilities
Documentation
use super::*;

// Parser.test.cpp: error_on_unicode
#[test]
fn error_on_unicode() {
    parse_errors(
        r#"
            local ☃ = 10
        "#,
    )
    .assert_first_message(
        "Expected identifier when parsing variable name, got Unicode character U+2603",
    );
}

// Parser.test.cpp: allow_unicode_in_string
#[test]
fn allow_unicode_in_string() {
    with_parse(
        r#"local snowman = "☃""#,
        ParseOptions::default(),
        |result| {
            let result = result.unwrap();
            assert!(result.metadata.errors.is_empty());
        },
    );
}

// Parser.test.cpp: error_on_confusable
#[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 '.'?)",
    );
}

// Parser.test.cpp: parse_error_broken_comment
#[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",
        );
    }
}

// Parser.test.cpp: string_literals_broken
#[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?");
    }
}

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