mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
PowerRename: Add Lookbehind (#7571)
* Add boost-regex library * If enabled use boost lib for regex Add property `_useBoostLib` to `CPowerRenameRegEx`. If enabled for replacements with regular expressions the Boost Library is used instead of the Standard Library. * Extend signatures to create RegEx with Boost Extend create and constructor singatures of `CPowerRenameRegEx` with an option to enable (or disabled, which is default) the Boost Library. * Verify Lookbehind fails with STD library To verify that the boost library is disabled as expected, check if a lookbehind fails. * Add Unit tests for RegEx with Boost Add unit tests to verify regex replacement with Boost Library. They are copied and adapted from the Standard Library tests. * Improve verify capturing groups test with Boost It is possible to use a capturing group followed by numbers as replacement if the group number is enclosed in curly braces. Added test cases based on the Standard Library tests. * Add useBoostLib to settings interface * Get library option from settings object * Reduce signatures of RegEx by "useBoost" Remove the parameter added in 19105cf, as it became obsolete. * Settings: Read useBoostLib from JSON file * Add UseBoostLib Option to UI * Boost Lib label states the regex syntax difference * Fix Regex with Boost Lib tests - Do not load settings another time in CPowerRenameRegEx ctor - Set flag correctly in standard library regex tests * Add "lookbehind" to dictionary * change Library to lowercase, and also add a comment As suggested by @enricogior. Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com> * Change Library to lowercase and add a comment As suggested by @enricogior. Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "pch.h"
|
||||
#include "CppUnitTest.h"
|
||||
#include "powerrename/lib/Settings.h"
|
||||
#include <PowerRenameInterfaces.h>
|
||||
#include <PowerRenameRegEx.h>
|
||||
#include "MockPowerRenameRegExEvents.h"
|
||||
@@ -18,8 +19,14 @@ namespace PowerRenameRegExTests
|
||||
|
||||
TEST_CLASS(SimpleTests){
|
||||
public:
|
||||
TEST_METHOD(GeneralReplaceTest){
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
TEST_CLASS_INITIALIZE(ClassInitialize)
|
||||
{
|
||||
CSettingsInstance().SetUseBoostLib(false);
|
||||
}
|
||||
|
||||
TEST_METHOD(GeneralReplaceTest)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->PutSearchTerm(L"foo") == S_OK);
|
||||
@@ -362,6 +369,30 @@ TEST_METHOD(VerifyHandleCapturingGroups)
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(VerifyLookbehindFails)
|
||||
{
|
||||
// Standard Library Regex Engine does not support lookbehind, thus test should fail.
|
||||
SearchReplaceExpected sreTable[] = {
|
||||
//search, replace, test, result
|
||||
{ L"(?<=E12).*", L"Foo", L"AAAAAA", nullptr },
|
||||
{ L"(?<!E12).*", L"Foo", L"AAAAAA", nullptr },
|
||||
};
|
||||
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->PutFlags(UseRegularExpressions) == S_OK);
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(sreTable); i++)
|
||||
{
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->PutSearchTerm(sreTable[i].search) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->PutReplaceTerm(sreTable[i].replace) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(sreTable[i].test, &result) == E_FAIL);
|
||||
Assert::AreEqual(sreTable[i].expected, result);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(VerifyEventsFire)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
|
||||
Reference in New Issue
Block a user