SectionPairRowListValueValidatorTest.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-19
  6. * Changed: 2023-02-23
  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. protected:
  23. SectionPairRowListValueValidatorTest() = default;
  24. ~SectionPairRowListValueValidatorTest() override = default;
  25. void SetUp() override
  26. {}
  27. void TearDown() override
  28. {}
  29. };
  30. class SectionPairRowListValueValidatorTest_ValidArgumentTest : public TestWithParam<string>
  31. {
  32. protected:
  33. SectionPairRowListValueValidatorTest_ValidArgumentTest() = default;
  34. ~SectionPairRowListValueValidatorTest_ValidArgumentTest() override = default;
  35. };
  36. class SectionPairRowListValueValidatorTest_InvalidArgumentTest : public TestWithParam<string>
  37. {
  38. protected:
  39. SectionPairRowListValueValidatorTest_InvalidArgumentTest() = default;
  40. ~SectionPairRowListValueValidatorTest_InvalidArgumentTest() override = default;
  41. };
  42. TEST_F(SectionPairRowListValueValidatorTest, getClassName)
  43. {
  44. ASSERT_STREQ("SectionPairRowListValueValidator", SectionPairRowListValueValidator{"empty"}.getClassName().c_str());
  45. }
  46. TEST_F(SectionPairRowListValueValidatorTest, getValidationRegex)
  47. {
  48. 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})))*)))";
  49. string actual = SectionPairRowListValueValidator::getValidationRegex();
  50. ASSERT_STREQ(expected.c_str(), actual.c_str());
  51. }
  52. TEST_P(SectionPairRowListValueValidatorTest_ValidArgumentTest, isValid)
  53. {
  54. ASSERT_TRUE(SectionPairRowListValueValidator{GetParam()}.isValid());
  55. }
  56. TEST_P(SectionPairRowListValueValidatorTest_InvalidArgumentTest, isValid_not_valid)
  57. {
  58. ASSERT_FALSE(SectionPairRowListValueValidator{GetParam()}.isValid());
  59. }
  60. 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"));
  61. INSTANTIATE_TEST_SUITE_P(InvalidArgumentTest, SectionPairRowListValueValidatorTest_InvalidArgumentTest, Values("colors:\nblue", "colors:\r\n hello!"));
  62. }