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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations