summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnder Conselvan de Oliveira <ander.deoliveira@mapbox.com>2019-04-02 16:22:37 +0300
committerAnder Conselvan de Oliveira <ander.deoliveira@mapbox.com>2019-05-21 12:14:22 +0300
commitd502b7244970db52b1f823ade64ac5ded7c78144 (patch)
tree38a79cb427ec522559e6ac07e229e48b88402565
parent1e620d3bd890f7efdf76ce7bff4cf57d41570bb2 (diff)
downloadqtlocation-mapboxgl-d502b7244970db52b1f823ade64ac5ded7c78144.tar.gz
[core] Pass legacy/categorical/*-default expression tests
Handle categorical function default value properly in conversion to expreexpression so related tests pass.
-rw-r--r--platform/node/test/ignores.json6
-rw-r--r--src/mbgl/style/conversion/function.cpp40
2 files changed, 26 insertions, 20 deletions
diff --git a/platform/node/test/ignores.json b/platform/node/test/ignores.json
index ec79ed8987..14e12f87e4 100644
--- a/platform/node/test/ignores.json
+++ b/platform/node/test/ignores.json
@@ -5,16 +5,10 @@
"expression-tests/is-supported-script/default": "This tests RTL text plugin behavior specific to GL JS",
"expression-tests/resolved-locale/basic": "Even the 'en' locale may not be present on some test systems.",
"expression-tests/legacy/categorical/array": "https://github.com/mapbox/mapbox-gl-native/issues/12747",
- "expression-tests/legacy/categorical/array-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747",
"expression-tests/legacy/categorical/boolean": "https://github.com/mapbox/mapbox-gl-native/issues/12747",
- "expression-tests/legacy/categorical/boolean-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747",
"expression-tests/legacy/categorical/color": "https://github.com/mapbox/mapbox-gl-native/issues/12747",
- "expression-tests/legacy/categorical/color-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747",
"expression-tests/legacy/categorical/number": "https://github.com/mapbox/mapbox-gl-native/issues/12747",
- "expression-tests/legacy/categorical/number-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747",
"expression-tests/legacy/categorical/string": "https://github.com/mapbox/mapbox-gl-native/issues/12747",
- "expression-tests/legacy/categorical/string-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747",
- "expression-tests/legacy/categorical/tokens": "https://github.com/mapbox/mapbox-gl-native/issues/12747",
"expression-tests/legacy/exponential/color-hcl": "https://github.com/mapbox/mapbox-gl-native/issues/12747",
"expression-tests/legacy/exponential/color-lab": "https://github.com/mapbox/mapbox-gl-native/issues/12747",
"expression-tests/legacy/identity/color-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747",
diff --git a/src/mbgl/style/conversion/function.cpp b/src/mbgl/style/conversion/function.cpp
index f00aa670b1..e6d23268ba 100644
--- a/src/mbgl/style/conversion/function.cpp
+++ b/src/mbgl/style/conversion/function.cpp
@@ -449,16 +449,25 @@ static std::unique_ptr<Expression> interpolate(type::Type type, Interpolator int
}
template <class T>
-std::unique_ptr<Expression> categorical(type::Type type, const std::string& property, std::map<T, std::unique_ptr<Expression>> branches) {
+std::unique_ptr<Expression> categorical(type::Type type,
+ const std::string& property,
+ std::map<T, std::unique_ptr<Expression>> branches,
+ optional<std::unique_ptr<Expression>> def) {
std::unordered_map<T, std::shared_ptr<Expression>> convertedBranches;
for (auto& b : branches) {
convertedBranches[b.first] = std::move(b.second);
}
- return std::make_unique<Match<T>>(type, get(literal(property)), std::move(convertedBranches), error("replaced with default"));
+ return std::make_unique<Match<T>>(type,
+ get(literal(property)),
+ std::move(convertedBranches),
+ def ? std::move(*def) : error("replaced with default"));
}
template <>
-std::unique_ptr<Expression> categorical<bool>(type::Type type, const std::string& property, std::map<bool, std::unique_ptr<Expression>> branches) {
+std::unique_ptr<Expression> categorical<bool>(type::Type type,
+ const std::string& property,
+ std::map<bool, std::unique_ptr<Expression>> branches,
+ optional<std::unique_ptr<Expression>> def) {
auto it = branches.find(true);
std::unique_ptr<Expression> trueCase = it == branches.end() ?
error("replaced with default") :
@@ -469,10 +478,12 @@ std::unique_ptr<Expression> categorical<bool>(type::Type type, const std::string
error("replaced with default") :
std::move(it->second);
- std::vector<typename Case::Branch> trueBranch;
- trueBranch.emplace_back(get(literal(property)), std::move(trueCase));
+ std::vector<typename Case::Branch> convertedBranches;
+ convertedBranches.emplace_back(eq(get(literal(property)), literal(Value(true))), std::move(trueCase));
+ convertedBranches.emplace_back(eq(get(literal(property)), literal(Value(false))), std::move(falseCase));
- return std::make_unique<Case>(type, std::move(trueBranch), std::move(falseCase));
+ return std::make_unique<Case>(type, std::move(convertedBranches),
+ def ? std::move(*def) : error("replaced with default"));
}
static std::unique_ptr<Expression> numberOrDefault(type::Type type,
@@ -531,7 +542,8 @@ static optional<std::unique_ptr<Expression>> convertExponentialFunction(type::Ty
static optional<std::unique_ptr<Expression>> convertCategoricalFunction(type::Type type,
const Convertible& value,
Error& err,
- const std::string& property) {
+ const std::string& property,
+ optional<std::unique_ptr<Expression>> def) {
auto stopsValue = objectMember(value, "stops");
if (!stopsValue) {
err.message = "function value must specify stops";
@@ -565,7 +577,7 @@ static optional<std::unique_ptr<Expression>> convertCategoricalFunction(type::Ty
if (!branches) {
return nullopt;
}
- return categorical(type, property, std::move(*branches));
+ return categorical(type, property, std::move(*branches), std::move(def));
}
if (toNumber(arrayMember(first, 0))) {
@@ -573,7 +585,7 @@ static optional<std::unique_ptr<Expression>> convertCategoricalFunction(type::Ty
if (!branches) {
return nullopt;
}
- return categorical(type, property, std::move(*branches));
+ return categorical(type, property, std::move(*branches), std::move(def));
}
if (toString(arrayMember(first, 0))) {
@@ -581,7 +593,7 @@ static optional<std::unique_ptr<Expression>> convertCategoricalFunction(type::Ty
if (!branches) {
return nullopt;
}
- return categorical(type, property, std::move(*branches));
+ return categorical(type, property, std::move(*branches), std::move(def));
}
err.message = "stop domain value must be a number, string, or boolean";
@@ -803,7 +815,7 @@ optional<std::unique_ptr<Expression>> convertFunctionToExpression(type::Type typ
case FunctionType::Exponential:
return convertExponentialFunction(type, value, err, getProperty, defaultExpr());
case FunctionType::Categorical:
- return convertCategoricalFunction(type, value, err, *property);
+ return convertCategoricalFunction(type, value, err, *property, defaultExpr());
default:
err.message = "unsupported function type";
return nullopt;
@@ -820,7 +832,7 @@ optional<std::unique_ptr<Expression>> convertFunctionToExpression(type::Type typ
switch (functionType) {
case FunctionType::Categorical:
return composite<bool>(type, value, err, [&] (type::Type type_, double, std::map<bool, std::unique_ptr<Expression>> stops) {
- return categorical<bool>(type_, *property, std::move(stops));
+ return categorical<bool>(type_, *property, std::move(stops), defaultExpr());
});
default:
err.message = "unsupported function type";
@@ -847,7 +859,7 @@ optional<std::unique_ptr<Expression>> convertFunctionToExpression(type::Type typ
});
case FunctionType::Categorical:
return composite<int64_t>(type, value, err, [&] (type::Type type_, double, std::map<int64_t, std::unique_ptr<Expression>> stops) {
- return categorical<int64_t>(type_, *property, std::move(stops));
+ return categorical<int64_t>(type_, *property, std::move(stops), defaultExpr());
});
default:
err.message = "unsupported function type";
@@ -859,7 +871,7 @@ optional<std::unique_ptr<Expression>> convertFunctionToExpression(type::Type typ
switch (functionType) {
case FunctionType::Categorical:
return composite<std::string>(type, value, err, [&] (type::Type type_, double, std::map<std::string, std::unique_ptr<Expression>> stops) {
- return categorical<std::string>(type_, *property, std::move(stops));
+ return categorical<std::string>(type_, *property, std::move(stops), defaultExpr());
});
default:
err.message = "unsupported function type";