SectionPairValueValidatorTest.cpp 2.3 KB

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