Package org.sonar.duplications.token

Examples of org.sonar.duplications.token.Token


public class ForgetLastTokenMatcherTest {

  @Test
  public void shouldMatch() {
    TokenQueue tokenQueue = spy(new TokenQueue());
    Token token = new Token("a", 0, 0);
    List<Token> output = Lists.newArrayList(token);
    ForgetLastTokenMatcher matcher = new ForgetLastTokenMatcher();

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


    new BridgeTokenMatcher("(", null);
  }

  @Test
  public void shouldMatch() {
    Token t1 = new Token("(", 1, 1);
    Token t2 = new Token("a", 2, 1);
    Token t3 = new Token("(", 3, 1);
    Token t4 = new Token("b", 4, 1);
    Token t5 = new Token(")", 5, 1);
    Token t6 = new Token("c", 6, 1);
    Token t7 = new Token(")", 7, 1);
    TokenQueue tokenQueue = spy(new TokenQueue(Arrays.asList(t1, t2, t3, t4, t5, t6, t7)));
    List<Token> output = mock(List.class);
    BridgeTokenMatcher matcher = new BridgeTokenMatcher("(", ")");

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

    verifyNoMoreInteractions(output);
  }

  @Test
  public void shouldNotMatchWhenNoLeft() {
    Token t1 = new Token("a", 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));
View Full Code Here

    verifyNoMoreInteractions(output);
  }

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

    new ExactTokenMatcher(null);
  }

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

    verifyNoMoreInteractions(output);
  }

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

public class AnyTokenMatcherTest {

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

    new UptoTokenMatcher(new String[] {});
  }

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

    verifyNoMoreInteractions(output);
  }

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

    verifyNoMoreInteractions(output);
  }

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

TOP

Related Classes of org.sonar.duplications.token.Token

Copyright © 2018 www.massapicom. 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.