Skip to content

Commit

Permalink
Fix raw expression parsing for list literal. (#1629)
Browse files Browse the repository at this point in the history
  • Loading branch information
pengdev authored Apr 17, 2023
1 parent 1bf7520 commit 77c34cb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ Mapbox welcomes participation and contributions from everyone.
| androidx.compose:compose-bom | | 2023.01.00 |
| com.pinterest:ktlint | 0.39.0 | 0.48.2 |

## Bug fixes 🐞
* Fix raw expression parsing for list literal.

# 10.12.0
## Bug fixes 🐞
* Fix regression from `v10.11.0` when applying geojson from loaded style to the new style could cause the crash or no data applied.
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 77c34cb

Please sign in to comment.