Search in sources :

Example 1 with CppTokenManager

use of net.sourceforge.pmd.lang.cpp.CppTokenManager in project pmd by pmd.

the class CPPTokenizerContinuationTest method parseWithContinuationCppTokenManager.

/**
 * Verifies the begin/end of a token. Uses the underlaying JavaCC Token and
 * not TokenEntry.
 */
@Test
public void parseWithContinuationCppTokenManager() throws Exception {
    String code = load("cpp_with_continuation.cpp");
    CppTokenManager tokenManager = new CppTokenManager(new StringReader(code));
    List<Token> tokens = new ArrayList<>();
    Token token = (Token) tokenManager.getNextToken();
    while (!token.image.isEmpty()) {
        tokens.add(token);
        token = (Token) tokenManager.getNextToken();
    }
    assertEquals(51, tokens.size());
    assertToken(tokens.get(2), "ab", 8, 12, 9, 1);
    assertToken(tokens.get(22), "\"2 Hello, world!\\n\"", 18, 16, 19, 9);
}
Also used : CppTokenManager(net.sourceforge.pmd.lang.cpp.CppTokenManager) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) Token(net.sourceforge.pmd.lang.cpp.ast.Token) Test(org.junit.Test)

Aggregations

StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 CppTokenManager (net.sourceforge.pmd.lang.cpp.CppTokenManager)1 Token (net.sourceforge.pmd.lang.cpp.ast.Token)1 Test (org.junit.Test)1