[android] Minimal Android wrapper on 'format' expression
For converting to Java types, flatten 'text-field' back to a string.
This commit is contained in:
committed by
Łukasz Paczos
parent
fc2afc1d23
commit
78a1c30e80
@@ -13,8 +13,6 @@ import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.*;
|
||||
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
|
||||
@@ -479,18 +477,8 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
assertEquals((String) layer.getTextField().getValue(), (String) "");
|
||||
|
||||
layer.setProperties(textField("{token}"));
|
||||
JsonArray formatExpression = new JsonArray();
|
||||
formatExpression.add("format");
|
||||
JsonArray getExpression = new JsonArray();
|
||||
getExpression.add("get");
|
||||
getExpression.add("token");
|
||||
JsonArray stringCoercion = new JsonArray();
|
||||
stringCoercion.add("to-string");
|
||||
stringCoercion.add(getExpression);
|
||||
formatExpression.add(stringCoercion);
|
||||
formatExpression.add(new JsonObject());
|
||||
assertEquals(layer.getTextField().getExpression(),
|
||||
Converter.convert(formatExpression));
|
||||
Expression.format(Expression.toString(Expression.get("token"))));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -503,17 +491,7 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
JsonArray formatExpression = new JsonArray();
|
||||
formatExpression.add("format");
|
||||
JsonArray getExpression = new JsonArray();
|
||||
getExpression.add("get");
|
||||
getExpression.add("undefined");
|
||||
JsonArray stringAssertion = new JsonArray();
|
||||
stringAssertion.add("string");
|
||||
stringAssertion.add(getExpression);
|
||||
formatExpression.add(stringAssertion);
|
||||
formatExpression.add(new JsonObject());
|
||||
Expression expression = Converter.convert(formatExpression);
|
||||
Expression expression = Expression.format(string(Expression.get("undefined")));
|
||||
layer.setProperties(textField(expression));
|
||||
assertEquals(layer.getTextField().getExpression(), expression);
|
||||
});
|
||||
|
||||
@@ -17,10 +17,6 @@ import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
<% if (type === 'symbol') { -%>
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
<% } -%>
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.*;
|
||||
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
|
||||
@@ -170,18 +166,8 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest {
|
||||
|
||||
layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>("{token}"));
|
||||
<% if (property.type === 'formatted') { -%>
|
||||
JsonArray formatExpression = new JsonArray();
|
||||
formatExpression.add("format");
|
||||
JsonArray getExpression = new JsonArray();
|
||||
getExpression.add("get");
|
||||
getExpression.add("token");
|
||||
JsonArray stringCoercion = new JsonArray();
|
||||
stringCoercion.add("to-string");
|
||||
stringCoercion.add(getExpression);
|
||||
formatExpression.add(stringCoercion);
|
||||
formatExpression.add(new JsonObject());
|
||||
assertEquals(layer.getTextField().getExpression(),
|
||||
Converter.convert(formatExpression));
|
||||
assertEquals(layer.get<%- camelize(property.name) %>().getExpression(),
|
||||
Expression.format(Expression.toString(Expression.get("token"))));
|
||||
<% } else { -%>
|
||||
assertEquals(layer.get<%- camelize(property.name) %>().getExpression(), Expression.toString(Expression.get("token")));
|
||||
<% } -%>
|
||||
@@ -201,17 +187,7 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest {
|
||||
|
||||
// Set and Get
|
||||
<% if (property.type === 'formatted') { -%>
|
||||
JsonArray formatExpression = new JsonArray();
|
||||
formatExpression.add("format");
|
||||
JsonArray getExpression = new JsonArray();
|
||||
getExpression.add("get");
|
||||
getExpression.add("undefined");
|
||||
JsonArray stringAssertion = new JsonArray();
|
||||
stringAssertion.add("string");
|
||||
stringAssertion.add(getExpression);
|
||||
formatExpression.add(stringAssertion);
|
||||
formatExpression.add(new JsonObject());
|
||||
Expression expression = Converter.convert(formatExpression);
|
||||
Expression expression = Expression.format(<%- defaultExpressionJava(property) %>(Expression.get("undefined")));
|
||||
<% } else { -%>
|
||||
Expression expression = <%- defaultExpressionJava(property) %>(Expression.get("undefined"));
|
||||
<% } -%>
|
||||
|
||||
Reference in New Issue
Block a user