diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2018-01-24 13:36:50 +0100 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2018-01-25 10:21:14 +0100 |
commit | 5dbc20dc75e7cf4f06602aa9e3a3eae55d2aa34a (patch) | |
tree | 4b2da569d13db5f6dbda2d8e994c61a3e8f1f948 | |
parent | 37e47e2f10e4c04d48e62665dd70c092dee4762a (diff) | |
download | qtlocation-mapboxgl-5dbc20dc75e7cf4f06602aa9e3a3eae55d2aa34a.tar.gz |
[android] - add toString to Expression to print out object array notation
2 files changed, 41 insertions, 0 deletions
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<T> { 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 |