use of com.oracle.truffle.tck.tests.ValueAssert.assertValue in project graal by oracle.
the class LanguageSPITest method testBindingsWithDefaultScope.
@Test
public void testBindingsWithDefaultScope() {
Context c = Context.create();
Value bindings = c.getBindings(ProxyLanguage.ID);
assertTrue(bindings.hasMembers());
assertFalse(bindings.hasMember(""));
assertTrue(bindings.getMemberKeys().isEmpty());
assertNull(bindings.getMember(""));
AbstractPolyglotTest.assertFails(() -> bindings.putMember("", ""), UnsupportedOperationException.class);
assertFalse(bindings.removeMember(""));
ValueAssert.assertValue(bindings);
c.close();
}
use of com.oracle.truffle.tck.tests.ValueAssert.assertValue in project graal by oracle.
the class LanguageSPITest method testBindingsWithSimpleScope.
private void testBindingsWithSimpleScope(TestScope scope) {
Context c = Context.create();
assertEquals(0, findScopeInvokes);
Value bindings = c.getBindings(ProxyLanguage.ID);
c.getBindings(ProxyLanguage.ID);
assertEquals(1, findScopeInvokes);
scope.values.put("foobar", "baz");
assertTrue(bindings.hasMembers());
assertFalse(bindings.hasMember(""));
assertTrue(bindings.hasMember("foobar"));
assertEquals(new HashSet<>(Arrays.asList("foobar")), bindings.getMemberKeys());
assertNull(bindings.getMember(""));
assertEquals("baz", bindings.getMember("foobar").asString());
AbstractPolyglotTest.assertFails(() -> bindings.putMember("", ""), UnsupportedOperationException.class);
assertFalse(bindings.removeMember(""));
AbstractPolyglotTest.assertFails(() -> bindings.removeMember("foobar"), UnsupportedOperationException.class);
ValueAssert.assertValue(bindings, ValueAssert.Trait.MEMBERS);
scope.insertable = true;
bindings.putMember("baz", "val");
assertEquals("val", scope.values.get("baz"));
assertEquals("val", bindings.getMember("baz").asString());
AbstractPolyglotTest.assertFails(() -> bindings.putMember("foobar", "42"), UnsupportedOperationException.class);
ValueAssert.assertValue(bindings, ValueAssert.Trait.MEMBERS);
scope.modifiable = true;
bindings.putMember("foobar", "val");
assertEquals("val", scope.values.get("foobar"));
assertEquals("val", bindings.getMember("foobar").asString());
ValueAssert.assertValue(bindings, ValueAssert.Trait.MEMBERS);
scope.removable = true;
assertFalse(bindings.removeMember(""));
assertTrue(bindings.removeMember("foobar"));
ValueAssert.assertValue(bindings, ValueAssert.Trait.MEMBERS);
assertEquals(1, findScopeInvokes);
c.close();
}
Aggregations