/* * This project is licensed under the MIT license. For more information see the * LICENSE file. */ #include #include "gmock/gmock.h" #include "maddy/checklistparser.h" // ----------------------------------------------------------------------------- class MADDY_CHECKLISTPARSER : public ::testing::Test { protected: std::shared_ptr clParser; void SetUp() override { std::function(const std::string& line)> getBlockParserForLineCallback = [](const std::string& line) { if (maddy::ChecklistParser::IsStartingLine(line)) { return std::static_pointer_cast( std::make_shared(nullptr, nullptr) ); } std::shared_ptr empty; return empty; }; this->clParser = std::make_shared( nullptr, getBlockParserForLineCallback ); } }; // ----------------------------------------------------------------------------- TEST_F(MADDY_CHECKLISTPARSER, IsStartingLineReturnsTrueWhenFacedWithBeginningOfList) { ASSERT_TRUE(maddy::ChecklistParser::IsStartingLine("- [ ] a")); ASSERT_TRUE(maddy::ChecklistParser::IsStartingLine("- [x] b")); } TEST_F(MADDY_CHECKLISTPARSER, IsFinishedAlwaysReturnsFalseInTheBeginning) { ASSERT_FALSE(clParser->IsFinished()); } TEST_F(MADDY_CHECKLISTPARSER, ItReplacesMarkdownWithAnHtmlChecklist) { std::vector markdown = { "- [ ] a" , "- [x] b" , "" }; std::string expected = "
"; for (std::string md : markdown) { clParser->AddLine(md); } ASSERT_TRUE(clParser->IsFinished()); std::stringstream& output(clParser->GetResult()); const std::string& outputString = output.str(); ASSERT_EQ(expected, outputString); } TEST_F(MADDY_CHECKLISTPARSER, ItReplacesMarkdownWithAnHierachicalHtmlList) { std::vector markdown = { "- [ ] a" , " - [ ] d" , " - [ ] e" , "- [ ] b" , " - [x] c" , "" }; std::string expected = "
"; for (std::string md : markdown) { clParser->AddLine(md); } ASSERT_TRUE(clParser->IsFinished()); std::stringstream& output(clParser->GetResult()); const std::string& outputString = output.str(); ASSERT_EQ(expected, outputString); }