summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2018-03-27 13:23:44 -0400
committerFabian Guerra <fabian.guerra@mapbox.com>2018-03-28 19:40:08 -0400
commitd84eede5729cef5778370072c1f3023ca29df90d (patch)
treef3e68b1a1a2015756d8a3e4b6becb9424a24dfe0
parent3b79fc9b4b6adbd4a18b51f2ffab21029e723d66 (diff)
downloadqtlocation-mapboxgl-d84eede5729cef5778370072c1f3023ca29df90d.tar.gz
[ios, macos] Add MGL_MATCH function placeholder.
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm22
-rw-r--r--platform/darwin/test/MGLExpressionTests.mm4
2 files changed, 16 insertions, 10 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index ef35c52e2c..776aed642b 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -65,6 +65,7 @@
// numbers of arguments. Vararg aftermarket functions need to be declared
// with an explicit and implicit first argument.
INSTALL_CONTROL_STRUCTURE(MGL_LET);
+ INSTALL_CONTROL_STRUCTURE(MGL_MATCH);
INSTALL_CONTROL_STRUCTURE(MGL_FUNCTION);
#undef INSTALL_AFTERMARKET_FN
@@ -108,6 +109,15 @@
}
/**
+ A placeholder for a method that evaluates an expression and returns the matching element.
+ */
+- (id)MGL_MATCH:(id)firstCondition, ... {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Assignment expressions lack underlying Objective-C implementations."];
+ return nil;
+}
+
+/**
A placeholder for a catch-all method that evaluates an arbitrary number of
arguments as an expression according to the Mapbox Style Specification’s
expression language.
@@ -616,18 +626,14 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
return [NSExpression expressionForFunction:firstConditional selectorName:@"mgl_case:" arguments:arguments];
} else if ([op isEqualToString:@"match"]) {
- NSExpression *operand = [NSExpression mgl_expressionWithJSONObject:argumentObjects[0]];
- NSArray *matchOptions = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)];
-
NSMutableArray *optionsArray = [NSMutableArray array];
- NSEnumerator *optionsEnumerator = matchOptions.objectEnumerator;
+ NSEnumerator *optionsEnumerator = argumentObjects.objectEnumerator;
while (id object = optionsEnumerator.nextObject) {
NSExpression *option = [NSExpression mgl_expressionWithJSONObject:object];
[optionsArray addObject:option];
}
- return [NSExpression expressionForFunction:operand
- selectorName:@"mgl_match:"
+ return [NSExpression expressionForFunction:@"MGL_MATCH"
arguments:optionsArray];
} else if ([op isEqualToString:@"coalesce"]) {
NSMutableArray *expressions = [NSMutableArray array];
@@ -837,8 +843,8 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
}
return expressionObject;
- } else if ([function isEqualToString:@"mgl_match:"]) {
- NSMutableArray *expressionObject = [NSMutableArray arrayWithObjects:@"match", self.operand.mgl_jsonExpressionObject, nil];
+ } else if ([function isEqualToString:@"MGL_MATCH"]) {
+ NSMutableArray *expressionObject = [NSMutableArray arrayWithObjects:@"match", nil];
for (NSExpression *option in self.arguments) {
diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm
index 5d94829b8f..5fb36ccbb9 100644
--- a/platform/darwin/test/MGLExpressionTests.mm
+++ b/platform/darwin/test/MGLExpressionTests.mm
@@ -628,7 +628,7 @@ using namespace std::string_literals;
- (void)testMatchExpressionObject {
{
- NSExpression *expression = [NSExpression expressionWithFormat:@"FUNCTION(2 - 1, 'mgl_match:', %@, %@, %@, %@, 'default')", MGLConstantExpression(@1),
+ NSExpression *expression = [NSExpression expressionWithFormat:@"MGL_MATCH(2 - 1, %@, %@, %@, %@, 'default')", MGLConstantExpression(@1),
MGLConstantExpression(@"one"),
MGLConstantExpression(@0),
MGLConstantExpression(@"zero")];
@@ -637,7 +637,7 @@ using namespace std::string_literals;
XCTAssertEqualObjects([NSExpression mgl_expressionWithJSONObject:jsonExpression], expression);
}
{
- NSExpression *expression = [NSExpression expressionWithFormat:@"FUNCTION(2 * 1, 'mgl_match:', %@, %@, 'default')", MGLConstantExpression(@1), MGLConstantExpression(@"one")];
+ NSExpression *expression = [NSExpression expressionWithFormat:@"MGL_MATCH(2 * 1, %@, %@, 'default')", MGLConstantExpression(@1), MGLConstantExpression(@"one")];
NSArray *jsonExpression = @[@"match", @[@"*", @2, @1], @1, @"one", @"default"];
XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
XCTAssertEqualObjects([NSExpression mgl_expressionWithJSONObject:jsonExpression], expression);