SectionPairIdentifierValidatorTest.cpp 2.3 KB

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