Search in sources :

Example 56 with InteropLibrary

use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.

the class InteropAssertionsTest method testToDisplayString.

@Test
public void testToDisplayString() {
    ToDisplayStringTest v = new ToDisplayStringTest();
    InteropLibrary l = createLibrary(InteropLibrary.class, v);
    v.toDisplayString = "myString";
    assertSame(v.toDisplayString, l.toDisplayString(v));
    v.toDisplayString = new TestStringWrapper("myString");
    assertSame(v.toDisplayString, l.toDisplayString(v));
    v.toDisplayString = null;
    assertFails(() -> l.toDisplayString(v, true), NullPointerException.class);
    v.toDisplayString = new TestEmpty();
    assertFails(() -> l.toDisplayString(v, true), AssertionError.class);
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) Test(org.junit.Test)

Example 57 with InteropLibrary

use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.

the class InteropAssertionsTest method testGetHashValuesIterator.

@Test
public void testGetHashValuesIterator() throws UnsupportedMessageException {
    HashTest hashTest = new HashTest();
    InteropLibrary hashLib = createLibrary(InteropLibrary.class, hashTest);
    hashLib.getHashValuesIterator(hashTest);
    hashTest.hasHashEntries = false;
    assertFails(() -> hashLib.getHashValuesIterator(hashTest), AssertionError.class);
    hashTest.hasHashEntries = true;
    hashTest.iterator = null;
    assertFails(() -> hashLib.getHashValuesIterator(hashTest), AssertionError.class);
    hashTest.hasHashEntries = true;
    hashTest.iterator = () -> null;
    assertFails(() -> hashLib.getHashValuesIterator(hashTest), AssertionError.class);
    hashTest.iterator = () -> new TruffleObject() {
    };
    assertFails(() -> hashLib.getHashValuesIterator(hashTest), AssertionError.class);
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 58 with InteropLibrary

use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.

the class InteropAssertionsTest method isExceptionIncompleteSource.

@Test
public void isExceptionIncompleteSource() throws UnsupportedMessageException {
    ExceptionTest exceptionTest = new ExceptionTest();
    InteropLibrary exceptionLib = createLibrary(InteropLibrary.class, exceptionTest);
    exceptionTest.exceptionType = ExceptionType.PARSE_ERROR;
    exceptionTest.isExceptionIncompleteSource = () -> true;
    assertEquals(exceptionTest.isExceptionIncompleteSource.get().booleanValue(), exceptionLib.isExceptionIncompleteSource(exceptionTest));
    exceptionTest.exceptionType = ExceptionType.RUNTIME_ERROR;
    assertFails(() -> exceptionLib.isExceptionIncompleteSource(exceptionTest), AssertionError.class);
    exceptionTest.exceptionType = ExceptionType.PARSE_ERROR;
    exceptionTest.isExceptionIncompleteSource = null;
    assertFails(() -> exceptionLib.isExceptionIncompleteSource(exceptionTest), AssertionError.class);
    TruffleObject empty = new TruffleObject() {
    };
    InteropLibrary objectLib = createLibrary(InteropLibrary.class, empty);
    assertFails(() -> objectLib.isExceptionIncompleteSource(empty), UnsupportedMessageException.class);
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 59 with InteropLibrary

use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.

the class InteropAssertionsTest method testGetExceptionMessage.

@Test
public void testGetExceptionMessage() throws UnsupportedMessageException {
    ExceptionTest exceptionTest = new ExceptionTest();
    InteropLibrary exceptionLib = createLibrary(InteropLibrary.class, exceptionTest);
    assertEquals(exceptionTest.getExceptionMessage.get(), exceptionLib.getExceptionMessage(exceptionTest));
    exceptionTest.hasExceptionMessage = false;
    assertFails(() -> exceptionLib.getExceptionMessage(exceptionTest), AssertionError.class);
    exceptionTest.hasExceptionMessage = true;
    exceptionTest.getExceptionMessage = null;
    assertFails(() -> exceptionLib.getExceptionMessage(exceptionTest), AssertionError.class);
    exceptionTest.getExceptionMessage = () -> null;
    assertFails(() -> exceptionLib.getExceptionMessage(exceptionTest), NullPointerException.class);
    exceptionTest.getExceptionMessage = () -> 1;
    assertFails(() -> exceptionLib.getExceptionMessage(exceptionTest), AssertionError.class);
    TruffleObject empty = new TruffleObject() {
    };
    InteropLibrary objectLib = createLibrary(InteropLibrary.class, empty);
    assertFails(() -> objectLib.getExceptionMessage(empty), UnsupportedMessageException.class);
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 60 with InteropLibrary

use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.

the class InteropAssertionsTest method testScope.

@Test
public void testScope() throws InteropException {
    ScopeTest v = new ScopeTest();
    InteropLibrary l = createLibrary(InteropLibrary.class, v);
    v.hasLanguage = false;
    v.isScope = false;
    v.hasScopeParent = false;
    v.getScopeParent = null;
    v.hasMembers = false;
    v.getMembers = null;
    assertFalse(l.isScope(v));
    assertFalse(l.hasScopeParent(v));
    assertFalse(l.hasMembers(v));
    assertFails(() -> l.getScopeParent(v), UnsupportedMessageException.class);
    v.isScope = false;
    v.hasScopeParent = true;
    assertFalse(l.isScope(v));
    assertFails(() -> l.hasScopeParent(v), AssertionError.class);
    assertFails(() -> l.getScopeParent(v), AssertionError.class);
    v.isScope = true;
    v.hasScopeParent = false;
    v.hasMembers = true;
    v.getMembers = () -> new Members();
    // It does not have a language
    assertFails(() -> l.isScope(v), AssertionError.class);
    v.hasLanguage = true;
    v.getLanguage = () -> ProxyLanguage.class;
    assertTrue(l.isScope(v));
    v.hasMembers = false;
    v.getMembers = null;
    assertFails(() -> l.isScope(v), AssertionError.class);
    assertFalse(l.hasScopeParent(v));
    assertFails(() -> l.getScopeParent(v), UnsupportedMessageException.class);
    v.hasMembers = true;
    v.getMembers = () -> new Members();
    assertTrue(l.isScope(v));
    assertFalse(l.hasScopeParent(v));
    assertFails(() -> l.getScopeParent(v), UnsupportedMessageException.class);
    v.hasScopeParent = false;
    v.getScopeParent = () -> "No Scope";
    assertTrue(l.isScope(v));
    assertFails(() -> l.hasScopeParent(v), AssertionError.class);
    assertFails(() -> l.getScopeParent(v), AssertionError.class);
    v.hasScopeParent = true;
    v.getScopeParent = () -> "No Scope";
    assertTrue(l.isScope(v));
    assertFails(() -> l.hasScopeParent(v), AssertionError.class);
    assertFails(() -> l.getScopeParent(v), AssertionError.class);
    ScopeTest parentScope = new ScopeTest();
    v.getScopeParent = () -> parentScope;
    assertFails(() -> l.hasScopeParent(v), AssertionError.class);
    assertFails(() -> l.getScopeParent(v), AssertionError.class);
    parentScope.isScope = true;
    parentScope.hasMembers = true;
    parentScope.getMembers = () -> new Members();
    parentScope.hasLanguage = true;
    parentScope.getLanguage = () -> ProxyLanguage.class;
    v.getScopeParent = () -> parentScope;
    assertTrue(l.isScope(v));
    assertTrue(l.hasScopeParent(v));
    assertEquals(parentScope, l.getScopeParent(v));
    v.isScope = false;
    assertFalse(l.isScope(v));
    assertFails(() -> l.hasScopeParent(v), AssertionError.class);
    assertFails(() -> l.getScopeParent(v), AssertionError.class);
    v.isScope = true;
    v.hasScopeParent = false;
    v.getScopeParent = () -> parentScope;
    assertFails(() -> l.hasScopeParent(v), AssertionError.class);
    assertFails(() -> l.getScopeParent(v), AssertionError.class);
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) Test(org.junit.Test)

Aggregations

InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)158 Test (org.junit.Test)76 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)60 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)51 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)18 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)18 ArityException (com.oracle.truffle.api.interop.ArityException)16 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)15 WasmInstance (org.graalvm.wasm.WasmInstance)15 WebAssembly (org.graalvm.wasm.api.WebAssembly)15 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)12 RootNode (com.oracle.truffle.api.nodes.RootNode)12 InteropException (com.oracle.truffle.api.interop.InteropException)11 InvalidArrayIndexException (com.oracle.truffle.api.interop.InvalidArrayIndexException)11 Dictionary (org.graalvm.wasm.api.Dictionary)8 SourceSection (com.oracle.truffle.api.source.SourceSection)6 CallTarget (com.oracle.truffle.api.CallTarget)5 Node (com.oracle.truffle.api.nodes.Node)5 ProxyObject (org.graalvm.polyglot.proxy.ProxyObject)5 WasmJsApiException (org.graalvm.wasm.exception.WasmJsApiException)5