Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
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 @@ -46,7 +46,7 @@ public boolean isNull() {
* @return true if this is a expression, false if not
*/
public boolean isExpression() {
return !isNull() && value instanceof JsonArray;
return !isNull() && (value instanceof JsonArray || value instanceof Expression);
}

/**
Expand All @@ -57,7 +57,9 @@ public boolean isExpression() {
@Nullable
public Expression getExpression() {
if (isExpression()) {
return Expression.Converter.convert((JsonArray) value);
return value instanceof JsonArray
? Expression.Converter.convert((JsonArray) value)
: (Expression) value;
} else {
Logger.w(TAG, "not a expression, try value");
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.mapbox.mapboxsdk.style.layers.PropertyFactory;

import com.mapbox.mapboxsdk.style.layers.PropertyValue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
Expand Down Expand Up @@ -87,6 +88,7 @@
import static com.mapbox.mapboxsdk.style.expressions.Expression.var;
import static com.mapbox.mapboxsdk.style.expressions.Expression.zoom;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineOpacity;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineWidth;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;

Expand All @@ -96,6 +98,18 @@
@RunWith(RobolectricTestRunner.class)
public class ExpressionTest {

@Test
public void testPropertyValueIsExpression() {
PropertyValue<?> property = lineWidth(Expression.get("width"));
assertTrue(property.isExpression());
}

@Test
public void testPropertyValueEqualsExpression() {
PropertyValue<?> property = lineWidth(Expression.get("width"));
assertEquals(Expression.get("width"), property.getExpression());
}

@Test
public void testRgb() throws Exception {
Object[] expected = new Object[] {"rgb", 0f, 0f, 0f};
Expand Down