SectionPairSectionValidatorTest.cpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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-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. protected:
  26. SectionPairSectionValidatorTest() = default;
  27. ~SectionPairSectionValidatorTest() override = default;
  28. void SetUp() override
  29. {}
  30. void TearDown() override
  31. {}
  32. };
  33. class SectionPairSectionValidatorTest_ValidArgumentTest : public TestWithParam<string>
  34. {
  35. protected:
  36. SectionPairSectionValidatorTest_ValidArgumentTest() = default;
  37. ~SectionPairSectionValidatorTest_ValidArgumentTest() override = default;
  38. };
  39. class SectionPairSectionValidatorTest_InvalidArgumentTest : public TestWithParam<string>
  40. {
  41. protected:
  42. SectionPairSectionValidatorTest_InvalidArgumentTest() = default;
  43. ~SectionPairSectionValidatorTest_InvalidArgumentTest() override = default;
  44. };
  45. TEST_F(SectionPairSectionValidatorTest, getClassName)
  46. {
  47. ASSERT_STREQ("SectionPairSectionValidator", SectionPairSectionValidator{"empty"}.getClassName().c_str());
  48. }
  49. TEST_F(SectionPairSectionValidatorTest, getValidationRegex)
  50. {
  51. string expected =
  52. R"(((\n)|(\r\n))\[{1}([a-z]([a-z0-9-]){1,31})\]{1}(((\n)|(\r\n)){2})(((([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})))*)))){1})(((([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})))*))))*))";
  53. ASSERT_STREQ(expected.c_str(), SectionPairSectionValidator::getValidationRegex().c_str());
  54. }
  55. TEST_P(SectionPairSectionValidatorTest_ValidArgumentTest, isValid)
  56. {
  57. ASSERT_TRUE(SectionPairSectionValidator{GetParam()}.isValid());
  58. }
  59. TEST_P(SectionPairSectionValidatorTest_InvalidArgumentTest, isValid_not_valid)
  60. {
  61. ASSERT_FALSE(SectionPairSectionValidator{GetParam()}.isValid());
  62. }
  63. INSTANTIATE_TEST_SUITE_P(ValidArgumentTest, SectionPairSectionValidatorTest_ValidArgumentTest, Values(SectionPairSectionProvider::createSerializedSectionWithTomExample(NewLine::getUnixNewLine()), SectionPairSectionProvider::createSerializedSectionWithTomExample(NewLine::getWindowsNewLine())));
  64. INSTANTIATE_TEST_SUITE_P(InvalidArgumentTest, SectionPairSectionValidatorTest_InvalidArgumentTest, Values("[general]\nage=22"));
  65. }