use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.
the class NodeAssertionsTest method testView.
@Test
@SuppressWarnings("hiding")
public void testView() {
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[] {});
TestAssertsNode n = new TestAssertsNode(ProxyLanguage.get(null), frame.getFrameDescriptor());
NodeLibrary l = createLibrary(NodeLibrary.class, n);
n.getView = (f, x) -> x;
assertFails(() -> l.getView(n, null, true), AssertionError.class);
assertFails(() -> l.getView(n, null, new Object()), AssertionError.class);
assertFails(() -> l.getView(n, frame, true), AssertionError.class);
assertFails(() -> l.getView(n, frame, new Object()), AssertionError.class);
NodeDefaultsTest.ProxyLanguageValue pv = new NodeDefaultsTest.ProxyLanguageValue();
assertSame(pv, l.getView(n, frame, pv));
assertFails(() -> l.getView(n, null, pv), AssertionError.class);
assertFails(() -> l.getView(new TestAssertsNode(ProxyLanguage.get(null), null), frame, pv), AssertionError.class);
assertFails(() -> l.getView(new TestAssertsNode(null, frame.getFrameDescriptor()), frame, pv), AssertionError.class);
}
}
use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.
the class NodeAssertionsTest method testScope.
@Test
public void testScope() throws UnsupportedMessageException {
TestAssertsNode n = new TestAssertsNode();
NodeLibrary l = createLibrary(NodeLibrary.class, n);
Object invalidScope = new TruffleObject() {
};
Object validScope = new ValidScope();
n.hasScope = false;
n.getScope = null;
assertFalse(l.hasScope(n, null));
assertFails(() -> l.getScope(n, null, true), UnsupportedMessageException.class);
n.hasScope = false;
n.getScope = (frame) -> validScope;
assertFails(() -> l.hasScope(n, null), AssertionError.class);
assertFails(() -> l.getScope(n, null, true), AssertionError.class);
n.hasScope = true;
n.getScope = null;
assertFails(() -> l.hasScope(n, null), AssertionError.class);
assertFails(() -> l.getScope(n, null, true), AssertionError.class);
n.hasScope = true;
n.getScope = frame -> validScope;
assertTrue(l.hasScope(n, null));
assertSame(validScope, l.getScope(n, null, true));
n.hasScope = true;
n.getScope = frame -> invalidScope;
assertFails(() -> l.hasScope(n, null), AssertionError.class);
assertFails(() -> l.getScope(n, null, true), AssertionError.class);
}
Aggregations