Package org.sonar.duplications.token

Examples of org.sonar.duplications.token.Token


  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


    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

   * <a href="http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.7">Comments</a>
   */
  @Test
  public void shouldIgnoreEndOfLineComment() {
    assertThat(chunk("// This is a comment"), isTokens());
    assertThat(chunk("// This is a comment \n and_this_is_not"), isTokens(new Token("and_this_is_not", 2, 1)));
  }
View Full Code Here

  /**
   * <a href="http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.8">Identifiers</a>
   */
  @Test
  public void shouldPreserveIdentifiers() {
    assertThat(chunk("String"), isTokens(new Token("String", 1, 0)));
    assertThat(chunk("i3"), isTokens(new Token("i3", 1, 0)));
    assertThat(chunk("MAX_VALUE"), isTokens(new Token("MAX_VALUE", 1, 0)));
    assertThat(chunk("isLetterOrDigit"), isTokens(new Token("isLetterOrDigit", 1, 0)));

    assertThat(chunk("_"), isTokens(new Token("_", 1, 0)));
    assertThat(chunk("_123_"), isTokens(new Token("_123_", 1, 0)));
    assertThat(chunk("_Field"), isTokens(new Token("_Field", 1, 0)));
    assertThat(chunk("_Field5"), isTokens(new Token("_Field5", 1, 0)));

    assertThat(chunk("$"), isTokens(new Token("$", 1, 0)));
    assertThat(chunk("$field"), isTokens(new Token("$field", 1, 0)));

    assertThat(chunk("i2j"), isTokens(new Token("i2j", 1, 0)));
    assertThat(chunk("from1to4"), isTokens(new Token("from1to4", 1, 0)));

    assertThat("identifier with unicode", chunk("αβγ"), isTokens(new Token("αβγ", 1, 0)));
  }
View Full Code Here

  /**
   * <a href="http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.9">Keywords</a>
   */
  @Test
  public void shouldPreserverKeywords() {
    assertThat(chunk("private static final"), isTokens(new Token("private", 1, 0), new Token("static", 1, 8), new Token("final", 1, 15)));
  }
View Full Code Here

  /**
   * <a href="http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.10.3">Boolean Literals</a>
   */
  @Test
  public void shouldPreserveBooleanLiterals() {
    assertThat(chunk("true false"), isTokens(new Token("true", 1, 0), new Token("false", 1, 5)));
  }
View Full Code Here

  /**
   * <a href="http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.10.7">The Null Literal</a>
   */
  @Test
  public void shouldPreserverNullLiteral() {
    assertThat(chunk("null"), isTokens(new Token("null", 1, 0)));
  }
View Full Code Here

   * <a href="http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.11">Separators</a>
   */
  @Test
  public void shouldPreserveSeparators() {
    assertThat(chunk("(){}[];,."), isTokens(
        new Token("(", 1, 0), new Token(")", 1, 1),
        new Token("{", 1, 2), new Token("}", 1, 3),
        new Token("[", 1, 4), new Token("]", 1, 5),
        new Token(";", 1, 6), new Token(",", 1, 7),
        new Token(".", 1, 8)));
  }
View Full Code Here

  /**
   * <a href="http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.12">Operators</a>
   */
  @Test
  public void shouldPreserveOperators() {
    assertThat(chunk("+="), isTokens(new Token("+", 1, 0), new Token("=", 1, 1)));
    assertThat(chunk("--"), isTokens(new Token("-", 1, 0), new Token("-", 1, 1)));
  }
View Full Code Here

      IOUtils.closeQuietly(reader);
    }
  }

  private static Matcher<List<Token>> isNumericLiteral() {
    return isTokens(new Token("$NUMBER", 1, 0));
  }
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.