1   package test.net.sourceforge.pmd.rules;
2   
3   import net.sourceforge.pmd.PMD;
4   import net.sourceforge.pmd.Rule;
5   import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
6   import test.net.sourceforge.pmd.testframework.TestDescriptor;
7   
8   public class SuspiciousOctalEscapeTest extends SimpleAggregatorTst {
9       private Rule rule;
10  
11      public void setUp() {
12          rule = findRule("controversial", "SuspiciousOctalEscape");
13      }
14      
15      public void testAll() {
16          runTests(new TestDescriptor[]{
17              new TestDescriptor(TEST1, "ok use of octal", 0, rule),
18              new TestDescriptor(TEST2, "should be flagged", 1, rule),
19              new TestDescriptor(TEST3, "should be flagged - different octal", 1, rule),
20              new TestDescriptor(TEST4, "should be flagged - different octal", 1, rule),
21          });
22      }
23  
24      private static final String TEST1 =
25              "public class Foo {" + PMD.EOL +
26              " void bar() {" + PMD.EOL +
27              "  int x = \128;" + PMD.EOL +
28              " }" + PMD.EOL +
29              "}";
30  
31      private static final String TEST2 =
32              "public class Foo {" + PMD.EOL +
33              " void bar() {" + PMD.EOL +
34              "  System.out.println(\"foo = //128\");" + PMD.EOL +
35              " }" + PMD.EOL +
36              "}";
37  
38      private static final String TEST3 =
39          "public class Foo {" + PMD.EOL +
40          " void bar() {" + PMD.EOL +
41          "  System.out.println(\"foo = //0008\");" + PMD.EOL +
42          " }" + PMD.EOL +
43          "}";
44      
45      private static final String TEST4 =
46          "public class Foo {" + PMD.EOL +
47          " void bar() {" + PMD.EOL +
48          "  System.out.println(\"foo = //4008\");" + PMD.EOL +
49          " }" + PMD.EOL +
50          "}";
51      
52  }