implements PLN-0093

This commit is contained in:
2026-07-15 06:57:19 +01:00
parent 917b0e1b9a
commit 2b25364252
7 changed files with 93 additions and 4 deletions
@@ -113,6 +113,55 @@ class PbsLexerTest {
diagnostics.stream().findFirst().orElseThrow().getCode());
}
@Test
void shouldLexDocumentationTextBlock() {
final var source = """
[Doc(markdown = \"""
Draws a sprite.
- `x`: screen x
- `y`: screen y
\""")]
""";
final var diagnostics = DiagnosticSink.empty();
final var tokens = PbsLexer.lex(source, new FileId(0), diagnostics);
final var docTextBlock = tokens.stream()
.filter(t -> t.kind() == PbsTokenKind.DOC_TEXT_BLOCK)
.findFirst()
.orElseThrow();
assertTrue(docTextBlock.lexeme().startsWith("\"\"\""));
assertTrue(docTextBlock.lexeme().endsWith("\"\"\""));
assertTrue(docTextBlock.lexeme().contains("Draws a sprite."));
assertTrue(docTextBlock.lexeme().contains("- `x`: screen x"));
assertTrue(diagnostics.isEmpty(), "Documentation text block should lex without diagnostics");
}
@Test
void shouldAllowSingleAndDoubleQuotesInsideDocumentationTextBlock() {
final var source = "[Doc(markdown = \"\"\"Uses \"quoted\" text and 'single' quotes.\"\"\")]";
final var diagnostics = DiagnosticSink.empty();
final var tokens = PbsLexer.lex(source, new FileId(0), diagnostics);
final var kinds = tokens.stream().map(PbsToken::kind).toList();
assertTrue(kinds.contains(PbsTokenKind.DOC_TEXT_BLOCK));
assertTrue(diagnostics.isEmpty(), "Quotes inside documentation text block should not need escaping");
}
@Test
void shouldReportUnterminatedDocumentationTextBlock() {
final var source = "[Doc(markdown = \"\"\"unterminated)]";
final var diagnostics = DiagnosticSink.empty();
PbsLexer.lex(source, new FileId(0), diagnostics);
assertTrue(diagnostics.hasErrors(), "Lexer should report unterminated documentation text blocks");
assertEquals(LexErrors.E_LEX_UNTERMINATED_DOC_TEXT_BLOCK.name(),
diagnostics.stream().findFirst().orElseThrow().getCode());
}
@Test
void shouldReportInvalidStringEscape() {
final var source = "\"bad\\q\"";