SectionPairRowListValueValidatorTest.cpp 2.5 KB

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