SectionPairIdentifierValidatorTest.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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-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::SectionPairIdentifierValidator;
  14. using std::string;
  15. using testing::Test;
  16. using testing::TestWithParam;
  17. using testing::Values;
  18. namespace
  19. {
  20. class SectionPairIdentifierValidatorTest : public Test
  21. {
  22. protected:
  23. SectionPairIdentifierValidatorTest() = default;
  24. ~SectionPairIdentifierValidatorTest() override = default;
  25. void SetUp() override
  26. {}
  27. void TearDown() override
  28. {}
  29. };
  30. class SectionPairIdentifierValidatorTest_ValidArgumentTest : public TestWithParam<string>
  31. {
  32. protected:
  33. SectionPairIdentifierValidatorTest_ValidArgumentTest() = default;
  34. ~SectionPairIdentifierValidatorTest_ValidArgumentTest() override = default;
  35. };
  36. class SectionPairIdentifierValidatorTest_InvalidArgumentTest : public TestWithParam<string>
  37. {
  38. protected:
  39. SectionPairIdentifierValidatorTest_InvalidArgumentTest() = default;
  40. ~SectionPairIdentifierValidatorTest_InvalidArgumentTest() override = default;
  41. };
  42. TEST_F(SectionPairIdentifierValidatorTest, getClassName)
  43. {
  44. ASSERT_STREQ("SectionPairIdentifierValidator", SectionPairIdentifierValidator{"tmp-key"}.getClassName().c_str());
  45. }
  46. TEST_F(SectionPairIdentifierValidatorTest, getValidationRegex)
  47. {
  48. ASSERT_STREQ(R"([a-z]([a-z0-9-]){1,31})", SectionPairIdentifierValidator{"tmp-key"}.getValidationRegex().c_str());
  49. }
  50. TEST_P(SectionPairIdentifierValidatorTest_ValidArgumentTest, isValid)
  51. {
  52. ASSERT_TRUE(SectionPairIdentifierValidator{GetParam()}.isValid());
  53. }
  54. TEST_P(SectionPairIdentifierValidatorTest_InvalidArgumentTest, isValid_not_valid)
  55. {
  56. ASSERT_FALSE(SectionPairIdentifierValidator{GetParam()}.isValid());
  57. }
  58. INSTANTIATE_TEST_SUITE_P(ValidArgumentTest, SectionPairIdentifierValidatorTest_ValidArgumentTest, Values("color", "favourite-color", "age", "name"));
  59. INSTANTIATE_TEST_SUITE_P(InvalidArgumentTest, SectionPairIdentifierValidatorTest_InvalidArgumentTest, Values("_color", "8color", "colOr", "color:", "-color", "color-is-valid-but-too-long-because-it-exceeds-32-characters"));
  60. }