[darwin] Fix image roundrip conversion
This commit is contained in:
@@ -153,12 +153,15 @@ global.objCTestValue = function (property, layerType, arraysAsStructs, indent) {
|
||||
case 'number':
|
||||
return '@"1"';
|
||||
case 'formatted':
|
||||
case 'resolvedImage':
|
||||
// Special 'string' case to handle constant expression text-field that automatically
|
||||
// converts Formatted back to string.
|
||||
return layerType === 'string' ?
|
||||
`@"'${_.startCase(propertyName)}'"` :
|
||||
`@"${_.startCase(propertyName)}"`;
|
||||
case 'resolvedImage':
|
||||
return layerType === 'string' ?
|
||||
`@"${_.startCase(propertyName)}"` :
|
||||
`@"MGL_FUNCTION('image', '${_.startCase(propertyName)}')"`;
|
||||
case 'string':
|
||||
return `@"'${_.startCase(propertyName)}'"`;
|
||||
case 'enum':
|
||||
@@ -209,7 +212,7 @@ global.mbglTestValue = function (property, layerType) {
|
||||
return '1.0';
|
||||
case 'formatted':
|
||||
case 'string':
|
||||
case 'resolvedImage': // TODO: replace once we implement image expressions
|
||||
case 'resolvedImage':
|
||||
return `"${_.startCase(propertyName)}"`;
|
||||
case 'enum': {
|
||||
let type = camelize(originalPropertyName(property));
|
||||
@@ -477,7 +480,7 @@ global.describeType = function (property) {
|
||||
return 'numeric';
|
||||
case 'formatted':
|
||||
case 'string':
|
||||
case 'resolvedImage': // TODO: replace once we implement image expressions
|
||||
case 'resolvedImage':
|
||||
return 'string';
|
||||
case 'enum':
|
||||
return '`MGL' + camelize(property.name) + '`';
|
||||
@@ -613,7 +616,7 @@ global.propertyType = function (property) {
|
||||
return 'NSNumber *';
|
||||
case 'formatted':
|
||||
case 'string':
|
||||
case 'resolvedImage': // TODO: replace once we implement image expressions
|
||||
case 'resolvedImage':
|
||||
return 'NSString *';
|
||||
case 'enum':
|
||||
return 'NSValue *';
|
||||
|
||||
@@ -1229,6 +1229,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
|
||||
|
||||
return expressionObject;
|
||||
}
|
||||
|
||||
return self.arguments.mgl_jsonExpressionObject;
|
||||
} else if (op == [MGLColor class] && [function isEqualToString:@"colorWithRed:green:blue:alpha:"]) {
|
||||
NSArray *arguments = self.arguments.mgl_jsonExpressionObject;
|
||||
|
||||
@@ -140,7 +140,7 @@
|
||||
@"background-pattern should be unset initially.");
|
||||
NSExpression *defaultExpression = layer.backgroundPattern;
|
||||
|
||||
NSExpression *constantExpression = [NSExpression expressionWithFormat:@"Background Pattern"];
|
||||
NSExpression *constantExpression = [NSExpression expressionForConstantValue:@"Background Pattern"];
|
||||
layer.backgroundPattern = constantExpression;
|
||||
mbgl::style::PropertyValue<mbgl::style::expression::Image> propertyValue = { "Background Pattern" };
|
||||
XCTAssertEqual(rawLayer->getBackgroundPattern(), propertyValue,
|
||||
@@ -148,14 +148,14 @@
|
||||
XCTAssertEqualObjects(layer.backgroundPattern, constantExpression,
|
||||
@"backgroundPattern should round-trip constant value expressions.");
|
||||
|
||||
constantExpression = [NSExpression expressionWithFormat:@"Background Pattern"];
|
||||
constantExpression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('image', 'Background Pattern')"];
|
||||
NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}];
|
||||
layer.backgroundPattern = functionExpression;
|
||||
|
||||
{
|
||||
using namespace mbgl::style::expression::dsl;
|
||||
propertyValue = mbgl::style::PropertyExpression<mbgl::style::expression::Image>(
|
||||
step(zoom(), literal("Background Pattern"), 18.0, literal("Background Pattern"))
|
||||
step(zoom(), image(literal("Background Pattern")), 18.0, image(literal("Background Pattern")))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -386,7 +386,7 @@
|
||||
@"fill-extrusion-pattern should be unset initially.");
|
||||
NSExpression *defaultExpression = layer.fillExtrusionPattern;
|
||||
|
||||
NSExpression *constantExpression = [NSExpression expressionWithFormat:@"Fill Extrusion Pattern"];
|
||||
NSExpression *constantExpression = [NSExpression expressionForConstantValue:@"Fill Extrusion Pattern"];
|
||||
layer.fillExtrusionPattern = constantExpression;
|
||||
mbgl::style::PropertyValue<mbgl::style::expression::Image> propertyValue = { "Fill Extrusion Pattern" };
|
||||
XCTAssertEqual(rawLayer->getFillExtrusionPattern(), propertyValue,
|
||||
@@ -394,14 +394,14 @@
|
||||
XCTAssertEqualObjects(layer.fillExtrusionPattern, constantExpression,
|
||||
@"fillExtrusionPattern should round-trip constant value expressions.");
|
||||
|
||||
constantExpression = [NSExpression expressionWithFormat:@"Fill Extrusion Pattern"];
|
||||
constantExpression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('image', 'Fill Extrusion Pattern')"];
|
||||
NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}];
|
||||
layer.fillExtrusionPattern = functionExpression;
|
||||
|
||||
{
|
||||
using namespace mbgl::style::expression::dsl;
|
||||
propertyValue = mbgl::style::PropertyExpression<mbgl::style::expression::Image>(
|
||||
step(zoom(), literal("Fill Extrusion Pattern"), 18.0, literal("Fill Extrusion Pattern"))
|
||||
step(zoom(), image(literal("Fill Extrusion Pattern")), 18.0, image(literal("Fill Extrusion Pattern")))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -333,7 +333,7 @@
|
||||
@"fill-pattern should be unset initially.");
|
||||
NSExpression *defaultExpression = layer.fillPattern;
|
||||
|
||||
NSExpression *constantExpression = [NSExpression expressionWithFormat:@"Fill Pattern"];
|
||||
NSExpression *constantExpression = [NSExpression expressionForConstantValue:@"Fill Pattern"];
|
||||
layer.fillPattern = constantExpression;
|
||||
mbgl::style::PropertyValue<mbgl::style::expression::Image> propertyValue = { "Fill Pattern" };
|
||||
XCTAssertEqual(rawLayer->getFillPattern(), propertyValue,
|
||||
@@ -341,14 +341,14 @@
|
||||
XCTAssertEqualObjects(layer.fillPattern, constantExpression,
|
||||
@"fillPattern should round-trip constant value expressions.");
|
||||
|
||||
constantExpression = [NSExpression expressionWithFormat:@"Fill Pattern"];
|
||||
constantExpression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('image', 'Fill Pattern')"];
|
||||
NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}];
|
||||
layer.fillPattern = functionExpression;
|
||||
|
||||
{
|
||||
using namespace mbgl::style::expression::dsl;
|
||||
propertyValue = mbgl::style::PropertyExpression<mbgl::style::expression::Image>(
|
||||
step(zoom(), literal("Fill Pattern"), 18.0, literal("Fill Pattern"))
|
||||
step(zoom(), image(literal("Fill Pattern")), 18.0, image(literal("Fill Pattern")))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -659,7 +659,7 @@
|
||||
@"line-pattern should be unset initially.");
|
||||
NSExpression *defaultExpression = layer.linePattern;
|
||||
|
||||
NSExpression *constantExpression = [NSExpression expressionWithFormat:@"Line Pattern"];
|
||||
NSExpression *constantExpression = [NSExpression expressionForConstantValue:@"Line Pattern"];
|
||||
layer.linePattern = constantExpression;
|
||||
mbgl::style::PropertyValue<mbgl::style::expression::Image> propertyValue = { "Line Pattern" };
|
||||
XCTAssertEqual(rawLayer->getLinePattern(), propertyValue,
|
||||
@@ -667,14 +667,14 @@
|
||||
XCTAssertEqualObjects(layer.linePattern, constantExpression,
|
||||
@"linePattern should round-trip constant value expressions.");
|
||||
|
||||
constantExpression = [NSExpression expressionWithFormat:@"Line Pattern"];
|
||||
constantExpression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('image', 'Line Pattern')"];
|
||||
NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}];
|
||||
layer.linePattern = functionExpression;
|
||||
|
||||
{
|
||||
using namespace mbgl::style::expression::dsl;
|
||||
propertyValue = mbgl::style::PropertyExpression<mbgl::style::expression::Image>(
|
||||
step(zoom(), literal("Line Pattern"), 18.0, literal("Line Pattern"))
|
||||
step(zoom(), image(literal("Line Pattern")), 18.0, image(literal("Line Pattern")))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,8 @@
|
||||
|
||||
<% if (property.type === 'formatted') { -%>
|
||||
NSExpression *constantExpression = [NSExpression expressionWithFormat:<%- objCTestValue(property, 'string', true, 3) %>];
|
||||
<% } else if (property.type === 'resolvedImage'){ -%>
|
||||
NSExpression *constantExpression = [NSExpression expressionForConstantValue:<%- objCTestValue(property, 'string', true, 3) %>];
|
||||
<% } else { -%>
|
||||
NSExpression *constantExpression = [NSExpression expressionWithFormat:<%- objCTestValue(property, type, true, 3) %>];
|
||||
<% } -%>
|
||||
@@ -98,6 +100,8 @@
|
||||
propertyValue = mbgl::style::PropertyExpression<<%- mbglType(property) %>>(
|
||||
<% if (property.type === 'formatted') { -%>
|
||||
step(zoom(), format(<%- mbglExpressionTestValue(property, type) %>), 18.0, format(<%- mbglExpressionTestValue(property, type) %>))
|
||||
<% } else if (property.type === 'resolvedImage') { -%>
|
||||
step(zoom(), image(literal(<%- mbglExpressionTestValue(property, type) %>)), 18.0, image(literal(<%- mbglExpressionTestValue(property, type) %>)))
|
||||
<% } else { -%>
|
||||
step(zoom(), literal(<%- mbglExpressionTestValue(property, type) %>), 18.0, literal(<%- mbglExpressionTestValue(property, type) %>))
|
||||
<% } -%>
|
||||
@@ -179,6 +183,8 @@
|
||||
propertyValue = mbgl::style::PropertyExpression<<%- mbglType(property) %>>(
|
||||
<% if (property.type === 'formatted') { -%>
|
||||
format(toString(get(literal("token"))))
|
||||
<% } else if (property.type === 'resolvedImage') { -%>
|
||||
image(toString(get(literal("token"))))
|
||||
<% } else { -%>
|
||||
toString(get(literal("token")))
|
||||
<% } -%>
|
||||
@@ -192,6 +198,8 @@
|
||||
MGLAttributedExpression *tokenAttibutedExpression = [[MGLAttributedExpression alloc] initWithExpression:[NSExpression expressionWithFormat:@"CAST(token, 'NSString')"]
|
||||
attributes:@{}];
|
||||
NSExpression* tokenExpression = [NSExpression mgl_expressionForAttributedExpressions:@[[NSExpression expressionForConstantValue:tokenAttibutedExpression]]];
|
||||
<% } else if (property.type === 'resolvedImage') { -%>
|
||||
NSExpression* tokenExpression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('image', CAST(token, \"NSString\"))"];
|
||||
<% } else { -%>
|
||||
NSExpression* tokenExpression = [NSExpression expressionWithFormat:@"CAST(token, \"NSString\")"];
|
||||
<% } -%>
|
||||
|
||||
@@ -182,7 +182,7 @@
|
||||
@"icon-image should be unset initially.");
|
||||
NSExpression *defaultExpression = layer.iconImageName;
|
||||
|
||||
NSExpression *constantExpression = [NSExpression expressionWithFormat:@"Icon Image"];
|
||||
NSExpression *constantExpression = [NSExpression expressionForConstantValue:@"Icon Image"];
|
||||
layer.iconImageName = constantExpression;
|
||||
mbgl::style::PropertyValue<mbgl::style::expression::Image> propertyValue = { "Icon Image" };
|
||||
XCTAssertEqual(rawLayer->getIconImage(), propertyValue,
|
||||
@@ -190,14 +190,14 @@
|
||||
XCTAssertEqualObjects(layer.iconImageName, constantExpression,
|
||||
@"iconImageName should round-trip constant value expressions.");
|
||||
|
||||
constantExpression = [NSExpression expressionWithFormat:@"Icon Image"];
|
||||
constantExpression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('image', 'Icon Image')"];
|
||||
NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}];
|
||||
layer.iconImageName = functionExpression;
|
||||
|
||||
{
|
||||
using namespace mbgl::style::expression::dsl;
|
||||
propertyValue = mbgl::style::PropertyExpression<mbgl::style::expression::Image>(
|
||||
step(zoom(), literal("Icon Image"), 18.0, literal("Icon Image"))
|
||||
step(zoom(), image(literal("Icon Image")), 18.0, image(literal("Icon Image")))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -219,14 +219,14 @@
|
||||
{
|
||||
using namespace mbgl::style::expression::dsl;
|
||||
propertyValue = mbgl::style::PropertyExpression<mbgl::style::expression::Image>(
|
||||
toString(get(literal("token")))
|
||||
image(toString(get(literal("token"))))
|
||||
);
|
||||
}
|
||||
|
||||
XCTAssertEqual(rawLayer->getIconImage(), propertyValue,
|
||||
@"Setting iconImageName to a constant string with tokens should convert to an expression.");
|
||||
|
||||
NSExpression* tokenExpression = [NSExpression expressionWithFormat:@"CAST(token, \"NSString\")"];
|
||||
NSExpression* tokenExpression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('image', CAST(token, \"NSString\"))"];
|
||||
XCTAssertEqualObjects(layer.iconImageName, tokenExpression,
|
||||
@"Setting iconImageName to a constant string with tokens should convert to an expression.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user