/
TestSourceFile.java
73 lines (61 loc) · 2.19 KB
/
TestSourceFile.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package org.epic.core.model;
import java.io.IOException;
import java.util.Iterator;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.epic.perl.editor.test.BaseTestCase;
import org.epic.perl.editor.test.Log;
import org.epic.perleditor.editors.PartitionTypes;
import org.epic.perleditor.editors.PerlPartitioner;
public class TestSourceFile extends BaseTestCase
{
public void testOutline() throws Exception
{
// Regression test for subroutine-to-package mappings
_testFile(
"workspace/EPICTest/lib/TestPackage.pm",
"test.in/TestSourceFile-expected1.txt");
_testFile(
"workspace/EPICTest/Twig.pm",
"test.in/TestSourceFile-expected2.txt");
}
private void _testFile(String inFile, String outFile) throws IOException
{
Document doc = new Document(readFile(inFile));
new PerlPartitioner(new Log(), doc);
String expected = readFile(outFile);
SourceFile src = new SourceFile(new Log(), doc);
src.parse();
StringBuffer buf = new StringBuffer();
for (Iterator i = src.getPackages().iterator(); i.hasNext();)
{
Package pkg = (Package) i.next();
buf.append(pkg.getName());
buf.append(':');
buf.append(pkg.getStartLine());
buf.append(':');
buf.append(pkg.getEndLine());
buf.append(':');
buf.append(pkg.getSubs().size());
buf.append(':');
buf.append('{');
for (Iterator j = pkg.getSubs().iterator(); j.hasNext();)
{
Subroutine sub = (Subroutine) j.next();
buf.append(sub.getName());
buf.append(':');
buf.append(sub.getBlockLevel());
buf.append(String.format("%n"));
}
buf.append('}');
buf.append(String.format("%n"));
}
/*
PrintWriter pw = new PrintWriter(
new FileWriter("/tmp/outf"));
pw.println(buf);
pw.close();
*/
assertEquals(expected, buf.toString());
}
}