diff options
author | Fabian Guerra <fabian.guerra@mapbox.com> | 2019-03-19 17:32:14 -0700 |
---|---|---|
committer | Fabian Guerra <fabian.guerra@mapbox.com> | 2019-03-19 17:32:14 -0700 |
commit | 68da494313f681d68e1130d1a3190986ae14d11a (patch) | |
tree | e8bb60b35a1dec12030df9bd212cc13b4cdcdaed | |
parent | 174c8fa7e4927ebf28a3d0e07c995d3e3d69de76 (diff) | |
download | qtlocation-mapboxgl-upstream/fabian-fix-format-exp-parser.tar.gz |
[ios, macos] Fix format expression parsing.upstream/fabian-fix-format-exp-parser
-rw-r--r-- | platform/darwin/src/NSExpression+MGLAdditions.mm | 8 | ||||
-rw-r--r-- | platform/darwin/test/MGLExpressionTests.mm | 23 |
2 files changed, 25 insertions, 6 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index f0f1d62ef7..22a91cda3c 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -1016,12 +1016,8 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { if ([constantValue isKindOfClass:[MGLAttributedExpression class]]) { MGLAttributedExpression *attributedExpression = (MGLAttributedExpression *)constantValue; id jsonObject = attributedExpression.expression.mgl_jsonExpressionObject; - NSMutableArray *attributes = [NSMutableArray array]; - if ([jsonObject isKindOfClass:[NSArray class]]) { - [attributes addObjectsFromArray:jsonObject]; - } else { - [attributes addObject:jsonObject]; - } + NSMutableArray *attributes = [NSMutableArray arrayWithObjects:jsonObject, nil]; + if (attributedExpression.attributes) { NSMutableDictionary *attributedDictionary = [NSMutableDictionary dictionaryWithDictionary:attributedExpression.attributes]; if (attributedDictionary[MGLFontNamesAttribute]) { diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm index 8e99ed596e..b13daa2f6b 100644 --- a/platform/darwin/test/MGLExpressionTests.mm +++ b/platform/darwin/test/MGLExpressionTests.mm @@ -1087,6 +1087,18 @@ using namespace std::string_literals; XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); } { + MGLAttributedExpression *attribute1 = [[MGLAttributedExpression alloc] initWithExpression:[NSExpression expressionWithFormat:@"CAST(x, 'NSString')"] + attributes:@{ MGLFontSizeAttribute: @(1.2), + MGLFontColorAttribute: [MGLColor redColor], + MGLFontNamesAttribute: @[ @"DIN Offc Pro Bold", @"Arial Unicode MS Bold" ] + }] ; + NSExpression *expression = [NSExpression expressionWithFormat:@"mgl_attributed:(%@)", MGLConstantExpression(attribute1)]; + + NSArray *jsonExpression = @[ @"format", @[@"to-string", @[@"get", @"x"]], @{ @"font-scale": @1.2, @"text-color": @[@"rgb", @255, @0, @0] , @"text-font" : @[ @"literal", @[ @"DIN Offc Pro Bold", @"Arial Unicode MS Bold" ]]} ]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); + } + { MGLAttributedExpression *attribute1 = [MGLAttributedExpression attributedExpression:[NSExpression expressionForConstantValue:@"foo"] fontNames:nil fontSize:@(1.2)]; @@ -1267,6 +1279,17 @@ using namespace std::string_literals; - (void)testConvenienceInitializers { { + NSExpression *hasPriceImageExpression = [NSExpression mgl_expressionForConditional:[NSPredicate predicateWithFormat:@"$featureIdentifier = 9800"] + trueExpression:[NSExpression expressionForConstantValue:@"1234"] + falseExpresssion:[NSExpression expressionForConstantValue:@"4567"]]; + NSExpression *imageExpression = [NSExpression mgl_expressionForConditional:[NSPredicate predicateWithFormat:@"$featureIdentifier = 9800"] + trueExpression:[NSExpression expressionForConstantValue:@"8900"] + falseExpresssion:[NSExpression expressionForConstantValue:@"1122"]]; + NSExpression *pinExpression = [NSExpression mgl_expressionForConditional:[NSPredicate predicateWithFormat:@"price = nil"] + trueExpression:imageExpression + falseExpresssion:hasPriceImageExpression]; + + NSArray *jsonExp = pinExpression.mgl_jsonExpressionObject; NSExpression *expression = [NSExpression mgl_expressionForConditional:[NSPredicate predicateWithFormat:@"1 = 2"] trueExpression:MGLConstantExpression(@YES) falseExpresssion:MGLConstantExpression(@NO)]; |