use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class InteropAssertionsTest method testRemoveHashEntry.
@Test
public void testRemoveHashEntry() throws UnsupportedMessageException, UnknownKeyException {
// we need no multi threaded context.
setupEnv(Context.create());
HashTest hashTest = new HashTest();
InteropLibrary hashLib = createLibrary(InteropLibrary.class, hashTest);
hashTest.writeHashEntry(1, -1);
hashLib.removeHashEntry(hashTest, 1);
assertFails(() -> {
hashLib.removeHashEntry(hashTest, null);
return null;
}, NullPointerException.class);
hashTest.writeHashEntry(1, -1);
hashTest.hasHashEntries = false;
assertFails(() -> {
hashLib.removeHashEntry(hashTest, 1);
return null;
}, AssertionError.class);
hashTest.writeHashEntry(1, -1);
hashTest.hasHashEntries = true;
hashTest.removeable = (k) -> false;
assertFails(() -> {
hashLib.removeHashEntry(hashTest, 1);
return null;
}, AssertionError.class);
hashTest.writeHashEntry(1, -1);
hashTest.hasHashEntries = true;
hashTest.removeable = (k) -> true;
hashTest.data = null;
assertFails(() -> {
hashLib.removeHashEntry(hashTest, 1);
return null;
}, AssertionError.class);
}
use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class InteropAssertionsTest method testIsHashEntryReadable.
@Test
public void testIsHashEntryReadable() {
HashTest hashTest = new HashTest();
InteropLibrary hashLib = createLibrary(InteropLibrary.class, hashTest);
assertFalse(hashLib.isHashEntryReadable(hashTest, 1));
hashTest.hasHashEntries = false;
hashTest.readable = (k) -> true;
assertFails(() -> hashLib.isHashEntryReadable(hashTest, 1), AssertionError.class);
hashTest.hasHashEntries = true;
hashTest.readable = (k) -> true;
hashTest.insertable = (k) -> true;
assertFails(() -> hashLib.isHashEntryReadable(hashTest, 1), AssertionError.class);
}
use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class InteropAssertionsTest method testIsHashEntryWritable.
@Test
public void testIsHashEntryWritable() {
HashTest hashTest = new HashTest();
InteropLibrary hashLib = createLibrary(InteropLibrary.class, hashTest);
assertTrue(hashLib.isHashEntryWritable(hashTest, 1));
hashTest.insertable = (k) -> false;
hashTest.modifiable = (k) -> false;
assertFalse(hashLib.isHashEntryWritable(hashTest, 1));
hashTest.writable = (k) -> true;
assertFails(() -> hashLib.isHashEntryWritable(hashTest, 1), AssertionError.class);
}
use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class InteropAssertionsTest method hasIteratorNextElement.
@Test
public void hasIteratorNextElement() throws UnsupportedMessageException {
IteratorTest iteratorTest = new IteratorTest(1);
InteropLibrary iteratorLib = createLibrary(InteropLibrary.class, iteratorTest);
assertEquals(true, iteratorLib.hasIteratorNextElement(iteratorTest));
iteratorTest.isIterator = false;
assertFails(() -> iteratorLib.hasIteratorNextElement(iteratorTest), AssertionError.class);
iteratorTest.isIterator = true;
iteratorTest.hasNext = null;
assertFails(() -> iteratorLib.hasIteratorNextElement(iteratorTest), AssertionError.class);
}
use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class InteropDateTimeTest method testDefaults.
@Test
public void testDefaults() {
Defaults o = new Defaults();
InteropLibrary library = createLibrary(InteropLibrary.class, o);
assertFalse(library.isDate(o));
assertFalse(library.isTime(o));
assertFalse(library.isTimeZone(o));
assertFalse(library.isDuration(o));
assertFails(() -> library.asInstant(o), UnsupportedMessageException.class);
assertFails(() -> library.asDate(o), UnsupportedMessageException.class);
assertFails(() -> library.asTime(o), UnsupportedMessageException.class);
assertFails(() -> library.asTimeZone(o), UnsupportedMessageException.class);
assertFails(() -> library.asDuration(o), UnsupportedMessageException.class);
}
Aggregations