SectionPairRowListValueValidatorTest.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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-20
  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. namespace
  17. {
  18. class SectionPairRowListValueValidatorTest : public ::testing::Test
  19. {
  20. protected:
  21. SectionPairRowListValueValidatorTest() = default;
  22. ~SectionPairRowListValueValidatorTest() override = default;
  23. void SetUp() override
  24. {}
  25. void TearDown() override
  26. {}
  27. };
  28. class SectionPairRowListValueValidatorIsValidTest : public ::testing::TestWithParam<string>
  29. {
  30. protected:
  31. SectionPairRowListValueValidatorIsValidTest() = default;
  32. ~SectionPairRowListValueValidatorIsValidTest() override = default;
  33. };
  34. class SectionPairRowListValueValidatorNotValidTest : public ::testing::TestWithParam<string>
  35. {
  36. protected:
  37. SectionPairRowListValueValidatorNotValidTest() = default;
  38. ~SectionPairRowListValueValidatorNotValidTest() override = default;
  39. };
  40. TEST_F(SectionPairRowListValueValidatorTest, getClassName)
  41. {
  42. ASSERT_STREQ("SectionPairRowListValueValidator", SectionPairRowListValueValidator{"tmp-key"}.getClassName().c_str());
  43. }
  44. TEST_F(SectionPairRowListValueValidatorTest, getValidationRegex)
  45. {
  46. string expected = R"(((((([a-z]([a-z0-9-]){1,15}):{1})\r{1}\n{1})( {2}[a-zA-Z0-9\-_#!?\[\]\{\}\(\)\$ۤ<>+:;., \*\/"]{1,32}\r{1}\n{1})){1}(( {2}[a-zA-Z0-9\-_#!?\[\]\{\}\(\)\$ۤ<>+:;., \*\/"]{1,32}\r{1}\n{1})*))|((((([a-z]([a-z0-9-]){1,15}):{1})\n{1})( {2}[a-zA-Z0-9\-_#!?\[\]\{\}\(\)\$ۤ<>+:;., \*\/"]{1,32}\n{1})){1}(( {2}[a-zA-Z0-9\-_#!?\[\]\{\}\(\)\$ۤ<>+:;., \*\/"]{1,32}\n{1})*)))";
  47. string actual = SectionPairRowListValueValidator::getValidationRegex();
  48. ASSERT_STREQ(expected.c_str(), actual.c_str());
  49. }
  50. TEST_P(SectionPairRowListValueValidatorIsValidTest, isValid)
  51. {
  52. ASSERT_TRUE(SectionPairRowListValueValidator{GetParam()}.isValid());
  53. }
  54. TEST_P(SectionPairRowListValueValidatorNotValidTest, isValid_not_valid)
  55. {
  56. ASSERT_FALSE(SectionPairRowListValueValidator{GetParam()}.isValid());
  57. }
  58. INSTANTIATE_TEST_SUITE_P(SectionPairRowListValueValidatorTest, SectionPairRowListValueValidatorIsValidTest, ::testing::Values("colors:\n blue\n red\n", "colors:\r\n blue\r\n green\r\n yellow\r\n"));
  59. INSTANTIATE_TEST_SUITE_P(SectionPairRowListValueValidatorTest, SectionPairRowListValueValidatorNotValidTest, ::testing::Values("colors:\nblue", "colors:\r\n hello!"));
  60. }