View Javadoc

1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.cpd;
5   
6   import static org.junit.Assert.assertEquals;
7   import net.sourceforge.pmd.PMD;
8   
9   import org.junit.Test;
10  
11  public class SourceCodeTest {
12  
13      @Test
14      public void testSimple() throws Throwable {
15          JavaTokenizer tokenizer = new JavaTokenizer();
16          SourceCode sourceCode = new SourceCode(new SourceCode.StringCodeLoader(MatchAlgorithmTest.getSampleCode(), "Foo.java"));
17          assertEquals("Foo.java", sourceCode.getFileName());
18          tokenizer.tokenize(sourceCode, new Tokens());
19  
20          assertEquals(MatchAlgorithmTest.LINE_1, sourceCode.getSlice(1, 1));
21          assertEquals(MatchAlgorithmTest.LINE_2, sourceCode.getSlice(2, 2));
22          assertEquals(MatchAlgorithmTest.LINE_1 + PMD.EOL + MatchAlgorithmTest.LINE_2, sourceCode.getSlice(1, 2));
23      }
24  
25      public static junit.framework.Test suite() {
26          return new junit.framework.JUnit4TestAdapter(SourceCodeTest.class);
27      }
28  }