summaryrefslogtreecommitdiff
path: root/platform/darwin
diff options
context:
space:
mode:
authorFabian Guerra Soto <fabian.guerra@mapbox.com>2019-03-07 19:28:20 -0800
committerGitHub <noreply@github.com>2019-03-07 19:28:20 -0800
commit79f3307c4be67ee1f9be1e90e4d5d2031e27ab8e (patch)
tree192396b53664ca8b983453e1ced4ce36582d0904 /platform/darwin
parentd0ffaa4245802c2081f899eaed80b730558c9227 (diff)
downloadqtlocation-mapboxgl-79f3307c4be67ee1f9be1e90e4d5d2031e27ab8e.tar.gz
[ios, macos] Fix a bug with multiple format expressions. (#14064)
Fixed a bug where `format` expressions using the generic `MGL_FUNCTION` binding ignored multiple formatting parameters.
Diffstat (limited to 'platform/darwin')
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm14
-rw-r--r--platform/darwin/test/MGLExpressionTests.mm17
2 files changed, 30 insertions, 1 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index 527cb64b3d..6aaba4dd90 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -1126,7 +1126,19 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
if (firstOp.expressionType == NSConstantValueExpressionType
&& [firstOp.constantValue isEqualToString:@"format"]) {
// Avoid wrapping format options object in literal expression.
- return @[@"format", self.arguments[1].mgl_jsonExpressionObject, self.arguments[2].constantValue];
+ NSMutableArray *expressionObject = [NSMutableArray array];
+ [expressionObject addObject:@"format"];
+
+ for (NSUInteger index = 1; index < self.arguments.count; index++) {
+ if (index % 2 == 1) {
+ [expressionObject addObject:self.arguments[index].mgl_jsonExpressionObject];
+ } else {
+ [expressionObject addObject:self.arguments[index].constantValue];
+ }
+
+ }
+
+ return expressionObject;
}
return self.arguments.mgl_jsonExpressionObject;
} else if (op == [MGLColor class] && [function isEqualToString:@"colorWithRed:green:blue:alpha:"]) {
diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm
index f869275dd3..bcc30e49fd 100644
--- a/platform/darwin/test/MGLExpressionTests.mm
+++ b/platform/darwin/test/MGLExpressionTests.mm
@@ -1002,6 +1002,23 @@ using namespace std::string_literals;
XCTAssertThrowsSpecificNamed([expression expressionValueWithObject:nil context:nil], NSException, NSInvalidArgumentException);
}
{
+ NSExpression *expression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('format', 'foo', %@, '\r', %@, 'biz', %@, 'bar', %@)", @{@"font-scale": @1.2}, @{}, @{@"font-scale": @1.0}, @{@"font-scale": @0.8}];
+ NSArray *jsonExpression = @[@"format", @"foo", @{@"font-scale": @1.2}, @"\r", @{}, @"biz", @{@"font-scale": @1.0}, @"bar", @{@"font-scale": @0.8}];
+
+ XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
+
+ NSExpression *encodedExpression = [NSExpression expressionWithMGLJSONObject:jsonExpression];
+
+ // Expressions encoded from a json create a different constant abstract type
+ // thus even tho knowing that the constant values are the same, the base
+ // class is not. This compares the resulting array which is type agnostic encoding.
+ for (NSUInteger index = 0; index < jsonExpression.count; index++) {
+ NSExpression *left = encodedExpression.mgl_jsonExpressionObject[index];
+ NSExpression *right = expression.mgl_jsonExpressionObject[index];
+ XCTAssertEqualObjects(left.mgl_jsonExpressionObject, right.mgl_jsonExpressionObject);
+ }
+ }
+ {
NSArray *arguments = @[
MGLConstantExpression(@"one"), MGLConstantExpression(@1),
[NSExpression expressionForVariable:@"one"],