From 5dbc20dc75e7cf4f06602aa9e3a3eae55d2aa34a Mon Sep 17 00:00:00 2001 From: Tobrun Date: Wed, 24 Jan 2018 13:36:50 +0100 Subject: [android] - add toString to Expression to print out object array notation --- .../mapboxsdk/style/expressions/Expression.java | 18 +++++++++++++++++ .../style/expressions/ExpressionTest.java | 23 ++++++++++++++++++++++ 2 files changed, 41 insertions(+) (limited to 'platform/android/MapboxGLAndroidSDK/src') diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java index a96b17b8ac..7b841a2580 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java @@ -1776,4 +1776,22 @@ public class Expression { 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(); + } } \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java index eb1ce8bfaa..c0b7832727 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java @@ -76,6 +76,7 @@ import static com.mapbox.mapboxsdk.style.expressions.Expression.upcase; 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. @@ -1007,4 +1008,26 @@ public class ExpressionTest { 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); + } } \ No newline at end of file -- cgit v1.2.1