Package org.sonar.channel

Examples of org.sonar.channel.CodeReader


  /**
   * SONAR-3531
   */
  @Test
  public void should_be_possible_to_use_two_instances() {
    CodeReader reader = new CodeReader("<!-- multi-line comment\n--> private part");
    MultilinesDocTokenizer tokenizer1 = new MultiLineDocTokenizerImpl("<!--", "-->");
    MultilinesDocTokenizer tokenizer2 = new MultiLineDocTokenizerImpl("<!--", "-->");
    assertThat(tokenizer1.consume(reader, codeBuilder)).isTrue();
    reader.pop();
    assertThat(tokenizer2.consume(reader, codeBuilder)).isFalse();
  }
View Full Code Here


  }

  @Test
  public void testRead() {
    CDocTokenizer tokenizer = new CDocTokenizer("<c>", "</c>");
    assertThat(tokenizer.consume(new CodeReader("//this is a comment"), codeBuilder)).isTrue();
    assertThat(codeBuilder.toString()).isEqualTo("<c>//this is a comment</c>");

    assertThat(tokenizer.consume(new CodeReader("this is not a comment"), codeBuilder)).isFalse();
    assertThat(codeBuilder.toString()).isEqualTo("<c>//this is a comment</c>");
  }
View Full Code Here

  @Test
  public void shouldAddTagsBetweenEachLine() {
    HtmlOptions options = new HtmlOptions().setGenerateTable(true).setGenerateHtmlHeader(false);
    HtmlDecorator decorator = new HtmlDecorator(options);
    CodeReader code = new CodeReader("\r\n\r");
    HtmlCodeBuilder output = new HtmlCodeBuilder();

    output.appendWithoutTransforming(decorator.getTagBeginOfFile());
    assertThat(decorator.consume(code, output)).isTrue();
    assertThat(decorator.consume(code, output)).isTrue();
View Full Code Here

  }

  @Test
  public void nextToken() {
    LiteralTokenizer tokenizer = new LiteralTokenizer("<s>", "</s>");
    assertTrue(tokenizer.consume(new CodeReader("\"toto\";"), codeBuilder));
    assertEquals("<s>\"toto\"</s>", codeBuilder.toString());
    init();
    assertTrue(tokenizer.consume(new CodeReader("\"\";"), codeBuilder));
    assertEquals("<s>\"\"</s>", codeBuilder.toString());
    init();
    assertTrue(tokenizer.consume(new CodeReader("\'\';"), codeBuilder));
    assertEquals("<s>\'\'</s>", codeBuilder.toString());
    init();
    assertTrue(tokenizer.consume(new CodeReader("\"(\\\"\").replace"), codeBuilder));
    assertEquals("<s>\"(\\\"\"</s>", codeBuilder.toString());
    init();
    assertTrue(tokenizer.consume(new CodeReader("\'\\\\\';"), codeBuilder));
    assertEquals("<s>\'\\\\\'</s>", codeBuilder.toString());
    init();
    assertTrue(tokenizer.consume(new CodeReader("\"to\\'to\""), codeBuilder));
    assertEquals("<s>\"to\\'to\"</s>", codeBuilder.toString());
  }
View Full Code Here

  }

  @Test
  public void testRead() {
    CppDocTokenizer javadocTokenizer = new CppDocTokenizer("<c>", "</c>");
    assertTrue(javadocTokenizer.consume(new CodeReader("/*this is a cpp comment*/ private"), codeBuilder));
    assertEquals("<c>/*this is a cpp comment*/</c>", codeBuilder.toString());
   
    assertFalse(javadocTokenizer.consume(new CodeReader("//this is not a cpp comment"), codeBuilder));
  }
View Full Code Here

 
  @Test
  public void testReadOnMultilines() {
    CppDocTokenizer javadocTokenizer = new CppDocTokenizer("<c>", "</c>");
    CodeReader reader = new CodeReader("/*this is \n a cpp comment*/ private");
    assertTrue(javadocTokenizer.consume(reader, codeBuilder));
    assertEquals("<c>/*this is </c>", codeBuilder.toString());
    codeBuilder.append((char)reader.pop());
    assertTrue(javadocTokenizer.consume(reader, codeBuilder));
    assertEquals("<c>/*this is </c>\n<c> a cpp comment*/</c>", codeBuilder.toString());
  }
View Full Code Here

  @Test
  public void shouldConsume() {
    TokenChannel channel = new TokenChannel("ABC");
    TokenQueue output = mock(TokenQueue.class);
    CodeReader codeReader = new CodeReader("ABCD");

    assertThat(channel.consume(codeReader, output), is(true));
    ArgumentCaptor<Token> token = ArgumentCaptor.forClass(Token.class);
    verify(output).add(token.capture());
    assertThat(token.getValue(), is(new Token("ABC", 1, 0)));
    verifyNoMoreInteractions(output);
    assertThat(codeReader.getLinePosition(), is(1));
    assertThat(codeReader.getColumnPosition(), is(3));
  }
View Full Code Here

  @Test
  public void shouldNormalize() {
    TokenChannel channel = new TokenChannel("ABC", "normalized");
    TokenQueue output = mock(TokenQueue.class);
    CodeReader codeReader = new CodeReader("ABCD");

    assertThat(channel.consume(codeReader, output), is(true));
    ArgumentCaptor<Token> token = ArgumentCaptor.forClass(Token.class);
    verify(output).add(token.capture());
    assertThat(token.getValue(), is(new Token("normalized", 1, 0)));
    verifyNoMoreInteractions(output);
    assertThat(codeReader.getLinePosition(), is(1));
    assertThat(codeReader.getColumnPosition(), is(3));
  }
View Full Code Here

  @Test
  public void shouldNotConsume() {
    TokenChannel channel = new TokenChannel("ABC");
    TokenQueue output = mock(TokenQueue.class);
    CodeReader codeReader = new CodeReader("123");

    assertThat(channel.consume(new CodeReader("123"), output), is(false));
    verifyZeroInteractions(output);
    assertThat(codeReader.getLinePosition(), is(1));
    assertThat(codeReader.getColumnPosition(), is(0));
  }
View Full Code Here

  @Test
  public void shouldCorrectlyDeterminePositionWhenTokenSpansMultipleLines() {
    TokenChannel channel = new TokenChannel("AB\nC");
    TokenQueue output = mock(TokenQueue.class);
    CodeReader codeReader = new CodeReader("AB\nCD");

    assertThat(channel.consume(codeReader, output), is(true));
    ArgumentCaptor<Token> token = ArgumentCaptor.forClass(Token.class);
    verify(output).add(token.capture());
    assertThat(token.getValue(), is(new Token("AB\nC", 1, 0)));
    verifyNoMoreInteractions(output);
    assertThat(codeReader.getLinePosition(), is(2));
    assertThat(codeReader.getColumnPosition(), is(1));
  }
View Full Code Here

TOP

Related Classes of org.sonar.channel.CodeReader

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.