SectionPairSectionValidatorTest.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-20
  6. * Changed: 2023-02-22
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls-std-io-test.hpp>
  11. #include <ls-std/ls-std-core.hpp>
  12. #include <ls-std/ls-std-io.hpp>
  13. #include <string>
  14. using namespace ls::std::core;
  15. using namespace ls::std::io;
  16. using namespace ::std;
  17. using namespace test::io;
  18. using namespace ::testing;
  19. namespace
  20. {
  21. class SectionPairSectionValidatorTest : public Test
  22. {
  23. protected:
  24. SectionPairSectionValidatorTest() = default;
  25. ~SectionPairSectionValidatorTest() override = default;
  26. void SetUp() override
  27. {}
  28. void TearDown() override
  29. {}
  30. };
  31. class SectionPairSectionValidatorTest_ValidArgumentTest : public TestWithParam<string>
  32. {
  33. protected:
  34. SectionPairSectionValidatorTest_ValidArgumentTest() = default;
  35. ~SectionPairSectionValidatorTest_ValidArgumentTest() override = default;
  36. };
  37. class SectionPairSectionValidatorTest_InvalidArgumentTest : public TestWithParam<string>
  38. {
  39. protected:
  40. SectionPairSectionValidatorTest_InvalidArgumentTest() = default;
  41. ~SectionPairSectionValidatorTest_InvalidArgumentTest() override = default;
  42. };
  43. TEST_F(SectionPairSectionValidatorTest, getClassName)
  44. {
  45. ASSERT_STREQ("SectionPairSectionValidator", SectionPairSectionValidator{"empty"}.getClassName().c_str());
  46. }
  47. TEST_F(SectionPairSectionValidatorTest, getValidationRegex)
  48. {
  49. string expected =
  50. R"(((\n)|(\r\n))\[{1}([a-z]([a-z0-9-]){1,31})\]{1}(((\n)|(\r\n)){2})(((([a-z]([a-z0-9-]){1,31})={1}([a-zA-Z0-9\-_#!?\[\]\{\}\(\)\$ۤ<>+:;., \*\/"]{1,32}){1}($|\n{1}|\r{1}\n{1}))|(((((([a-z]([a-z0-9-]){1,31}):{1})((\n{1})|(\r{1}\n{1})))( {2}[a-zA-Z0-9\-_#!?\[\]\{\}\(\)\$ۤ<>+:;., \*\/"]{1,32}((\n{1})|(\r{1}\n{1})))){1}(( {2}[a-zA-Z0-9\-_#!?\[\]\{\}\(\)\$ۤ<>+:;., \*\/"]{1,32}((\n{1})|(\r{1}\n{1})))*)))){1})(((([a-z]([a-z0-9-]){1,31})={1}([a-zA-Z0-9\-_#!?\[\]\{\}\(\)\$ۤ<>+:;., \*\/"]{1,32}){1}($|\n{1}|\r{1}\n{1}))|(((((([a-z]([a-z0-9-]){1,31}):{1})((\n{1})|(\r{1}\n{1})))( {2}[a-zA-Z0-9\-_#!?\[\]\{\}\(\)\$ۤ<>+:;., \*\/"]{1,32}((\n{1})|(\r{1}\n{1})))){1}(( {2}[a-zA-Z0-9\-_#!?\[\]\{\}\(\)\$ۤ<>+:;., \*\/"]{1,32}((\n{1})|(\r{1}\n{1})))*))))*))";
  51. ASSERT_STREQ(expected.c_str(), SectionPairSectionValidator::getValidationRegex().c_str());
  52. }
  53. TEST_P(SectionPairSectionValidatorTest_ValidArgumentTest, isValid)
  54. {
  55. ASSERT_TRUE(SectionPairSectionValidator{GetParam()}.isValid());
  56. }
  57. TEST_P(SectionPairSectionValidatorTest_InvalidArgumentTest, isValid_not_valid)
  58. {
  59. ASSERT_FALSE(SectionPairSectionValidator{GetParam()}.isValid());
  60. }
  61. INSTANTIATE_TEST_SUITE_P(ValidArgumentTest, SectionPairSectionValidatorTest_ValidArgumentTest, Values(SectionPairSectionProvider::createSerializedSectionWithTomExample(NewLine::getUnixNewLine()), SectionPairSectionProvider::createSerializedSectionWithTomExample(NewLine::getWindowsNewLine())));
  62. INSTANTIATE_TEST_SUITE_P(InvalidArgumentTest, SectionPairSectionValidatorTest_InvalidArgumentTest, Values("[general]\nage=22"));
  63. }