KVParserTest.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-12-25
  6. * Changed: 2020-12-25
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls_std/ls_std.hpp>
  11. namespace {
  12. class KVParserTest : public ::testing::Test {
  13. protected:
  14. KVParserTest() = default;
  15. ~KVParserTest() override = default;
  16. void SetUp() override {}
  17. void TearDown() override {}
  18. };
  19. TEST_F(KVParserTest, getDocument)
  20. {
  21. ls_std::KVParser parser {std::make_shared<ls_std::KVDocument>()};
  22. ASSERT_TRUE(parser.getDocument() != nullptr);
  23. }
  24. TEST_F(KVParserTest, parse)
  25. {
  26. std::shared_ptr<ls_std::KVDocument> document = std::make_shared<ls_std::KVDocument>();
  27. ls_std::KVParser parser {document};
  28. ls_std::byte_field data = "# starting comment\n\nport=8080; # some comment\nhost=localhost;\nservice-name=deamon;";
  29. parser.parse(data);
  30. ASSERT_EQ(3, document->getPairs().size());
  31. ASSERT_TRUE(document->hasPair("port"));
  32. ASSERT_TRUE(document->hasPair("host"));
  33. ASSERT_TRUE(document->hasPair("service-name"));
  34. ASSERT_STREQ("8080", document->getPairs().at("port").getValue().c_str());
  35. ASSERT_STREQ("localhost", document->getPairs().at("host").getValue().c_str());
  36. ASSERT_STREQ("deamon", document->getPairs().at("service-name").getValue().c_str());
  37. }
  38. TEST_F(KVParserTest, setDocument)
  39. {
  40. std::shared_ptr<ls_std::KVDocument> document1 = std::make_shared<ls_std::KVDocument>();
  41. std::shared_ptr<ls_std::KVDocument> document2 = std::make_shared<ls_std::KVDocument>();
  42. ls_std::KVParser parser {document1};
  43. ASSERT_TRUE(parser.getDocument() == document1);
  44. parser.setDocument(document2);
  45. ASSERT_TRUE(parser.getDocument() == document2);
  46. }
  47. }