SectionPairRowValidatorTest.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-20
  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::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. protected:
  23. SectionPairRowValidatorTest() = default;
  24. ~SectionPairRowValidatorTest() override = default;
  25. void SetUp() override
  26. {}
  27. void TearDown() override
  28. {}
  29. };
  30. class SectionPairRowValidatorTest_ValidArgumentTest : public TestWithParam<string>
  31. {
  32. protected:
  33. SectionPairRowValidatorTest_ValidArgumentTest() = default;
  34. ~SectionPairRowValidatorTest_ValidArgumentTest() override = default;
  35. };
  36. class SectionPairRowValidatorTest_InvalidArgumentTest : public TestWithParam<string>
  37. {
  38. protected:
  39. SectionPairRowValidatorTest_InvalidArgumentTest() = default;
  40. ~SectionPairRowValidatorTest_InvalidArgumentTest() override = default;
  41. };
  42. TEST_F(SectionPairRowValidatorTest, getClassName)
  43. {
  44. ASSERT_STREQ("SectionPairRowValidator", SectionPairRowValidator{"empty"}.getClassName().c_str());
  45. }
  46. TEST_F(SectionPairRowValidatorTest, getValidationRegex)
  47. {
  48. string expected = R"((([a-z]([a-z0-9-]){1,31})={1}([a-zA-Z0-9\-_#!?\[\]\{\}\(\)\$ۤ<>+:;., \*\/"]{1,32}){1}($|\n{1}|\r{1}\n{1}))|(((((([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. ASSERT_STREQ(expected.c_str(), SectionPairRowValidator::getValidationRegex().c_str());
  50. }
  51. TEST_P(SectionPairRowValidatorTest_ValidArgumentTest, isValid)
  52. {
  53. ASSERT_TRUE(SectionPairRowValidator{GetParam()}.isValid());
  54. }
  55. TEST_P(SectionPairRowValidatorTest_InvalidArgumentTest, isValid_not_valid)
  56. {
  57. ASSERT_FALSE(SectionPairRowValidator{GetParam()}.isValid());
  58. }
  59. 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"));
  60. INSTANTIATE_TEST_SUITE_P(InvalidArgumentTest, SectionPairRowValidatorTest_InvalidArgumentTest, Values("color blue", "a row\nand so on"));
  61. }