summaryrefslogtreecommitdiff
path: root/platform/darwin/test
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/test')
-rw-r--r--platform/darwin/test/MGLDocumentationExampleTests.swift34
-rw-r--r--platform/darwin/test/MGLExpressionTests.mm55
-rw-r--r--platform/darwin/test/MGLShapeSourceTests.mm5
3 files changed, 93 insertions, 1 deletions
diff --git a/platform/darwin/test/MGLDocumentationExampleTests.swift b/platform/darwin/test/MGLDocumentationExampleTests.swift
index 9fbb0cc329..7d6bdbed54 100644
--- a/platform/darwin/test/MGLDocumentationExampleTests.swift
+++ b/platform/darwin/test/MGLDocumentationExampleTests.swift
@@ -554,7 +554,39 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate {
XCTAssertNotNil(attributedExpression)
}
-
+
+ func testMGLShapeSourceOptionClusterProperties() {
+ //#-example-code
+ let firstExpression = NSExpression(format: "sum:({$featureAccumulated, sumValue})")
+ let secondExpression = NSExpression(forKeyPath: "magnitude")
+ let clusterPropertiesDictionary = ["sumValue" : [firstExpression, secondExpression]]
+
+ let options : [MGLShapeSourceOption : Any] = [.clustered : true,
+ .clusterProperties: clusterPropertiesDictionary]
+ //#-end-example-code
+ let geoJSON: [String: Any] = [
+ "type" : "Feature",
+ "geometry" : [
+ "coordinates" : [
+ -77.00896639534831,
+ 38.87031006108791,
+ 0.0
+ ],
+ "type" : "Point"
+ ],
+ "properties" : [
+ "cluster" : true,
+ "cluster_id" : 123,
+ "point_count" : 4567,
+ ]
+ ]
+
+ let clusterShapeData = try! JSONSerialization.data(withJSONObject: geoJSON, options: [])
+ let shape = try! MGLShape(data: clusterShapeData, encoding: String.Encoding.utf8.rawValue)
+ let source = MGLShapeSource(identifier: "source", shape: shape, options: options)
+ mapView.style?.addSource(source)
+
+ }
// For testMGLMapView().
func myCustomFunction() {}
}
diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm
index f1fe3ea878..4ccd7adb6e 100644
--- a/platform/darwin/test/MGLExpressionTests.mm
+++ b/platform/darwin/test/MGLExpressionTests.mm
@@ -180,6 +180,13 @@ using namespace std::string_literals;
XCTAssertEqualObjects([expression expressionValueWithObject:nil context:context], @1);
}
{
+ NSExpression *expression = [NSExpression expressionForVariable:@"featureAccumulated"];
+ XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, @[@"accumulated"]);
+ XCTAssertEqualObjects([NSExpression expressionWithFormat:@"$featureAccumulated"].mgl_jsonExpressionObject, @[@"accumulated"]);
+ XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:@[@"accumulated"]], expression);
+ }
+
+ {
NSExpression *expression = [NSExpression expressionForVariable:@"geometryType"];
XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, @[@"geometry-type"]);
XCTAssertEqualObjects([NSExpression expressionWithFormat:@"$geometryType"].mgl_jsonExpressionObject, @[@"geometry-type"]);
@@ -381,6 +388,26 @@ using namespace std::string_literals;
XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression);
}
{
+ NSExpression *testExpression = [NSExpression expressionWithFormat:@"sum:({1, 1, 2})"];
+ NSExpression *expression = [NSExpression expressionForFunction:@"sum:" arguments:@[[NSExpression expressionForAggregate:@[MGLConstantExpression(@1), MGLConstantExpression(@1), MGLConstantExpression(@2)]]]];
+
+ NSArray *jsonExpression = @[@"+", @1, @1, @2];
+
+ XCTAssertEqualObjects(testExpression.mgl_jsonExpressionObject, jsonExpression);
+ XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
+ XCTAssertEqualObjects(expression, testExpression);
+ }
+ {
+ NSExpression *expression = [NSExpression expressionForFunction:@"sum:" arguments:@[MGLConstantExpression(@1), MGLConstantExpression(@1), MGLConstantExpression(@2)]];
+ NSArray *jsonExpression = @[@"+", @1, @1, @2];
+ XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
+
+ // - [NSExpression expressionWithMGLJSONObject:] creates an expression with an aggregate expression as an argument. This is not equal to an expression with an array of expressions as an argument. For testing purposes, we will compare their operands and arrays of expressions.
+ NSExpression *aggregateExpression = [NSExpression expressionWithMGLJSONObject:jsonExpression];
+ XCTAssertEqualObjects(aggregateExpression.operand, expression.operand);
+ XCTAssertEqualObjects(aggregateExpression.arguments.firstObject.collection, expression.arguments);
+ }
+ {
NSArray *threeArguments = @[MGLConstantExpression(@1), MGLConstantExpression(@1), MGLConstantExpression(@1)];
NSExpression *expression = [NSExpression expressionForFunction:@"add:to:" arguments:threeArguments];
NSArray *jsonExpression = @[@"+", @1, @1, @1];
@@ -418,6 +445,24 @@ using namespace std::string_literals;
XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression);
}
{
+ NSExpression *expression = [NSExpression expressionForFunction:@"max:" arguments:arguments];
+ NSArray *jsonExpression = @[@"max", @1, @1];
+ XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
+
+ NSExpression *aggregateExpression = [NSExpression expressionWithMGLJSONObject:jsonExpression];
+ XCTAssertEqualObjects(aggregateExpression.operand, expression.operand);
+ XCTAssertEqualObjects(aggregateExpression.arguments.firstObject.collection, expression.arguments);
+ }
+ {
+ NSExpression *expression = [NSExpression expressionForFunction:@"min:" arguments:arguments];
+ NSArray *jsonExpression = @[@"min", @1, @1];
+ XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
+
+ NSExpression *aggregateExpression = [NSExpression expressionWithMGLJSONObject:jsonExpression];
+ XCTAssertEqualObjects(aggregateExpression.operand, expression.operand);
+ XCTAssertEqualObjects(aggregateExpression.arguments.firstObject.collection, expression.arguments);
+ }
+ {
NSExpression *expression = [NSExpression expressionForFunction:@"ceiling:" arguments:@[MGLConstantExpression(@1.5)]];
NSArray *jsonExpression = @[@"ceil", @1.5];
XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
@@ -622,6 +667,16 @@ using namespace std::string_literals;
XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], aftermarketExpression);
}
{
+ NSExpression *expression = [NSExpression expressionForFunction:@"mgl_join:" arguments:@[@"Old", @"MacDonald"]];
+ NSExpression *aftermarketExpression = [NSExpression expressionWithFormat:@"mgl_join({'Old', 'MacDonald'})"];
+ NSArray *jsonExpression = @[@"concat", @"Old", @"MacDonald"];
+ XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
+
+ XCTAssertEqualObjects(aftermarketExpression.mgl_jsonExpressionObject, expression.mgl_jsonExpressionObject);
+ NSExpression *aggregateExpression = [NSExpression expressionWithMGLJSONObject:jsonExpression];
+ XCTAssertEqualObjects(aggregateExpression.operand, expression.operand);
+ }
+ {
NSExpression *expression = [NSExpression expressionForFunction:@"uppercase:" arguments:arguments];
NSArray *jsonExpression = @[@"upcase", @"MacDonald"];
XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
diff --git a/platform/darwin/test/MGLShapeSourceTests.mm b/platform/darwin/test/MGLShapeSourceTests.mm
index 3459fb1733..3bf3ef04bd 100644
--- a/platform/darwin/test/MGLShapeSourceTests.mm
+++ b/platform/darwin/test/MGLShapeSourceTests.mm
@@ -13,8 +13,12 @@
@implementation MGLShapeSourceTests
- (void)testGeoJSONOptionsFromDictionary {
+ NSExpression *reduceExpression = [NSExpression expressionForFunction:@"sum:" arguments:@[[NSExpression expressionForKeyPath:@"featureAccumulated"], [NSExpression expressionForKeyPath:@"sumValue"]]];
+ NSExpression *mapExpression = [NSExpression expressionForKeyPath:@"mag"];
+ NSArray *clusterPropertyArray = @[reduceExpression, mapExpression];
NSDictionary *options = @{MGLShapeSourceOptionClustered: @YES,
MGLShapeSourceOptionClusterRadius: @42,
+ MGLShapeSourceOptionClusterProperties: @{@"sumValue": clusterPropertyArray},
MGLShapeSourceOptionMaximumZoomLevelForClustering: @98,
MGLShapeSourceOptionMaximumZoomLevel: @99,
MGLShapeSourceOptionBuffer: @1976,
@@ -29,6 +33,7 @@
XCTAssertEqual(mbglOptions.buffer, 1976);
XCTAssertEqual(mbglOptions.tolerance, 0.42);
XCTAssertTrue(mbglOptions.lineMetrics);
+ XCTAssertTrue(!mbglOptions.clusterProperties.empty());
options = @{MGLShapeSourceOptionClustered: @"number 1"};
XCTAssertThrows(MGLGeoJSONOptionsFromDictionary(options));