SectionPairRowSingleValueValidatorTest.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-19
  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 SectionPairRowSingleValueValidatorTest : public Test
  20. {
  21. protected:
  22. SectionPairRowSingleValueValidatorTest() = default;
  23. ~SectionPairRowSingleValueValidatorTest() override = default;
  24. void SetUp() override
  25. {}
  26. void TearDown() override
  27. {}
  28. };
  29. class SectionPairRowSingleValueValidatorTest_ValidArgumentTest : public TestWithParam<string>
  30. {
  31. protected:
  32. SectionPairRowSingleValueValidatorTest_ValidArgumentTest() = default;
  33. ~SectionPairRowSingleValueValidatorTest_ValidArgumentTest() override = default;
  34. };
  35. class SectionPairRowSingleValueValidatorTest_InvalidArgumentTest : public TestWithParam<string>
  36. {
  37. protected:
  38. SectionPairRowSingleValueValidatorTest_InvalidArgumentTest() = default;
  39. ~SectionPairRowSingleValueValidatorTest_InvalidArgumentTest() override = default;
  40. };
  41. TEST_F(SectionPairRowSingleValueValidatorTest, getClassName)
  42. {
  43. ASSERT_STREQ("SectionPairRowSingleValueValidator", SectionPairRowSingleValueValidator{"empty"}.getClassName().c_str());
  44. }
  45. TEST_F(SectionPairRowSingleValueValidatorTest, getValidationRegex)
  46. {
  47. string expected = R"(([a-z]([a-z0-9-]){1,31})={1}([a-zA-Z0-9\-_#!?\[\]\{\}\(\)\$ۤ<>+:;., \*\/"]{1,32}){1}($|\n{1}|\r{1}\n{1}))";
  48. ASSERT_STREQ(expected.c_str(), SectionPairRowSingleValueValidator::getValidationRegex().c_str());
  49. }
  50. TEST_P(SectionPairRowSingleValueValidatorTest_ValidArgumentTest, isValid)
  51. {
  52. ASSERT_TRUE(SectionPairRowSingleValueValidator{GetParam()}.isValid());
  53. }
  54. TEST_P(SectionPairRowSingleValueValidatorTest_InvalidArgumentTest, isValid_not_valid)
  55. {
  56. ASSERT_FALSE(SectionPairRowSingleValueValidator{GetParam()}.isValid());
  57. }
  58. INSTANTIATE_TEST_SUITE_P(ValidArgumentTest, SectionPairRowSingleValueValidatorTest_ValidArgumentTest, Values("favourite-color=blue" + NewLine::getUnixNewLine(), "hair-color=red" + NewLine::getWindowsNewLine(), "height=167"));
  59. INSTANTIATE_TEST_SUITE_P(InvalidArgumentTest, SectionPairRowSingleValueValidatorTest_InvalidArgumentTest, Values("color blue", "a value\n"));
  60. }