SectionPairRowSingleValueValidatorTest.cpp 2.5 KB

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