From f50ddc471f2492bf6608f325e45c0805072f511f Mon Sep 17 00:00:00 2001 From: Vlada Kanivets Date: Mon, 4 Aug 2025 16:16:06 +0200 Subject: [PATCH 1/7] add tests for USimpleString::matches --- test/CMakeLists.txt | 1 + test/USimpleStringTest.cpp | 133 +++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 test/USimpleStringTest.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0c2103b..628eda7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -44,6 +44,7 @@ wdk_add_driver(kf-test WINVER NTDDI_WIN10 STL HexTest.cpp MapTest.cpp Vector.cpp + USimpleStringTest.cpp ) target_link_libraries(kf-test kf::kf kmtest::kmtest) diff --git a/test/USimpleStringTest.cpp b/test/USimpleStringTest.cpp new file mode 100644 index 0000000..b994ea1 --- /dev/null +++ b/test/USimpleStringTest.cpp @@ -0,0 +1,133 @@ +#include "pch.h" +#include + +SCENARIO("USimpleString::matches") +{ + GIVEN("A pattern with '*' wildcard") + { + kf::USimpleString pattern = L"*.txt"; + + WHEN("The string matches the pattern") + { + kf::USimpleString matchingStr = L"example.txt"; + kf::USimpleString matchingStr2 = L"other-example123.txt"; + + THEN("Strings match the pattern") + { + REQUIRE(matchingStr.matches(pattern)); + REQUIRE(matchingStr2.matches(pattern)); + } + } + + WHEN("The string does not match the pattern") + { + kf::USimpleString nonMatchingStr = L"non-matching.exe"; + + THEN("The string does not match") + { + REQUIRE(!nonMatchingStr.matches(pattern)); + } + } + } + + GIVEN("A pattern with '?' wildcard") + { + kf::USimpleString pattern = L"e?amp?e.txt"; + + WHEN("The string matches the pattern") + { + kf::USimpleString matchingStr = L"example.txt"; + kf::USimpleString matchingStr2 = L"eeamppe.txt"; + + THEN("The string matches the pattern") + { + REQUIRE(matchingStr.matches(pattern)); + REQUIRE(matchingStr2.matches(pattern)); + } + } + + WHEN("The string does not match the pattern") + { + kf::USimpleString nonMatchingStr = L"nonExample.exe"; + + THEN("The string does not match") + { + REQUIRE(!nonMatchingStr.matches(pattern)); + } + } + } + + GIVEN("A pattern with mixed '*' and '?' wildcards") + { + kf::USimpleString pattern = L"?xample*.txt"; + + WHEN("The string matches the pattern") + { + kf::USimpleString matchingStr = L"xxample_123.txt"; + + THEN("The string matches the pattern") + { + REQUIRE(matchingStr.matches(pattern)); + } + } + + WHEN("The string does not match the pattern") + { + kf::USimpleString str = L"non-example.exe"; + + THEN("The string does not match") + { + REQUIRE(!str.matches(pattern)); + } + } + } + + WHEN("Empty pattern and empty string") + { + kf::USimpleString pattern = L""; + kf::USimpleString str = L""; + + THEN("They match") + { + REQUIRE(str.matches(pattern)); + } + } + + WHEN("Pattern is '*' and string is empty") + { + kf::USimpleString pattern = L"*"; + kf::USimpleString str = L""; + + THEN("'*' does not match an empty string") + { + REQUIRE(!str.matches(pattern)); + } + } + + WHEN("Pattern is empty and string is not") + { + kf::USimpleString pattern = L""; + kf::USimpleString str = L"file.txt"; + + THEN("They do not match") + { + REQUIRE(!str.matches(pattern)); + } + } + + WHEN("The string has different case") + { + kf::USimpleString pattern = L"example.txt"; + + kf::USimpleString str1 = L"Example.txt"; + kf::USimpleString str2 = L"EXAMPLE.TXT"; + kf::USimpleString str3 = L"eXample.TxT"; + + THEN("They do not match") + { + REQUIRE(!str1.matches(pattern)); + REQUIRE(!str2.matches(pattern)); + REQUIRE(!str3.matches(pattern)); + } + } +} From a5fb3be5199b55f5710ab3695f4493a6cf1f306c Mon Sep 17 00:00:00 2001 From: Vlada Kanivets Date: Mon, 4 Aug 2025 19:18:15 +0200 Subject: [PATCH 2/7] make USimpleString::matches irql independent --- include/kf/USimpleString.h | 75 +++++++++++++++++++++++++++++++++++++- test/CMakeLists.txt | 2 +- 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/include/kf/USimpleString.h b/include/kf/USimpleString.h index 176ec6f..32a3f66 100644 --- a/include/kf/USimpleString.h +++ b/include/kf/USimpleString.h @@ -573,7 +573,80 @@ namespace kf inline bool USimpleString::matches(_In_ const USimpleString& expression) const { - return !!::FsRtlIsNameInExpression(const_cast(&expression.string()), const_cast(&string()), false, NULL); + if (isEmpty() && !expression.isEmpty()) + { + return false; + } + + const auto& pattern = expression.m_str; + constexpr auto kStarSymbol = L'*'; + constexpr auto kQuestionMarkSymbol = L'?'; + + int starPos = -1; + int patternPos = 0; + + for (int currentPos = 0; currentPos < charLength(); currentPos++) + { + if (patternPos >= expression.charLength()) + { + // If we are at the end of the pattern, but not at the end of the string, it does not match + return false; + } + + // '*' is the last symbol in the pattern, so it matches everything + if (pattern.Buffer[patternPos] == kStarSymbol && patternPos == expression.charLength() - 1) + { + return true; + } + + if (pattern.Buffer[patternPos] == kStarSymbol) + { + patternPos++; + starPos = currentPos; + } + else if (starPos != -1) + { + int nextWildCPos = expression.charLength() - 1; + int asteriskIndex = expression.indexOf(kQuestionMarkSymbol, patternPos); + int questionMarkIndex = expression.indexOf(kStarSymbol, patternPos); + + if (asteriskIndex != -1 && questionMarkIndex != -1) + { + nextWildCPos = min(asteriskIndex, questionMarkIndex); + } + else if (asteriskIndex != -1) + { + nextWildCPos = asteriskIndex; + } + else if (questionMarkIndex != -1) + { + nextWildCPos = questionMarkIndex; + } + + auto patternSubString = expression.substring(patternPos, nextWildCPos + 1); + + auto restOfString = substring(currentPos); + int matchPos = restOfString.indexOf(patternSubString); + if (matchPos == -1) + { + return false; + } + + currentPos += matchPos + patternSubString.charLength() - 1; + patternPos = nextWildCPos; + starPos = -1; // reset star position + } + else if (pattern.Buffer[patternPos] == kQuestionMarkSymbol || pattern.Buffer[patternPos] == m_str.Buffer[currentPos]) + { + patternPos++; + } + else + { + return false; + } + } + + return true; } inline bool USimpleString::matchesIgnoreCase(_In_ const USimpleString& expression) const diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 628eda7..4b9e706 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -44,7 +44,7 @@ wdk_add_driver(kf-test WINVER NTDDI_WIN10 STL HexTest.cpp MapTest.cpp Vector.cpp - USimpleStringTest.cpp + USimpleStringTest.cpp ) target_link_libraries(kf-test kf::kf kmtest::kmtest) From 34a63aef7d494428a9e88b468ba81af9d49bb564 Mon Sep 17 00:00:00 2001 From: Vlada Kanivets Date: Tue, 5 Aug 2025 16:07:05 +0200 Subject: [PATCH 3/7] add more tests, fix USimpleString matches --- include/kf/USimpleString.h | 5 +- test/USimpleStringTest.cpp | 242 +++++++++++++++++++++++++++++++------ 2 files changed, 211 insertions(+), 36 deletions(-) diff --git a/include/kf/USimpleString.h b/include/kf/USimpleString.h index 32a3f66..89bf48e 100644 --- a/include/kf/USimpleString.h +++ b/include/kf/USimpleString.h @@ -603,10 +603,11 @@ namespace kf { patternPos++; starPos = currentPos; + currentPos--; // '*' can match zero characters, so we will check the current character on the next iteration } else if (starPos != -1) { - int nextWildCPos = expression.charLength() - 1; + int nextWildCPos = expression.charLength(); int asteriskIndex = expression.indexOf(kQuestionMarkSymbol, patternPos); int questionMarkIndex = expression.indexOf(kStarSymbol, patternPos); @@ -623,7 +624,7 @@ namespace kf nextWildCPos = questionMarkIndex; } - auto patternSubString = expression.substring(patternPos, nextWildCPos + 1); + auto patternSubString = expression.substring(patternPos, nextWildCPos); auto restOfString = substring(currentPos); int matchPos = restOfString.indexOf(patternSubString); diff --git a/test/USimpleStringTest.cpp b/test/USimpleStringTest.cpp index b994ea1..7289053 100644 --- a/test/USimpleStringTest.cpp +++ b/test/USimpleStringTest.cpp @@ -5,65 +5,160 @@ SCENARIO("USimpleString::matches") { GIVEN("A pattern with '*' wildcard") { - kf::USimpleString pattern = L"*.txt"; - - WHEN("The string matches the pattern") + WHEN("'*' at the beginning") { - kf::USimpleString matchingStr = L"example.txt"; - kf::USimpleString matchingStr2 = L"other-example123.txt"; + kf::USimpleString pattern(L"*.txt"); + kf::USimpleString matchingStr(L"example.txt"); + kf::USimpleString matchingStr2(L"other-example123.txt"); + kf::USimpleString matchingStr3(L"file.doc"); - THEN("Strings match the pattern") + THEN("example.txt and other-example123.txt match the pattern") { REQUIRE(matchingStr.matches(pattern)); REQUIRE(matchingStr2.matches(pattern)); } + + THEN("file.doc doesn't match the pattern") + { + REQUIRE(!matchingStr3.matches(pattern)); + } } - WHEN("The string does not match the pattern") + WHEN("'*' in the middle") { - kf::USimpleString nonMatchingStr = L"non-matching.exe"; + kf::USimpleString pattern(L"ex*.txt"); + kf::USimpleString matchingStr(L"example.txt"); + kf::USimpleString nonMatching(L"other-example123.txt"); - THEN("The string does not match") + THEN("example.txt matches the pattern ex*.txt") { - REQUIRE(!nonMatchingStr.matches(pattern)); + REQUIRE(matchingStr.matches(pattern)); + } + + THEN("other-example123.txt doesn't match the pattern ex*.txt") + { + REQUIRE(!nonMatching.matches(pattern)); } } - } - GIVEN("A pattern with '?' wildcard") - { - kf::USimpleString pattern = L"e?amp?e.txt"; + WHEN("'*' in the end") + { + kf::USimpleString pattern(L"example*"); + kf::USimpleString matchingStr(L"example.txt"); + kf::USimpleString nonMatching(L"other-example123.txt"); - WHEN("The string matches the pattern") + THEN("example.txt matches the pattern example*") + { + REQUIRE(matchingStr.matches(pattern)); + } + + THEN("other-example123.txt doesn't match the pattern example*") + { + REQUIRE(!nonMatching.matches(pattern)); + } + } + + WHEN("'*' at the beginning, in the middle and in the end") { - kf::USimpleString matchingStr = L"example.txt"; - kf::USimpleString matchingStr2 = L"eeamppe.txt"; + kf::USimpleString pattern(L"*ex*le*"); + kf::USimpleString matchingStr(L"example.txt"); + kf::USimpleString matchingStr2(L"other-example123.txt"); + kf::USimpleString nonMatching(L"file.csv"); - THEN("The string matches the pattern") + THEN("example.txt and other-example123.txt match the pattern *ex*le*") { REQUIRE(matchingStr.matches(pattern)); REQUIRE(matchingStr2.matches(pattern)); } + + THEN("file.csv doesn't match the pattern *ex*le*") + { + REQUIRE(!nonMatching.matches(pattern)); + } } + } - WHEN("The string does not match the pattern") + GIVEN("A pattern with '?' wildcard") + { + WHEN("'?' at the beginning") { - kf::USimpleString nonMatchingStr = L"nonExample.exe"; + kf::USimpleString pattern(L"?xample.txt"); + kf::USimpleString matchingStr (L"example.txt"); + kf::USimpleString nonMatchingStr (L"eeamppe.txt"); - THEN("The string does not match") + THEN("example.txt matches the pattern") + { + REQUIRE(matchingStr.matches(pattern)); + } + + THEN("eeamppe.txt does not match the pattern") { REQUIRE(!nonMatchingStr.matches(pattern)); } } + + GIVEN("A pattern with '?' wildcard") + { + WHEN("'?' at the beginning") + { + kf::USimpleString pattern(L"?xample.txt"); + kf::USimpleString matchingStr(L"example.txt"); + kf::USimpleString nonMatchingStr(L"eeamppe.txt"); + + THEN("example.txt matches the pattern ?xample.txt") + { + REQUIRE(matchingStr.matches(pattern)); + } + + THEN("eeamppe.txt does not match the pattern ?xample.txt") + { + REQUIRE(!nonMatchingStr.matches(pattern)); + } + } + + WHEN("'?' in the middle") + { + kf::USimpleString pattern(L"exa?ple.txt"); + kf::USimpleString matchingStr(L"example.txt"); + kf::USimpleString nonMatchingStr(L"eeamppe.txt"); + + THEN("example.txt matches the pattern exa?ple.txt") + { + REQUIRE(matchingStr.matches(pattern)); + } + + THEN("eeamppe.txt does not match the pattern exa?ple.txt") + { + REQUIRE(!nonMatchingStr.matches(pattern)); + } + } + + WHEN("'?' in the end") + { + kf::USimpleString pattern(L"example.tx?"); + kf::USimpleString matchingStr(L"example.txt"); + kf::USimpleString nonMatchingStr(L"eeamppe.txt"); + + THEN("example.txt matches the pattern example.tx?") + { + REQUIRE(matchingStr.matches(pattern)); + } + + THEN("eeamppe.txt does not match the pattern example.tx?") + { + REQUIRE(!nonMatchingStr.matches(pattern)); + } + } + } } GIVEN("A pattern with mixed '*' and '?' wildcards") { - kf::USimpleString pattern = L"?xample*.txt"; + kf::USimpleString pattern (L"?xample*.txt"); WHEN("The string matches the pattern") { - kf::USimpleString matchingStr = L"xxample_123.txt"; + kf::USimpleString matchingStr (L"xxample_123.txt"); THEN("The string matches the pattern") { @@ -73,7 +168,7 @@ SCENARIO("USimpleString::matches") WHEN("The string does not match the pattern") { - kf::USimpleString str = L"non-example.exe"; + kf::USimpleString str (L"non-example.exe"); THEN("The string does not match") { @@ -84,8 +179,8 @@ SCENARIO("USimpleString::matches") WHEN("Empty pattern and empty string") { - kf::USimpleString pattern = L""; - kf::USimpleString str = L""; + kf::USimpleString pattern (L""); + kf::USimpleString str (L""); THEN("They match") { @@ -95,8 +190,8 @@ SCENARIO("USimpleString::matches") WHEN("Pattern is '*' and string is empty") { - kf::USimpleString pattern = L"*"; - kf::USimpleString str = L""; + kf::USimpleString pattern (L"*"); + kf::USimpleString str (L""); THEN("'*' does not match an empty string") { @@ -106,8 +201,8 @@ SCENARIO("USimpleString::matches") WHEN("Pattern is empty and string is not") { - kf::USimpleString pattern = L""; - kf::USimpleString str = L"file.txt"; + kf::USimpleString pattern (L""); + kf::USimpleString str (L"file.txt"); THEN("They do not match") { @@ -117,11 +212,11 @@ SCENARIO("USimpleString::matches") WHEN("The string has different case") { - kf::USimpleString pattern = L"example.txt"; + kf::USimpleString pattern (L"example.txt"); - kf::USimpleString str1 = L"Example.txt"; - kf::USimpleString str2 = L"EXAMPLE.TXT"; - kf::USimpleString str3 = L"eXample.TxT"; + kf::USimpleString str1 (L"Example.txt"); + kf::USimpleString str2 (L"EXAMPLE.TXT"); + kf::USimpleString str3 (L"eXample.TxT"); THEN("They do not match") { @@ -131,3 +226,82 @@ SCENARIO("USimpleString::matches") } } } + +SCENARIO("USimpleString::matchesIgnoreCase") +{ + GIVEN("A pattern with '*' wildcard") + { + kf::USimpleString pattern(L"*.TXT"); + + kf::USimpleString matchingStr (L"EXAMPLE.TXT"); + kf::USimpleString matchingStr2 (L"Example.txt"); + kf::USimpleString matchingStr3 (L"example.txt"); + kf::USimpleString nonMatchingStr (L"NoN-matching.ExE"); + + THEN("EXAMPLE.TXT, Example.txt, example.txt match the pattern *.txt") + { + REQUIRE(matchingStr.matchesIgnoreCase(pattern)); + REQUIRE(matchingStr2.matchesIgnoreCase(pattern)); + REQUIRE(matchingStr3.matchesIgnoreCase(pattern)); + } + + THEN("NoN-matching.ExE does not match *.txt") + { + REQUIRE(!nonMatchingStr.matchesIgnoreCase(pattern)); + } + } + + GIVEN("A pattern with '?' wildcard") + { + kf::USimpleString pattern (L"E?AMP?E.TXT"); + + kf::USimpleString matchingStr (L"EXAMPLE.txt"); + kf::USimpleString matchingStr2 (L"eeamppe.txt"); + kf::USimpleString matchingStr3 (L"eXampLe.TXT"); + kf::USimpleString nonMatchingStr (L"Example.EXE"); + + THEN("EXAMPLE.txt, eeamppe.txt, eXampLe.TXT match the pattern e?amp?e.txt") + { + REQUIRE(matchingStr.matchesIgnoreCase(pattern)); + REQUIRE(matchingStr2.matchesIgnoreCase(pattern)); + REQUIRE(matchingStr3.matchesIgnoreCase(pattern)); + } + + THEN("Example.EXE does not match e?amp?e.txt") + { + REQUIRE(!nonMatchingStr.matchesIgnoreCase(pattern)); + } + } + + GIVEN("A pattern with mixed '*' and '?' wildcards") + { + kf::USimpleString pattern (L"?XAMPLE*.TXT"); + kf::USimpleString matchingStr (L"xxample_123.txt"); + kf::USimpleString matchingStr2 (L"xxAMPle_123.TXT"); + kf::USimpleString str (L"NoN-Example.exe"); + + THEN("xxample_123.txt, xxAMPle_123.TXT match the pattern ?xample*.txt") + { + REQUIRE(matchingStr.matchesIgnoreCase(pattern)); + REQUIRE(matchingStr2.matchesIgnoreCase(pattern)); + } + + THEN("NoN-Example.exe does not match the pattern ?xample*.txt") + { + REQUIRE(!str.matchesIgnoreCase(pattern)); + } + } + + WHEN("Pattern is empty and string is not") + { + kf::USimpleString pattern (L""); + kf::USimpleString str (L"file.txt"); + kf::USimpleString str2 (L"FILE.TXT"); + + THEN("They do not match") + { + REQUIRE(!str.matchesIgnoreCase(pattern)); + REQUIRE(!str2.matchesIgnoreCase(pattern)); + } + } +} From 272626d380a865f87c89ddff18fdd31d76d025fc Mon Sep 17 00:00:00 2001 From: Vlada Kanivets Date: Wed, 6 Aug 2025 13:06:26 +0200 Subject: [PATCH 4/7] remove Test-postfix from file names --- test/CMakeLists.txt | 6 +++--- test/{HexTest.cpp => Hex.cpp} | 0 test/{MapTest.cpp => Map.cpp} | 0 test/{USimpleStringTest.cpp => USimpleString.cpp} | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename test/{HexTest.cpp => Hex.cpp} (100%) rename test/{MapTest.cpp => Map.cpp} (100%) rename test/{USimpleStringTest.cpp => USimpleString.cpp} (100%) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4b9e706..c89d3fb 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -41,10 +41,10 @@ wdk_add_driver(kf-test WINVER NTDDI_WIN10 STL AdjacentView.cpp Bitmap.cpp BitmapRangeIterator.cpp - HexTest.cpp - MapTest.cpp + Hex.cpp + Map.cpp Vector.cpp - USimpleStringTest.cpp + USimpleString.cpp ) target_link_libraries(kf-test kf::kf kmtest::kmtest) diff --git a/test/HexTest.cpp b/test/Hex.cpp similarity index 100% rename from test/HexTest.cpp rename to test/Hex.cpp diff --git a/test/MapTest.cpp b/test/Map.cpp similarity index 100% rename from test/MapTest.cpp rename to test/Map.cpp diff --git a/test/USimpleStringTest.cpp b/test/USimpleString.cpp similarity index 100% rename from test/USimpleStringTest.cpp rename to test/USimpleString.cpp From 9e46517c9332e644d15a12ee69616dc4023b3e65 Mon Sep 17 00:00:00 2001 From: Vlada Kanivets Date: Wed, 6 Aug 2025 13:09:53 +0200 Subject: [PATCH 5/7] revert USimpleString::matches --- include/kf/USimpleString.h | 76 +------------------------------------- 1 file changed, 1 insertion(+), 75 deletions(-) diff --git a/include/kf/USimpleString.h b/include/kf/USimpleString.h index 89bf48e..176ec6f 100644 --- a/include/kf/USimpleString.h +++ b/include/kf/USimpleString.h @@ -573,81 +573,7 @@ namespace kf inline bool USimpleString::matches(_In_ const USimpleString& expression) const { - if (isEmpty() && !expression.isEmpty()) - { - return false; - } - - const auto& pattern = expression.m_str; - constexpr auto kStarSymbol = L'*'; - constexpr auto kQuestionMarkSymbol = L'?'; - - int starPos = -1; - int patternPos = 0; - - for (int currentPos = 0; currentPos < charLength(); currentPos++) - { - if (patternPos >= expression.charLength()) - { - // If we are at the end of the pattern, but not at the end of the string, it does not match - return false; - } - - // '*' is the last symbol in the pattern, so it matches everything - if (pattern.Buffer[patternPos] == kStarSymbol && patternPos == expression.charLength() - 1) - { - return true; - } - - if (pattern.Buffer[patternPos] == kStarSymbol) - { - patternPos++; - starPos = currentPos; - currentPos--; // '*' can match zero characters, so we will check the current character on the next iteration - } - else if (starPos != -1) - { - int nextWildCPos = expression.charLength(); - int asteriskIndex = expression.indexOf(kQuestionMarkSymbol, patternPos); - int questionMarkIndex = expression.indexOf(kStarSymbol, patternPos); - - if (asteriskIndex != -1 && questionMarkIndex != -1) - { - nextWildCPos = min(asteriskIndex, questionMarkIndex); - } - else if (asteriskIndex != -1) - { - nextWildCPos = asteriskIndex; - } - else if (questionMarkIndex != -1) - { - nextWildCPos = questionMarkIndex; - } - - auto patternSubString = expression.substring(patternPos, nextWildCPos); - - auto restOfString = substring(currentPos); - int matchPos = restOfString.indexOf(patternSubString); - if (matchPos == -1) - { - return false; - } - - currentPos += matchPos + patternSubString.charLength() - 1; - patternPos = nextWildCPos; - starPos = -1; // reset star position - } - else if (pattern.Buffer[patternPos] == kQuestionMarkSymbol || pattern.Buffer[patternPos] == m_str.Buffer[currentPos]) - { - patternPos++; - } - else - { - return false; - } - } - - return true; + return !!::FsRtlIsNameInExpression(const_cast(&expression.string()), const_cast(&string()), false, NULL); } inline bool USimpleString::matchesIgnoreCase(_In_ const USimpleString& expression) const From 627cec30946973a11d511252a1c27274f41b0336 Mon Sep 17 00:00:00 2001 From: Vlada Kanivets Date: Tue, 12 Aug 2025 12:36:51 +0200 Subject: [PATCH 6/7] remove duplicated test --- test/USimpleString.cpp | 74 +++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 47 deletions(-) diff --git a/test/USimpleString.cpp b/test/USimpleString.cpp index 7289053..118baba 100644 --- a/test/USimpleString.cpp +++ b/test/USimpleString.cpp @@ -83,71 +83,51 @@ SCENARIO("USimpleString::matches") WHEN("'?' at the beginning") { kf::USimpleString pattern(L"?xample.txt"); - kf::USimpleString matchingStr (L"example.txt"); - kf::USimpleString nonMatchingStr (L"eeamppe.txt"); + kf::USimpleString matchingStr(L"example.txt"); + kf::USimpleString nonMatchingStr(L"eeamppe.txt"); - THEN("example.txt matches the pattern") + THEN("example.txt matches the pattern ?xample.txt") { REQUIRE(matchingStr.matches(pattern)); } - THEN("eeamppe.txt does not match the pattern") + THEN("eeamppe.txt does not match the pattern ?xample.txt") { REQUIRE(!nonMatchingStr.matches(pattern)); } } - GIVEN("A pattern with '?' wildcard") + WHEN("'?' in the middle") { - WHEN("'?' at the beginning") + kf::USimpleString pattern(L"exa?ple.txt"); + kf::USimpleString matchingStr(L"example.txt"); + kf::USimpleString nonMatchingStr(L"eeamppe.txt"); + + THEN("example.txt matches the pattern exa?ple.txt") + { + REQUIRE(matchingStr.matches(pattern)); + } + + THEN("eeamppe.txt does not match the pattern exa?ple.txt") { - kf::USimpleString pattern(L"?xample.txt"); - kf::USimpleString matchingStr(L"example.txt"); - kf::USimpleString nonMatchingStr(L"eeamppe.txt"); - - THEN("example.txt matches the pattern ?xample.txt") - { - REQUIRE(matchingStr.matches(pattern)); - } - - THEN("eeamppe.txt does not match the pattern ?xample.txt") - { - REQUIRE(!nonMatchingStr.matches(pattern)); - } + REQUIRE(!nonMatchingStr.matches(pattern)); } + } - WHEN("'?' in the middle") + WHEN("'?' in the end") + { + kf::USimpleString pattern(L"example.tx?"); + kf::USimpleString matchingStr(L"example.txt"); + kf::USimpleString nonMatchingStr(L"eeamppe.txt"); + + THEN("example.txt matches the pattern example.tx?") { - kf::USimpleString pattern(L"exa?ple.txt"); - kf::USimpleString matchingStr(L"example.txt"); - kf::USimpleString nonMatchingStr(L"eeamppe.txt"); - - THEN("example.txt matches the pattern exa?ple.txt") - { - REQUIRE(matchingStr.matches(pattern)); - } - - THEN("eeamppe.txt does not match the pattern exa?ple.txt") - { - REQUIRE(!nonMatchingStr.matches(pattern)); - } + REQUIRE(matchingStr.matches(pattern)); } - WHEN("'?' in the end") + THEN("eeamppe.txt does not match the pattern example.tx?") { - kf::USimpleString pattern(L"example.tx?"); - kf::USimpleString matchingStr(L"example.txt"); - kf::USimpleString nonMatchingStr(L"eeamppe.txt"); - - THEN("example.txt matches the pattern example.tx?") - { - REQUIRE(matchingStr.matches(pattern)); - } - - THEN("eeamppe.txt does not match the pattern example.tx?") - { - REQUIRE(!nonMatchingStr.matches(pattern)); - } + REQUIRE(!nonMatchingStr.matches(pattern)); } } } From 4b7fc7cedcf0abb8eda7272a6a8ddff90155e4ef Mon Sep 17 00:00:00 2001 From: Vlada Kanivets Date: Tue, 12 Aug 2025 22:38:06 +0200 Subject: [PATCH 7/7] revert cpp names --- test/CMakeLists.txt | 6 +++--- test/{Hex.cpp => HexTest.cpp} | 0 test/{Map.cpp => MapTest.cpp} | 0 test/{USimpleString.cpp => USimpleStringTest.cpp} | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename test/{Hex.cpp => HexTest.cpp} (100%) rename test/{Map.cpp => MapTest.cpp} (100%) rename test/{USimpleString.cpp => USimpleStringTest.cpp} (100%) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c89d3fb..4b9e706 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -41,10 +41,10 @@ wdk_add_driver(kf-test WINVER NTDDI_WIN10 STL AdjacentView.cpp Bitmap.cpp BitmapRangeIterator.cpp - Hex.cpp - Map.cpp + HexTest.cpp + MapTest.cpp Vector.cpp - USimpleString.cpp + USimpleStringTest.cpp ) target_link_libraries(kf-test kf::kf kmtest::kmtest) diff --git a/test/Hex.cpp b/test/HexTest.cpp similarity index 100% rename from test/Hex.cpp rename to test/HexTest.cpp diff --git a/test/Map.cpp b/test/MapTest.cpp similarity index 100% rename from test/Map.cpp rename to test/MapTest.cpp diff --git a/test/USimpleString.cpp b/test/USimpleStringTest.cpp similarity index 100% rename from test/USimpleString.cpp rename to test/USimpleStringTest.cpp