diff options
author | Fabian Guerra <fabian.guerra@mapbox.com> | 2018-04-26 11:40:39 -0400 |
---|---|---|
committer | Fabian Guerra <fabian.guerra@mapbox.com> | 2018-04-26 11:40:39 -0400 |
commit | 1572edfa75058466f833d7ed23aa375acc338cbe (patch) | |
tree | eba761896ac46a84b039a412afae2624f30d0d92 | |
parent | 8de14901c44db8d4ab9a2111f5721333c276c43f (diff) | |
download | qtlocation-mapboxgl-upstream/fabian-subscripting-11757.tar.gz |
[ios, macos] Refactor LAST subscripting expression.upstream/fabian-subscripting-11757
-rw-r--r-- | platform/darwin/src/NSExpression+MGLAdditions.mm | 3 | ||||
-rw-r--r-- | platform/darwin/test/MGLExpressionTests.mm | 2 |
2 files changed, 2 insertions, 3 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index d74e388b8e..3f41c08401 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -1107,8 +1107,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { index = [NSExpression expressionForConstantValue:@0].mgl_jsonExpressionObject; } else if ([value isEqualToString:@"LAST"]) { NSExpression *count = [NSExpression expressionWithFormat:@"count(%@) - 1", self.arguments[0]]; - id last = [count expressionValueWithObject:nil context:nil]; - index = [NSExpression expressionForConstantValue:last].mgl_jsonExpressionObject; + index = count.mgl_jsonExpressionObject; } else if ([value isEqualToString:@"SIZE"]) { return [NSExpression expressionWithFormat:@"count(%@)", self.arguments[0]].mgl_jsonExpressionObject; } diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm index 31ed806c41..c6c85bdc58 100644 --- a/platform/darwin/test/MGLExpressionTests.mm +++ b/platform/darwin/test/MGLExpressionTests.mm @@ -842,7 +842,7 @@ using namespace std::string_literals; MGLConstantExpression(@7)]]; NSExpression *expression = [NSExpression expressionForFunction:@"objectFrom:withIndex:" arguments:@[array, MGLConstantExpression(@"LAST")]]; - NSArray *jsonExpression = @[@"at", @2, @[ @"literal", @[@9, @8, @7]]]; + NSArray *jsonExpression = @[@"at", @[@"-", @[@"length", @[ @"literal", @[@9, @8, @7]]], @1], @[ @"literal", @[@9, @8, @7]]]; XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); } { |