summaryrefslogtreecommitdiff
path: root/platform/darwin/test/MGLExpressionTests.mm
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2018-10-25 04:32:45 -0700
committerMinh Nguyễn <mxn@1ec5.org>2018-10-27 23:01:52 -0700
commit5a3089aaeecf124302c4b82bfde9348fcaf0fd43 (patch)
tree908f58c309c8f2af6f938afd8c2ae1d439cdb430 /platform/darwin/test/MGLExpressionTests.mm
parentaa329d061187a93c9f6cee608082fbf045b819b6 (diff)
downloadqtlocation-mapboxgl-upstream/1ec5-e8n-vararg-colon-13026.tar.gz
[ios, macos] Fixed crash on nullary vararg expression functionupstream/1ec5-e8n-vararg-colon-13026
Equate the nullary and unary forms of vararg-style aftermarket expression functions when converting to JSON objects.
Diffstat (limited to 'platform/darwin/test/MGLExpressionTests.mm')
-rw-r--r--platform/darwin/test/MGLExpressionTests.mm38
1 files changed, 37 insertions, 1 deletions
diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm
index 6cb7bfdc3d..1b0630cef3 100644
--- a/platform/darwin/test/MGLExpressionTests.mm
+++ b/platform/darwin/test/MGLExpressionTests.mm
@@ -988,9 +988,45 @@ using namespace std::string_literals;
NSArray *jsonExpression = @[@"random", @1, @2, @3, @4, @5];
XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression);
- expression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('random', 1, 2, 3, 4)"];
+ }
+ {
+ NSExpression *expression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('random', 1, 2, 3, 4)"];
XCTAssertThrowsSpecificNamed([expression expressionValueWithObject:nil context:nil], NSException, NSInvalidArgumentException);
}
+ {
+ NSArray *arguments = @[
+ MGLConstantExpression(@"one"), MGLConstantExpression(@1),
+ [NSExpression expressionForVariable:@"one"],
+ ];
+ NSExpression *nullaryExpression = [NSExpression expressionForFunction:@"MGL_LET" arguments:arguments];
+ NSExpression *unaryExpression = [NSExpression expressionForFunction:@"MGL_LET:" arguments:arguments];
+ XCTAssertEqualObjects(nullaryExpression.mgl_jsonExpressionObject, unaryExpression.mgl_jsonExpressionObject);
+ }
+ {
+ NSArray *arguments = @[
+ [NSExpression expressionForVariable:@"x"],
+ MGLConstantExpression(@YES), MGLConstantExpression(@"yes"),
+ MGLConstantExpression(@NO), MGLConstantExpression(@"no"),
+ ];
+ NSExpression *nullaryExpression = [NSExpression expressionForFunction:@"MGL_MATCH" arguments:arguments];
+ NSExpression *unaryExpression = [NSExpression expressionForFunction:@"MGL_MATCH:" arguments:arguments];
+ XCTAssertEqualObjects(nullaryExpression.mgl_jsonExpressionObject, unaryExpression.mgl_jsonExpressionObject);
+ }
+ {
+ NSArray *arguments = @[
+ [NSPredicate predicateWithValue:YES],
+ MGLConstantExpression(@"yes"), MGLConstantExpression(@"no"),
+ ];
+ NSExpression *nullaryExpression = [NSExpression expressionForFunction:@"MGL_IF" arguments:arguments];
+ NSExpression *unaryExpression = [NSExpression expressionForFunction:@"MGL_IF:" arguments:arguments];
+ XCTAssertEqualObjects(nullaryExpression.mgl_jsonExpressionObject, unaryExpression.mgl_jsonExpressionObject);
+ }
+ {
+ NSArray *arguments = @[MGLConstantExpression(@"zoom")];
+ NSExpression *nullaryExpression = [NSExpression expressionForFunction:@"MGL_FUNCTION" arguments:arguments];
+ NSExpression *unaryExpression = [NSExpression expressionForFunction:@"MGL_FUNCTION:" arguments:arguments];
+ XCTAssertEqualObjects(nullaryExpression.mgl_jsonExpressionObject, unaryExpression.mgl_jsonExpressionObject);
+ }
}
#pragma mark - Localization tests