Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Expression#toString() #11024

Merged
merged 1 commit into from
Jan 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1758,4 +1758,22 @@ private static Expression[] join(Expression[] left, Expression[] right) {
return output;
}


@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("[\"").append(operator).append("\"");
if (arguments != null) {
for (Expression argument : arguments) {
builder.append(", ");
if (argument instanceof ExpressionLiteral) {
builder.append(((ExpressionLiteral) argument).toValue());
} else {
builder.append(argument.toString());
}
}
}
builder.append("]");
return builder.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import static com.mapbox.mapboxsdk.style.expressions.Expression.var;
import static com.mapbox.mapboxsdk.style.expressions.Expression.zoom;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;

/**
* Expression unit tests that validate the expression output with the expected Object[]array representation.
Expand Down Expand Up @@ -1007,4 +1008,26 @@ public void testCubicBezierExpressionLiteral() throws Exception {
literal(1)), get("x"), stop(0, 100), stop(100, 200)).toArray();
assertTrue("expression should match", Arrays.deepEquals(expected, actual));
}

@Test
public void testExpressionConcatToString() throws Exception {
String expected = "[\"concat\", foo, bar]";
String actual = concat(literal("foo"), literal("bar")).toString();
assertEquals("toString should match", expected, actual);
}

@Test
public void testExpressionMinToString() throws Exception {
String expected = "[\"min\", 0, 1, 2, 3]";
String actual = min(0, 1, 2, 3).toString();
assertEquals("toString should match", expected, actual);
}

@Test
public void testExpressionExponentialToString() throws Exception {
String expected = "[\"interpolate\", [\"cubic-bezier\", 1, 1, 1, 1], [\"get\", x], 0, 100, 100, 200]";
String actual = interpolate(cubicBezier(literal(1), literal(1), literal(1), literal(1)),
get(literal("x")), literal(0), literal(100), literal(100), literal(200)).toString();
assertEquals("toString should match", expected, actual);
}
}