Skip to content

Commit 2f0a526

Browse files
committed
added tests
1 parent bd063a4 commit 2f0a526

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/test/java/com/igormaznitsa/prologparser/IntegrationTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import static org.junit.jupiter.api.Assertions.assertNotSame;
2626
import static org.junit.jupiter.api.Assertions.assertSame;
2727
import static org.junit.jupiter.api.Assertions.assertThrows;
28+
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
2829
import static org.junit.jupiter.api.Assertions.assertTrue;
2930
import static org.junit.jupiter.api.Assertions.fail;
3031
import static org.mockito.Mockito.clearInvocations;
@@ -51,8 +52,10 @@
5152
import java.io.StringReader;
5253
import java.math.BigDecimal;
5354
import java.nio.charset.StandardCharsets;
55+
import java.util.ArrayList;
5456
import java.util.HashMap;
5557
import java.util.HashSet;
58+
import java.util.List;
5659
import java.util.Map;
5760
import java.util.NoSuchElementException;
5861
import java.util.Objects;
@@ -65,6 +68,35 @@
6568
"resource"})
6669
class IntegrationTest extends AbstractIntegrationTest {
6770

71+
@Test
72+
void testIteration_Empty() throws Exception {
73+
final List<PrologTerm> termList = new ArrayList<>();
74+
try (final PrologParser parser = parseEd("")) {
75+
while (parser.hasNext()) {
76+
termList.add(parser.next());
77+
}
78+
}
79+
assertTrue(termList.isEmpty());
80+
}
81+
82+
@Test
83+
void testIteration_Empty_NoSuchElementException() throws Exception {
84+
try (final PrologParser parser = parseEd("")) {
85+
assertThrowsExactly(NoSuchElementException.class, parser::next);
86+
}
87+
}
88+
89+
@Test
90+
void testIteration_Presented() throws Exception {
91+
final List<PrologTerm> termList = new ArrayList<>();
92+
try (final PrologParser parser = parseEd("one(1). two(2). three(3).")) {
93+
while (parser.hasNext()) {
94+
termList.add(parser.next());
95+
}
96+
}
97+
assertEquals(3, termList.size());
98+
}
99+
68100
@Test
69101
void testReadingClausesTokensAndCharsFromSameParser() throws Exception {
70102
try (final PrologParser parser = parseEd("lsome(a). alone. next(b).c")) {

0 commit comments

Comments
 (0)