SectionPairIdentifierValidatorTest.cpp 2.2 KB

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