diff --git a/tweed5/serde-hjson/src/main/java/de/siphalor/tweed5/data/hjson/HjsonLexer.java b/tweed5/serde-hjson/src/main/java/de/siphalor/tweed5/data/hjson/HjsonLexer.java index 128b047..3476ecc 100644 --- a/tweed5/serde-hjson/src/main/java/de/siphalor/tweed5/data/hjson/HjsonLexer.java +++ b/tweed5/serde-hjson/src/main/java/de/siphalor/tweed5/data/hjson/HjsonLexer.java @@ -423,6 +423,8 @@ public class HjsonLexer implements AutoCloseable { lastWasAsterisk = true; } else if (lastWasAsterisk && codePoint == '/') { break; + } else { + lastWasAsterisk = false; } } } diff --git a/tweed5/serde-hjson/src/test/java/de/siphalor/tweed5/data/hjson/HjsonLexerTest.java b/tweed5/serde-hjson/src/test/java/de/siphalor/tweed5/data/hjson/HjsonLexerTest.java index e876498..70586a3 100644 --- a/tweed5/serde-hjson/src/test/java/de/siphalor/tweed5/data/hjson/HjsonLexerTest.java +++ b/tweed5/serde-hjson/src/test/java/de/siphalor/tweed5/data/hjson/HjsonLexerTest.java @@ -1,5 +1,6 @@ package de.siphalor.tweed5.data.hjson; +import lombok.SneakyThrows; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; import org.junit.jupiter.params.ParameterizedTest; @@ -128,6 +129,28 @@ class HjsonLexerTest { assertGeneralEof(lexer, new HjsonReadPosition(1, input.length() + 1)); } + @ParameterizedTest + @CsvSource(textBlock = """ + '// 123 + true', TRUE + '# hash comments are cool + false', FALSE + '/* + multiline + comment + */456', NUMBER + '/* multiline comment + * with/slashes + */456', NUMBER + """) + @SneakyThrows + void chompComment(String input, HjsonLexerToken.Type tokenType) { + HjsonLexer lexer = createLexer(input); + + HjsonLexerToken token = lexer.nextGeneralToken(); + assertEquals(tokenType, token.type()); + } + private HjsonLexer createLexer(String input) { return new HjsonLexer(new StringReader(input)); } @@ -138,4 +161,4 @@ class HjsonLexerTest { assertDoesNotThrow(lexer::nextGeneralToken) ); } -} \ No newline at end of file +}