mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Test sane double brace lexing
This commit is contained in:
parent
adbe64fffc
commit
89f407a587
2 changed files with 27 additions and 2 deletions
|
@ -98,6 +98,7 @@ Lexeme::Lexeme(const Location& location, Type type, const char* data, size_t siz
|
||||||
|| type == InterpStringMid
|
|| type == InterpStringMid
|
||||||
|| type == InterpStringEnd
|
|| type == InterpStringEnd
|
||||||
|| type == InterpStringSimple
|
|| type == InterpStringSimple
|
||||||
|
|| type == BrokenInterpDoubleBrace
|
||||||
|| type == Number
|
|| type == Number
|
||||||
|| type == Comment
|
|| type == Comment
|
||||||
|| type == BlockComment
|
|| type == BlockComment
|
||||||
|
@ -638,12 +639,16 @@ Lexeme Lexer::readInterpolatedStringSection(Position start, Lexeme::Type formatT
|
||||||
|
|
||||||
case '{':
|
case '{':
|
||||||
{
|
{
|
||||||
|
braceStack.push_back(BraceType::InterpolatedString);
|
||||||
|
|
||||||
if (peekch(1) == '{')
|
if (peekch(1) == '{')
|
||||||
{
|
{
|
||||||
return Lexeme(Location(start, position()), Lexeme::BrokenInterpDoubleBrace);
|
Lexeme brokenDoubleBrace = Lexeme(Location(start, position()), Lexeme::BrokenInterpDoubleBrace, &buffer[startOffset], offset - startOffset);
|
||||||
|
consume();
|
||||||
|
consume();
|
||||||
|
return brokenDoubleBrace;
|
||||||
}
|
}
|
||||||
|
|
||||||
braceStack.push_back(BraceType::InterpolatedString);
|
|
||||||
Lexeme lexemeOutput(Location(start, position()), Lexeme::InterpStringBegin, &buffer[startOffset], offset - startOffset);
|
Lexeme lexemeOutput(Location(start, position()), Lexeme::InterpStringBegin, &buffer[startOffset], offset - startOffset);
|
||||||
consume();
|
consume();
|
||||||
return lexemeOutput;
|
return lexemeOutput;
|
||||||
|
|
|
@ -157,6 +157,26 @@ TEST_CASE("string_interpolation_basic")
|
||||||
CHECK_EQ(interpEnd.type, Lexeme::InterpStringEnd);
|
CHECK_EQ(interpEnd.type, Lexeme::InterpStringEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("string_interpolation_double_brace")
|
||||||
|
{
|
||||||
|
ScopedFastFlag sff{"LuauInterpolatedStringBaseSupport", true};
|
||||||
|
|
||||||
|
const std::string testInput = R"(`foo{{bad}}bar`)";
|
||||||
|
Luau::Allocator alloc;
|
||||||
|
AstNameTable table(alloc);
|
||||||
|
Lexer lexer(testInput.c_str(), testInput.size(), table);
|
||||||
|
|
||||||
|
auto brokenInterpBegin = lexer.next();
|
||||||
|
CHECK_EQ(brokenInterpBegin.type, Lexeme::BrokenInterpDoubleBrace);
|
||||||
|
CHECK_EQ(std::string(brokenInterpBegin.data, brokenInterpBegin.length), std::string("foo"));
|
||||||
|
|
||||||
|
CHECK_EQ(lexer.next().type, Lexeme::Name);
|
||||||
|
|
||||||
|
auto interpEnd = lexer.next();
|
||||||
|
CHECK_EQ(interpEnd.type, Lexeme::InterpStringEnd);
|
||||||
|
CHECK_EQ(std::string(interpEnd.data, interpEnd.length), std::string("}bar"));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("string_interpolation_unmatched_brace")
|
TEST_CASE("string_interpolation_unmatched_brace")
|
||||||
{
|
{
|
||||||
ScopedFastFlag sff{"LuauInterpolatedStringBaseSupport", true};
|
ScopedFastFlag sff{"LuauInterpolatedStringBaseSupport", true};
|
||||||
|
|
Loading…
Add table
Reference in a new issue