Skip to content

Commit e4a9c16

Browse files
committed
Add replace many test to ensure that logic doesn't regress again.
1 parent 5d7295f commit e4a9c16

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

src/UnitTests/UnitTest1.cs

+56-1
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,48 @@ public void TestFind()
15841584
// find should not modify the document, so we should be able to exit without saveas dialog.
15851585
}
15861586

1587+
[TestMethod]
1588+
[Timeout(TestMethodTimeout)]
1589+
public void TestReplaceMany()
1590+
{
1591+
ResetFindOptions();
1592+
1593+
Trace.WriteLine("TestReplace==========================================================");
1594+
string testFile = _testDir + "UnitTests\\test10.xml";
1595+
var w = LaunchNotepad(testFile);
1596+
1597+
w.SendKeystrokes("{HOME}");
1598+
w.SendKeystrokes("^c");
1599+
var original = GetClipboardText();
1600+
var findDialog = OpenReplaceDialog();
1601+
1602+
// replace all instances of "item" with something longer "xxxxxxx";
1603+
findDialog.Window.SendKeystrokes("item{TAB}xxxxxxx%a");
1604+
findDialog.Window.DismissPopUp("{ESC}");
1605+
1606+
w.SendKeystrokes("{ESC}{HOME}");
1607+
CheckOuterXml(original.Replace("item", "xxxxxxx"));
1608+
1609+
Trace.WriteLine("Check compound undo.");
1610+
Undo();
1611+
w.SendKeystrokes("{HOME}");
1612+
CheckOuterXml(original);
1613+
1614+
findDialog = OpenReplaceDialog();
1615+
1616+
// replace all instances of "item" with something shorter "YY";
1617+
findDialog.Window.SendKeystrokes("item{TAB}YY%a");
1618+
findDialog.Window.DismissPopUp("{ESC}");
1619+
1620+
w.SendKeystrokes("{ESC}{HOME}");
1621+
CheckOuterXml(original.Replace("item", "YY"));
1622+
1623+
Trace.WriteLine("Check compound undo.");
1624+
Undo();
1625+
w.SendKeystrokes("{HOME}");
1626+
CheckOuterXml(original);
1627+
}
1628+
15871629
[TestMethod]
15881630
[Timeout(TestMethodTimeout)]
15891631
public void TestReplace()
@@ -1596,7 +1638,6 @@ public void TestReplace()
15961638

15971639
w.SendKeystrokes("{HOME}");
15981640
var findDialog = OpenReplaceDialog();
1599-
findDialog.ClearFindCheckBoxes();
16001641

16011642
Trace.WriteLine("Toggle dialog using ctrl+f & ctrl+h");
16021643
findDialog.Window.SendKeystrokes("^f");
@@ -3064,6 +3105,20 @@ void CheckProperties(AutomationWrapper node)
30643105
//Trace.WriteLine("\tHelpTopic=" + node.GetHelpTopic(out filename));
30653106
}
30663107

3108+
public string GetClipboardText()
3109+
{
3110+
int retries = 5;
3111+
while (retries-- > 0)
3112+
{
3113+
if (Clipboard.ContainsText())
3114+
{
3115+
return Clipboard.GetText();
3116+
}
3117+
Sleep(250);
3118+
}
3119+
3120+
throw new ApplicationException("clipboard does not contain any text!");
3121+
}
30673122
public override void CheckClipboard(string expected)
30683123
{
30693124
int retries = 5;

src/UnitTests/UnitTests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<Content Include="Test1.xml">
7575
<SubType>Designer</SubType>
7676
</Content>
77+
<Content Include="test10.xml" />
7778
<Content Include="test2.xml" />
7879
<Content Include="test3.xml" />
7980
<Content Include="test4.xml" />

src/UnitTests/test10.xml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<test>
2+
<item>Apple</item>
3+
<item>Banana</item>
4+
<item>Grape</item>
5+
<item>Peach</item>
6+
<item>This contains multiple matching items and item and item</item>
7+
<item>Watermelon</item>
8+
</test>

0 commit comments

Comments
 (0)