SectionPairRowSingleValueValidatorTest.cpp 2.5 KB

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