-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added basic tests for PrimitiveLoader
Signed-off-by: Stefan Marr <git@stefan-marr.de>
- Loading branch information
Showing
4 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package bd.primitives; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
import org.junit.Test; | ||
|
||
import bd.testsetup.AddNodeFactory; | ||
import bd.testsetup.ExprNode; | ||
|
||
|
||
public class PrimitiveTests { | ||
|
||
private final Primitives ps = new Primitives(null); | ||
|
||
@Test | ||
public void testPrimitiveAnnotation() { | ||
Primitive[] annotations = ps.getPrimitiveAnnotation(AddNodeFactory.getInstance()); | ||
Primitive p = annotations[0]; | ||
|
||
assertEquals("Int", p.className()); | ||
assertEquals("+", p.primitive()); | ||
assertEquals(1, annotations.length); | ||
} | ||
|
||
@Test | ||
public void testEagerSpecializer() { | ||
Specializer<Void, ExprNode, String> s = ps.getEagerSpecializer("+", null, null); | ||
assertNotNull(s); | ||
|
||
assertEquals("AddNodeFactory", s.getName()); | ||
} | ||
|
||
@Test | ||
public void testParserSpecializer() { | ||
Specializer<Void, ExprNode, String> s = ps.getParserSpecializer("+", null); | ||
assertNotNull(s); | ||
|
||
assertEquals("AddNodeFactory", s.getName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package bd.primitives; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.oracle.truffle.api.dsl.NodeFactory; | ||
|
||
import bd.testsetup.AddNodeFactory; | ||
import bd.testsetup.ExprNode; | ||
|
||
|
||
public class Primitives extends PrimitiveLoader<Void, ExprNode, String> { | ||
protected Primitives(final Void context) { | ||
super(context); | ||
initialize(); | ||
} | ||
|
||
@Override | ||
protected List<NodeFactory<? extends ExprNode>> getFactories() { | ||
List<NodeFactory<? extends ExprNode>> allFactories = new ArrayList<>(); | ||
allFactories.add(AddNodeFactory.getInstance()); | ||
return allFactories; | ||
} | ||
|
||
@Override | ||
protected void registerPrimitive(final Primitive prim, | ||
final Specializer<Void, ExprNode, String> specializer) {} | ||
|
||
@Override | ||
protected String getId(final String id) { | ||
return id.intern(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters