SectionPairRowValidatorTest.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-20
  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 SectionPairRowValidatorTest : public ::testing::Test
  19. {
  20. protected:
  21. SectionPairRowValidatorTest() = default;
  22. ~SectionPairRowValidatorTest() override = default;
  23. void SetUp() override
  24. {}
  25. void TearDown() override
  26. {}
  27. };
  28. class SectionPairRowValidatorTest_ValidArgumentTest : public ::testing::TestWithParam<string>
  29. {
  30. protected:
  31. SectionPairRowValidatorTest_ValidArgumentTest() = default;
  32. ~SectionPairRowValidatorTest_ValidArgumentTest() override = default;
  33. };
  34. class SectionPairRowValidatorTest_InvalidArgumentTest : public ::testing::TestWithParam<string>
  35. {
  36. protected:
  37. SectionPairRowValidatorTest_InvalidArgumentTest() = default;
  38. ~SectionPairRowValidatorTest_InvalidArgumentTest() override = default;
  39. };
  40. TEST_F(SectionPairRowValidatorTest, getClassName)
  41. {
  42. ASSERT_STREQ("SectionPairRowValidator", SectionPairRowValidator{"empty"}.getClassName().c_str());
  43. }
  44. TEST_F(SectionPairRowValidatorTest, 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}))|(((((([a-z]([a-z0-9-]){1,31}):{1})((\n{1})|(\r{1}\n{1})))( {2}[a-zA-Z0-9\-_#!?\[\]\{\}\(\)\$ۤ<>+:;., \*\/"]{1,32}((\n{1})|(\r{1}\n{1})))){1}(( {2}[a-zA-Z0-9\-_#!?\[\]\{\}\(\)\$ۤ<>+:;., \*\/"]{1,32}((\n{1})|(\r{1}\n{1})))*))))";
  47. ASSERT_STREQ(expected.c_str(), SectionPairRowValidator::getValidationRegex().c_str());
  48. }
  49. TEST_P(SectionPairRowValidatorTest_ValidArgumentTest, isValid)
  50. {
  51. ASSERT_TRUE(SectionPairRowValidator{GetParam()}.isValid());
  52. }
  53. TEST_P(SectionPairRowValidatorTest_InvalidArgumentTest, isValid_not_valid)
  54. {
  55. ASSERT_FALSE(SectionPairRowValidator{GetParam()}.isValid());
  56. }
  57. INSTANTIATE_TEST_SUITE_P(ValidArgumentTest, SectionPairRowValidatorTest_ValidArgumentTest, ::testing::Values("favourite-color=blue\n", "color=red\r\n", "colors:\n red\n blue\n", "colors:\r\n red\r\n yellow\r\n", "graphics-card=GTX 720\n"));
  58. INSTANTIATE_TEST_SUITE_P(InvalidArgumentTest, SectionPairRowValidatorTest_InvalidArgumentTest, ::testing::Values("color blue", "a row\nand so on"));
  59. }