[core] Fix most identity function with default legacy expression tests
Add handling of default value to the conversion of legacy identity functions. The color and enum tests still don't pass though.
This commit is contained in:
@@ -660,6 +660,11 @@ optional<std::unique_ptr<Expression>> convertFunctionToExpression(type::Type typ
|
||||
}
|
||||
}
|
||||
|
||||
optional<std::unique_ptr<Expression>> defaultExpr;
|
||||
if (objectMember(value, "default")) {
|
||||
defaultExpr = convertLiteral(type, *objectMember(value, "default"), err);
|
||||
}
|
||||
|
||||
if (!objectMember(value, "property")) {
|
||||
// Camera function.
|
||||
switch (functionType) {
|
||||
@@ -688,22 +693,22 @@ optional<std::unique_ptr<Expression>> convertFunctionToExpression(type::Type typ
|
||||
if (functionType == FunctionType::Identity) {
|
||||
return type.match(
|
||||
[&] (const type::StringType&) -> optional<std::unique_ptr<Expression>> {
|
||||
return string(get(literal(*property)));
|
||||
return string(get(literal(*property)), std::move(defaultExpr));
|
||||
},
|
||||
[&] (const type::NumberType&) -> optional<std::unique_ptr<Expression>> {
|
||||
return number(get(literal(*property)));
|
||||
return number(get(literal(*property)), std::move(defaultExpr));
|
||||
},
|
||||
[&] (const type::BooleanType&) -> optional<std::unique_ptr<Expression>> {
|
||||
return boolean(get(literal(*property)));
|
||||
return boolean(get(literal(*property)), std::move(defaultExpr));
|
||||
},
|
||||
[&] (const type::ColorType&) -> optional<std::unique_ptr<Expression>> {
|
||||
return toColor(get(literal(*property)));
|
||||
return toColor(get(literal(*property)), std::move(defaultExpr));
|
||||
},
|
||||
[&] (const type::Array& array) -> optional<std::unique_ptr<Expression>> {
|
||||
return assertion(array, get(literal(*property)));
|
||||
return assertion(array, get(literal(*property)), std::move(defaultExpr));
|
||||
},
|
||||
[&] (const type::FormattedType&) -> optional<std::unique_ptr<Expression>> {
|
||||
return format(get(literal(*property)));
|
||||
return toFormatted(get(literal(*property)), std::move(defaultExpr));
|
||||
},
|
||||
[&] (const auto&) -> optional<std::unique_ptr<Expression>> {
|
||||
assert(false); // No properties use this type.
|
||||
|
||||
@@ -54,32 +54,54 @@ std::unique_ptr<Expression> literal(std::initializer_list<const char *> value) {
|
||||
return literal(values);
|
||||
}
|
||||
|
||||
std::unique_ptr<Expression> assertion(type::Type type, std::unique_ptr<Expression> value) {
|
||||
return std::make_unique<Assertion>(type, vec(std::move(value)));
|
||||
std::unique_ptr<Expression> assertion(type::Type type,
|
||||
std::unique_ptr<Expression> value,
|
||||
optional<std::unique_ptr<Expression>> def) {
|
||||
std::vector<std::unique_ptr<Expression>> v = vec(std::move(value));
|
||||
if (def) {
|
||||
v.push_back(std::move(*def));
|
||||
}
|
||||
return std::make_unique<Assertion>(type, std::move(v));
|
||||
}
|
||||
|
||||
std::unique_ptr<Expression> number(std::unique_ptr<Expression> value) {
|
||||
return assertion(type::Number, std::move(value));
|
||||
std::unique_ptr<Expression> number(std::unique_ptr<Expression> value,
|
||||
optional<std::unique_ptr<Expression>> def) {
|
||||
return assertion(type::Number, std::move(value), std::move(def));
|
||||
}
|
||||
|
||||
std::unique_ptr<Expression> string(std::unique_ptr<Expression> value) {
|
||||
return assertion(type::String, std::move(value));
|
||||
std::unique_ptr<Expression> string(std::unique_ptr<Expression> value,
|
||||
optional<std::unique_ptr<Expression>> def) {
|
||||
return assertion(type::String, std::move(value), std::move(def));
|
||||
}
|
||||
|
||||
std::unique_ptr<Expression> boolean(std::unique_ptr<Expression> value) {
|
||||
return assertion(type::Boolean, std::move(value));
|
||||
std::unique_ptr<Expression> boolean(std::unique_ptr<Expression> value,
|
||||
optional<std::unique_ptr<Expression>> def) {
|
||||
return assertion(type::Boolean, std::move(value), std::move(def));
|
||||
}
|
||||
|
||||
std::unique_ptr<Expression> toColor(std::unique_ptr<Expression> value) {
|
||||
return std::make_unique<Coercion>(type::Color, vec(std::move(value)));
|
||||
std::unique_ptr<Expression> coercion(type::Type type,
|
||||
std::unique_ptr<Expression> value,
|
||||
optional<std::unique_ptr<Expression>> def) {
|
||||
std::vector<std::unique_ptr<Expression>> v = vec(std::move(value));
|
||||
if (def) {
|
||||
v.push_back(std::move(*def));
|
||||
}
|
||||
return std::make_unique<Coercion>(type, std::move(v));
|
||||
}
|
||||
|
||||
std::unique_ptr<Expression> toString(std::unique_ptr<Expression> value) {
|
||||
return std::make_unique<Coercion>(type::String, vec(std::move(value)));
|
||||
std::unique_ptr<Expression> toColor(std::unique_ptr<Expression> value,
|
||||
optional<std::unique_ptr<Expression>> def) {
|
||||
return coercion(type::Color, std::move(value), std::move(def));
|
||||
}
|
||||
|
||||
std::unique_ptr<Expression> toFormatted(std::unique_ptr<Expression> value) {
|
||||
return std::make_unique<Coercion>(type::Formatted, vec(std::move(value)));
|
||||
std::unique_ptr<Expression> toString(std::unique_ptr<Expression> value,
|
||||
optional<std::unique_ptr<Expression>> def) {
|
||||
return coercion(type::String, std::move(value), std::move(def));
|
||||
}
|
||||
|
||||
std::unique_ptr<Expression> toFormatted(std::unique_ptr<Expression> value,
|
||||
optional<std::unique_ptr<Expression>> def) {
|
||||
return coercion(type::Formatted, std::move(value), std::move(def));
|
||||
}
|
||||
|
||||
std::unique_ptr<Expression> get(const char* value) {
|
||||
|
||||
Reference in New Issue
Block a user