SectionPairRowValidatorTest.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-20
  6. * Changed: 2023-06-06
  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::SectionPairRowValidator;
  14. using std::string;
  15. using testing::Test;
  16. using testing::TestWithParam;
  17. using testing::Values;
  18. namespace
  19. {
  20. class SectionPairRowValidatorTest : public Test
  21. {
  22. public:
  23. SectionPairRowValidatorTest() = default;
  24. ~SectionPairRowValidatorTest() override = default;
  25. };
  26. class SectionPairRowValidatorTest_ValidArgumentTest : public TestWithParam<string>
  27. {
  28. public:
  29. SectionPairRowValidatorTest_ValidArgumentTest() = default;
  30. ~SectionPairRowValidatorTest_ValidArgumentTest() override = default;
  31. };
  32. class SectionPairRowValidatorTest_InvalidArgumentTest : public TestWithParam<string>
  33. {
  34. public:
  35. SectionPairRowValidatorTest_InvalidArgumentTest() = default;
  36. ~SectionPairRowValidatorTest_InvalidArgumentTest() override = default;
  37. };
  38. TEST_F(SectionPairRowValidatorTest, getClassName)
  39. {
  40. ASSERT_STREQ("SectionPairRowValidator", SectionPairRowValidator{"empty"}.getClassName().c_str());
  41. }
  42. TEST_F(SectionPairRowValidatorTest, getValidationRegex)
  43. {
  44. string expected = R"((([a-z]([a-z0-9-]){1,63})={1}([a-zA-Z0-9\-_#!?\[\]\{\}\(\)\$€\\§<>+:;., \*\/"]{1,512}){1}($|\n{1}|\r{1}\n{1}))|(((((([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})))*))))";
  45. ASSERT_STREQ(expected.c_str(), SectionPairRowValidator::getValidationRegex().c_str());
  46. }
  47. TEST_P(SectionPairRowValidatorTest_ValidArgumentTest, isValid)
  48. {
  49. ASSERT_TRUE(SectionPairRowValidator{GetParam()}.isValid());
  50. }
  51. TEST_P(SectionPairRowValidatorTest_InvalidArgumentTest, isValid_not_valid)
  52. {
  53. ASSERT_FALSE(SectionPairRowValidator{GetParam()}.isValid());
  54. }
  55. INSTANTIATE_TEST_SUITE_P(ValidArgumentTest, SectionPairRowValidatorTest_ValidArgumentTest, Values("favourite-color=blue\n", "color=red\r\n", "colors:\n red\n blue\n", "colors:\r\n red\r\n yellow\r\n", "graphics-card=GTX 720\n"));
  56. INSTANTIATE_TEST_SUITE_P(InvalidArgumentTest, SectionPairRowValidatorTest_InvalidArgumentTest, Values("color blue", "a row\nand so on"));
  57. }