    1   /***
    2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
    3    */
    4   package test.net.sourceforge.pmd.cpd;
    5
    6   import junit.framework.TestCase;
    7   import net.sourceforge.pmd.PMD;
    8   import net.sourceforge.pmd.cpd.JavaTokenizer;
    9   import net.sourceforge.pmd.cpd.SourceCode;
    10  import net.sourceforge.pmd.cpd.Tokens;
    11
    12  public class SourceCodeTest extends TestCase {
    13
    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  }