1
2
3
4 package net.sourceforge.pmd.cpd;
5
6 import static org.junit.Assert.assertEquals;
7
8 import java.util.ArrayList;
9
10 import net.sourceforge.pmd.PMD;
11
12 import org.junit.Test;
13
14 public class SourceCodeTest {
15
16 private static final String SAMPLE_CODE =
17 "Line 1\n" +
18 "Line 2\n" +
19 "Line 3\n" +
20 "Line 4\n";
21
22 @Test
23 public void testSimple() throws Throwable {
24 Tokenizer tokenizer = new AbstractTokenizer() {
25 {
26 this.stringToken = new ArrayList<String>();
27 this.ignorableCharacter = new ArrayList<String>();
28 this.ignorableStmt = new ArrayList<String>();
29 }
30 };
31 SourceCode sourceCode = new SourceCode(new SourceCode.StringCodeLoader(SAMPLE_CODE, "Foo.java"));
32 assertEquals("Foo.java", sourceCode.getFileName());
33 tokenizer.tokenize(sourceCode, new Tokens());
34
35 assertEquals("Line 1", sourceCode.getSlice(1, 1));
36 assertEquals("Line 2", sourceCode.getSlice(2, 2));
37 assertEquals("Line 1" + PMD.EOL + "Line 2", sourceCode.getSlice(1, 2));
38 }
39 }