mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-22 12:59:07 -06:00
Add ability to StringVerifier to test for non-emptiness
This commit is contained in:
@@ -156,7 +156,17 @@ struct IntVerifier : public TemplateVerifier<int> {
|
||||
* <code>std::string</code>. No implicit conversion is considered in this testing.
|
||||
*/
|
||||
struct StringVerifier : public TemplateVerifier<std::string> {
|
||||
StringVerifier(bool mustBeNotEmpty = false);
|
||||
|
||||
TestResult operator()(const ghoul::Dictionary& dictionary,
|
||||
const std::string& key) const override;
|
||||
|
||||
std::string type() const override;
|
||||
|
||||
bool mustBeNotEmpty() const;
|
||||
|
||||
private:
|
||||
bool _mustBeNotEmpty = false;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -174,6 +174,33 @@ std::string IntVerifier::type() const {
|
||||
return "Integer";
|
||||
}
|
||||
|
||||
StringVerifier::StringVerifier(bool mustBeNotEmpty)
|
||||
: TemplateVerifier<std::string>()
|
||||
, _mustBeNotEmpty(mustBeNotEmpty)
|
||||
{}
|
||||
|
||||
TestResult StringVerifier::operator()(const ghoul::Dictionary& dictionary,
|
||||
const std::string& key) const
|
||||
{
|
||||
TestResult res = TemplateVerifier<std::string>::operator()(dictionary, key);
|
||||
if (!res.success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string value = dictionary.value<std::string>(key);
|
||||
if (value.empty() && _mustBeNotEmpty) {
|
||||
res.success = false;
|
||||
res.offenses.push_back({
|
||||
key, TestResult::Offense::Reason::Verification, "value must not be empty"
|
||||
});
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
bool StringVerifier::mustBeNotEmpty() const {
|
||||
return _mustBeNotEmpty;
|
||||
}
|
||||
|
||||
std::string StringVerifier::type() const {
|
||||
return "String";
|
||||
}
|
||||
|
||||
@@ -103,7 +103,6 @@ std::unique_ptr<ghoul::logging::Log> createLog(const ghoul::Dictionary& dictiona
|
||||
bool dateStamp = p.dateStamping.value_or(true);
|
||||
bool categoryStamp = p.categoryStamping.value_or(true);
|
||||
bool logLevelStamp = p.logLevelStamping.value_or(true);
|
||||
Parameters::LogLevel logLevel = p.logLevel.value_or(Parameters::LogLevel::AllLogging);
|
||||
ghoul::logging::LogLevel level = [](Parameters::LogLevel l) {
|
||||
switch (l) {
|
||||
case Parameters::LogLevel::AllLogging:
|
||||
|
||||
Reference in New Issue
Block a user