SectionPairSectionValidatorTest.cpp 3.1 KB

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