return this;
}
- public void expectNextToken(final String value)
+ public void expectAndConsumeNextToken(final String value)
throws InvalidSyntaxException {
final TokenizerMatch match = getNextToken();
if (!value.equals(match.token))
}
public boolean peekIsOneOf(String ... possibilities){
- TokenizerMatch nextToken = peekNextToken();
+ String nextToken = peekNextToken().token;
for (String possibility : possibilities)
if (possibility.equals(nextToken))
--- /dev/null
+package eu.svjatoslav.commons.string.tokenizer;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class TokenizerTest {
+
+
+ @Test
+ public void peekNextToken() throws Exception {
+ Tokenizer tokenizer = new Tokenizer("this is a test")
+ .addTerminator(" ", Terminator.TerminationStrategy.DROP);
+
+ tokenizer.expectAndConsumeNextToken("this");
+
+ assertEquals("is", tokenizer.peekNextToken().token);
+
+ assertEquals("is", tokenizer.peekNextToken().token);
+
+ assertEquals(true, tokenizer.peekIsOneOf("maybe", "is", "that"));
+ }
+
+}
\ No newline at end of file