PatternMatcherTests.cpp 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzTest/AzTest.h>
  9. #include <SceneAPI/SceneCore/Utilities/PatternMatcher.h>
  10. namespace AZ
  11. {
  12. namespace SceneAPI
  13. {
  14. namespace SceneCore
  15. {
  16. TEST(PatternMatcherTest, MatchesPattern_MatchingNameWithPostFix_ReturnsTrue)
  17. {
  18. PatternMatcher matcher("_postfix", PatternMatcher::MatchApproach::PostFix);
  19. EXPECT_TRUE(matcher.MatchesPattern("string_with_postfix"));
  20. }
  21. TEST(PatternMatcherTest, MatchesPattern_NonMatchingNameWithPostFix_ReturnsFalse)
  22. {
  23. PatternMatcher matcher("_postfix", PatternMatcher::MatchApproach::PostFix);
  24. EXPECT_FALSE(matcher.MatchesPattern("string_with_something_else"));
  25. }
  26. TEST(PatternMatcherTest, MatchesPattern_CaseInsensitiveMatchingNameWithPostFix_ReturnsTrue)
  27. {
  28. PatternMatcher matcher("_PoStFiX", PatternMatcher::MatchApproach::PostFix);
  29. EXPECT_TRUE(matcher.MatchesPattern("string_with_postfix"));
  30. }
  31. TEST(PatternMatcherTest, MatchesPattern_NonMatchingNameWithPostFixAndEarlyOutForSmallerTestThanPattern_ReturnsFalse)
  32. {
  33. PatternMatcher matcher("_postfix", PatternMatcher::MatchApproach::PostFix);
  34. EXPECT_FALSE(matcher.MatchesPattern("small"));
  35. }
  36. TEST(PatternMatcherTest, MatchesPattern_MatchingNameWithPreFix_ReturnsTrue)
  37. {
  38. PatternMatcher matcher("prefix_", PatternMatcher::MatchApproach::PreFix);
  39. EXPECT_TRUE(matcher.MatchesPattern("prefix_for_string"));
  40. }
  41. TEST(PatternMatcherTest, MatchesPattern_NonMatchingNameWithPreFix_ReturnsFalse)
  42. {
  43. PatternMatcher matcher("prefix_", PatternMatcher::MatchApproach::PreFix);
  44. EXPECT_FALSE(matcher.MatchesPattern("string_with_something_else"));
  45. }
  46. TEST(PatternMatcherTest, MatchesPattern_CaseInsensitiveMatchingNameWithPreFix_ReturnsTrue)
  47. {
  48. PatternMatcher matcher("PrEFiX_", PatternMatcher::MatchApproach::PreFix);
  49. EXPECT_TRUE(matcher.MatchesPattern("prefix_for_string"));
  50. }
  51. TEST(PatternMatcherTest, MatchesPattern_MatchingNameWithRegex_ReturnsTrue)
  52. {
  53. PatternMatcher matcher("^.{4}$", PatternMatcher::MatchApproach::Regex);
  54. EXPECT_TRUE(matcher.MatchesPattern("fits"));
  55. }
  56. TEST(PatternMatcherTest, MatchesPattern_NonMatchingNameWithRegex_ReturnsFalse)
  57. {
  58. PatternMatcher matcher("^.{4}$", PatternMatcher::MatchApproach::Regex);
  59. EXPECT_FALSE(matcher.MatchesPattern("string_to_long_for_regex"));
  60. }
  61. TEST(PatternMatcherTest, MatchesPattern_MatchingPrefixInArrayOfPatterns_ReturnsTrue)
  62. {
  63. constexpr auto patterns = AZStd::to_array<AZStd::string_view>({ "postfix", "xxx", "prefix_" });
  64. PatternMatcher matcher(patterns, PatternMatcher::MatchApproach::PreFix);
  65. EXPECT_TRUE(matcher.MatchesPattern("prefix_for_string"));
  66. }
  67. TEST(PatternMatcherTest, MatchesPattern_NonMatchingPrefixInArrayOfPatterns_ReturnsFalse)
  68. {
  69. constexpr auto patterns = AZStd::to_array<AZStd::string_view>({ "postfix", "xxx" });
  70. PatternMatcher matcher(patterns, PatternMatcher::MatchApproach::PreFix);
  71. EXPECT_FALSE(matcher.MatchesPattern("prefix_for_string"));
  72. }
  73. } // SceneCore
  74. } // SceneAPI
  75. } // AZ