SectionPairRowListValueValidatorTest.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-19
  6. * Changed: 2023-06-06
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls-std/ls-std-io.hpp>
  11. #include <string>
  12. using ls::std::io::SectionPairRowListValueValidator;
  13. using std::string;
  14. using testing::Test;
  15. using testing::TestWithParam;
  16. using testing::Values;
  17. namespace
  18. {
  19. class SectionPairRowListValueValidatorTest : public Test
  20. {
  21. public:
  22. SectionPairRowListValueValidatorTest() = default;
  23. ~SectionPairRowListValueValidatorTest() override = default;
  24. };
  25. class SectionPairRowListValueValidatorTest_ValidArgumentTest : public TestWithParam<string>
  26. {
  27. public:
  28. SectionPairRowListValueValidatorTest_ValidArgumentTest() = default;
  29. ~SectionPairRowListValueValidatorTest_ValidArgumentTest() override = default;
  30. };
  31. class SectionPairRowListValueValidatorTest_InvalidArgumentTest : public TestWithParam<string>
  32. {
  33. public:
  34. SectionPairRowListValueValidatorTest_InvalidArgumentTest() = default;
  35. ~SectionPairRowListValueValidatorTest_InvalidArgumentTest() override = default;
  36. };
  37. TEST_F(SectionPairRowListValueValidatorTest, getClassName)
  38. {
  39. ASSERT_STREQ("SectionPairRowListValueValidator", SectionPairRowListValueValidator{"empty"}.getClassName().c_str());
  40. }
  41. TEST_F(SectionPairRowListValueValidatorTest, getValidationRegex)
  42. {
  43. string expected = R"(((((([a-z]([a-z0-9-]){1,63}):{1})((\n{1})|(\r{1}\n{1})))( {2}[a-zA-Z0-9\-_#!?\[\]\{\}\(\)\$€\\§<>+:;., \*\/"]{1,512}((\n{1})|(\r{1}\n{1})))){1}(( {2}[a-zA-Z0-9\-_#!?\[\]\{\}\(\)\$€\\§<>+:;., \*\/"]{1,512}((\n{1})|(\r{1}\n{1})))*)))";
  44. string actual = SectionPairRowListValueValidator::getValidationRegex();
  45. ASSERT_STREQ(expected.c_str(), actual.c_str());
  46. }
  47. TEST_P(SectionPairRowListValueValidatorTest_ValidArgumentTest, isValid)
  48. {
  49. ASSERT_TRUE(SectionPairRowListValueValidator{GetParam()}.isValid());
  50. }
  51. TEST_P(SectionPairRowListValueValidatorTest_InvalidArgumentTest, isValid_not_valid)
  52. {
  53. ASSERT_FALSE(SectionPairRowListValueValidator{GetParam()}.isValid());
  54. }
  55. INSTANTIATE_TEST_SUITE_P(ValidArgumentTest, SectionPairRowListValueValidatorTest_ValidArgumentTest, Values("colors:\n blue\n red\n", "colors:\r\n blue\r\n green\r\n yellow\r\n"));
  56. INSTANTIATE_TEST_SUITE_P(InvalidArgumentTest, SectionPairRowListValueValidatorTest_InvalidArgumentTest, Values("colors:\nblue", "colors:\r\n hello!"));
  57. }