forked from MarkusEble/Compilerbau24
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InterpreterTestMain.java
64 lines (53 loc) · 2.38 KB
/
InterpreterTestMain.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
public class InterpreterTestMain {
public static void main(String[] args) throws Exception {
// open input file
String testSuiteContent = compiler.InputReader.fileToString("InterpreterTestInput.txt");
compiler.InputReader inputReader = new compiler.InputReader(testSuiteContent);
test.TestSuite testSuite = new test.TestSuite();
testSuite.execute(inputReader, new InterpreterTest());
}
public static java.util.Vector<test.TestCaseContent> parseTestSuite(compiler.InputReader inputReader) throws Exception {
java.util.Vector<test.TestCaseContent> testCaseContentArr = new java.util.Vector<test.TestCaseContent>();
while (inputReader.lookAheadChar() != 0 ) {
testCaseContentArr.addElement(parseTestCase(inputReader));
}
return testCaseContentArr;
}
public static test.TestCaseContent parseTestCase(compiler.InputReader inputReader) throws Exception {
parseDollarIn(inputReader);
String input = parseInput(inputReader);
parseDollarOut(inputReader);
String expectedOutput = parseExpectedOutput(inputReader);
test.TestCaseContent testCaseContent = new test.TestCaseContent(input, expectedOutput);
return testCaseContent;
}
public static void parseDollarIn(compiler.InputReader inputReader) throws Exception {
inputReader.expect('$');
inputReader.expect('I');
inputReader.expect('N');
inputReader.expect('\n');
}
public static String parseInput(compiler.InputReader inputReader) throws Exception {
String input = new String();
while (inputReader.lookAheadChar() != '$' && inputReader.lookAheadChar() != 0) {
input += inputReader.lookAheadChar();
inputReader.advance();
}
return input;
}
public static void parseDollarOut(compiler.InputReader inputReader) throws Exception {
inputReader.expect('$');
inputReader.expect('O');
inputReader.expect('U');
inputReader.expect('T');
inputReader.expect('\n');
}
public static String parseExpectedOutput(compiler.InputReader inputReader) throws Exception {
String expectedOutput = new String();
while (inputReader.lookAheadChar() != '$' && inputReader.lookAheadChar() != 0) {
expectedOutput += inputReader.lookAheadChar();
inputReader.advance();
}
return expectedOutput;
}
}