提交 cd3c17be 编写于 作者: G Gen Lu

Add a mocked clipboard for interactive window tests

上级 e2ded549
...@@ -543,18 +543,16 @@ private static void DoEvents() ...@@ -543,18 +543,16 @@ private static void DoEvents()
#endregion #endregion
internal class ClipboardWrapper internal class ClipboardWrapper
{ {
internal virtual void Clear() => Clipboard.Clear(); internal bool ContainsData(string format) => Clipboard.ContainsData(format);
internal virtual bool ContainsData(string format) => Clipboard.ContainsData(format);
internal virtual object GetData(string format) => Clipboard.GetData(format); internal object GetData(string format) => Clipboard.GetData(format);
internal virtual bool ContainsText() => Clipboard.ContainsText(); internal bool ContainsText() => Clipboard.ContainsText();
internal virtual string GetText() => Clipboard.GetText(); internal string GetText() => Clipboard.GetText();
internal virtual void SetDataObject(object data, bool copy) => Clipboard.SetDataObject(data, copy); internal void SetDataObject(object data, bool copy) => Clipboard.SetDataObject(data, copy);
} }
} }
} }
...@@ -25,6 +25,8 @@ public InteractiveWindowTests() ...@@ -25,6 +25,8 @@ public InteractiveWindowTests()
{ {
_states = new List<InteractiveWindow.State>(); _states = new List<InteractiveWindow.State>();
_testHost = new InteractiveWindowTestHost(_states.Add); _testHost = new InteractiveWindowTestHost(_states.Add);
((InteractiveWindow)Window).InteractiveWindowClipboard = new TestClipboard();
} }
void IDisposable.Dispose() void IDisposable.Dispose()
...@@ -34,6 +36,8 @@ void IDisposable.Dispose() ...@@ -34,6 +36,8 @@ void IDisposable.Dispose()
private IInteractiveWindow Window => _testHost.Window; private IInteractiveWindow Window => _testHost.Window;
private InteractiveWindow.ClipboardWrapper WindowClipboard => ((InteractiveWindow)Window).InteractiveWindowClipboard;
private static IEnumerable<IInteractiveWindowCommand> MockCommands(params string[] commandNames) private static IEnumerable<IInteractiveWindowCommand> MockCommands(params string[] commandNames)
{ {
foreach (var name in commandNames) foreach (var name in commandNames)
...@@ -582,7 +586,7 @@ public void ReformatBraces() ...@@ -582,7 +586,7 @@ public void ReformatBraces()
[Fact(Skip = "5544"), WorkItem(5544, "https://github.com/dotnet/roslyn/issues/5544")] [Fact(Skip = "5544"), WorkItem(5544, "https://github.com/dotnet/roslyn/issues/5544")]
public void CopyWithinInput() public void CopyWithinInput()
{ {
Clipboard.Clear(); ClearClipboard();
Window.InsertCode("1 + 2"); Window.InsertCode("1 + 2");
Window.Operations.SelectAll(); Window.Operations.SelectAll();
...@@ -601,7 +605,7 @@ public void CopyWithinInput() ...@@ -601,7 +605,7 @@ public void CopyWithinInput()
[Fact(Skip = "5544"), WorkItem(5544, "https://github.com/dotnet/roslyn/issues/5544")] [Fact(Skip = "5544"), WorkItem(5544, "https://github.com/dotnet/roslyn/issues/5544")]
public void CopyInputAndOutput() public void CopyInputAndOutput()
{ {
Clipboard.Clear(); ClearClipboard();
Submit( Submit(
@"foreach (var o in new[] { 1, 2, 3 }) @"foreach (var o in new[] { 1, 2, 3 })
...@@ -644,7 +648,7 @@ public void CopyInputAndOutput() ...@@ -644,7 +648,7 @@ public void CopyInputAndOutput()
[Fact(Skip = "5544"), WorkItem(5544, "https://github.com/dotnet/roslyn/issues/5544")] [Fact(Skip = "5544"), WorkItem(5544, "https://github.com/dotnet/roslyn/issues/5544")]
public void CutWithinInput() public void CutWithinInput()
{ {
Clipboard.Clear(); ClearClipboard();
Window.InsertCode("foreach (var o in new[] { 1, 2, 3 })"); Window.InsertCode("foreach (var o in new[] { 1, 2, 3 })");
Window.Operations.BreakLine(); Window.Operations.BreakLine();
...@@ -672,7 +676,7 @@ public void CutWithinInput() ...@@ -672,7 +676,7 @@ public void CutWithinInput()
[Fact(Skip = "5544"), WorkItem(5544, "https://github.com/dotnet/roslyn/issues/5544")] [Fact(Skip = "5544"), WorkItem(5544, "https://github.com/dotnet/roslyn/issues/5544")]
public void CutInputAndOutput() public void CutInputAndOutput()
{ {
Clipboard.Clear(); ClearClipboard();
Submit( Submit(
@"foreach (var o in new[] { 1, 2, 3 }) @"foreach (var o in new[] { 1, 2, 3 })
...@@ -719,7 +723,7 @@ private void CopyNoSelectionAndVerify(int start, int end, string expectedText, s ...@@ -719,7 +723,7 @@ private void CopyNoSelectionAndVerify(int start, int end, string expectedText, s
var snapshot = Window.TextView.TextBuffer.CurrentSnapshot; var snapshot = Window.TextView.TextBuffer.CurrentSnapshot;
for (int i = start; i < end; i++) for (int i = start; i < end; i++)
{ {
Clipboard.Clear(); ClearClipboard();
caret.MoveTo(new SnapshotPoint(snapshot, i)); caret.MoveTo(new SnapshotPoint(snapshot, i));
Window.Operations.Copy(); Window.Operations.Copy();
VerifyClipboardData(expectedText, expectedRtf, expectedRepl); VerifyClipboardData(expectedText, expectedRtf, expectedRepl);
...@@ -1115,8 +1119,8 @@ public void CutWithOutSelectionInReadOnlyArea() ...@@ -1115,8 +1119,8 @@ public void CutWithOutSelectionInReadOnlyArea()
"); ");
Window.InsertCode("2"); Window.InsertCode("2");
var caret = Window.TextView.Caret; var caret = Window.TextView.Caret;
Clipboard.Clear(); ClearClipboard();
// Cut() with caret in readonly area, no-op // Cut() with caret in readonly area, no-op
caret.MoveToPreviousCaretPosition(); caret.MoveToPreviousCaretPosition();
...@@ -1152,7 +1156,7 @@ public void CutWithSelectionInReadonlyArea() ...@@ -1152,7 +1156,7 @@ public void CutWithSelectionInReadonlyArea()
var caret = Window.TextView.Caret; var caret = Window.TextView.Caret;
var selection = Window.TextView.Selection; var selection = Window.TextView.Selection;
Clipboard.Clear(); ClearClipboard();
// Cut() with selection in readonly area, no-op // Cut() with selection in readonly area, no-op
...@@ -1211,7 +1215,7 @@ public void PasteWithOutSelectionInReadOnlyArea() ...@@ -1211,7 +1215,7 @@ public void PasteWithOutSelectionInReadOnlyArea()
var caret = Window.TextView.Caret; var caret = Window.TextView.Caret;
Clipboard.Clear(); ClearClipboard();
Window.Operations.Home(true); Window.Operations.Home(true);
Window.Operations.Copy(); Window.Operations.Copy();
VerifyClipboardData("2", @"\ansi{\fonttbl{\f0 Consolas;}}{\colortbl;\red0\green0\blue0;\red255\green255\blue255;}\f0 \fs24 \cf1 \cb2 \highlight2 2", @"[{""content"":""2"",""kind"":2}]"); VerifyClipboardData("2", @"\ansi{\fonttbl{\f0 Consolas;}}{\colortbl;\red0\green0\blue0;\red255\green255\blue255;}\f0 \fs24 \cf1 \cb2 \highlight2 2", @"[{""content"":""2"",""kind"":2}]");
...@@ -1236,7 +1240,7 @@ public void PasteWithOutSelectionInReadOnlyArea() ...@@ -1236,7 +1240,7 @@ public void PasteWithOutSelectionInReadOnlyArea()
AssertCaretVirtualPosition(2, 3); AssertCaretVirtualPosition(2, 3);
} }
[Fact(Skip = "5544"), WorkItem(5544, "https://github.com/dotnet/roslyn/issues/5544")] [Fact(Skip = "5544"), WorkItem(5544, "https://github.com/dotnet/roslyn/issues/5544")]
public void PasteWithSelectionInReadonlyArea() public void PasteWithSelectionInReadonlyArea()
{ {
Submit( Submit(
...@@ -1248,7 +1252,7 @@ public void PasteWithSelectionInReadonlyArea() ...@@ -1248,7 +1252,7 @@ public void PasteWithSelectionInReadonlyArea()
var caret = Window.TextView.Caret; var caret = Window.TextView.Caret;
var selection = Window.TextView.Selection; var selection = Window.TextView.Selection;
Clipboard.Clear(); ClearClipboard();
Window.Operations.Home(true); Window.Operations.Home(true);
Window.Operations.Copy(); Window.Operations.Copy();
VerifyClipboardData("23", @"\ansi{\fonttbl{\f0 Consolas;}}{\colortbl;\red0\green0\blue0;\red255\green255\blue255;}\f0 \fs24 \cf1 \cb2 \highlight2 23", @"[{""content"":""23"",""kind"":2}]"); VerifyClipboardData("23", @"\ansi{\fonttbl{\f0 Consolas;}}{\colortbl;\red0\green0\blue0;\red255\green255\blue255;}\f0 \fs24 \cf1 \cb2 \highlight2 23", @"[{""content"":""23"",""kind"":2}]");
...@@ -1295,6 +1299,11 @@ public void PasteWithSelectionInReadonlyArea() ...@@ -1295,6 +1299,11 @@ public void PasteWithSelectionInReadonlyArea()
AssertCaretVirtualPosition(2, 4); AssertCaretVirtualPosition(2, 4);
} }
private void ClearClipboard()
{
((TestClipboard)((InteractiveWindow)Window).InteractiveWindowClipboard).Clear();
}
private void Submit(string submission, string output) private void Submit(string submission, string output)
{ {
Task.Run(() => Window.SubmitAsync(new[] { submission })).PumpingWait(); Task.Run(() => Window.SubmitAsync(new[] { submission })).PumpingWait();
...@@ -1362,4 +1371,21 @@ internal static void Copy(this IInteractiveWindowOperations operations) ...@@ -1362,4 +1371,21 @@ internal static void Copy(this IInteractiveWindowOperations operations)
((IInteractiveWindowOperations2)operations).Copy(); ((IInteractiveWindowOperations2)operations).Copy();
} }
} }
internal sealed class TestClipboard : InteractiveWindow.ClipboardWrapper
{
private DataObject _data = null;
internal void Clear() => _data = null;
internal new bool ContainsData(string format) => _data?.GetData(format) != null;
internal new object GetData(string format) => _data?.GetData(format);
internal new bool ContainsText() => _data != null ? _data.ContainsText() : false;
internal new string GetText() => _data?.GetText();
internal new void SetDataObject(object data, bool copy) => _data = data as DataObject;
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册