Skip to content

Commit

Permalink
2nd multi value argument conversions do not work
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Dec 20, 2024
1 parent c17a45f commit d30da41
Showing 1 changed file with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public void multiValueToInteger() throws Exception {
conv style v = case style of
0 -> v.to Integer
1 -> v:Integer
2 -> v.to Text
3 -> v:Text
99 -> eq
""";
Expand All @@ -74,4 +72,46 @@ public void multiValueToInteger() throws Exception {
});
assertTrue("Any.to and : give the same result", eq.asBoolean());
}

@Test
public void multiValueToText() throws Exception {
multiValueToText(2);
}

@Test
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());
}
}

0 comments on commit d30da41

Please sign in to comment.