Search in sources :

Example 1 with ValueAssert.assertValue

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();
}
Also used : Context(org.graalvm.polyglot.Context) LanguageContext(com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext) TruffleContext(com.oracle.truffle.api.TruffleContext) ValueAssert.assertValue(com.oracle.truffle.tck.tests.ValueAssert.assertValue) Value(org.graalvm.polyglot.Value) Test(org.junit.Test)

Example 2 with ValueAssert.assertValue

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();
}
Also used : Context(org.graalvm.polyglot.Context) LanguageContext(com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext) TruffleContext(com.oracle.truffle.api.TruffleContext) ValueAssert.assertValue(com.oracle.truffle.tck.tests.ValueAssert.assertValue) Value(org.graalvm.polyglot.Value)

Aggregations

TruffleContext (com.oracle.truffle.api.TruffleContext)2 LanguageContext (com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext)2 ValueAssert.assertValue (com.oracle.truffle.tck.tests.ValueAssert.assertValue)2 Context (org.graalvm.polyglot.Context)2 Value (org.graalvm.polyglot.Value)2 Test (org.junit.Test)1