-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCompilerTest.java
More file actions
79 lines (66 loc) · 1.57 KB
/
CompilerTest.java
File metadata and controls
79 lines (66 loc) · 1.57 KB
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
74
75
76
77
78
79
/*
* I got sick of my bash script not working, so I've come up with
* this program to test the compiler class. The expressions.txt file
* should now be a CSV file with (expression,valid) where expression
* is the expression to test, and valid is true if it should parse and
* compile as valid regex.
*
* Dan Collins 2014
* 1183446
*/
import java.nio.charset.*;
import java.nio.file.*;
import java.io.*;
import java.util.ArrayList;
class CompilerTest {
public static void main(String[] args) {
Path p;
BufferedReader r;
ArrayList<String> l;
String inLine;
String[] data;
String exp;
boolean valid, pass;
Compiler c;
if (args.length < 1) {
System.err.println("Invalid input arguments!");
return;
}
p = Paths.get(args[0]).toAbsolutePath();
try {
r = Files.newBufferedReader(p,
Charset.forName("US-ASCII"));
} catch (IOException e) {
System.err.println("Failed to open file.");
return;
}
l = new ArrayList<String>();
c = new Compiler();
try {
while ((inLine = r.readLine()) != null) {
data = inLine.split(",");
if (data.length != 2)
continue;
exp = data[0];
valid = data[1].equals("true") ? true : false;
c.setExpression(exp);
try {
c.compile();
pass = true;
} catch (IllegalArgumentException e) {
pass = false;
}
if (pass != valid)
l.add(exp);
}
} catch (IOException e) {
System.err.println("Error reading line from file.");
}
if (l.size() > 0) {
System.out.println("Failed tests:");
for (String s : l) {
System.out.println(s);
}
}
}
}