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