SectionPairValueValidatorTest.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-09
  6. * Changed: 2023-02-22
  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 namespace ls::std::core;
  14. using namespace ls::std::io;
  15. using namespace ::std;
  16. using namespace ::testing;
  17. namespace
  18. {
  19. class SectionPairValueValidatorTest : public Test
  20. {
  21. protected:
  22. SectionPairValueValidatorTest() = default;
  23. ~SectionPairValueValidatorTest() override = default;
  24. void SetUp() override
  25. {}
  26. void TearDown() override
  27. {}
  28. };
  29. class SectionPairValueValidatorTest_ValidArgumentTest : public TestWithParam<string>
  30. {
  31. protected:
  32. SectionPairValueValidatorTest_ValidArgumentTest() = default;
  33. ~SectionPairValueValidatorTest_ValidArgumentTest() override = default;
  34. };
  35. class SectionPairValueValidatorTest_InvalidArgumentTest : public TestWithParam<string>
  36. {
  37. protected:
  38. SectionPairValueValidatorTest_InvalidArgumentTest() = default;
  39. ~SectionPairValueValidatorTest_InvalidArgumentTest() override = default;
  40. };
  41. TEST_F(SectionPairValueValidatorTest, getClassName)
  42. {
  43. ASSERT_STREQ("SectionPairValueValidator", SectionPairValueValidator{"empty"}.getClassName().c_str());
  44. }
  45. TEST_F(SectionPairValueValidatorTest, getValidationRegex)
  46. {
  47. string expected = R"([a-zA-Z0-9\-_#!?\[\]\{\}\(\)\$ۤ<>+:;., \*\/"]{1,32})";
  48. string actual = SectionPairValueValidator::getValidationRegex();
  49. ASSERT_STREQ(expected.c_str(), actual.c_str());
  50. }
  51. TEST_P(SectionPairValueValidatorTest_ValidArgumentTest, isValid)
  52. {
  53. ASSERT_TRUE(SectionPairValueValidator{GetParam()}.isValid());
  54. }
  55. TEST_P(SectionPairValueValidatorTest_InvalidArgumentTest, isValid_not_valid)
  56. {
  57. ASSERT_FALSE(SectionPairValueValidator{GetParam()}.isValid());
  58. }
  59. INSTANTIATE_TEST_SUITE_P(ValidArgumentTest, SectionPairValueValidatorTest_ValidArgumentTest, Values("blue is my favourite color!", "Age", "Tom", "\"Tom\"", "Hello!" + NewLine::getUnixNewLine(), "Hello!" + NewLine::getWindowsNewLine()));
  60. INSTANTIATE_TEST_SUITE_P(InvalidArgumentTest, SectionPairValueValidatorTest_InvalidArgumentTest, Values("1+2=3", "\\escape"));
  61. }