Skip to content

Commit

Permalink
Add replace many test to ensure that logic doesn't regress again.
Browse files Browse the repository at this point in the history
  • Loading branch information
clovett committed Mar 20, 2022
1 parent 5d7295f commit e4a9c16
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
57 changes: 56 additions & 1 deletion src/UnitTests/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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");
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<Content Include="Test1.xml">
<SubType>Designer</SubType>
</Content>
<Content Include="test10.xml" />
<Content Include="test2.xml" />
<Content Include="test3.xml" />
<Content Include="test4.xml" />
Expand Down
8 changes: 8 additions & 0 deletions src/UnitTests/test10.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<test>
<item>Apple</item>
<item>Banana</item>
<item>Grape</item>
<item>Peach</item>
<item>This contains multiple matching items and item and item</item>
<item>Watermelon</item>
</test>

0 comments on commit e4a9c16

Please sign in to comment.