SectionPairIdentifierValidatorTest.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-09
  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 SectionPairIdentifierValidatorTest : public Test
  20. {
  21. protected:
  22. SectionPairIdentifierValidatorTest() = default;
  23. ~SectionPairIdentifierValidatorTest() override = default;
  24. void SetUp() override
  25. {}
  26. void TearDown() override
  27. {}
  28. };
  29. class SectionPairIdentifierValidatorTest_ValidArgumentTest : public TestWithParam<string>
  30. {
  31. protected:
  32. SectionPairIdentifierValidatorTest_ValidArgumentTest() = default;
  33. ~SectionPairIdentifierValidatorTest_ValidArgumentTest() override = default;
  34. };
  35. class SectionPairIdentifierValidatorTest_InvalidArgumentTest : public TestWithParam<string>
  36. {
  37. protected:
  38. SectionPairIdentifierValidatorTest_InvalidArgumentTest() = default;
  39. ~SectionPairIdentifierValidatorTest_InvalidArgumentTest() override = default;
  40. };
  41. TEST_F(SectionPairIdentifierValidatorTest, getClassName)
  42. {
  43. ASSERT_STREQ("SectionPairIdentifierValidator", SectionPairIdentifierValidator{"tmp-key"}.getClassName().c_str());
  44. }
  45. TEST_F(SectionPairIdentifierValidatorTest, getValidationRegex)
  46. {
  47. ASSERT_STREQ(R"([a-z]([a-z0-9-]){1,31})", SectionPairIdentifierValidator{"tmp-key"}.getValidationRegex().c_str());
  48. }
  49. TEST_P(SectionPairIdentifierValidatorTest_ValidArgumentTest, isValid)
  50. {
  51. ASSERT_TRUE(SectionPairIdentifierValidator{GetParam()}.isValid());
  52. }
  53. TEST_P(SectionPairIdentifierValidatorTest_InvalidArgumentTest, isValid_not_valid)
  54. {
  55. ASSERT_FALSE(SectionPairIdentifierValidator{GetParam()}.isValid());
  56. }
  57. INSTANTIATE_TEST_SUITE_P(ValidArgumentTest, SectionPairIdentifierValidatorTest_ValidArgumentTest, Values("color", "favourite-color", "age", "name"));
  58. INSTANTIATE_TEST_SUITE_P(InvalidArgumentTest, SectionPairIdentifierValidatorTest_InvalidArgumentTest, Values("_color", "8color", "colOr", "color:", "-color", "color-is-valid-but-too-long-because-it-exceeds-32-characters"));
  59. }