use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.
the class NodeDefaultsTest method testReceiverDefaults.
@Test
public void testReceiverDefaults() {
Node n = new TestNode();
NodeLibrary l = createLibrary(NodeLibrary.class, n);
assertFalse(l.hasReceiverMember(n, null));
assertFails(() -> l.getReceiverMember(n, null), UnsupportedMessageException.class);
}
use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.
the class NodeDefaultsTest method testRootInstanceDefaults.
@Test
public void testRootInstanceDefaults() {
Node n = new TestNode();
NodeLibrary l = createLibrary(NodeLibrary.class, n);
assertFalse(l.hasRootInstance(n, null));
assertFails(() -> l.getRootInstance(n, null), UnsupportedMessageException.class);
}
use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.
the class NodeDefaultsTest method testViewDefaults.
@Test
@SuppressWarnings("hiding")
public void testViewDefaults() {
try (Context context = Context.create()) {
ProxyLanguage language = new ProxyLanguage();
ProxyLanguage.setDelegate(language);
context.initialize(ProxyLanguage.ID);
context.enter();
Frame frame = Truffle.getRuntime().createMaterializedFrame(new Object[] {});
Node n = new TestNode(ProxyLanguage.get(null), frame.getFrameDescriptor());
NodeLibrary l = createLibrary(NodeLibrary.class, n);
Object v = 42 * 42;
// Integer is not associated with a language
assertFails(() -> l.getView(n, frame, v), AssertionError.class);
Object pv = new ProxyLanguageValue();
assertSame(pv, l.getView(n, frame, pv));
}
}
use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.
the class NodeAssertionsTest method testReceiver.
@Test
public void testReceiver() throws UnsupportedMessageException {
TestAssertsNode n = new TestAssertsNode();
NodeLibrary l = createLibrary(NodeLibrary.class, n);
Object invalidReceiverName = new Object();
Object validReceiverName = "receiver";
n.hasReceiverMember = false;
n.getReceiverMember = null;
assertFalse(l.hasReceiverMember(n, null));
assertFails(() -> l.getReceiverMember(n, null), UnsupportedMessageException.class);
n.hasReceiverMember = false;
n.getReceiverMember = (frame) -> validReceiverName;
assertFails(() -> l.hasReceiverMember(n, null), AssertionError.class);
assertFails(() -> l.getReceiverMember(n, null), AssertionError.class);
n.hasReceiverMember = true;
n.getReceiverMember = null;
assertFails(() -> l.hasReceiverMember(n, null), AssertionError.class);
assertFails(() -> l.getReceiverMember(n, null), AssertionError.class);
n.hasReceiverMember = true;
n.getReceiverMember = (frame) -> validReceiverName;
assertTrue(l.hasReceiverMember(n, null));
assertSame(validReceiverName, l.getReceiverMember(n, null));
n.hasReceiverMember = true;
n.getReceiverMember = (frame) -> invalidReceiverName;
assertFails(() -> l.hasReceiverMember(n, null), AssertionError.class);
assertFails(() -> l.getReceiverMember(n, null), AssertionError.class);
n.hasReceiverMember = true;
n.getReceiverMember = (frame) -> validReceiverName;
assertTrue(l.hasReceiverMember(n, null));
assertSame(validReceiverName, l.getReceiverMember(n, null));
}
use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.
the class NodeAssertionsTest method testRootInstance.
@Test
public void testRootInstance() throws UnsupportedMessageException {
TestAssertsNode n = new TestAssertsNode();
NodeLibrary l = createLibrary(NodeLibrary.class, n);
Object invalidRootInstance = new TruffleObject() {
};
// not executable
Object validRootInstance = new ValidRootInstance();
n.hasRootInstance = false;
n.getRootInstance = null;
assertFalse(l.hasRootInstance(n, null));
assertFails(() -> l.getRootInstance(n, null), UnsupportedMessageException.class);
n.hasRootInstance = false;
n.getRootInstance = (frame) -> validRootInstance;
assertFails(() -> l.hasRootInstance(n, null), AssertionError.class);
assertFails(() -> l.getRootInstance(n, null), AssertionError.class);
n.hasRootInstance = true;
n.getRootInstance = null;
assertFails(() -> l.hasRootInstance(n, null), AssertionError.class);
assertFails(() -> l.getRootInstance(n, null), AssertionError.class);
n.hasRootInstance = true;
n.getRootInstance = frame -> validRootInstance;
assertTrue(l.hasRootInstance(n, null));
assertSame(validRootInstance, l.getRootInstance(n, null));
n.hasRootInstance = true;
n.getRootInstance = frame -> invalidRootInstance;
assertFails(() -> l.hasRootInstance(n, null), AssertionError.class);
assertFails(() -> l.getRootInstance(n, null), AssertionError.class);
}
Aggregations