mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
More tests
This commit is contained in:
parent
83dad7bdf3
commit
cbe84bd5ea
3 changed files with 60 additions and 2 deletions
|
@ -621,7 +621,6 @@ Lexeme Lexer::readInterpolatedStringSection(Position start, Lexeme::Type formatT
|
||||||
case 0:
|
case 0:
|
||||||
case '\r':
|
case '\r':
|
||||||
case '\n':
|
case '\n':
|
||||||
// INTERP TODO: Clear anything we've added to the brace stack, and write a test to see what happens if we don't
|
|
||||||
return Lexeme(Location(start, position()), Lexeme::BrokenString);
|
return Lexeme(Location(start, position()), Lexeme::BrokenString);
|
||||||
|
|
||||||
case '\\':
|
case '\\':
|
||||||
|
@ -647,6 +646,7 @@ Lexeme Lexer::readInterpolatedStringSection(Position start, Lexeme::Type formatT
|
||||||
}
|
}
|
||||||
|
|
||||||
consume();
|
consume();
|
||||||
|
|
||||||
return Lexeme(Location(start, position()), endType, &buffer[startOffset], offset - startOffset - 1);
|
return Lexeme(Location(start, position()), endType, &buffer[startOffset], offset - startOffset - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -138,7 +138,7 @@ TEST_CASE("lookahead")
|
||||||
CHECK_EQ(lexer.lookahead().type, Lexeme::Eof);
|
CHECK_EQ(lexer.lookahead().type, Lexeme::Eof);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("stringInterpolation")
|
TEST_CASE("string_interpolation_basic")
|
||||||
{
|
{
|
||||||
ScopedFastFlag sff{"LuauInterpolatedStringBaseSupport", true};
|
ScopedFastFlag sff{"LuauInterpolatedStringBaseSupport", true};
|
||||||
|
|
||||||
|
@ -157,4 +157,22 @@ TEST_CASE("stringInterpolation")
|
||||||
CHECK_EQ(interpEnd.type, Lexeme::InterpStringEnd);
|
CHECK_EQ(interpEnd.type, Lexeme::InterpStringEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("string_interpolation_unmatched_brace")
|
||||||
|
{
|
||||||
|
ScopedFastFlag sff{"LuauInterpolatedStringBaseSupport", true};
|
||||||
|
|
||||||
|
const std::string testInput = R"({
|
||||||
|
`hello {"world"}
|
||||||
|
} -- this might be incorrectly parsed as a string)";
|
||||||
|
Luau::Allocator alloc;
|
||||||
|
AstNameTable table(alloc);
|
||||||
|
Lexer lexer(testInput.c_str(), testInput.size(), table);
|
||||||
|
|
||||||
|
CHECK_EQ(lexer.next().type, '{');
|
||||||
|
CHECK_EQ(lexer.next().type, Lexeme::InterpStringBegin);
|
||||||
|
CHECK_EQ(lexer.next().type, Lexeme::QuotedString);
|
||||||
|
CHECK_EQ(lexer.next().type, Lexeme::BrokenString);
|
||||||
|
CHECK_EQ(lexer.next().type, '}');
|
||||||
|
}
|
||||||
|
|
||||||
TEST_SUITE_END();
|
TEST_SUITE_END();
|
||||||
|
|
|
@ -966,6 +966,46 @@ TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_without_end_brace")
|
||||||
CHECK_NE(columnOfEndBraceError("_ = `{a`"), columnOfEndBraceError("_ = `{a`"));
|
CHECK_NE(columnOfEndBraceError("_ = `{a`"), columnOfEndBraceError("_ = `{a`"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_without_end_brace_in_table")
|
||||||
|
{
|
||||||
|
ScopedFastFlag sff{"LuauInterpolatedStringBaseSupport", true};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
parse(R"(
|
||||||
|
_ = { `{a` }
|
||||||
|
)");
|
||||||
|
FAIL("Expected ParseErrors to be thrown");
|
||||||
|
}
|
||||||
|
catch (const ParseErrors& e)
|
||||||
|
{
|
||||||
|
CHECK_EQ(e.getErrors().size(), 2);
|
||||||
|
|
||||||
|
CHECK_EQ("Malformed interpolated string, did you forget to add a '}'?", e.getErrors().front().getMessage());
|
||||||
|
CHECK_EQ("Expected '}' (to close '{' at line 2), got <eof>", e.getErrors().back().getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_mid_without_end_brace_in_table")
|
||||||
|
{
|
||||||
|
ScopedFastFlag sff{"LuauInterpolatedStringBaseSupport", true};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
parse(R"(
|
||||||
|
_ = { `x {"y"} {z` }
|
||||||
|
)");
|
||||||
|
FAIL("Expected ParseErrors to be thrown");
|
||||||
|
}
|
||||||
|
catch (const ParseErrors& e)
|
||||||
|
{
|
||||||
|
CHECK_EQ(e.getErrors().size(), 2);
|
||||||
|
|
||||||
|
CHECK_EQ("Malformed interpolated string, did you forget to add a '}'?", e.getErrors().front().getMessage());
|
||||||
|
CHECK_EQ("Expected '}' (to close '{' at line 2), got <eof>", e.getErrors().back().getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_as_type_fail")
|
TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_as_type_fail")
|
||||||
{
|
{
|
||||||
ScopedFastFlag sff{"LuauInterpolatedStringBaseSupport", true};
|
ScopedFastFlag sff{"LuauInterpolatedStringBaseSupport", true};
|
||||||
|
|
Loading…
Add table
Reference in a new issue