#include #include "fgc/HelpText.h" #include using namespace fgc; namespace { std::string join(const std::vector& v) { std::string s; for (const auto& l : v) s += l + "\n"; return s; } } // namespace TEST_CASE("helpCatalog is well-formed") { const auto& cat = helpCatalog(); REQUIRE_FALSE(cat.empty()); for (const auto& sec : cat) { CHECK_FALSE(sec.title.empty()); CHECK_FALSE(sec.entries.empty()); for (const auto& e : sec.entries) { CHECK_FALSE(e.syntax.empty()); CHECK_FALSE(e.summary.empty()); } } } TEST_CASE("renderHelp() with no topic lists every section and entry") { std::string out = join(renderHelp("")); CHECK(out.find("help ") != std::string::npos); // the usage hint // Each catalog section title and entry syntax should appear. for (const auto& sec : helpCatalog()) { CHECK(out.find(sec.title) != std::string::npos); for (const auto& e : sec.entries) CHECK(out.find(e.syntax) != std::string::npos); } // A couple of the commands added this session. CHECK(out.find("goto") != std::string::npos); CHECK(out.find("dump") != std::string::npos); } TEST_CASE("renderHelp(
) expands that section with detail") { std::string out = join(renderHelp("positioning")); CHECK(out.find("goto ") != std::string::npos); // Detail lines (example) are only emitted in topic mode. CHECK(out.find("goto 30 -10") != std::string::npos); } TEST_CASE("renderHelp() matches a single command, case-insensitively") { std::string lower = join(renderHelp("goto")); std::string upper = join(renderHelp("GOTO")); CHECK(lower.find("goto ") != std::string::npos); CHECK(upper.find("goto ") != std::string::npos); CHECK(lower == upper); } TEST_CASE("renderHelp(unknown) reports no match") { std::string out = join(renderHelp("definitely-not-a-command")); CHECK(out.find("No help topic") != std::string::npos); }