From e4a9c16c99feb8bc1c2df1dd7b90c6ab2ab98f13 Mon Sep 17 00:00:00 2001 From: Chris Lovett Date: Sat, 19 Mar 2022 18:06:58 -0700 Subject: [PATCH] Add replace many test to ensure that logic doesn't regress again. --- src/UnitTests/UnitTest1.cs | 57 +++++++++++++++++++++++++++++++++- src/UnitTests/UnitTests.csproj | 1 + src/UnitTests/test10.xml | 8 +++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/UnitTests/test10.xml diff --git a/src/UnitTests/UnitTest1.cs b/src/UnitTests/UnitTest1.cs index 565f42fb..7f0a315e 100644 --- a/src/UnitTests/UnitTest1.cs +++ b/src/UnitTests/UnitTest1.cs @@ -1584,6 +1584,48 @@ public void TestFind() // find should not modify the document, so we should be able to exit without saveas dialog. } + [TestMethod] + [Timeout(TestMethodTimeout)] + public void TestReplaceMany() + { + ResetFindOptions(); + + Trace.WriteLine("TestReplace=========================================================="); + string testFile = _testDir + "UnitTests\\test10.xml"; + var w = LaunchNotepad(testFile); + + w.SendKeystrokes("{HOME}"); + w.SendKeystrokes("^c"); + var original = GetClipboardText(); + var findDialog = OpenReplaceDialog(); + + // replace all instances of "item" with something longer "xxxxxxx"; + findDialog.Window.SendKeystrokes("item{TAB}xxxxxxx%a"); + findDialog.Window.DismissPopUp("{ESC}"); + + w.SendKeystrokes("{ESC}{HOME}"); + CheckOuterXml(original.Replace("item", "xxxxxxx")); + + Trace.WriteLine("Check compound undo."); + Undo(); + w.SendKeystrokes("{HOME}"); + CheckOuterXml(original); + + findDialog = OpenReplaceDialog(); + + // replace all instances of "item" with something shorter "YY"; + findDialog.Window.SendKeystrokes("item{TAB}YY%a"); + findDialog.Window.DismissPopUp("{ESC}"); + + w.SendKeystrokes("{ESC}{HOME}"); + CheckOuterXml(original.Replace("item", "YY")); + + Trace.WriteLine("Check compound undo."); + Undo(); + w.SendKeystrokes("{HOME}"); + CheckOuterXml(original); + } + [TestMethod] [Timeout(TestMethodTimeout)] public void TestReplace() @@ -1596,7 +1638,6 @@ public void TestReplace() w.SendKeystrokes("{HOME}"); var findDialog = OpenReplaceDialog(); - findDialog.ClearFindCheckBoxes(); Trace.WriteLine("Toggle dialog using ctrl+f & ctrl+h"); findDialog.Window.SendKeystrokes("^f"); @@ -3064,6 +3105,20 @@ void CheckProperties(AutomationWrapper node) //Trace.WriteLine("\tHelpTopic=" + node.GetHelpTopic(out filename)); } + public string GetClipboardText() + { + int retries = 5; + while (retries-- > 0) + { + if (Clipboard.ContainsText()) + { + return Clipboard.GetText(); + } + Sleep(250); + } + + throw new ApplicationException("clipboard does not contain any text!"); + } public override void CheckClipboard(string expected) { int retries = 5; diff --git a/src/UnitTests/UnitTests.csproj b/src/UnitTests/UnitTests.csproj index 5e85651b..94664827 100644 --- a/src/UnitTests/UnitTests.csproj +++ b/src/UnitTests/UnitTests.csproj @@ -74,6 +74,7 @@ Designer + diff --git a/src/UnitTests/test10.xml b/src/UnitTests/test10.xml new file mode 100644 index 00000000..fa5ab766 --- /dev/null +++ b/src/UnitTests/test10.xml @@ -0,0 +1,8 @@ + + Apple + Banana + Grape + Peach + This contains multiple matching items and item and item + Watermelon + \ No newline at end of file