summaryrefslogtreecommitdiff
path: root/platform/darwin/test
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2018-07-17 12:21:50 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2018-07-20 12:35:00 -0700
commit2c5d0e74a1ef6743a23dbd346b79958e4b2f8614 (patch)
tree5dd56c0079294b6cebf2d26970bcb12852add27e /platform/darwin/test
parentaf89318b1d3bef15e92e591887c9d65b10be54ce (diff)
downloadqtlocation-mapboxgl-2c5d0e74a1ef6743a23dbd346b79958e4b2f8614.tar.gz
[ios, macos] Convert token strings to expressions on input
Removes mgl_expressionByReplacingTokensWithKeyPaths and associated code. Converting on output is no longer necessary: from the prior commit, core converts token strings to expressions at parse time; all that's necessary is to ensure that the runtime styling API does so as well.
Diffstat (limited to 'platform/darwin/test')
-rw-r--r--platform/darwin/test/MGLExpressionTests.mm41
-rw-r--r--platform/darwin/test/MGLStyleLayerTests.mm.ejs17
-rw-r--r--platform/darwin/test/MGLSymbolStyleLayerTests.mm30
3 files changed, 47 insertions, 41 deletions
diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm
index 01a279950b..5ae98e5244 100644
--- a/platform/darwin/test/MGLExpressionTests.mm
+++ b/platform/darwin/test/MGLExpressionTests.mm
@@ -995,47 +995,6 @@ using namespace std::string_literals;
#pragma mark - Localization tests
-- (void)testTokenReplacement {
- {
- NSExpression *original = MGLConstantExpression(@"");
- NSExpression *expected = original;
- XCTAssertEqualObjects(original.mgl_expressionByReplacingTokensWithKeyPaths, expected);
- }
- {
- NSExpression *original = MGLConstantExpression(@"{");
- NSExpression *expected = original;
- XCTAssertEqualObjects(original.mgl_expressionByReplacingTokensWithKeyPaths, expected);
- }
- {
- NSExpression *original = MGLConstantExpression(@"{token");
- NSExpression *expected = original;
- XCTAssertEqualObjects(original.mgl_expressionByReplacingTokensWithKeyPaths, expected);
- }
- {
- NSExpression *original = MGLConstantExpression(@"{token}");
- NSExpression *expected = [NSExpression expressionForKeyPath:@"token"];
- XCTAssertEqualObjects(original.mgl_expressionByReplacingTokensWithKeyPaths, expected);
- }
- {
- NSExpression *original = MGLConstantExpression(@"{token} {token}");
- NSExpression *expected = [NSExpression expressionWithFormat:@"mgl_join({token, ' ', token})"];
- XCTAssertEqualObjects(original.mgl_expressionByReplacingTokensWithKeyPaths, expected);
- }
- {
- NSExpression *original = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, '{short}', %@)", @{
- @1: MGLConstantExpression(@"{short}"),
- @2: @"…",
- @3: @"{long}",
- }];
- NSExpression *expected = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, short, %@)", @{
- @1: [NSExpression expressionForKeyPath:@"short"],
- @2: @"…",
- @3: [NSExpression expressionForKeyPath:@"long"],
- }];
- XCTAssertEqualObjects(original.mgl_expressionByReplacingTokensWithKeyPaths, expected);
- }
-}
-
- (void)testLocalization {
{
NSExpression *original = MGLConstantExpression(@"");
diff --git a/platform/darwin/test/MGLStyleLayerTests.mm.ejs b/platform/darwin/test/MGLStyleLayerTests.mm.ejs
index 44996fa125..02c4a04e6f 100644
--- a/platform/darwin/test/MGLStyleLayerTests.mm.ejs
+++ b/platform/darwin/test/MGLStyleLayerTests.mm.ejs
@@ -156,6 +156,23 @@
XCTAssertEqual(<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %>Transition.delay, transitionTest.delay);
XCTAssertEqual(<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %>Transition.duration, transitionTest.duration);
<% } -%>
+<% if (property.tokens) { -%>
+
+ // Tokens test
+ layer.<%- objCName(property) %> = [NSExpression expressionForConstantValue:@"{token}"];
+
+ {
+ using namespace mbgl::style::expression::dsl;
+ propertyValue = mbgl::style::PropertyExpression<<%- mbglType(property) %>>(
+ toString(get(literal("token")))
+ );
+ }
+
+ XCTAssertEqual(rawLayer->get<%- camelize(originalPropertyName(property)) %>(), propertyValue,
+ @"Setting <%- objCName(property) %> to a constant string with tokens should convert to an expression.");
+ XCTAssertEqualObjects(layer.<%- objCName(property) %>, [NSExpression expressionWithFormat:@"CAST(token, \"NSString\")"],
+ @"Setting <%- objCName(property) %> to a constant string with tokens should convert to an expression.");
+<% } -%>
}
<% } -%>
}
diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.mm b/platform/darwin/test/MGLSymbolStyleLayerTests.mm
index 7566617872..8643e8388b 100644
--- a/platform/darwin/test/MGLSymbolStyleLayerTests.mm
+++ b/platform/darwin/test/MGLSymbolStyleLayerTests.mm
@@ -211,6 +211,21 @@
@"Unsetting iconImageName should return icon-image to the default value.");
XCTAssertEqualObjects(layer.iconImageName, defaultExpression,
@"iconImageName should return the default value after being unset.");
+
+ // Tokens test
+ layer.iconImageName = [NSExpression expressionForConstantValue:@"{token}"];
+
+ {
+ using namespace mbgl::style::expression::dsl;
+ propertyValue = mbgl::style::PropertyExpression<std::string>(
+ toString(get(literal("token")))
+ );
+ }
+
+ XCTAssertEqual(rawLayer->getIconImage(), propertyValue,
+ @"Setting iconImageName to a constant string with tokens should convert to an expression.");
+ XCTAssertEqualObjects(layer.iconImageName, [NSExpression expressionWithFormat:@"CAST(token, \"NSString\")"],
+ @"Setting iconImageName to a constant string with tokens should convert to an expression.");
}
// icon-offset
@@ -1065,6 +1080,21 @@
@"Unsetting text should return text-field to the default value.");
XCTAssertEqualObjects(layer.text, defaultExpression,
@"text should return the default value after being unset.");
+
+ // Tokens test
+ layer.text = [NSExpression expressionForConstantValue:@"{token}"];
+
+ {
+ using namespace mbgl::style::expression::dsl;
+ propertyValue = mbgl::style::PropertyExpression<std::string>(
+ toString(get(literal("token")))
+ );
+ }
+
+ XCTAssertEqual(rawLayer->getTextField(), propertyValue,
+ @"Setting text to a constant string with tokens should convert to an expression.");
+ XCTAssertEqualObjects(layer.text, [NSExpression expressionWithFormat:@"CAST(token, \"NSString\")"],
+ @"Setting text to a constant string with tokens should convert to an expression.");
}
// text-allow-overlap