|
| 1 | +// Copyright (c) 2025 by mOctave |
| 2 | +// |
| 3 | +// This program is free software: you can redistribute it and/or modify it under the |
| 4 | +// terms of the GNU Affero General Public License as published by the Free Software |
| 5 | +// Foundation, either version 3 of the License, or (at your option) any later version. |
| 6 | +// |
| 7 | +// This program is distributed in the hope that it will be useful, but WITHOUT ANY |
| 8 | +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 9 | +// PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. |
| 10 | +// |
| 11 | +// You should have received a copy of the GNU Affero General Public License along with |
| 12 | +// this program. If not, see <https://www.gnu.org/licenses/>. |
| 13 | + |
| 14 | +package io.github.moctave.weftspace; |
| 15 | + |
| 16 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 17 | +import org.junit.jupiter.api.Test; |
| 18 | + |
| 19 | +/** Unit tests for DataReader */ |
| 20 | +public class TestDataReader { |
| 21 | + |
| 22 | + /** Tests for {@link DataReader#getIndentSubstring()}. */ |
| 23 | + @Test |
| 24 | + public void getIndentSubstring() { |
| 25 | + assertEquals("", DataReader.getIndentSubstring("", 0)); |
| 26 | + assertEquals("\t", DataReader.getIndentSubstring("\tHello World", 0)); |
| 27 | + assertEquals("\t\t", DataReader.getIndentSubstring("\t\tHello World", 0)); |
| 28 | + assertEquals("\t", DataReader.getIndentSubstring("\t\tHello World", 1)); |
| 29 | + assertEquals(" ", DataReader.getIndentSubstring(" Hello World", 2)); |
| 30 | + assertEquals(" ", DataReader.getIndentSubstring(" Hello World", 3)); |
| 31 | + assertEquals("\t", DataReader.getIndentSubstring(" \tHello World", 1)); |
| 32 | + } |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + /** Tests for {@link DataReader#trimComments()}. */ |
| 37 | + @Test |
| 38 | + public void trimComments() { |
| 39 | + assertEquals("", DataReader.trimComments("")); |
| 40 | + assertEquals(" ", DataReader.trimComments(" ")); |
| 41 | + assertEquals("", DataReader.trimComments("#only comment")); |
| 42 | + assertEquals("only text", DataReader.trimComments("only text")); |
| 43 | + assertEquals("text and ", DataReader.trimComments("text and #comment")); |
| 44 | + assertEquals("Here is a", DataReader.trimComments("Here is a# double #comment")); |
| 45 | + } |
| 46 | + |
| 47 | + |
| 48 | + /** Tests for {@link DataReader#countLeadingWhitespace(String)}. */ |
| 49 | + @Test |
| 50 | + public void countLeadingWhitespace() { |
| 51 | + assertEquals(0, DataReader.countLeadingWhitespace("")); |
| 52 | + assertEquals(1, DataReader.countLeadingWhitespace(" ")); |
| 53 | + assertEquals(2, DataReader.countLeadingWhitespace("\t\t")); |
| 54 | + assertEquals(0, DataReader.countLeadingWhitespace("hello world")); |
| 55 | + assertEquals(2, DataReader.countLeadingWhitespace(" hello world ")); |
| 56 | + assertEquals(3, DataReader.countLeadingWhitespace("\t \tGoodbye World!\t")); |
| 57 | + } |
| 58 | + |
| 59 | + |
| 60 | + /** Tests for {@link DataReader#containsOnlyWhitespace(String)} */ |
| 61 | + @Test |
| 62 | + public void containsOnlyWhitespace() { |
| 63 | + assertEquals(true, DataReader.containsOnlyWhitespace("")); |
| 64 | + assertEquals(false, DataReader.containsOnlyWhitespace("foo")); |
| 65 | + assertEquals(true, DataReader.containsOnlyWhitespace(" ")); |
| 66 | + assertEquals(true, DataReader.containsOnlyWhitespace("\t")); |
| 67 | + assertEquals(true, DataReader.containsOnlyWhitespace(" \t ")); |
| 68 | + assertEquals(false, DataReader.containsOnlyWhitespace("a \t")); |
| 69 | + assertEquals(false, DataReader.containsOnlyWhitespace(" b")); |
| 70 | + } |
| 71 | +} |
0 commit comments