-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24b40ce
commit db5353b
Showing
3 changed files
with
93 additions
and
9 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/AnyToTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package org.enso.interpreter.test; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import org.enso.interpreter.runtime.data.EnsoMultiValue; | ||
import org.enso.interpreter.runtime.data.Type; | ||
import org.enso.interpreter.runtime.data.text.Text; | ||
import org.enso.test.utils.ContextUtils; | ||
import org.graalvm.polyglot.Context; | ||
import org.graalvm.polyglot.Source; | ||
import org.junit.AfterClass; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class AnyToTest { | ||
private static Context ctx; | ||
|
||
private static final ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
|
||
@BeforeClass | ||
public static void initCtx() { | ||
ctx = ContextUtils.createDefaultContext(out); | ||
} | ||
|
||
@AfterClass | ||
public static void disposeCtx() { | ||
ctx.close(); | ||
ctx = null; | ||
} | ||
|
||
@Before | ||
public void resetOutput() { | ||
out.reset(); | ||
} | ||
|
||
private String getStdOut() { | ||
return out.toString(StandardCharsets.UTF_8); | ||
} | ||
|
||
@Test | ||
public void multiValueToInteger() throws Exception { | ||
var ensoCtx = ContextUtils.leakContext(ctx); | ||
var types = | ||
new Type[] {ensoCtx.getBuiltins().number().getInteger(), ensoCtx.getBuiltins().text()}; | ||
var code = | ||
""" | ||
from Standard.Base import all | ||
private eq a b = a == b | ||
conv style v = case style of | ||
0 -> v.to Integer | ||
1 -> v:Integer | ||
2 -> v.to Text | ||
3 -> v:Text | ||
99 -> eq | ||
"""; | ||
var conv = | ||
ContextUtils.evalModule(ctx, Source.newBuilder("enso", code, "conv.enso").build(), "conv"); | ||
var both = EnsoMultiValue.create(types, types.length, new Object[] {2L, Text.create("Two")}); | ||
var eq = | ||
ContextUtils.executeInContext( | ||
ctx, | ||
() -> { | ||
var bothValue = ctx.asValue(both); | ||
var asIntegerTo = conv.execute(0, bothValue); | ||
var asIntegerCast = conv.execute(1, bothValue); | ||
var equals = conv.execute(99, null); | ||
return equals.execute(asIntegerTo, asIntegerCast); | ||
}); | ||
assertTrue("Any.to and : give the same result", eq.asBoolean()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters