diff options
Diffstat (limited to 'platform/darwin/test')
-rw-r--r-- | platform/darwin/test/MGLExpressionTests.mm | 99 | ||||
-rw-r--r-- | platform/darwin/test/MGLStyleLayerTests.mm.ejs | 13 | ||||
-rw-r--r-- | platform/darwin/test/MGLSymbolStyleLayerTests.mm | 9 |
3 files changed, 101 insertions, 20 deletions
diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm index bcc30e49fd..8b8a79f184 100644 --- a/platform/darwin/test/MGLExpressionTests.mm +++ b/platform/darwin/test/MGLExpressionTests.mm @@ -12,6 +12,7 @@ #else #import "NSColor+MGLAdditions.h" #endif +#import "MGLAttributedExpression.h" #define MGLAssertEqualValues(actual, expected, ...) \ XCTAssertTrue(actual.is<__typeof__(expected)>()); \ @@ -990,6 +991,87 @@ using namespace std::string_literals; } } +- (void)testFormatExpressionObject { + { + MGLAttributedExpression *attribute1 = [MGLAttributedExpression attributedExpression:[NSExpression expressionForConstantValue:@"foo"] + fontNames:nil + fontSize:@(1.2)]; + MGLAttributedExpression *attribute2 = [MGLAttributedExpression attributedExpression:[NSExpression expressionForConstantValue:@"biz"] + fontNames:nil + fontSize:@(1.0)]; + MGLAttributedExpression *attribute3 = [MGLAttributedExpression attributedExpression:[NSExpression expressionForConstantValue:@"bar"] + fontNames:nil + fontSize:@(0.8)]; + MGLAttributedExpression *attribute4 = [MGLAttributedExpression attributedExpression:[NSExpression expressionForConstantValue:@"\r"] + fontNames:@[] + fontSize:nil]; + NSExpression *expression = [NSExpression expressionWithFormat:@"mgl_attributed:(%@, %@, %@, %@)", + MGLConstantExpression(attribute1), + MGLConstantExpression(attribute4), + MGLConstantExpression(attribute2), + MGLConstantExpression(attribute3)]; + NSArray *jsonExpression = @[@"format", @"foo", @{@"font-scale": @1.2}, @"\r", @{}, @"biz", @{@"font-scale": @1.0}, @"bar", @{@"font-scale": @0.8}]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); + } + { + MGLAttributedExpression *attribute1 = [MGLAttributedExpression attributedExpression:[NSExpression expressionForConstantValue:@"foo"] + fontNames:nil + fontSize:@(1.2)]; + MGLAttributedExpression *attribute2 = [MGLAttributedExpression attributedExpression:[NSExpression expressionForConstantValue:@"biz"] + fontNames:nil + fontSize:@(1.0)]; + MGLAttributedExpression *attribute3 = [MGLAttributedExpression attributedExpression:[NSExpression expressionForConstantValue:@"bar"] + fontNames:nil + fontSize:@(0.8)]; + MGLAttributedExpression *attribute4 = [MGLAttributedExpression attributedExpression:[NSExpression expressionForConstantValue:@"\n"] + fontNames:@[] + fontSize:nil]; + NSExpression *expression = [NSExpression expressionWithFormat:@"mgl_attributed:(%@, %@, %@, %@)", + MGLConstantExpression(attribute1), + MGLConstantExpression(attribute4), + MGLConstantExpression(attribute2), + MGLConstantExpression(attribute3)]; + NSArray *jsonExpression = @[@"format", @"foo", @{@"font-scale": @1.2}, @"\n", @{}, @"biz", @{@"font-scale": @1.0}, @"bar", @{@"font-scale": @0.8}]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); + } + { + MGLAttributedExpression *attribute1 = [MGLAttributedExpression attributedExpression:[NSExpression expressionForConstantValue:@"foo"] + fontNames:nil + fontSize:@(1.2)]; + NSExpression *expression = [NSExpression expressionWithFormat:@"mgl_attributed:(%@)", MGLConstantExpression(attribute1)]; + + NSExpression *compatibilityExpression = [NSExpression expressionForFunction:@"mgl_attributed:" arguments:@[MGLConstantExpression(attribute1)]]; + NSArray *jsonExpression = @[@"format", @"foo", @{@"font-scale": @1.2}]; + XCTAssertEqualObjects(compatibilityExpression.mgl_jsonExpressionObject, expression.mgl_jsonExpressionObject); + XCTAssertEqualObjects(compatibilityExpression, expression); + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); + } + { + MGLAttributedExpression *attribute1 = [MGLAttributedExpression attributedExpression:[NSExpression expressionForConstantValue:@"foo"] + fontNames:nil + fontSize:@(1.2)]; + MGLAttributedExpression *attribute2 = [MGLAttributedExpression attributedExpression:[NSExpression expressionForConstantValue:@"biz"] + fontNames:nil + fontSize:@(1.0)]; + MGLAttributedExpression *attribute3 = [MGLAttributedExpression attributedExpression:[NSExpression expressionForConstantValue:@"bar"] + fontNames:nil + fontSize:@(0.8)]; + MGLAttributedExpression *attribute4 = [MGLAttributedExpression attributedExpression:[NSExpression expressionForConstantValue:@"\n"] + fontNames:@[] + fontSize:nil]; + NSExpression *expression = [NSExpression mgl_expressionForAttributedExpressions:@[MGLConstantExpression(attribute1), + MGLConstantExpression(attribute4), + MGLConstantExpression(attribute2), + MGLConstantExpression(attribute3)]]; + NSArray *jsonExpression = @[@"format", @"foo", @{@"font-scale": @1.2}, @"\n", @{}, @"biz", @{@"font-scale": @1.0}, @"bar", @{@"font-scale": @0.8}]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); + } +} + - (void)testGenericExpressionObject { { NSExpression *expression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('random', 1, 2, 3, 4, 5)"]; @@ -1002,23 +1084,6 @@ using namespace std::string_literals; XCTAssertThrowsSpecificNamed([expression expressionValueWithObject:nil context:nil], NSException, NSInvalidArgumentException); } { - NSExpression *expression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('format', 'foo', %@, '\r', %@, 'biz', %@, 'bar', %@)", @{@"font-scale": @1.2}, @{}, @{@"font-scale": @1.0}, @{@"font-scale": @0.8}]; - NSArray *jsonExpression = @[@"format", @"foo", @{@"font-scale": @1.2}, @"\r", @{}, @"biz", @{@"font-scale": @1.0}, @"bar", @{@"font-scale": @0.8}]; - - XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); - - NSExpression *encodedExpression = [NSExpression expressionWithMGLJSONObject:jsonExpression]; - - // Expressions encoded from a json create a different constant abstract type - // thus even tho knowing that the constant values are the same, the base - // class is not. This compares the resulting array which is type agnostic encoding. - for (NSUInteger index = 0; index < jsonExpression.count; index++) { - NSExpression *left = encodedExpression.mgl_jsonExpressionObject[index]; - NSExpression *right = expression.mgl_jsonExpressionObject[index]; - XCTAssertEqualObjects(left.mgl_jsonExpressionObject, right.mgl_jsonExpressionObject); - } - } - { NSArray *arguments = @[ MGLConstantExpression(@"one"), MGLConstantExpression(@1), [NSExpression expressionForVariable:@"one"], diff --git a/platform/darwin/test/MGLStyleLayerTests.mm.ejs b/platform/darwin/test/MGLStyleLayerTests.mm.ejs index ba878b8bbe..4a38070007 100644 --- a/platform/darwin/test/MGLStyleLayerTests.mm.ejs +++ b/platform/darwin/test/MGLStyleLayerTests.mm.ejs @@ -8,6 +8,9 @@ #import "MGLStyleLayerTests.h" #import "../../darwin/src/NSDate+MGLAdditions.h" +<% if (type === 'symbol') { -%> +#include "../../darwin/src/MGLAttributedExpression.h" +<% } -%> #import "MGLStyleLayer_Private.h" @@ -80,7 +83,13 @@ XCTAssertEqualObjects(layer.<%- objCName(property) %>, constantExpression, @"<%- objCName(property) %> should round-trip constant value expressions."); +<% if (property.type !== 'formatted') { -%> constantExpression = [NSExpression expressionWithFormat:<%- objCTestValue(property, type, false, 3) %>]; +<% } else { -%> + MGLAttributedExpression *attributedConstantExpression = [[MGLAttributedExpression alloc] initWithExpression:[NSExpression expressionWithFormat:<%- objCTestValue(property, 'string', true, 3) %>] + attributes:@{}]; + constantExpression = [NSExpression mgl_expressionForAttributedExpressions:@[[NSExpression expressionForConstantValue:attributedConstantExpression]]]; +<% } -%> NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.<%- objCName(property) %> = functionExpression; @@ -180,7 +189,9 @@ @"Setting <%- objCName(property) %> to a constant string with tokens should convert to an expression."); <% if (property.type === 'formatted') { -%> - NSExpression* tokenExpression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('format', CAST(token, 'NSString'), %@)", @{}]; + MGLAttributedExpression *tokenAttibutedExpression = [[MGLAttributedExpression alloc] initWithExpression:[NSExpression expressionWithFormat:@"CAST(token, 'NSString')"] + attributes:@{}]; + NSExpression* tokenExpression = [NSExpression mgl_expressionForAttributedExpressions:@[[NSExpression expressionForConstantValue:tokenAttibutedExpression]]]; <% } else { -%> NSExpression* tokenExpression = [NSExpression expressionWithFormat:@"CAST(token, \"NSString\")"]; <% } -%> diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.mm b/platform/darwin/test/MGLSymbolStyleLayerTests.mm index f02c5d496e..2f4206a96b 100644 --- a/platform/darwin/test/MGLSymbolStyleLayerTests.mm +++ b/platform/darwin/test/MGLSymbolStyleLayerTests.mm @@ -3,6 +3,7 @@ #import "MGLStyleLayerTests.h" #import "../../darwin/src/NSDate+MGLAdditions.h" +#include "../../darwin/src/MGLAttributedExpression.h" #import "MGLStyleLayer_Private.h" @@ -1104,7 +1105,9 @@ XCTAssertEqualObjects(layer.text, constantExpression, @"text should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('format', 'Text Field', %@)", @{}]; + MGLAttributedExpression *attributedConstantExpression = [[MGLAttributedExpression alloc] initWithExpression:[NSExpression expressionWithFormat:@"'Text Field'"] + attributes:@{}]; + constantExpression = [NSExpression mgl_expressionForAttributedExpressions:@[[NSExpression expressionForConstantValue:attributedConstantExpression]]]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.text = functionExpression; @@ -1140,7 +1143,9 @@ XCTAssertEqual(rawLayer->getTextField(), propertyValue, @"Setting text to a constant string with tokens should convert to an expression."); - NSExpression* tokenExpression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('format', CAST(token, 'NSString'), %@)", @{}]; + MGLAttributedExpression *tokenAttibutedExpression = [[MGLAttributedExpression alloc] initWithExpression:[NSExpression expressionWithFormat:@"CAST(token, 'NSString')"] + attributes:@{}]; + NSExpression* tokenExpression = [NSExpression mgl_expressionForAttributedExpressions:@[[NSExpression expressionForConstantValue:tokenAttibutedExpression]]]; XCTAssertEqualObjects(layer.text, tokenExpression, @"Setting text to a constant string with tokens should convert to an expression."); } |