Skip to content

Commit

Permalink
added tests to cover also the trees with keyword parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Nov 2, 2023
1 parent 5ff2a93 commit 6348911
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/org/rascalmpl/MatchFingerprintTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.rascalmpl.interpreter.env.ModuleEnvironment;
import io.usethesource.vallang.IConstructor;
import io.usethesource.vallang.IInteger;
import io.usethesource.vallang.ISourceLocation;
import io.usethesource.vallang.exceptions.FactTypeUseException;
import io.usethesource.vallang.io.StandardTextReader;
import io.usethesource.vallang.type.Type;
Expand Down Expand Up @@ -60,13 +61,20 @@ public void testFunctionFingerPrintStability() {

public void testTreeApplFingerPrintStability() {
String prodString = "prod(sort(\"E\"),[],{})";
ISourceLocation loc = VF.sourceLocation("BLABLA");

try {
IConstructor prod = (IConstructor) new StandardTextReader().read(VF, RascalFunctionValueFactory.getStore(), RascalFunctionValueFactory.Production, new StringReader(prodString));
ITree tree = VF.appl(prod, VF.list());

assertEquals(tree.getMatchFingerprint(), "appl".hashCode() + 131 * 2);
assertEquals(tree.getConcreteMatchFingerprint(), "tree".hashCode() + 41 * prod.hashCode());

// and now WITH a keyword parameter
tree = (ITree) tree.asWithKeywordParameters().setParameter("src", loc);

assertEquals(tree.getMatchFingerprint(), "appl".hashCode() + 131 * 2);
assertEquals(tree.getConcreteMatchFingerprint(), "tree".hashCode() + 41 * prod.hashCode());
}
catch (FactTypeUseException | IOException e) {
fail(e.getMessage());
Expand All @@ -76,6 +84,7 @@ public void testTreeApplFingerPrintStability() {
public void testTreeAmbFingerPrintStability() {
String prodString1 = "prod(sort(\"E\"),[],{})";
String prodString2 = "prod(sort(\"E\"),[empty()],{})";
ISourceLocation loc = VF.sourceLocation("BLABLA");

try {
IConstructor prod1= (IConstructor) new StandardTextReader().read(VF, RascalFunctionValueFactory.getStore(), RascalFunctionValueFactory.Production, new StringReader(prodString1));
Expand All @@ -87,30 +96,52 @@ public void testTreeAmbFingerPrintStability() {

assertEquals(amb.getMatchFingerprint(), "amb".hashCode() + 131);
assertEquals(amb.getConcreteMatchFingerprint(), "amb".hashCode() + 43 * TreeAdapter.getType(amb).hashCode());

// and now WITH a keyword parameter
amb = (ITree) amb.asWithKeywordParameters().setParameter("src", loc);

assertEquals(amb.getMatchFingerprint(), "amb".hashCode() + 131);
assertEquals(amb.getConcreteMatchFingerprint(), "amb".hashCode() + 43 * TreeAdapter.getType(amb).hashCode());
}
catch (FactTypeUseException | IOException e) {
fail(e.getMessage());
}
}

public void testTreeCharFingerPrintStability() {
ISourceLocation loc = VF.sourceLocation("BLABLA");

try {
ITree theChar = (ITree) new StandardTextReader().read(VF, RascalFunctionValueFactory.getStore(), RascalFunctionValueFactory.Tree, new StringReader("char(32)"));

assertEquals(theChar.getMatchFingerprint(), "char".hashCode() + 131);
assertEquals(theChar.getConcreteMatchFingerprint(), "char".hashCode() + ((IInteger) theChar.get(0)).intValue());

// and now WITH a keyword parameter
theChar = (ITree) theChar.asWithKeywordParameters().setParameter("src", loc);

assertEquals(theChar.getMatchFingerprint(), "char".hashCode() + 131);
assertEquals(theChar.getConcreteMatchFingerprint(), "char".hashCode() + ((IInteger) theChar.get(0)).intValue());
}
catch (FactTypeUseException | IOException e) {
fail(e.getMessage());
}
}

public void testTreeCycleFingerPrintStability() {
ISourceLocation loc = VF.sourceLocation("BLABLA");

try {
ITree theCycle = (ITree) new StandardTextReader().read(VF, RascalFunctionValueFactory.getStore(), RascalFunctionValueFactory.Tree, new StringReader("cycle(sort(\"A\"), 3)"));

assertEquals(theCycle.getMatchFingerprint(), "cycle".hashCode() + 2 * 131);
assertEquals(theCycle.getConcreteMatchFingerprint(), "cycle".hashCode() + 13 * theCycle.get(0).hashCode());

// and now WITH a keyword parameter
theCycle = (ITree) theCycle.asWithKeywordParameters().setParameter("src", loc);

assertEquals(theCycle.getMatchFingerprint(), "cycle".hashCode() + 2 * 131);
assertEquals(theCycle.getConcreteMatchFingerprint(), "cycle".hashCode() + 13 * theCycle.get(0).hashCode());
}
catch (FactTypeUseException | IOException e) {
fail(e.getMessage());
Expand Down

0 comments on commit 6348911

Please sign in to comment.