Skip to content

Commit

Permalink
Check the lazy behavior for ProxyArray
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Sep 7, 2022
1 parent 8336c8e commit 981829c
Showing 1 changed file with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.graalvm.polyglot.Engine;
import org.graalvm.polyglot.Language;
import org.graalvm.polyglot.Source;
import org.graalvm.polyglot.Value;
import org.graalvm.polyglot.proxy.ProxyArray;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -137,18 +139,47 @@ public int size() {
};
}

public static ProxyArray lazyProxy() {
return new ProxyArray() {
@Override
public Object get(long index) {
QUERIED.set((int) index);
return "at" + index;
}

@Override
public void set(long index, Value value) {
throw new UnsupportedOperationException();
}

@Override
public long getSize() {
return 10;
}
};
}

@Test
public void noCopyLazyJavaList() throws Exception {
noCopyTest("lazyList");
}

@Test
public void noCopyLazyProxyArray() throws Exception {
noCopyTest("lazyProxy");
}

private void noCopyTest(String factoryName) throws Exception {
final URI uri = new URI("memory://how_long.enso");
final Source src = Source.newBuilder("enso", """
import Standard.Base.Data.Vector
polyglot java import org.enso.interpreter.test.VectorTest
raw = VectorTest.lazyList
copy = Vector.from_array VectorTest.lazyList
lazy = Vector.from_polyglot_array VectorTest.lazyList
raw = VectorTest.${call}
copy = Vector.from_array VectorTest.${call}
lazy = Vector.from_polyglot_array VectorTest.${call}
""", "how_long.enso")
""".replace("${call}", factoryName), "vectors.enso")
.uri(uri)
.buildLiteral();

Expand Down

0 comments on commit 981829c

Please sign in to comment.