diff options
Diffstat (limited to 'platform/darwin/test/MGLFillStyleLayerTests.mm')
-rw-r--r-- | platform/darwin/test/MGLFillStyleLayerTests.mm | 103 |
1 files changed, 72 insertions, 31 deletions
diff --git a/platform/darwin/test/MGLFillStyleLayerTests.mm b/platform/darwin/test/MGLFillStyleLayerTests.mm index 25521f3ede..1747dded85 100644 --- a/platform/darwin/test/MGLFillStyleLayerTests.mm +++ b/platform/darwin/test/MGLFillStyleLayerTests.mm @@ -54,7 +54,7 @@ @"fill-antialias should be unset initially."); NSExpression *defaultExpression = layer.fillAntialiased; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"false"]; + NSExpression *constantExpression = [NSExpression mgl_expressionForValue:@NO]; layer.fillAntialiased = constantExpression; mbgl::style::PropertyValue<bool> propertyValue = { false }; XCTAssertEqual(rawLayer->getFillAntialias(), propertyValue, @@ -62,8 +62,10 @@ XCTAssertEqualObjects(layer.fillAntialiased, constantExpression, @"fillAntialiased should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"false"]; - NSExpression *functionExpression = [NSExpression expressionWithFormat:@"FUNCTION($zoomLevel, 'mgl_stepWithMinimum:stops:', %@, %@)", constantExpression, @{@18: constantExpression}]; + constantExpression = [NSExpression mgl_expressionForValue:@NO]; + NSExpression *functionExpression = [NSExpression mgl_expressionForStepFunction:[NSExpression mgl_expressionForString:MGLExpressionStyleFunctionZoomLevel] + defaultExpression:constantExpression + stops:[NSExpression expressionWithFormat:@"%@", @{@18: constantExpression}]]; layer.fillAntialiased = functionExpression; mbgl::style::IntervalStops<bool> intervalStops = {{ @@ -87,8 +89,11 @@ functionExpression = [NSExpression expressionForKeyPath:@"bogus"]; XCTAssertThrowsSpecificNamed(layer.fillAntialiased = functionExpression, NSException, NSInvalidArgumentException, @"MGLFillLayer should raise an exception if a camera-data expression is applied to a property that does not support key paths to feature attributes."); - functionExpression = [NSExpression expressionWithFormat:@"FUNCTION(bogus, 'mgl_stepWithMinimum:stops:', %@, %@)", constantExpression, @{@18: constantExpression}]; - functionExpression = [NSExpression expressionWithFormat:@"FUNCTION($zoomLevel, 'mgl_interpolateWithCurveType:parameters:stops:', 'linear', nil, %@)", @{@10: functionExpression}]; + functionExpression = [NSExpression mgl_expressionForStepFunction:[NSExpression expressionForKeyPath:@"bogus"] + defaultExpression:constantExpression + stops:[NSExpression expressionWithFormat:@"%@", @{@18: constantExpression}]]; + functionExpression = [NSExpression mgl_expressionForInterpolateFunction:MGLExpressionStyleFunctionZoomLevel + curveType:MGLExpressionInterpolationModeLinear steps:@{@10: functionExpression}]; XCTAssertThrowsSpecificNamed(layer.fillAntialiased = functionExpression, NSException, NSInvalidArgumentException, @"MGLFillLayer should raise an exception if a camera-data expression is applied to a property that does not support key paths to feature attributes."); } @@ -98,7 +103,7 @@ @"fill-color should be unset initially."); NSExpression *defaultExpression = layer.fillColor; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"%@", [MGLColor redColor]]; + NSExpression *constantExpression = [NSExpression mgl_expressionForColor:[MGLColor redColor]]; layer.fillColor = constantExpression; mbgl::style::DataDrivenPropertyValue<mbgl::Color> propertyValue = { { 1, 0, 0, 1 } }; XCTAssertEqual(rawLayer->getFillColor(), propertyValue, @@ -106,8 +111,10 @@ XCTAssertEqualObjects(layer.fillColor, constantExpression, @"fillColor should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"%@", [MGLColor redColor]]; - NSExpression *functionExpression = [NSExpression expressionWithFormat:@"FUNCTION($zoomLevel, 'mgl_stepWithMinimum:stops:', %@, %@)", constantExpression, @{@18: constantExpression}]; + constantExpression = [NSExpression mgl_expressionForColor:[MGLColor redColor]]; + NSExpression *functionExpression = [NSExpression mgl_expressionForStepFunction:[NSExpression mgl_expressionForString:MGLExpressionStyleFunctionZoomLevel] + defaultExpression:constantExpression + stops:[NSExpression expressionWithFormat:@"%@", @{@18: constantExpression}]]; layer.fillColor = functionExpression; mbgl::style::IntervalStops<mbgl::Color> intervalStops = {{ @@ -121,7 +128,11 @@ XCTAssertEqualObjects(layer.fillColor, functionExpression, @"fillColor should round-trip camera expressions."); - functionExpression = [NSExpression expressionWithFormat:@"FUNCTION(keyName, 'mgl_interpolateWithCurveType:parameters:stops:', 'linear', nil, %@)", @{@18: constantExpression}]; + functionExpression = [NSExpression mgl_expressionForInterpolateFunction:[NSExpression expressionForKeyPath:@"keyName"] + curveType:MGLExpressionInterpolationModeLinear + parameters:nil + steps:[NSExpression expressionWithFormat:@"%@", @{@18: constantExpression}]]; + layer.fillColor = functionExpression; mbgl::style::ExponentialStops<mbgl::Color> exponentialStops = { {{18, { 1, 0, 0, 1 }}}, 1.0 }; @@ -132,7 +143,8 @@ XCTAssertEqualObjects(layer.fillColor, functionExpression, @"fillColor should round-trip data expressions."); - functionExpression = [NSExpression expressionWithFormat:@"FUNCTION($zoomLevel, 'mgl_interpolateWithCurveType:parameters:stops:', 'linear', nil, %@)", @{@10: functionExpression}]; + functionExpression = [NSExpression mgl_expressionForInterpolateFunction:MGLExpressionStyleFunctionZoomLevel + curveType:MGLExpressionInterpolationModeLinear steps:@{@10: functionExpression}]; layer.fillColor = functionExpression; std::map<float, mbgl::Color> innerStops { {18, { 1, 0, 0, 1 }} }; @@ -168,7 +180,7 @@ @"fill-opacity should be unset initially."); NSExpression *defaultExpression = layer.fillOpacity; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression mgl_expressionForValue:@0xff]; layer.fillOpacity = constantExpression; mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; XCTAssertEqual(rawLayer->getFillOpacity(), propertyValue, @@ -176,8 +188,10 @@ XCTAssertEqualObjects(layer.fillOpacity, constantExpression, @"fillOpacity should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; - NSExpression *functionExpression = [NSExpression expressionWithFormat:@"FUNCTION($zoomLevel, 'mgl_stepWithMinimum:stops:', %@, %@)", constantExpression, @{@18: constantExpression}]; + constantExpression = [NSExpression mgl_expressionForValue:@0xff]; + NSExpression *functionExpression = [NSExpression mgl_expressionForStepFunction:[NSExpression mgl_expressionForString:MGLExpressionStyleFunctionZoomLevel] + defaultExpression:constantExpression + stops:[NSExpression expressionWithFormat:@"%@", @{@18: constantExpression}]]; layer.fillOpacity = functionExpression; mbgl::style::IntervalStops<float> intervalStops = {{ @@ -191,7 +205,11 @@ XCTAssertEqualObjects(layer.fillOpacity, functionExpression, @"fillOpacity should round-trip camera expressions."); - functionExpression = [NSExpression expressionWithFormat:@"FUNCTION(keyName, 'mgl_interpolateWithCurveType:parameters:stops:', 'linear', nil, %@)", @{@18: constantExpression}]; + functionExpression = [NSExpression mgl_expressionForInterpolateFunction:[NSExpression expressionForKeyPath:@"keyName"] + curveType:MGLExpressionInterpolationModeLinear + parameters:nil + steps:[NSExpression expressionWithFormat:@"%@", @{@18: constantExpression}]]; + layer.fillOpacity = functionExpression; mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; @@ -202,7 +220,8 @@ XCTAssertEqualObjects(layer.fillOpacity, functionExpression, @"fillOpacity should round-trip data expressions."); - functionExpression = [NSExpression expressionWithFormat:@"FUNCTION($zoomLevel, 'mgl_interpolateWithCurveType:parameters:stops:', 'linear', nil, %@)", @{@10: functionExpression}]; + functionExpression = [NSExpression mgl_expressionForInterpolateFunction:MGLExpressionStyleFunctionZoomLevel + curveType:MGLExpressionInterpolationModeLinear steps:@{@10: functionExpression}]; layer.fillOpacity = functionExpression; std::map<float, float> innerStops { {18, 0xff} }; @@ -238,7 +257,7 @@ @"fill-outline-color should be unset initially."); NSExpression *defaultExpression = layer.fillOutlineColor; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"%@", [MGLColor redColor]]; + NSExpression *constantExpression = [NSExpression mgl_expressionForColor:[MGLColor redColor]]; layer.fillOutlineColor = constantExpression; mbgl::style::DataDrivenPropertyValue<mbgl::Color> propertyValue = { { 1, 0, 0, 1 } }; XCTAssertEqual(rawLayer->getFillOutlineColor(), propertyValue, @@ -246,8 +265,10 @@ XCTAssertEqualObjects(layer.fillOutlineColor, constantExpression, @"fillOutlineColor should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"%@", [MGLColor redColor]]; - NSExpression *functionExpression = [NSExpression expressionWithFormat:@"FUNCTION($zoomLevel, 'mgl_stepWithMinimum:stops:', %@, %@)", constantExpression, @{@18: constantExpression}]; + constantExpression = [NSExpression mgl_expressionForColor:[MGLColor redColor]]; + NSExpression *functionExpression = [NSExpression mgl_expressionForStepFunction:[NSExpression mgl_expressionForString:MGLExpressionStyleFunctionZoomLevel] + defaultExpression:constantExpression + stops:[NSExpression expressionWithFormat:@"%@", @{@18: constantExpression}]]; layer.fillOutlineColor = functionExpression; mbgl::style::IntervalStops<mbgl::Color> intervalStops = {{ @@ -261,7 +282,11 @@ XCTAssertEqualObjects(layer.fillOutlineColor, functionExpression, @"fillOutlineColor should round-trip camera expressions."); - functionExpression = [NSExpression expressionWithFormat:@"FUNCTION(keyName, 'mgl_interpolateWithCurveType:parameters:stops:', 'linear', nil, %@)", @{@18: constantExpression}]; + functionExpression = [NSExpression mgl_expressionForInterpolateFunction:[NSExpression expressionForKeyPath:@"keyName"] + curveType:MGLExpressionInterpolationModeLinear + parameters:nil + steps:[NSExpression expressionWithFormat:@"%@", @{@18: constantExpression}]]; + layer.fillOutlineColor = functionExpression; mbgl::style::ExponentialStops<mbgl::Color> exponentialStops = { {{18, { 1, 0, 0, 1 }}}, 1.0 }; @@ -272,7 +297,8 @@ XCTAssertEqualObjects(layer.fillOutlineColor, functionExpression, @"fillOutlineColor should round-trip data expressions."); - functionExpression = [NSExpression expressionWithFormat:@"FUNCTION($zoomLevel, 'mgl_interpolateWithCurveType:parameters:stops:', 'linear', nil, %@)", @{@10: functionExpression}]; + functionExpression = [NSExpression mgl_expressionForInterpolateFunction:MGLExpressionStyleFunctionZoomLevel + curveType:MGLExpressionInterpolationModeLinear steps:@{@10: functionExpression}]; layer.fillOutlineColor = functionExpression; std::map<float, mbgl::Color> innerStops { {18, { 1, 0, 0, 1 }} }; @@ -308,7 +334,7 @@ @"fill-pattern should be unset initially."); NSExpression *defaultExpression = layer.fillPattern; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"'Fill Pattern'"]; + NSExpression *constantExpression = [NSExpression mgl_expressionForString:@"'Fill Pattern'"]; layer.fillPattern = constantExpression; mbgl::style::PropertyValue<std::string> propertyValue = { "Fill Pattern" }; XCTAssertEqual(rawLayer->getFillPattern(), propertyValue, @@ -316,8 +342,10 @@ XCTAssertEqualObjects(layer.fillPattern, constantExpression, @"fillPattern should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"'Fill Pattern'"]; - NSExpression *functionExpression = [NSExpression expressionWithFormat:@"FUNCTION($zoomLevel, 'mgl_stepWithMinimum:stops:', %@, %@)", constantExpression, @{@18: constantExpression}]; + constantExpression = [NSExpression mgl_expressionForString:@"'Fill Pattern'"]; + NSExpression *functionExpression = [NSExpression mgl_expressionForStepFunction:[NSExpression mgl_expressionForString:MGLExpressionStyleFunctionZoomLevel] + defaultExpression:constantExpression + stops:[NSExpression expressionWithFormat:@"%@", @{@18: constantExpression}]]; layer.fillPattern = functionExpression; mbgl::style::IntervalStops<std::string> intervalStops = {{ @@ -341,8 +369,11 @@ functionExpression = [NSExpression expressionForKeyPath:@"bogus"]; XCTAssertThrowsSpecificNamed(layer.fillPattern = functionExpression, NSException, NSInvalidArgumentException, @"MGLFillLayer should raise an exception if a camera-data expression is applied to a property that does not support key paths to feature attributes."); - functionExpression = [NSExpression expressionWithFormat:@"FUNCTION(bogus, 'mgl_stepWithMinimum:stops:', %@, %@)", constantExpression, @{@18: constantExpression}]; - functionExpression = [NSExpression expressionWithFormat:@"FUNCTION($zoomLevel, 'mgl_interpolateWithCurveType:parameters:stops:', 'linear', nil, %@)", @{@10: functionExpression}]; + functionExpression = [NSExpression mgl_expressionForStepFunction:[NSExpression expressionForKeyPath:@"bogus"] + defaultExpression:constantExpression + stops:[NSExpression expressionWithFormat:@"%@", @{@18: constantExpression}]]; + functionExpression = [NSExpression mgl_expressionForInterpolateFunction:MGLExpressionStyleFunctionZoomLevel + curveType:MGLExpressionInterpolationModeLinear steps:@{@10: functionExpression}]; XCTAssertThrowsSpecificNamed(layer.fillPattern = functionExpression, NSException, NSInvalidArgumentException, @"MGLFillLayer should raise an exception if a camera-data expression is applied to a property that does not support key paths to feature attributes."); // Transition property test layer.fillPatternTransition = transitionTest; @@ -376,7 +407,9 @@ @"fillTranslation should round-trip constant value expressions."); constantExpression = [NSExpression expressionWithFormat:@"{1, 1}"]; - NSExpression *functionExpression = [NSExpression expressionWithFormat:@"FUNCTION($zoomLevel, 'mgl_stepWithMinimum:stops:', %@, %@)", constantExpression, @{@18: constantExpression}]; + NSExpression *functionExpression = [NSExpression mgl_expressionForStepFunction:[NSExpression mgl_expressionForString:MGLExpressionStyleFunctionZoomLevel] + defaultExpression:constantExpression + stops:[NSExpression expressionWithFormat:@"%@", @{@18: constantExpression}]]; layer.fillTranslation = functionExpression; mbgl::style::IntervalStops<std::array<float, 2>> intervalStops = {{ @@ -400,8 +433,11 @@ functionExpression = [NSExpression expressionForKeyPath:@"bogus"]; XCTAssertThrowsSpecificNamed(layer.fillTranslation = functionExpression, NSException, NSInvalidArgumentException, @"MGLFillLayer should raise an exception if a camera-data expression is applied to a property that does not support key paths to feature attributes."); - functionExpression = [NSExpression expressionWithFormat:@"FUNCTION(bogus, 'mgl_stepWithMinimum:stops:', %@, %@)", constantExpression, @{@18: constantExpression}]; - functionExpression = [NSExpression expressionWithFormat:@"FUNCTION($zoomLevel, 'mgl_interpolateWithCurveType:parameters:stops:', 'linear', nil, %@)", @{@10: functionExpression}]; + functionExpression = [NSExpression mgl_expressionForStepFunction:[NSExpression expressionForKeyPath:@"bogus"] + defaultExpression:constantExpression + stops:[NSExpression expressionWithFormat:@"%@", @{@18: constantExpression}]]; + functionExpression = [NSExpression mgl_expressionForInterpolateFunction:MGLExpressionStyleFunctionZoomLevel + curveType:MGLExpressionInterpolationModeLinear steps:@{@10: functionExpression}]; XCTAssertThrowsSpecificNamed(layer.fillTranslation = functionExpression, NSException, NSInvalidArgumentException, @"MGLFillLayer should raise an exception if a camera-data expression is applied to a property that does not support key paths to feature attributes."); } @@ -420,7 +456,9 @@ @"fillTranslationAnchor should round-trip constant value expressions."); constantExpression = [NSExpression expressionWithFormat:@"'viewport'"]; - NSExpression *functionExpression = [NSExpression expressionWithFormat:@"FUNCTION($zoomLevel, 'mgl_stepWithMinimum:stops:', %@, %@)", constantExpression, @{@18: constantExpression}]; + NSExpression *functionExpression = [NSExpression mgl_expressionForStepFunction:[NSExpression mgl_expressionForString:MGLExpressionStyleFunctionZoomLevel] + defaultExpression:constantExpression + stops:[NSExpression expressionWithFormat:@"%@", @{@18: constantExpression}]]; layer.fillTranslationAnchor = functionExpression; mbgl::style::IntervalStops<mbgl::style::TranslateAnchorType> intervalStops = {{ @@ -444,8 +482,11 @@ functionExpression = [NSExpression expressionForKeyPath:@"bogus"]; XCTAssertThrowsSpecificNamed(layer.fillTranslationAnchor = functionExpression, NSException, NSInvalidArgumentException, @"MGLFillLayer should raise an exception if a camera-data expression is applied to a property that does not support key paths to feature attributes."); - functionExpression = [NSExpression expressionWithFormat:@"FUNCTION(bogus, 'mgl_stepWithMinimum:stops:', %@, %@)", constantExpression, @{@18: constantExpression}]; - functionExpression = [NSExpression expressionWithFormat:@"FUNCTION($zoomLevel, 'mgl_interpolateWithCurveType:parameters:stops:', 'linear', nil, %@)", @{@10: functionExpression}]; + functionExpression = [NSExpression mgl_expressionForStepFunction:[NSExpression expressionForKeyPath:@"bogus"] + defaultExpression:constantExpression + stops:[NSExpression expressionWithFormat:@"%@", @{@18: constantExpression}]]; + functionExpression = [NSExpression mgl_expressionForInterpolateFunction:MGLExpressionStyleFunctionZoomLevel + curveType:MGLExpressionInterpolationModeLinear steps:@{@10: functionExpression}]; XCTAssertThrowsSpecificNamed(layer.fillTranslationAnchor = functionExpression, NSException, NSInvalidArgumentException, @"MGLFillLayer should raise an exception if a camera-data expression is applied to a property that does not support key paths to feature attributes."); } } |