From 09c1b4be6d0edd76d9fa2d2e6703a4b3d85fe05b Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Wed, 14 Sep 2016 16:38:58 +0200 Subject: [PATCH] Add unit test to check nested optional/required combinations --- tests/test_documentation.inl | 64 ++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/tests/test_documentation.inl b/tests/test_documentation.inl index dfe11b297a..0ee05b4dfe 100644 --- a/tests/test_documentation.inl +++ b/tests/test_documentation.inl @@ -516,8 +516,8 @@ TEST_F(DocumentationTest, Optional) { using namespace openspace::documentation; Documentation doc { - { "Bool_Force", new BoolVerifier, Optional::No }, - { "Bool_Optional", new BoolVerifier, Optional::Yes } + { "Bool_Force", new BoolVerifier, "", Optional::No }, + { "Bool_Optional", new BoolVerifier, "", Optional::Yes } }; ghoul::Dictionary positive { @@ -560,6 +560,66 @@ TEST_F(DocumentationTest, Optional) { EXPECT_EQ("Bool_Optional", negativeRes.offenders[0]); } +TEST_F(DocumentationTest, RequiredInOptional) { + using namespace openspace::documentation; + + Documentation doc { + { + "a", + new TableVerifier({ + { + "b", + new IntVerifier + }, + { + "c", + new IntVerifier, + "", + Optional::Yes + } + }), + "", + Optional::Yes + } + }; + + ghoul::Dictionary positive { + { + "a", ghoul::Dictionary{ + { "b", 1 } + } + } + }; + TestResult positiveRes = testSpecification(doc, positive); + EXPECT_TRUE(positiveRes.success); + EXPECT_EQ(0, positiveRes.offenders.size()); + + ghoul::Dictionary positive2 { + { + "a", ghoul::Dictionary{ + { "b", 1 }, + { "c", 2 } + } + } + }; + positiveRes = testSpecification(doc, positive2); + EXPECT_TRUE(positiveRes.success); + EXPECT_EQ(0, positiveRes.offenders.size()); + + ghoul::Dictionary positive3 {}; + positiveRes = testSpecification(doc, positive3); + EXPECT_TRUE(positiveRes.success); + EXPECT_EQ(0, positiveRes.offenders.size()); + + ghoul::Dictionary negative { + { "a", ghoul::Dictionary{ { "c", 2 }}} + }; + TestResult negativeRes = testSpecification(doc, negative); + EXPECT_FALSE(negativeRes.success); + ASSERT_EQ(1, negativeRes.offenders.size()); + EXPECT_EQ("a.b", negativeRes.offenders[0]); +} + TEST_F(DocumentationTest, LessInt) { using namespace openspace::documentation;