SectionPairIdentifierValidatorTest.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Co-Author: Claude Sonnet 4.6 (LLM)
  4. * Company: Lynar Studios
  5. * E-Mail: webmaster@lynarstudios.com
  6. * Created: 2023-02-09
  7. * Changed: 2026-06-23
  8. *
  9. * */
  10. #include <gtest/gtest.h>
  11. #include <ls-std/ls-std-core.hpp>
  12. #include <ls-std/ls-std-io.hpp>
  13. #include <string>
  14. using ls::standard::io::SectionPairIdentifierValidator;
  15. using std::string;
  16. using testing::Test;
  17. using testing::TestWithParam;
  18. using testing::Values;
  19. namespace
  20. {
  21. class SectionPairIdentifierValidatorTest : public Test
  22. {
  23. public:
  24. SectionPairIdentifierValidatorTest() = default;
  25. ~SectionPairIdentifierValidatorTest() override = default;
  26. };
  27. class SectionPairIdentifierValidatorTest_ValidArgumentTest : public TestWithParam<string>
  28. {
  29. public:
  30. SectionPairIdentifierValidatorTest_ValidArgumentTest() = default;
  31. ~SectionPairIdentifierValidatorTest_ValidArgumentTest() override = default;
  32. };
  33. class SectionPairIdentifierValidatorTest_InvalidArgumentTest : public TestWithParam<string>
  34. {
  35. public:
  36. SectionPairIdentifierValidatorTest_InvalidArgumentTest() = default;
  37. ~SectionPairIdentifierValidatorTest_InvalidArgumentTest() override = default;
  38. };
  39. TEST_F(SectionPairIdentifierValidatorTest, getClassName)
  40. {
  41. ASSERT_STREQ("SectionPairIdentifierValidator", SectionPairIdentifierValidator{"tmp-key"}.getClassName().c_str());
  42. }
  43. TEST_F(SectionPairIdentifierValidatorTest, getValidationRegex)
  44. {
  45. ASSERT_STREQ(R"([a-z]([a-z0-9-]){1,63})", SectionPairIdentifierValidator{"tmp-key"}.getValidationRegex().c_str());
  46. }
  47. TEST_P(SectionPairIdentifierValidatorTest_ValidArgumentTest, isValid)
  48. {
  49. ASSERT_TRUE(SectionPairIdentifierValidator{GetParam()}.isValid());
  50. }
  51. TEST_P(SectionPairIdentifierValidatorTest_InvalidArgumentTest, isValid_not_valid)
  52. {
  53. ASSERT_FALSE(SectionPairIdentifierValidator{GetParam()}.isValid());
  54. }
  55. INSTANTIATE_TEST_SUITE_P(ValidArgumentTest, SectionPairIdentifierValidatorTest_ValidArgumentTest, Values("color", "favourite-color", "age", "name"));
  56. 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"));
  57. }