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