SectionPairRowValidatorTest.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Co-Author: Claude Sonnet 4.6 (LLM)
  4. * Company: Lynar Studios
  5. * E-Mail: webmaster@lynarstudios.com
  6. * Created: 2023-02-20
  7. * Changed: 2026-06-23
  8. *
  9. * */
  10. #include <gtest/gtest.h>
  11. #include <ls-std/ls-std-core.hpp>
  12. #include <ls-std/ls-std-io.hpp>
  13. #include <string>
  14. using ls::standard::io::SectionPairRowValidator;
  15. using std::string;
  16. using testing::Test;
  17. using testing::TestWithParam;
  18. using testing::Values;
  19. namespace
  20. {
  21. class SectionPairRowValidatorTest : public Test
  22. {
  23. public:
  24. SectionPairRowValidatorTest() = default;
  25. ~SectionPairRowValidatorTest() override = default;
  26. };
  27. class SectionPairRowValidatorTest_ValidArgumentTest : public TestWithParam<string>
  28. {
  29. public:
  30. SectionPairRowValidatorTest_ValidArgumentTest() = default;
  31. ~SectionPairRowValidatorTest_ValidArgumentTest() override = default;
  32. };
  33. class SectionPairRowValidatorTest_InvalidArgumentTest : public TestWithParam<string>
  34. {
  35. public:
  36. SectionPairRowValidatorTest_InvalidArgumentTest() = default;
  37. ~SectionPairRowValidatorTest_InvalidArgumentTest() override = default;
  38. };
  39. TEST_F(SectionPairRowValidatorTest, getClassName)
  40. {
  41. ASSERT_STREQ("SectionPairRowValidator", SectionPairRowValidator{"empty"}.getClassName().c_str());
  42. }
  43. TEST_F(SectionPairRowValidatorTest, getValidationRegex)
  44. {
  45. const 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})))*))))";
  46. ASSERT_STREQ(expected.c_str(), SectionPairRowValidator::getValidationRegex().c_str());
  47. }
  48. TEST_P(SectionPairRowValidatorTest_ValidArgumentTest, isValid)
  49. {
  50. ASSERT_TRUE(SectionPairRowValidator{GetParam()}.isValid());
  51. }
  52. TEST_P(SectionPairRowValidatorTest_InvalidArgumentTest, isValid_not_valid)
  53. {
  54. ASSERT_FALSE(SectionPairRowValidator{GetParam()}.isValid());
  55. }
  56. 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"));
  57. INSTANTIATE_TEST_SUITE_P(InvalidArgumentTest, SectionPairRowValidatorTest_InvalidArgumentTest, Values("color blue", "a row\nand so on"));
  58. }