SectionPairSectionValidatorTest.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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-io-test.hpp>
  11. #include <ls-std/ls-std-core.hpp>
  12. #include <ls-std/ls-std-io.hpp>
  13. #include <string>
  14. using ls::std::io::NewLine;
  15. using ls::std::io::SectionPairSectionValidator;
  16. using std::string;
  17. using test::io::SectionPairSectionProvider;
  18. using testing::Test;
  19. using testing::TestWithParam;
  20. using testing::Values;
  21. namespace
  22. {
  23. class SectionPairSectionValidatorTest : public Test
  24. {
  25. public:
  26. SectionPairSectionValidatorTest() = default;
  27. ~SectionPairSectionValidatorTest() override = default;
  28. };
  29. class SectionPairSectionValidatorTest_ValidArgumentTest : public TestWithParam<string>
  30. {
  31. public:
  32. SectionPairSectionValidatorTest_ValidArgumentTest() = default;
  33. ~SectionPairSectionValidatorTest_ValidArgumentTest() override = default;
  34. };
  35. class SectionPairSectionValidatorTest_InvalidArgumentTest : public TestWithParam<string>
  36. {
  37. public:
  38. SectionPairSectionValidatorTest_InvalidArgumentTest() = default;
  39. ~SectionPairSectionValidatorTest_InvalidArgumentTest() override = default;
  40. };
  41. TEST_F(SectionPairSectionValidatorTest, getClassName)
  42. {
  43. ASSERT_STREQ("SectionPairSectionValidator", SectionPairSectionValidator{"empty"}.getClassName().c_str());
  44. }
  45. TEST_F(SectionPairSectionValidatorTest, getValidationRegex)
  46. {
  47. string expected =
  48. R"(((\n)|(\r\n))\[{1}([a-z]([a-z0-9-]){1,63})\]{1}(((\n)|(\r\n)){2})(((([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})))*)))){1})(((([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})))*))))*))";
  49. ASSERT_STREQ(expected.c_str(), SectionPairSectionValidator::getValidationRegex().c_str());
  50. }
  51. TEST_P(SectionPairSectionValidatorTest_ValidArgumentTest, isValid)
  52. {
  53. ASSERT_TRUE(SectionPairSectionValidator{GetParam()}.isValid());
  54. }
  55. TEST_P(SectionPairSectionValidatorTest_InvalidArgumentTest, isValid_not_valid)
  56. {
  57. ASSERT_FALSE(SectionPairSectionValidator{GetParam()}.isValid());
  58. }
  59. INSTANTIATE_TEST_SUITE_P(ValidArgumentTest, SectionPairSectionValidatorTest_ValidArgumentTest, Values(SectionPairSectionProvider::createSerializedSectionWithTomExample(NewLine::getUnixNewLine()), SectionPairSectionProvider::createSerializedSectionWithTomExample(NewLine::getWindowsNewLine())));
  60. INSTANTIATE_TEST_SUITE_P(InvalidArgumentTest, SectionPairSectionValidatorTest_InvalidArgumentTest, Values("[general]\nage=22"));
  61. }