Skip to content

Commit

Permalink
Fix raw expression parsing for list literal. (#1629) (#1632)
Browse files Browse the repository at this point in the history
* Fix raw expression parsing for list literal. (#1629)

* Update CHANGELOG.md
  • Loading branch information
pengdev committed Apr 17, 2023
1 parent 8cf3052 commit 9a297ca
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@ Mapbox welcomes participation and contributions from everyone.

## Bug fixes 🐞
* Fix 3d location layer properties `model-scale-transition` and `model-rotation-transition`, made them non-transitionable.
* Fix raw expression parsing for list literal.


# 10.13.0-beta.1 April 05, 2023
Expand Down
Expand Up @@ -1874,6 +1874,23 @@ class ExpressionTest : BaseStyleTest() {
assertEquals(expression.toString(), layer.textColorAsExpression.toString())
}

/**
* Test constructing an match Expression from raw string.
*/
@Test
@UiThreadTest
fun rawMatchExpressionTest() {
val expressionString = """
["match",["get","data_property"],[0,1],true,false]
""".trimIndent()
val expression = Expression.fromRaw(expressionString)
val layer = symbolLayer("id", "source") {
filter(expression)
}
setupLayer(layer)
assertEquals(expressionString, layer.filter!!.toJson())
}

/**
* Returns the shortest distance in meters between the evaluated feature and the input geometry. The input value can be a valid GeoJSON of type Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon, Feature, or FeatureCollection. Distance values returned may vary in precision due to loss in precision from encoding geometries, particularly below zoom level 13.
*/
Expand Down
Expand Up @@ -232,7 +232,7 @@ fun Value.unwrapToExpression(): Expression {
is List<*> -> {
@Suppress("UNCHECKED_CAST")
val listValue = input as List<Value>
val operator = listValue.first().contents as String
val operator = listValue.first().contents as? String ?: return Expression(input)
if ("literal" == operator) {
when (val literalValue = listValue.last().contents) {
is List<*> -> {
Expand Down
Expand Up @@ -632,5 +632,15 @@ class TypeUtilsTest {
assertEquals(Value.valueOf(featureString), actual)
}

@Test
fun unwrapRawExpression() {
val expressionString = """
["match",["get","data_property"],[0],true,false]
""".trimIndent()
val value = Value.fromJson(expressionString)
val expression = value.value!!.unwrapToExpression()
assertEquals(expressionString, expression.toJson())
}

internal data class MockData(val a: Int, val b: String)
}

0 comments on commit 9a297ca

Please sign in to comment.