From: Svjatoslav Agejenko Date: Wed, 11 Oct 2017 15:08:09 +0000 (+0300) Subject: Fixed lookahead. X-Git-Tag: svjatoslavcommons-1.8~52 X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=4d4a86dce1b84d9ef26d95168f2fea5477cedaa5;p=svjatoslav_commons.git Fixed lookahead. --- diff --git a/src/main/java/eu/svjatoslav/commons/string/tokenizer/Tokenizer.java b/src/main/java/eu/svjatoslav/commons/string/tokenizer/Tokenizer.java index 4855c18..01216d8 100755 --- a/src/main/java/eu/svjatoslav/commons/string/tokenizer/Tokenizer.java +++ b/src/main/java/eu/svjatoslav/commons/string/tokenizer/Tokenizer.java @@ -46,7 +46,7 @@ public class Tokenizer { 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)) @@ -111,7 +111,7 @@ public class Tokenizer { } public boolean peekIsOneOf(String ... possibilities){ - TokenizerMatch nextToken = peekNextToken(); + String nextToken = peekNextToken().token; for (String possibility : possibilities) if (possibility.equals(nextToken)) diff --git a/src/test/java/eu/svjatoslav/commons/string/tokenizer/TokenizerTest.java b/src/test/java/eu/svjatoslav/commons/string/tokenizer/TokenizerTest.java new file mode 100644 index 0000000..e40b401 --- /dev/null +++ b/src/test/java/eu/svjatoslav/commons/string/tokenizer/TokenizerTest.java @@ -0,0 +1,24 @@ +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