Examples of TokenQueue


Examples of org.sonar.duplications.token.TokenQueue

  }

  @Test
  public void shouldNotMatchWhenNoRight() {
    Token t1 = new Token("(", 1, 1);
    TokenQueue tokenQueue = spy(new TokenQueue(Arrays.asList(t1)));
    List<Token> output = mock(List.class);
    BridgeTokenMatcher matcher = new BridgeTokenMatcher("(", ")");

    assertThat(matcher.matchToken(tokenQueue, output), is(false));
    verify(tokenQueue, times(1)).isNextTokenValue("(");
View Full Code Here

Examples of org.sonar.duplications.token.TokenQueue

  @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);
    ExactTokenMatcher matcher = new ExactTokenMatcher("a");

    assertThat(matcher.matchToken(tokenQueue, output), is(true));
    verify(tokenQueue).isNextTokenValue("a");
View Full Code Here

Examples of org.sonar.duplications.token.TokenQueue

  @Test
  public void shouldNotMatch() {
    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);
    ExactTokenMatcher matcher = new ExactTokenMatcher("b");

    assertThat(matcher.matchToken(tokenQueue, output), is(false));
    verify(tokenQueue).isNextTokenValue("b");
View Full Code Here

Examples of org.sonar.duplications.token.TokenQueue

    new OptTokenMatcher(null);
  }

  @Test
  public void shouldMatch() {
    TokenQueue tokenQueue = spy(new TokenQueue());
    TokenMatcher delegate = mock(TokenMatcher.class);
    OptTokenMatcher matcher = new OptTokenMatcher(delegate);
    List<Token> output = mock(List.class);

    assertThat(matcher.matchToken(tokenQueue, output), is(true));
View Full Code Here

Examples of org.sonar.duplications.token.TokenQueue

  @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();
View Full Code Here

Examples of org.sonar.duplications.token.TokenQueue

  @Test
  public void shouldMatch() {
    Token t1 = new Token("a", 1, 1);
    Token t2 = new Token(";", 2, 1); // should stop on this token
    Token t3 = new Token(";", 3, 1);
    TokenQueue tokenQueue = spy(new TokenQueue(Arrays.asList(t1, t2, t3)));
    List<Token> output = mock(List.class);
    UptoTokenMatcher matcher = new UptoTokenMatcher(new String[] { ";" });

    assertThat(matcher.matchToken(tokenQueue, output), is(true));
    verify(tokenQueue, times(2)).poll();
View Full Code Here

Examples of org.sonar.duplications.token.TokenQueue

  public void shouldMatchAnyOfProvidedTokens() {
    Token t1 = new Token("a", 1, 1);
    Token t2 = new Token("{", 2, 1);
    Token t3 = new Token("b", 3, 1);
    Token t4 = new Token("}", 4, 1);
    TokenQueue tokenQueue = spy(new TokenQueue(Arrays.asList(t1, t2, t3, t4)));
    List<Token> output = mock(List.class);
    UptoTokenMatcher matcher = new UptoTokenMatcher(new String[] { "{", "}" });

    assertThat(matcher.matchToken(tokenQueue, output), is(true));
    assertThat(matcher.matchToken(tokenQueue, output), is(true));
View Full Code Here

Examples of org.sonar.duplications.token.TokenQueue

  @Test
  public void shouldNotMatch() {
    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);
    UptoTokenMatcher matcher = new UptoTokenMatcher(new String[] { ";" });

    assertThat(matcher.matchToken(tokenQueue, output), is(false));
    verify(tokenQueue, times(2)).poll();
View Full Code Here

Examples of org.sonar.duplications.token.TokenQueue

  @Test(expected = IllegalStateException.class)
  public void shouldThrowAnException() {
    TokenMatcher tokenMatcher = mock(TokenMatcher.class);
    StatementChannel channel = StatementChannel.create(tokenMatcher);
    StatementChannelDisptacher dispatcher = new StatementChannelDisptacher(Arrays.asList(channel));
    TokenQueue tokenQueue = mock(TokenQueue.class);
    when(tokenQueue.peek()).thenReturn(new Token("a", 1, 0)).thenReturn(null);
    List<Statement> statements = mock(List.class);

    dispatcher.consume(tokenQueue, statements);
  }
View Full Code Here

Examples of org.sonar.duplications.token.TokenQueue

  public void shouldConsume() {
    TokenMatcher tokenMatcher = mock(TokenMatcher.class);
    when(tokenMatcher.matchToken(any(TokenQueue.class), anyListOf(Token.class))).thenReturn(true);
    StatementChannel channel = StatementChannel.create(tokenMatcher);
    StatementChannelDisptacher dispatcher = new StatementChannelDisptacher(Arrays.asList(channel));
    TokenQueue tokenQueue = mock(TokenQueue.class);
    when(tokenQueue.peek()).thenReturn(new Token("a", 1, 0)).thenReturn(null);
    List<Statement> statements = mock(List.class);

    assertThat(dispatcher.consume(tokenQueue, statements), is(true));
    verify(tokenQueue, times(2)).peek();
    verifyNoMoreInteractions(tokenQueue);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.