mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-06 19:50:03 -06:00
Add and and or verifiers that combine multiple verifiers
This commit is contained in:
@@ -273,6 +273,30 @@ struct AnnotationVerifier : public T {
|
||||
std::string annotation;
|
||||
};
|
||||
|
||||
// Boolean Verifiers
|
||||
|
||||
struct AndVerifier : public Verifier {
|
||||
AndVerifier(Verifier* a, Verifier* b);
|
||||
|
||||
bool test(const ghoul::Dictionary& dict, const std::string& key) const override;
|
||||
|
||||
std::string documentation() const override;
|
||||
|
||||
std::shared_ptr<Verifier> a;
|
||||
std::shared_ptr<Verifier> b;
|
||||
};
|
||||
|
||||
struct OrVerifier : public Verifier {
|
||||
OrVerifier(Verifier* a, Verifier* b);
|
||||
|
||||
bool test(const ghoul::Dictionary& dict, const std::string& key) const override;
|
||||
|
||||
std::string documentation() const override;
|
||||
|
||||
std::shared_ptr<Verifier> a;
|
||||
std::shared_ptr<Verifier> b;
|
||||
};
|
||||
|
||||
using IntLessVerifier = LessVerifier<IntVerifier>;
|
||||
using DoubleLessVerifier = LessVerifier<DoubleVerifier>;
|
||||
using IntLessEqualVerifier = LessEqualVerifier<IntVerifier>;
|
||||
|
||||
@@ -235,5 +235,30 @@ std::string TableVerifier::documentation() const {
|
||||
return "Type: Table" + '\n' + generateDocumentation(doc);
|
||||
}
|
||||
|
||||
AndVerifier::AndVerifier(Verifier* a, Verifier* b)
|
||||
: a(a)
|
||||
, b(b) {}
|
||||
|
||||
bool AndVerifier::test(const ghoul::Dictionary& dict, const std::string& key) const {
|
||||
return a->test(dict, key) && b->test(dict, key);
|
||||
}
|
||||
|
||||
std::string AndVerifier::documentation() const {
|
||||
return a->documentation() + " and " + b->documentation();
|
||||
}
|
||||
|
||||
OrVerifier::OrVerifier(Verifier* a, Verifier* b)
|
||||
: a(a)
|
||||
, b(b)
|
||||
{}
|
||||
|
||||
bool OrVerifier::test(const ghoul::Dictionary& dict, const std::string& key) const {
|
||||
return a->test(dict, key) || b->test(dict, key);
|
||||
}
|
||||
|
||||
std::string OrVerifier::documentation() const {
|
||||
return a->documentation() + " or " + b->documentation();
|
||||
}
|
||||
|
||||
} // namespace documentation
|
||||
} // namespace openspace
|
||||
|
||||
@@ -1648,3 +1648,68 @@ TEST_F(DocumentationTest, WildcardMixed) {
|
||||
EXPECT_EQ("a", negativeRes.offenders[0]);
|
||||
EXPECT_EQ("c", negativeRes.offenders[1]);
|
||||
}
|
||||
|
||||
TEST_F(DocumentationTest, AndOperator) {
|
||||
using namespace openspace::documentation;
|
||||
|
||||
Documentation doc {
|
||||
{ "a", new AndVerifier(
|
||||
new IntGreaterEqualVerifier(2), new IntLessEqualVerifier(5)
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
ghoul::Dictionary positive {
|
||||
{ "a", 4 }
|
||||
};
|
||||
TestResult positiveRes = testSpecification(doc, positive);
|
||||
EXPECT_TRUE(positiveRes.success);
|
||||
EXPECT_EQ(0, positiveRes.offenders.size());
|
||||
|
||||
ghoul::Dictionary negative {
|
||||
{ "a", 0 }
|
||||
};
|
||||
TestResult negativeRes = testSpecification(doc, negative);
|
||||
EXPECT_FALSE(negativeRes.success);
|
||||
ASSERT_EQ(1, negativeRes.offenders.size());
|
||||
EXPECT_EQ("a", negativeRes.offenders[0]);
|
||||
|
||||
ghoul::Dictionary negative2 {
|
||||
{ "a", 8 }
|
||||
};
|
||||
negativeRes = testSpecification(doc, negative2);
|
||||
EXPECT_FALSE(negativeRes.success);
|
||||
ASSERT_EQ(1, negativeRes.offenders.size());
|
||||
EXPECT_EQ("a", negativeRes.offenders[0]);
|
||||
}
|
||||
|
||||
TEST_F(DocumentationTest, OrOperator) {
|
||||
using namespace openspace::documentation;
|
||||
using namespace std::string_literals;
|
||||
|
||||
Documentation doc {
|
||||
{ "a", new OrVerifier(new StringVerifier, new IntVerifier)}
|
||||
};
|
||||
|
||||
ghoul::Dictionary positive {
|
||||
{ "a", ""s}
|
||||
};
|
||||
TestResult positiveRes = testSpecification(doc, positive);
|
||||
EXPECT_TRUE(positiveRes.success);
|
||||
EXPECT_EQ(0, positiveRes.offenders.size());
|
||||
|
||||
ghoul::Dictionary positive2 {
|
||||
{ "a", 1 }
|
||||
};
|
||||
positiveRes = testSpecification(doc, positive2);
|
||||
EXPECT_TRUE(positiveRes.success);
|
||||
EXPECT_EQ(0, positiveRes.offenders.size());
|
||||
|
||||
ghoul::Dictionary negative {
|
||||
{ "a", false }
|
||||
};
|
||||
TestResult negativeRes = testSpecification(doc, negative);
|
||||
EXPECT_FALSE(negativeRes.success);
|
||||
ASSERT_EQ(1, negativeRes.offenders.size());
|
||||
EXPECT_EQ("a", negativeRes.offenders[0]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user