Skip to content

Commit

Permalink
Start unit testing pragma support
Browse files Browse the repository at this point in the history
  • Loading branch information
povik committed Nov 14, 2024
1 parent 3359f7b commit ecaffcf
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/unittests/parsing/LexerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1278,3 +1278,58 @@ TEST_CASE("Hex escape corner case") {
CHECK(diagnostics[0].code == diag::InvalidHexEscapeCode);
CHECK(diagnostics[1].code == diag::ExpectedClosingQuote);
}

TEST_CASE("Compat translate_on/off pragmas") {
LexerOptions options;
options.enableTranslateOnOffCompat = true;

auto buffer = getSourceManager().assignText(R"(
a
// pragma synthesis_off
b
// pragma synthesis_on
c
// synthesis translate_off
d
// synthesis translate_off
e
// synthesis translate_on
f
)"sv);
diagnostics.clear();
Lexer lexer(buffer, alloc, diagnostics, options);
CHECK(diagnostics.empty());
for (auto &text : {"a"sv, "c"sv, "f"sv}) {
Token tok = lexer.lex();
REQUIRE(tok.kind == TokenKind::Identifier);
CHECK(!tok.rawText().compare(text));
}
CHECK(lexer.lex().kind == TokenKind::EndOfFile);
}

TEST_CASE("Compat translate_on/off pragmas unclosed") {
LexerOptions options;
options.enableTranslateOnOffCompat = true;

auto buffer = getSourceManager().assignText(R"(
a
// pragma synthesis_off
b
// pragma synthesis_on
c
// synthesis translate_off
d
e
f
)"sv);
diagnostics.clear();
Lexer lexer(buffer, alloc, diagnostics, options);
for (auto &text : {"a"sv, "c"sv}) {
Token tok = lexer.lex();
REQUIRE(tok.kind == TokenKind::Identifier);
CHECK(!tok.rawText().compare(text));
}
CHECK(lexer.lex().kind == TokenKind::EndOfFile);
REQUIRE(diagnostics.size() == 1);
CHECK(diagnostics[0].code == diag::UnclosedTranslateOff);
}

0 comments on commit ecaffcf

Please sign in to comment.