|
24 | 24 | import org.junit.jupiter.params.provider.MethodSource;
|
25 | 25 |
|
26 | 26 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
| 27 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
27 | 28 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
28 | 29 |
|
29 | 30 | /*
|
@@ -131,4 +132,71 @@ void testComputeIndexForCharacter_CloseToPreviousWord_WriteTwoCharacters() {
|
131 | 132 | assertEquals(" AB" + " ".repeat(22), textLine.getLine());
|
132 | 133 | }
|
133 | 134 |
|
| 135 | +@Test |
| 136 | +void testZeroLineLength() { |
| 137 | +TextLine textLine = new TextLine(0); |
| 138 | +assertEquals(0, textLine.getLineLength()); |
| 139 | +assertEquals("", textLine.getLine()); |
| 140 | + |
| 141 | +// Writing to zero-length line should not cause issues |
| 142 | +Character character = new Character('A', 0, false, false, false, false); |
| 143 | +textLine.writeCharacterAtIndex(character); |
| 144 | +assertEquals("", textLine.getLine()); |
| 145 | +} |
| 146 | + |
| 147 | +@Test |
| 148 | +void testLineLengthNotDivisibleByCharacterWidth() { |
| 149 | +// Test with line length that doesn't divide evenly by |
| 150 | +// OUTPUT_SPACE_CHARACTER_WIDTH_IN_PT |
| 151 | +TextLine textLine = new TextLine(103); |
| 152 | +int expectedLength = 103 / ForkPDFLayoutTextStripper.OUTPUT_SPACE_CHARACTER_WIDTH_IN_PT; |
| 153 | +assertEquals(expectedLength, textLine.getLineLength()); |
| 154 | +assertEquals(" ".repeat(expectedLength), textLine.getLine()); |
| 155 | +} |
| 156 | + |
| 157 | +@Test |
| 158 | +void testBoundaryConditionsForLineLength() { |
| 159 | +// Test minimum valid line length |
| 160 | +TextLine textLine1 = new TextLine(1); |
| 161 | +assertEquals(0, textLine1.getLineLength()); // 1/4 = 0 in integer division |
| 162 | +assertEquals("", textLine1.getLine()); |
| 163 | + |
| 164 | +// Test line length just under OUTPUT_SPACE_CHARACTER_WIDTH_IN_PT |
| 165 | +TextLine textLine2 = new TextLine(3); |
| 166 | +assertEquals(0, textLine2.getLineLength()); // 3/4 = 0 in integer division |
| 167 | +assertEquals("", textLine2.getLine()); |
| 168 | + |
| 169 | +// Test line length exactly at OUTPUT_SPACE_CHARACTER_WIDTH_IN_PT |
| 170 | +TextLine textLine3 = new TextLine(ForkPDFLayoutTextStripper.OUTPUT_SPACE_CHARACTER_WIDTH_IN_PT); |
| 171 | +assertEquals(1, textLine3.getLineLength()); |
| 172 | +assertEquals(" ", textLine3.getLine()); |
| 173 | +} |
| 174 | + |
| 175 | +@Test |
| 176 | +void testWriteCharacterAtNegativeIndex() { |
| 177 | +TextLine textLine = new TextLine(100); |
| 178 | +Character character = new Character('A', -10, false, false, false, false); |
| 179 | + |
| 180 | +textLine.writeCharacterAtIndex(character); |
| 181 | +// Should handle negative index gracefully without throwing exception |
| 182 | +assertEquals(" ".repeat(25), textLine.getLine()); |
| 183 | +} |
| 184 | + |
| 185 | +@Test |
| 186 | +void testWriteNonPrintableCharacters() { |
| 187 | +TextLine textLine = new TextLine(100); |
| 188 | +// Test control characters |
| 189 | +Character tab = new Character('\t', 0, false, false, false, false); |
| 190 | +Character newline = new Character('\n', 4, false, false, false, false); |
| 191 | +Character nullChar = new Character('\0', 8, false, false, false, false); |
| 192 | + |
| 193 | +textLine.writeCharacterAtIndex(tab); |
| 194 | +textLine.writeCharacterAtIndex(newline); |
| 195 | +textLine.writeCharacterAtIndex(nullChar); |
| 196 | + |
| 197 | +// Verify how non-printable characters are handled |
| 198 | +String line = textLine.getLine(); |
| 199 | +assertNotNull(line); |
| 200 | +} |
| 201 | + |
134 | 202 | }
|
0 commit comments