-
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.
Symetric, transitive and reflexive equality for intersection types (#…
- Loading branch information
1 parent
d87484b
commit e8f781a
Showing
14 changed files
with
390 additions
and
74 deletions.
There are no files selected for viewing
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
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
120 changes: 120 additions & 0 deletions
120
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,120 @@ | ||
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.Ignore; | ||
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 | ||
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()); | ||
} | ||
|
||
@Test | ||
@Ignore | ||
public void multiValueToText() throws Exception { | ||
multiValueToText(2); | ||
} | ||
|
||
@Test | ||
@Ignore | ||
public void multiValueToTextHidden() throws Exception { | ||
multiValueToText(1); | ||
} | ||
|
||
private void multiValueToText(int dispatchLength) 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:Integer v = case style of | ||
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, dispatchLength, new Object[] {2L, Text.create("Two")}); | ||
var eq = | ||
ContextUtils.executeInContext( | ||
ctx, | ||
() -> { | ||
var bothValue = ctx.asValue(both); | ||
var asIntegerCast = conv.execute(3, bothValue); | ||
var asIntegerTo = conv.execute(2, 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
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
Oops, something went wrong.