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

Commit

Permalink
[android] - add toString to Expression to print out object array nota…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
tobrun committed Jan 25, 2018
1 parent 37e47e2 commit 5dbc20d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1776,4 +1776,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);
}
}

0 comments on commit 5dbc20d

Please sign in to comment.