-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4134 from jlerbsc/lookhead
Minor refactoring: Simplifies how to group deleted tokens by extracting a method into an independent class
- Loading branch information
Showing
13 changed files
with
699 additions
and
331 deletions.
There are no files selected for viewing
126 changes: 126 additions & 0 deletions
126
.../src/test/java/com/github/javaparser/printer/lexicalpreservation/PeekingIteratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package com.github.javaparser.printer.lexicalpreservation; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.NoSuchElementException; | ||
|
||
import org.junit.jupiter.api.*; | ||
|
||
class PeekingIteratorTest { | ||
|
||
private static final List<String> EMPTY_LIST = new ArrayList(); | ||
|
||
private static List<String> NON_EMPTY_LIST ; | ||
|
||
private PeekingIterator<String> peekingIterator; | ||
|
||
@BeforeAll | ||
static void setUpBeforeClass() throws Exception { | ||
} | ||
|
||
@AfterAll | ||
static void tearDownAfterClass() throws Exception { | ||
} | ||
|
||
@BeforeEach | ||
void setUp() throws Exception { | ||
NON_EMPTY_LIST = Arrays.asList("A", "B", "C"); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() throws Exception { | ||
} | ||
|
||
@Test | ||
void testHasNext() { | ||
peekingIterator = new PeekingIterator(EMPTY_LIST.listIterator()); | ||
assertFalse(peekingIterator.hasNext()); | ||
peekingIterator = new PeekingIterator(NON_EMPTY_LIST.listIterator()); | ||
assertTrue(peekingIterator.hasNext()); | ||
} | ||
|
||
@Test | ||
void testPeek() { | ||
peekingIterator = new PeekingIterator(EMPTY_LIST.listIterator()); | ||
assertEquals(null, peekingIterator.peek()); | ||
peekingIterator = new PeekingIterator(NON_EMPTY_LIST.listIterator()); | ||
assertEquals("A", peekingIterator.peek()); | ||
assertEquals("A", peekingIterator.next()); | ||
} | ||
|
||
@Test | ||
void testElement() { | ||
peekingIterator = new PeekingIterator(EMPTY_LIST.listIterator()); | ||
assertEquals(null, peekingIterator.peek()); | ||
peekingIterator = new PeekingIterator(NON_EMPTY_LIST.listIterator()); | ||
assertEquals("A", peekingIterator.peek()); | ||
assertEquals(1, peekingIterator.nextIndex()); | ||
} | ||
|
||
@Test | ||
void testNext() { | ||
peekingIterator = new PeekingIterator(EMPTY_LIST.listIterator()); | ||
assertThrows(NoSuchElementException.class, () -> peekingIterator.next()); | ||
peekingIterator = new PeekingIterator(NON_EMPTY_LIST.listIterator()); | ||
assertEquals("A", peekingIterator.next()); | ||
} | ||
|
||
@Test | ||
void testRemove() { | ||
peekingIterator = new PeekingIterator(EMPTY_LIST.listIterator()); | ||
assertThrows(IllegalStateException.class, () -> peekingIterator.remove()); | ||
peekingIterator = new PeekingIterator(NON_EMPTY_LIST.listIterator()); | ||
assertThrows(IllegalStateException.class, () -> peekingIterator.remove()); | ||
String result = peekingIterator.next(); | ||
assertThrows(UnsupportedOperationException.class, () -> peekingIterator.remove()); | ||
} | ||
|
||
@Test | ||
void testHasPrevious() { | ||
peekingIterator = new PeekingIterator(EMPTY_LIST.listIterator()); | ||
assertFalse(peekingIterator.hasPrevious()); | ||
peekingIterator = new PeekingIterator(NON_EMPTY_LIST.listIterator()); | ||
assertFalse(peekingIterator.hasPrevious()); | ||
String result = peekingIterator.next(); | ||
assertTrue(peekingIterator.hasPrevious()); | ||
} | ||
|
||
@Test | ||
void testPrevious() { | ||
peekingIterator = new PeekingIterator(EMPTY_LIST.listIterator()); | ||
assertThrows(NoSuchElementException.class, () -> peekingIterator.previous()); | ||
peekingIterator = new PeekingIterator(NON_EMPTY_LIST.listIterator()); | ||
assertThrows(NoSuchElementException.class, () -> peekingIterator.previous()); | ||
} | ||
|
||
@Test | ||
void testNextIndex() { | ||
peekingIterator = new PeekingIterator(EMPTY_LIST.listIterator()); | ||
assertEquals(0, peekingIterator.nextIndex()); | ||
peekingIterator = new PeekingIterator(NON_EMPTY_LIST.listIterator()); | ||
assertEquals(0, peekingIterator.nextIndex()); | ||
} | ||
|
||
@Test | ||
void testPreviousIndex() { | ||
peekingIterator = new PeekingIterator(EMPTY_LIST.listIterator()); | ||
assertEquals(-1, peekingIterator.previousIndex()); | ||
peekingIterator = new PeekingIterator(NON_EMPTY_LIST.listIterator()); | ||
assertEquals(-1, peekingIterator.previousIndex()); | ||
} | ||
|
||
@Test | ||
void testSet() { | ||
peekingIterator = new PeekingIterator(EMPTY_LIST.listIterator()); | ||
assertThrows(IllegalStateException.class, () -> peekingIterator.set("D")); | ||
peekingIterator = new PeekingIterator(NON_EMPTY_LIST.listIterator()); | ||
assertThrows(IllegalStateException.class, () -> peekingIterator.set("D")); | ||
peekingIterator.next(); | ||
peekingIterator.set("D"); | ||
assertEquals(3, NON_EMPTY_LIST.size()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.