SectionPairValueValidatorTest.cpp 2.3 KB

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