SectionPairRowListValueValidatorTest.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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-22
  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 namespace ls::std::core;
  14. using namespace ls::std::io;
  15. using namespace ::std;
  16. using namespace ::testing;
  17. namespace
  18. {
  19. class SectionPairRowListValueValidatorTest : public Test
  20. {
  21. protected:
  22. SectionPairRowListValueValidatorTest() = default;
  23. ~SectionPairRowListValueValidatorTest() override = default;
  24. void SetUp() override
  25. {}
  26. void TearDown() override
  27. {}
  28. };
  29. class SectionPairRowListValueValidatorTest_ValidArgumentTest : public TestWithParam<string>
  30. {
  31. protected:
  32. SectionPairRowListValueValidatorTest_ValidArgumentTest() = default;
  33. ~SectionPairRowListValueValidatorTest_ValidArgumentTest() override = default;
  34. };
  35. class SectionPairRowListValueValidatorTest_InvalidArgumentTest : public TestWithParam<string>
  36. {
  37. protected:
  38. SectionPairRowListValueValidatorTest_InvalidArgumentTest() = default;
  39. ~SectionPairRowListValueValidatorTest_InvalidArgumentTest() override = default;
  40. };
  41. TEST_F(SectionPairRowListValueValidatorTest, getClassName)
  42. {
  43. ASSERT_STREQ("SectionPairRowListValueValidator", SectionPairRowListValueValidator{"empty"}.getClassName().c_str());
  44. }
  45. TEST_F(SectionPairRowListValueValidatorTest, getValidationRegex)
  46. {
  47. 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})))*)))";
  48. string actual = SectionPairRowListValueValidator::getValidationRegex();
  49. ASSERT_STREQ(expected.c_str(), actual.c_str());
  50. }
  51. TEST_P(SectionPairRowListValueValidatorTest_ValidArgumentTest, isValid)
  52. {
  53. ASSERT_TRUE(SectionPairRowListValueValidator{GetParam()}.isValid());
  54. }
  55. TEST_P(SectionPairRowListValueValidatorTest_InvalidArgumentTest, isValid_not_valid)
  56. {
  57. ASSERT_FALSE(SectionPairRowListValueValidator{GetParam()}.isValid());
  58. }
  59. 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"));
  60. INSTANTIATE_TEST_SUITE_P(InvalidArgumentTest, SectionPairRowListValueValidatorTest_InvalidArgumentTest, Values("colors:\nblue", "colors:\r\n hello!"));
  61. }