From 987a27bd75ebbdcc4dcbe996bfa56f634bacec0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Hohwiller?= Date: Wed, 25 Dec 2024 21:05:18 +0100 Subject: [PATCH] m-m-m/base#8: cover bugfix in tests --- .../AbstractCharStreamScannerTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/core/src/test/java/io/github/mmm/scanner/AbstractCharStreamScannerTest.java b/core/src/test/java/io/github/mmm/scanner/AbstractCharStreamScannerTest.java index 729313a..a83bfb2 100644 --- a/core/src/test/java/io/github/mmm/scanner/AbstractCharStreamScannerTest.java +++ b/core/src/test/java/io/github/mmm/scanner/AbstractCharStreamScannerTest.java @@ -352,6 +352,56 @@ public void testReadUntilWithSyntaxAltDobuleQuotesLazy() { check('x', true, syntax, "\"\"a\"\"\"\"b\"\"\"c\"dx", "\"a\"\"b\"cd"); } + /** + * Test of {@link CharStreamScanner#readUntil(CharFilter, boolean)} reading until stop char was hit. + */ + @Test + public void testReadUntilWithCharFilter() { + + // arrange + String string = " blabla_$"; + CharStreamScanner scanner; + scanner = scanner(string); + // act + String result = scanner.readUntil(cp -> cp == '$', true); + // assert + assertThat(result).isEqualTo(" blabla_"); + } + + /** + * Test of {@link CharStreamScanner#readUntil(CharFilter, boolean)} reading until EOT if no stop char was hit but + * {@code acceptEnd} was {@code true}. + */ + @Test + public void testReadUntilWithCharFilterEot() { + + // arrange + String string = " blabla_$"; + CharStreamScanner scanner; + scanner = scanner(string); + // act + String result = scanner.readUntil(CharFilter.NEWLINE, true); + // assert + assertThat(result).isEqualTo(string); + } + + /** + * Test of {@link CharStreamScanner#readUntil(CharFilter, boolean)} returning {@code null} if no stop char was hit but + * {@code acceptEnd} was {@code false}. + */ + @Test + public void testReadUntilWithCharFilterNoEot() { + + // arrange + String string = " blabla_$"; + CharStreamScanner scanner; + scanner = scanner(string); + // act + String result = scanner.readUntil(CharFilter.NEWLINE, false); + // assert + assertThat(result).isNull(); + } + /** * Test of {@link CharStreamScanner#readUntil(CharFilter, boolean, String, boolean ignoreCase, boolean)} with buffer * limit overflow.