TokenStream { public String consume() throws ParsingException, IllegalStateException { if (completed) { throwNoMoreContent(); } String result = currentToken().value(); moveToNextToken(); return result; } TokenStream(String content,
                       Tokenizer tokenizer,
                       boolean caseSensitive); TokenStream start(); void rewind(); Marker mark(); boolean rewind(Marker marker); boolean advance(Marker marker); Position previousPosition(); Position previousPosition(int count); Position nextPosition(); int consumeInteger(); long consumeLong(); boolean consumeBoolean(); String consume(); String peek(); TokenStream consume(String expected); TokenStream consume(char expected); TokenStream consume(int expectedType); TokenStream consume(String expected,
                               String... expectedForNextTokens); TokenStream consume(String[] nextTokens); TokenStream consume(Iterable<String> nextTokens); String consumeAnyOf(int... typeOptions); String consumeAnyOf(String... options); TokenStream consumeThrough(char expected); TokenStream consumeThrough(char expected, char skipMatchingTokens); TokenStream consumeThrough(String expected); TokenStream consumeThrough(String expected, String skipMatchingTokens); TokenStream consumeUntil(char expected); TokenStream consumeUntil(char expected, char skipMatchingTokens); TokenStream consumeUntil(String expected); TokenStream consumeUntil(String expected, String... skipMatchingTokens); TokenStream consumeUntilEndOrOneOf(String... stopTokens); boolean canConsumeInteger(IntConsumer consumer); boolean canConsumeBoolean(BooleanConsumer consumer); boolean canConsumeLong(LongConsumer consumer); boolean canConsume(String expected); boolean canConsume(int type, String expected); boolean canConsumeWord(String expected); boolean canConsume(char expected); boolean canConsume(int expectedType); boolean canConsume(String currentExpected,
                              String... expectedForNextTokens); boolean canConsume(int type, String currentExpected, String... expectedForNextTokens); boolean canConsumeWords(String currentExpected, String... expectedForNextTokens); boolean canConsume(String[] nextTokens); boolean canConsume(Iterable<String> nextTokens); boolean canConsumeAnyOf(String firstOption,
                                   String... additionalOptions); boolean canConsumeAnyOf(String[] options); boolean canConsumeAnyOf(Iterable<String> options); boolean canConsumeAnyOf(int firstTypeOption,
                                   int... additionalTypeOptions); boolean canConsumeAnyOf(int[] typeOptions); boolean matches(String expected); boolean matches(int type, String expected); boolean matchesWord(String expected); boolean matches(char expected); boolean matches(int expectedType); boolean matches(String currentExpected,
                           String... expectedForNextTokens); boolean matches(String[] nextTokens); boolean matches(Iterable<String> nextTokens); boolean matches(int currentExpectedType,
                           int... expectedTypeForNextTokens); boolean matches(int[] typesForNextTokens); boolean matchesAnyOf(String firstOption,
                                String... additionalOptions); boolean matchesAnyOf(int type, String firstOption, String... additionalOptions); boolean matchesAnyWordOf(String firstOption, String... additionalOptions); boolean matchesAnyOf(String[] options); boolean matchesAnyOf(Iterable<String> options); boolean matchesAnyOf(int firstTypeOption,
                                int... additionalTypeOptions); boolean matchesAnyOf(int[] typeOptions); boolean hasNext(); @Override String toString(); String getContentFrom(Marker starting); String getContentBetween(Marker starting,
                                    Position end); String getContentBetween(Position starting,
                                    Position end); final Token previousToken(int count); static BasicTokenizer basicTokenizer(boolean includeComments); String getInputString(); static final String ANY_VALUE; static final int ANY_TYPE; }
@Test(expected = ParsingException.class) public void shouldFailToConsumeInCaseSensitiveMannerWithExpectedValuesWhenMatchingIncorrectCase() { makeCaseSensitive(); tokens.consume("Select"); tokens.consume("all"); tokens.consume("Columns"); }
@Test(expected = ParsingException.class) public void shouldFailToConsumeInCaseInsensitiveMannerWithExpectedValuesWhenMatchingStringIsInLowerCase() { makeCaseInsensitive(); tokens.consume("SELECT"); tokens.consume("ALL"); tokens.consume("columns"); }
@Test public void shouldConsumeCaseInsensitiveStringInOriginalCase() { makeCaseInsensitive(); String firstToken = tokens.consume(); assertThat(firstToken).isEqualTo("Select"); }
@Test(expected = ParsingException.class) public void shouldFailToConsumeMultipleTokensIfTheyDoNotMatch() { makeCaseInsensitive(); tokens.consume("SELECT", "ALL", "COLUMNS", "FROM", "TABLE"); }