SectionPairValueValidatorTest.cpp 2.2 KB

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