SectionPairRowSingleValueValidatorTest.cpp 2.4 KB

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