1 package test.net.sourceforge.pmd.cpd;
2
3 import static org.junit.Assert.assertEquals;
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 import org.junit.Test;
10
11 public class CPPTokenizerTest {
12
13 @Test
14 public void testMultiLineMacros() throws Throwable {
15 CPPTokenizer tokenizer = new CPPTokenizer();
16 SourceCode code = new SourceCode(new SourceCode.StringCodeLoader(TEST1));
17 Tokens tokens = new Tokens();
18 tokenizer.tokenize(code, tokens);
19 assertEquals(7, tokens.size());
20 }
21
22 @Test
23 public void testDollarSignInIdentifier() {
24 parse(TEST2);
25 }
26
27 @Test
28 public void testDollarSignStartingIdentifier() {
29 parse(TEST3);
30 }
31
32 @Test
33 public void testWideCharacters() {
34 parse(TEST4);
35 }
36
37 private void parse(String snippet) {
38 CPPTokenizer tokenizer = new CPPTokenizer();
39 SourceCode code = new SourceCode(new SourceCode.StringCodeLoader(snippet));
40 Tokens tokens = new Tokens();
41 tokenizer.tokenize(code, tokens);
42 }
43
44 private static final String TEST1 =
45 "#define FOO a +\\" + PMD.EOL +
46 " b +\\" + PMD.EOL +
47 " c +\\" + PMD.EOL +
48 " d +\\" + PMD.EOL +
49 " e +\\" + PMD.EOL +
50 " f +\\" + PMD.EOL +
51 " g" + PMD.EOL +
52 " void main() {}";
53
54 private static final String TEST2 =
55 " void main() { int x$y = 42; }";
56
57 private static final String TEST3 =
58 " void main() { int $x = 42; }";
59
60 private static final String TEST4 =
61 " void main() { char x = L'a'; }";
62
63 public static junit.framework.Test suite() {
64 return new junit.framework.JUnit4TestAdapter(CPPTokenizerTest.class);
65 }
66 }