m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2019-11-11 13:21:30 +0100
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2019-11-11 13:21:30 +0100
commitfba2e1f41625a998624c6918eaf034cf3e9bd71a (patch)
tree1df8815b9a65d8f92ff72de6f5a918a796c9b897 /src/main/java
parent900fb0aee0b68cbb88f578f20019738b4416f436 (diff)
Add interpreter tests
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Main.java21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Main.java b/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Main.java
index a9857ed..76ea1e6 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Main.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Main.java
@@ -25,6 +25,8 @@
package pl.edu.mimuw.cloudatlas.interpreter;
import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.PrintStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.ParseException;
@@ -53,30 +55,35 @@ public class Main {
private static ZMI root;
public static void main(String[] args) throws Exception {
+ runTest(System.in, System.out);
+ }
+
+ public static void runTest(InputStream in, PrintStream out) throws Exception {
root = createTestHierarchy();
- Scanner scanner = new Scanner(System.in);
+ Scanner scanner = new Scanner(in);
scanner.useDelimiter("\\n");
- while(scanner.hasNext())
- executeQueries(root, scanner.next());
+ while(scanner.hasNext()) {
+ executeQueries(root, scanner.next(), out);
+ }
scanner.close();
- }
+ }
private static PathName getPathName(ZMI zmi) {
String name = ((ValueString)zmi.getAttributes().get("name")).getValue();
return zmi.getFather() == null? PathName.ROOT : getPathName(zmi.getFather()).levelDown(name);
}
- private static void executeQueries(ZMI zmi, String query) throws Exception {
+ private static void executeQueries(ZMI zmi, String query, PrintStream out) throws Exception {
if(!zmi.getSons().isEmpty()) {
for(ZMI son : zmi.getSons())
- executeQueries(son, query);
+ executeQueries(son, query, out);
Interpreter interpreter = new Interpreter(zmi);
Yylex lex = new Yylex(new ByteArrayInputStream(query.getBytes()));
try {
List<QueryResult> result = interpreter.interpretProgram((new parser(lex)).pProgram());
PathName zone = getPathName(zmi);
for(QueryResult r : result) {
- System.out.println(zone + ": " + r);
+ out.println(zone + ": " + r);
zmi.getAttributes().addOrChange(r.getName(), r.getValue());
}
} catch(InterpreterException exception) {}