Add ability to StringVerifier to test for non-emptiness

This commit is contained in:
Alexander Bock
2021-03-23 00:09:02 +01:00
parent 45b2d0e014
commit 196a98b0c6
3 changed files with 37 additions and 1 deletions

View File

@@ -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;
};
/**

View File

@@ -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";
}

View File

@@ -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: