Commit f2055430 authored by Johannes Mey's avatar Johannes Mey
Browse files

add initial test for new feature

parent 0a2769f0
......@@ -3,3 +3,4 @@ all:
cd valid && make test
cd errors && make test
cd multipleFiles && make test
cd resolverHelper && make test
/AST/*
/*Gen.ast
/*Gen.jadd
AST/*
All.ast
All.jadd
AllGen.jadd
AllGen.ast
\ No newline at end of file
/AST/*
/All.ast
All.jadd
AllRefResolver.jadd
public class AbstractTests {
protected void assertException() {
check(false, "should throw exception");
}
protected void assertTrue(boolean b) {
check(b, "value should be true (is false)");
}
protected void assertFalse(boolean b) {
check(!b, "value should be flase (is true)");
}
protected void assertNull(Object obj) {
check(obj == null, "Object not null: " + obj);
}
protected void assertSame(Object o1, Object o2) {
check(o1 == o2, "Objects not same: " + o1 + ", " + o2);
}
protected void assertEquals(Object o1, Object o2) {
check(o1.equals(o2), "Objects not equals: " + o1 + ", " + o2);
}
protected void check(boolean b, String message) {
if (!b) {
throw new RuntimeException(message);
}
}
}
\ No newline at end of file
import AST.*;
import java.util.*;
@SuppressWarnings("ArraysAsListWithZeroOrOneArgument")
public class All extends AbstractTests {
private Root r;
private A a1;
private A a2;
private A a3;
private B b1;
private B b2;
private B b3;
public static void main(String args[]) {
new All().test();
}
public void test() {
testNameRes1();
}
/**
* rel A.Di1 -> B;
*/
private void testNameRes1() {
setup();
a1.setRel1(NamedElement.createRef("b2"));
System.out.println("Rel 1 of a1 has type " + a1.getRel1().getClass().getSimpleName());
assertSame(a1.getRel1(), b2);
}
private void setup() {
r = new Root();
a1 = new A("a1");
a2 = new A("a2");
a3 = new A("a3");
b1 = new B("b1");
b2 = new B("b2");
b3 = new B("b3");
r.addA(a1);
r.addA(a2);
r.addA(a3);
r.addB(b1);
r.addB(b2);
r.addB(b3);
}
}
Root ::= A* B*;
abstract NamedElement ::= <Name:String>;
A:NamedElement;
B:NamedElement;
rel A.Rel1 -> NamedElement;
rel A.Rel2 -> NamedElement;
all: build-jar test
test: clean test1
@echo "#"
@echo "# RESOLVER HELPER TESTS OK"
@echo "#"
build-jar:
(cd ../../ && ./gradlew jar)
test1:
java -jar ../../build/libs/relast.jar Grammar.relast --file --grammarName=All --resolverHelper
java -jar ../../tools/jastadd2.jar --package=AST --rewrite=cnta All.ast All.jadd AllRefResolver.jadd MyRefResolver.jadd Utils.jadd
javac AST/*.java All.java
java All
clean:
rm -rf AST
rm -f *.class
rm -f *.ast
\ No newline at end of file
aspect MyRewrites {
// context-independent name resolution
refine RefResolverStubs eq ASTNode.resolveNamedElement(String id) {
System.out.println("resolving " + id + " to " + root().findNamedElement(id));
return root().findNamedElement(id);
}
refine RefResolverStubs eq A.resolveRel2(String id) {
// default to context-independent name resolution
return resolveNamedElement(id);
}
}
aspect Utils {
public String NamedElement.toString() {
return getName();
}
inh Root ASTNode.root();
eq Root.getA(int i).root() = this;
eq Root.getB(int i).root() = this;
syn NamedElement Root.findNamedElement(String name) {
for (A a : getAList()) {
if (a.getName().equals(name)) {
return a;
}
}
for (B b : getBList()) {
if (b.getName().equals(name)) {
return b;
}
}
return null;
}
syn A Root.findA(String name) {
for (A a : getAList()) {
if (a.getName().equals(name)) {
return a;
}
}
return null;
}
syn B Root.findB(String name) {
for (B b : getBList()) {
if (b.getName().equals(name)) {
return b;
}
}
return null;
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment