diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2018-04-05 21:13:58 -0700 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2018-04-06 13:47:49 -0700 |
commit | f9e32d59ad17fe50a42c8efc60472a2ba88348e8 (patch) | |
tree | 054a8566064810c9f53f25ca4f39bd4e6dd55f95 /platform | |
parent | e32a0586f2097ad29496636453837f215612ad7b (diff) | |
download | qtlocation-mapboxgl-f9e32d59ad17fe50a42c8efc60472a2ba88348e8.tar.gz |
[ios, macos] Distinguish between conditionals and expressions in case expression
Diffstat (limited to 'platform')
-rw-r--r-- | platform/darwin/src/NSExpression+MGLAdditions.mm | 8 | ||||
-rw-r--r-- | platform/darwin/test/MGLExpressionTests.mm | 16 |
2 files changed, 19 insertions, 5 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index 17b130639f..58b9e2683b 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -662,9 +662,9 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { NSMutableArray *arguments = [NSMutableArray array]; for (NSUInteger index = 0; index < argumentObjects.count; index++) { - if ([argumentObjects[index] isKindOfClass:[NSArray class]]) { - NSPredicate *conditional = [NSPredicate mgl_predicateWithJSONObject:argumentObjects[index]]; - NSExpression *argument = [NSExpression expressionWithFormat:@"%@", conditional]; + if (index % 2 == 0 && index != argumentObjects.count - 1) { + NSPredicate *predicate = [NSPredicate mgl_predicateWithJSONObject:argumentObjects[index]]; + NSExpression *argument = [NSExpression expressionForConstantValue:predicate]; [arguments addObject:argument]; } else { [arguments addObject:[NSExpression mgl_expressionWithJSONObject:argumentObjects[index]]]; @@ -673,7 +673,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { if (@available(iOS 9.0, *)) { if (arguments.count == 3) { - NSPredicate *conditional = [NSPredicate mgl_predicateWithJSONObject:argumentObjects.firstObject]; + NSPredicate *conditional = [arguments.firstObject constantValue]; return [NSExpression expressionForConditional:conditional trueExpression:arguments[1] falseExpression:arguments[2]]; } } diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm index 35f97326c6..579d2505f2 100644 --- a/platform/darwin/test/MGLExpressionTests.mm +++ b/platform/darwin/test/MGLExpressionTests.mm @@ -743,7 +743,21 @@ using namespace std::string_literals; XCTAssertEqualObjects([NSExpression mgl_expressionWithJSONObject:jsonExpression], expression); XCTAssertEqualObjects([expression expressionValueWithObject:nil context:nil], @YES); } - + { + NSArray *jsonExpression = @[ + @"case", + @[ + @"<", + @[@"get", @"area"], + @80000 + ], + @[@"get", @"abbr"], + @[@"get", @"name_en"] + ]; + NSExpression *expression = [NSExpression expressionWithFormat:@"TERNARY(area < 80000, abbr, name_en)"]; + XCTAssertEqualObjects([NSExpression mgl_expressionWithJSONObject:jsonExpression], expression); + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + } } - (void)testLookupExpressionObject { |