public static TokenMatcher anyToken() { // TODO Godin: we can return singleton instance return new AnyTokenMatcher(); }
@Test public void shouldNotCreateStatement() { TokenQueue tokenQueue = spy(new TokenQueue(Arrays.asList(new Token("a", 1, 1)))); TokenMatcher matcher = spy(new AnyTokenMatcher()); StatementChannel channel = StatementChannel.create(matcher); List<Statement> output = mock(List.class); assertThat(channel.consume(tokenQueue, output), is(true)); verify(matcher).matchToken(eq(tokenQueue), anyList()); verifyNoMoreInteractions(matcher); verify(output).add(any()); verifyNoMoreInteractions(output); }
@Test public void shouldMatch() { Token t1 = new Token("a", 1, 1); Token t2 = new Token("b", 2, 1); TokenQueue tokenQueue = spy(new TokenQueue(Arrays.asList(t1, t2))); List<Token> output = mock(List.class); AnyTokenMatcher matcher = new AnyTokenMatcher(); assertThat(matcher.matchToken(tokenQueue, output), is(true)); verify(tokenQueue).poll(); verifyNoMoreInteractions(tokenQueue); verify(output).add(t1); verifyNoMoreInteractions(output); }
@Test public void shouldCreateStatement() { Token token = new Token("a", 1, 1); TokenQueue tokenQueue = spy(new TokenQueue(Arrays.asList(token))); TokenMatcher matcher = spy(new AnyTokenMatcher()); StatementChannel channel = StatementChannel.create(matcher); List<Statement> output = mock(List.class); assertThat(channel.consume(tokenQueue, output), is(true)); verify(matcher).matchToken(eq(tokenQueue), anyList()); verifyNoMoreInteractions(matcher); ArgumentCaptor<Statement> statement = ArgumentCaptor.forClass(Statement.class); verify(output).add(statement.capture()); assertThat(statement.getValue().getValue(), is("a")); assertThat(statement.getValue().getStartLine(), is(1)); assertThat(statement.getValue().getEndLine(), is(1)); verifyNoMoreInteractions(output); }
public static TokenMatcher anyToken() { // TODO Godin: we can return singleton instance return new AnyTokenMatcher(); }