Skip to content

Commit

Permalink
More testa for chained operator syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Dec 1, 2023
1 parent fee11f7 commit 248075e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,16 @@ private Expression translateCall(Tree ast, boolean isMethod) {
if (self == null || !invoke) {
return null;
}
var expr = translateExpression(l.getExpression().getExpression(), true);
if (expr instanceof Application.Prefix pref) {
var arg = new CallArgument.Specified(Option.empty(), self, self.location(), meta(), diag());
expr = new Application.Prefix(pref.function(), join(arg, pref.arguments()), false, expr.location(), meta(), diag());
}
var expr = switch (translateExpression(l.getExpression().getExpression(), true)) {
case Application.Prefix pref -> {
var arg = new CallArgument.Specified(Option.empty(), self, self.location(), meta(), diag());
yield new Application.Prefix(pref.function(), join(arg, pref.arguments()), false, pref.location(), meta(), diag());
}
case Expression any -> {
var arg = new CallArgument.Specified(Option.empty(), self, self.location(), meta(), diag());
yield new Application.Prefix(any, join(arg, nil()), false, any.location(), meta(), diag());
}
};
var loc = getIdentifiedLocation(l.getExpression().getExpression());
args.add(at, new CallArgument.Specified(Option.empty(), expr, loc, meta(), diag()));
self = expr;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package org.enso.compiler.core;

import com.oracle.truffle.api.source.Source;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.List;
import java.util.function.Function;

import org.enso.compiler.core.ir.Module;
import org.junit.AfterClass;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.junit.BeforeClass;
import org.junit.Test;

Expand Down Expand Up @@ -1280,6 +1279,28 @@ public void testBlockSyntaxOperators2() throws Exception {
""");
}

@Test
public void testBlockSyntaxOperators3() throws Exception {
equivalenceTest("""
v = (rect1 . width) . center
""", """
v = rect1
. width
. center
""");
}

@Test
public void testBlockSyntaxOperators4() throws Exception {
equivalenceTest("""
v = (rect1 . width 4) . center 3 2
""", """
v = rect1
. width 4
. center 3 2
""");
}

@Test
public void testPrivateModules() throws Exception {
List<String> moduleCodes = List.of(
Expand Down Expand Up @@ -1338,8 +1359,7 @@ private static Module compile(String code) {
}

public static Module compile(EnsoParser c, String code) {
var src = Source.newBuilder("enso", code, "test-" + Integer.toHexString(code.hashCode()) + ".enso").build();
var ir = c.compile(src.getCharacters());
var ir = c.compile(code);
assertNotNull("IR was generated", ir);
return ir;
}
Expand Down

0 comments on commit 248075e

Please sign in to comment.