1   package test.net.sourceforge.pmd.cpd;
2   
3   import junit.framework.TestCase;
4   import net.sourceforge.pmd.PMD;
5   import net.sourceforge.pmd.cpd.CPPTokenizer;
6   import net.sourceforge.pmd.cpd.SourceCode;
7   import net.sourceforge.pmd.cpd.Tokens;
8   
9   public class CPPTokenizerTest extends TestCase {
10  
11      public void testMultiLineMacros() throws Throwable {
12          CPPTokenizer tokenizer = new CPPTokenizer();
13          SourceCode code = new SourceCode(new SourceCode.StringCodeLoader(TEST1));
14          Tokens tokens = new Tokens();
15          tokenizer.tokenize(code, tokens);
16          assertEquals(7, tokens.size());
17      }
18  
19      public void testDollarSignInIdentifier() {
20          parse(TEST2);
21      }
22  
23      public void testDollarSignStartingIdentifier() {
24          parse(TEST3);
25      }
26  
27      public void testWideCharacters() {
28          parse(TEST4);
29      }
30  
31      private void parse(String snippet) {
32          CPPTokenizer tokenizer = new CPPTokenizer();
33          SourceCode code = new SourceCode(new SourceCode.StringCodeLoader(snippet));
34          Tokens tokens = new Tokens();
35          tokenizer.tokenize(code, tokens);
36      }
37  
38      private static final String TEST1 =
39              "#define FOO a +//" + PMD.EOL +
40              "            b +//" + PMD.EOL +
41              "            c +//" + PMD.EOL +
42              "            d +//" + PMD.EOL +
43              "            e +//" + PMD.EOL +
44              "            f +//" + PMD.EOL +
45              "            g" + PMD.EOL +
46              " void main() {}";
47  
48      private static final String TEST2 =
49              " void main() { int x$y = 42; }";
50  
51      private static final String TEST3 =
52              " void main() { int $x = 42; }";
53  
54      private static final String TEST4 =
55              " void main() { char x = L'a'; }";
56  
57  
58  }