Use std::optional instead of mbgl::optional (#911)
This commit is contained in:
@@ -75,7 +75,7 @@ std::string toString(const JSValue& value) {
|
||||
return { value.GetString(), value.GetStringLength() };
|
||||
}
|
||||
|
||||
optional<Value> toValue(const JSValue& jsvalue) {
|
||||
std::optional<Value> toValue(const JSValue& jsvalue) {
|
||||
if (jsvalue.IsNull()) {
|
||||
return Value{};
|
||||
}
|
||||
@@ -105,7 +105,7 @@ optional<Value> toValue(const JSValue& jsvalue) {
|
||||
return toValue(Convertible(&jsvalue));
|
||||
}
|
||||
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
style::expression::type::Type stringToType(const std::string& type) {
|
||||
@@ -133,7 +133,7 @@ style::expression::type::Type stringToType(const std::string& type) {
|
||||
return type::Null;
|
||||
}
|
||||
|
||||
optional<style::expression::type::Type> toExpressionType(const PropertySpec& spec) {
|
||||
std::optional<style::expression::type::Type> toExpressionType(const PropertySpec& spec) {
|
||||
using namespace style::expression;
|
||||
if (spec.type == "array") {
|
||||
type::Type itemType = spec.value.empty() ? type::Value : stringToType(spec.value);
|
||||
@@ -147,7 +147,7 @@ optional<style::expression::type::Type> toExpressionType(const PropertySpec& spe
|
||||
return {type::String};
|
||||
}
|
||||
|
||||
return spec.type.empty() ? nullopt : optional<type::Type>{stringToType(spec.type)};
|
||||
return spec.type.empty() ? std::nullopt : std::optional<type::Type>{stringToType(spec.type)};
|
||||
}
|
||||
|
||||
void parseCompiled(const JSValue& compiledValue, TestData& data) {
|
||||
@@ -246,7 +246,7 @@ bool parseInputs(const JSValue& inputsValue, TestData& data) {
|
||||
assert(input[1].IsObject());
|
||||
|
||||
// Parse evaluation context, zoom.
|
||||
optional<float> zoom;
|
||||
std::optional<float> zoom;
|
||||
const auto& evaluationContext = input[0].GetObject();
|
||||
if (evaluationContext.HasMember("zoom")) {
|
||||
assert(evaluationContext["zoom"].IsNumber());
|
||||
@@ -254,14 +254,14 @@ bool parseInputs(const JSValue& inputsValue, TestData& data) {
|
||||
}
|
||||
|
||||
// Parse heatmap density
|
||||
optional<double> heatmapDensity;
|
||||
std::optional<double> heatmapDensity;
|
||||
if (evaluationContext.HasMember("heatmapDensity")) {
|
||||
assert(evaluationContext["heatmapDensity"].IsNumber());
|
||||
heatmapDensity = evaluationContext["heatmapDensity"].GetDouble();
|
||||
}
|
||||
|
||||
// Parse canonicalID
|
||||
optional<CanonicalTileID> canonical;
|
||||
std::optional<CanonicalTileID> canonical;
|
||||
if (evaluationContext.HasMember("canonicalID")) {
|
||||
const auto& canonicalIDObject = evaluationContext["canonicalID"];
|
||||
assert(canonicalIDObject.IsObject());
|
||||
@@ -344,7 +344,7 @@ std::tuple<filesystem::path, std::vector<filesystem::path>, bool, uint32_t> pars
|
||||
|
||||
filesystem::path rootPath {std::string(TEST_RUNNER_ROOT_PATH).append("/maplibre-gl-js/test/integration/expression-tests")};
|
||||
if (!filesystem::exists(rootPath)) {
|
||||
Log::Error(Event::General, "Test path '%s' does not exist.", rootPath.string().c_str());
|
||||
Log::Error(Event::General, "Test path '" + rootPath.string() + "' does not exist.");
|
||||
exit(3);
|
||||
}
|
||||
|
||||
@@ -363,7 +363,7 @@ std::tuple<filesystem::path, std::vector<filesystem::path>, bool, uint32_t> pars
|
||||
testPaths.reserve(paths.size());
|
||||
for (const auto& path : paths) {
|
||||
if (!filesystem::exists(path)) {
|
||||
Log::Warning(Event::General, "Provided test folder '%s' does not exist.", path.string().c_str());
|
||||
Log::Warning(Event::General, "Provided test folder '" + path.string() + "' does not exist.");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -404,20 +404,20 @@ Ignores parseExpressionIgnores() {
|
||||
return ignores;
|
||||
}
|
||||
|
||||
optional<TestData> parseTestData(const filesystem::path& path) {
|
||||
std::optional<TestData> parseTestData(const filesystem::path& path) {
|
||||
TestData data;
|
||||
auto maybeJson = readJson(path.string());
|
||||
if (!maybeJson.is<JSDocument>()) { // NOLINT
|
||||
Log::Error(Event::General, "Cannot parse test '%s'.", path.string().c_str());
|
||||
return nullopt;
|
||||
mbgl::Log::Error(mbgl::Event::General, "Cannot parse test '" + path.string() + "'.");
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
data.document = std::move(maybeJson.get<JSDocument>());
|
||||
|
||||
// Check that mandatory test data members are present.
|
||||
if (!data.document.HasMember("expression") || !data.document.HasMember("expected")) {
|
||||
Log::Error(Event::General, "Test fixture '%s' does not contain required data.", path.string().c_str());
|
||||
return nullopt;
|
||||
Log::Error(Event::General, "Test fixture '" + path.string() + "' does not contain required data.");
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Parse propertySpec
|
||||
@@ -431,8 +431,8 @@ optional<TestData> parseTestData(const filesystem::path& path) {
|
||||
|
||||
// Parse inputs
|
||||
if (data.document.HasMember("inputs") && !parseInputs(data.document["inputs"], data)) {
|
||||
Log::Error(Event::General,"Can't convert inputs value for '%s'", path.string().c_str());
|
||||
return nullopt;
|
||||
Log::Error(Event::General, std::string("Can't convert inputs value for '") + path.string() + "'");
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return {std::move(data)};
|
||||
@@ -471,14 +471,14 @@ Value toValue(const Compiled& compiled) {
|
||||
// Serializes native expression types to JS format.
|
||||
// Color and Formatted are exceptions.
|
||||
// TODO: harmonize serialized format to remove this conversion.
|
||||
optional<Value> toValue(const expression::Value& exprValue) {
|
||||
std::optional<Value> toValue(const expression::Value& exprValue) {
|
||||
return exprValue.match(
|
||||
[](const Color& c) -> optional<Value> {
|
||||
[](const Color& c) -> std::optional<Value> {
|
||||
std::vector<Value> color { static_cast<double>(c.r), static_cast<double>(c.g), static_cast<double>(c.b), static_cast<double>(c.a) };
|
||||
return {Value{std::move(color)}};
|
||||
},
|
||||
[](const expression::Formatted& formatted) -> optional<Value> { return {formatted.toObject()}; },
|
||||
[](const std::vector<expression::Value>& values) -> optional<Value> {
|
||||
[](const expression::Formatted& formatted) -> std::optional<Value> { return {formatted.toObject()}; },
|
||||
[](const std::vector<expression::Value>& values) -> std::optional<Value> {
|
||||
std::vector<Value> mbglValues;
|
||||
for (const auto& value : values) {
|
||||
if (auto converted = expression::fromExpressionValue<Value>(value)) {
|
||||
@@ -487,7 +487,7 @@ optional<Value> toValue(const expression::Value& exprValue) {
|
||||
}
|
||||
return {Value{std::move(mbglValues)}};
|
||||
},
|
||||
[](const std::unordered_map<std::string, expression::Value>& valueMap) -> optional<Value> {
|
||||
[](const std::unordered_map<std::string, expression::Value>& valueMap) -> std::optional<Value> {
|
||||
std::unordered_map<std::string, Value> mbglValueMap;
|
||||
for (const auto& pair : valueMap) {
|
||||
if (auto converted = expression::fromExpressionValue<Value>(pair.second)) {
|
||||
@@ -500,9 +500,9 @@ optional<Value> toValue(const expression::Value& exprValue) {
|
||||
}
|
||||
|
||||
std::unique_ptr<style::expression::Expression> parseExpression(const JSValue& value,
|
||||
optional<PropertySpec>& spec,
|
||||
std::optional<PropertySpec>& spec,
|
||||
TestResult& result) {
|
||||
optional<style::expression::type::Type> expected = spec ? toExpressionType(*spec) : nullopt;
|
||||
std::optional<style::expression::type::Type> expected = spec ? toExpressionType(*spec) : std::nullopt;
|
||||
expression::ParsingContext ctx = expected ? expression::ParsingContext(*expected) :
|
||||
expression::ParsingContext();
|
||||
Convertible convertible(&value);
|
||||
@@ -538,8 +538,8 @@ std::unique_ptr<style::expression::Expression> parseExpression(const JSValue& va
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<style::expression::Expression> parseExpression(const optional<Value>& value,
|
||||
optional<PropertySpec>& spec,
|
||||
std::unique_ptr<style::expression::Expression> parseExpression(const std::optional<Value>& value,
|
||||
std::optional<PropertySpec>& spec,
|
||||
TestResult& result) {
|
||||
assert(value);
|
||||
auto document = toDocument(*value);
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#include <mbgl/style/expression/expression.hpp>
|
||||
#include <mbgl/util/feature.hpp>
|
||||
#include <mbgl/util/optional.hpp>
|
||||
#include <mbgl/util/rapidjson.hpp>
|
||||
|
||||
#include <set>
|
||||
@@ -14,9 +13,9 @@
|
||||
using namespace mbgl;
|
||||
|
||||
struct Input {
|
||||
Input(optional<float> zoom_,
|
||||
optional<double> heatmapDensity_,
|
||||
optional<CanonicalTileID> canonical_,
|
||||
Input(std::optional<float> zoom_,
|
||||
std::optional<double> heatmapDensity_,
|
||||
std::optional<CanonicalTileID> canonical_,
|
||||
std::set<std::string> availableImages_,
|
||||
Feature feature_)
|
||||
: zoom(std::move(zoom_)),
|
||||
@@ -24,9 +23,9 @@ struct Input {
|
||||
canonical(std::move(canonical_)),
|
||||
availableImages(std::move(availableImages_)),
|
||||
feature(std::move(feature_)) {}
|
||||
optional<float> zoom;
|
||||
optional<double> heatmapDensity;
|
||||
optional<CanonicalTileID> canonical;
|
||||
std::optional<float> zoom;
|
||||
std::optional<double> heatmapDensity;
|
||||
std::optional<CanonicalTileID> canonical;
|
||||
std::set<std::string> availableImages;
|
||||
Feature feature;
|
||||
};
|
||||
@@ -50,9 +49,9 @@ struct Compiled {
|
||||
|
||||
struct TestResult {
|
||||
Compiled compiled;
|
||||
optional<Value> expression;
|
||||
optional<Value> outputs;
|
||||
optional<Value> serialized;
|
||||
std::optional<Value> expression;
|
||||
std::optional<Value> outputs;
|
||||
std::optional<Value> serialized;
|
||||
};
|
||||
|
||||
struct PropertySpec {
|
||||
@@ -60,7 +59,7 @@ struct PropertySpec {
|
||||
std::string value;
|
||||
std::size_t length = 0;
|
||||
bool isDataDriven = false;
|
||||
optional<Value> expression;
|
||||
std::optional<Value> expression;
|
||||
};
|
||||
|
||||
class TestData {
|
||||
@@ -69,7 +68,7 @@ public:
|
||||
TestResult expected;
|
||||
TestResult result;
|
||||
TestResult recompiled;
|
||||
optional<PropertySpec> spec;
|
||||
std::optional<PropertySpec> spec;
|
||||
JSDocument document;
|
||||
};
|
||||
|
||||
@@ -87,17 +86,17 @@ Arguments parseArguments(int argc, char** argv);
|
||||
|
||||
using Ignores = std::vector<Ignore>;
|
||||
Ignores parseExpressionIgnores();
|
||||
optional<TestData> parseTestData(const filesystem::path&);
|
||||
std::optional<TestData> parseTestData(const filesystem::path&);
|
||||
|
||||
std::string toJSON(const Value& value, unsigned indent = 0, bool singleLine = false);
|
||||
JSDocument toDocument(const Value&);
|
||||
Value toValue(const Compiled&);
|
||||
optional<Value> toValue(const style::expression::Value&);
|
||||
std::optional<Value> toValue(const style::expression::Value&);
|
||||
|
||||
std::unique_ptr<style::expression::Expression> parseExpression(const JSValue&,
|
||||
optional<PropertySpec>&,
|
||||
std::optional<PropertySpec>&,
|
||||
TestResult&);
|
||||
std::unique_ptr<style::expression::Expression> parseExpression(const optional<Value>&,
|
||||
optional<PropertySpec>&,
|
||||
std::unique_ptr<style::expression::Expression> parseExpression(const std::optional<Value>&,
|
||||
std::optional<PropertySpec>&,
|
||||
TestResult&);
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ try {
|
||||
ignoreReason = (*it).reason;
|
||||
}
|
||||
|
||||
optional<TestRunOutput> testRun;
|
||||
std::optional<TestRunOutput> testRun;
|
||||
if (auto testData = parseTestData(path)) {
|
||||
testRun = runExpressionTest(*testData, rootPath.string(), id);
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ bool deepEqual(const Value& a, const Value& b) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool deepEqual(const optional<Value>& a, const optional<Value>& b) {
|
||||
bool deepEqual(const std::optional<Value>& a, const std::optional<Value>& b) {
|
||||
if ((a && !b) || (!a && b)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -10,4 +10,4 @@ using namespace mbgl;
|
||||
Value stripPrecision(const Value& value);
|
||||
std::vector<std::string> tokenize(std::string str);
|
||||
bool deepEqual(const Value& a, const Value& b);
|
||||
bool deepEqual(const optional<Value>& a, const optional<Value>& b);
|
||||
bool deepEqual(const std::optional<Value>& a, const std::optional<Value>& b);
|
||||
|
||||
Reference in New Issue
Block a user