forked from PowerShell/PSReadLine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreenCaptureTest.cs
More file actions
85 lines (70 loc) · 3.66 KB
/
Copy pathScreenCaptureTest.cs
File metadata and controls
85 lines (70 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Linq;
using System.Windows;
using Microsoft.QualityTools.Testing.Fakes;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PSConsoleUtilities;
namespace UnitTestPSReadLine
{
// Disgusting language hack to make it easier to read a sequence of keys.
using _ = Keys;
public partial class UnitTest
{
[TestMethod]
public void TestCaptureScreen()
{
TestSetup(KeyMode.Cmd,
new KeyHandler("Ctrl+Z", PSConsoleReadLine.CaptureScreen));
var line = new [] {"echo alpha", "echo beta", "echo phi", "echo rho"};
Test(line[0], Keys(line[0], _.CtrlZ, _.Enter, _.Enter));
AssertScreenCaptureClipboardIs(line[0]);
var cancelKeys = new[] {_.Escape, _.CtrlC, _.CtrlG};
for (int i = 0; i < cancelKeys.Length; i++)
{
// Start CaptureScreen but cancel
Test(line[i + 1], Keys(line[i + 1], _.CtrlZ, cancelKeys[i], _.Enter), resetCursor: false);
// Make sure the clipboard doesn't change
AssertScreenCaptureClipboardIs(line[0]);
}
// Make sure we know where we are on the screen.
AssertCursorTopIs(4);
var shiftUpArrow = new ConsoleKeyInfo((char)0, ConsoleKey.UpArrow, true, false, false);
var shiftDownArrow = new ConsoleKeyInfo((char)0, ConsoleKey.DownArrow, true, false, false);
using (ShimsContext.Create())
{
bool ding = false;
PSConsoleUtilities.Fakes.ShimPSConsoleReadLine.Ding =
() => ding = true;
Test("", Keys(
// Basic up/down arrows
_.CtrlZ, _.UpArrow, _.Enter, CheckThat(() => AssertScreenCaptureClipboardIs(line[3])),
_.CtrlZ, _.UpArrow, _.UpArrow, _.Enter, CheckThat(() => AssertScreenCaptureClipboardIs(line[2])),
_.CtrlZ, _.UpArrow, _.UpArrow, _.DownArrow, _.Enter, CheckThat(() => AssertScreenCaptureClipboardIs(line[3])),
// Select multiple lines
_.CtrlZ, _.UpArrow, shiftUpArrow, _.Enter,
CheckThat(() => AssertScreenCaptureClipboardIs(line[2], line[3])),
_.CtrlZ, Enumerable.Repeat(_.UpArrow, 10), shiftDownArrow, _.Enter,
CheckThat(() => AssertScreenCaptureClipboardIs(line[0], line[1])),
// Select multiple lines, then shorten selection
_.CtrlZ, _.UpArrow, shiftUpArrow, shiftUpArrow, shiftDownArrow, _.Enter,
CheckThat(() => AssertScreenCaptureClipboardIs(line[2], line[3])),
_.CtrlZ, Enumerable.Repeat(_.UpArrow, 10), shiftDownArrow, shiftDownArrow, shiftUpArrow, _.Enter,
CheckThat(() => AssertScreenCaptureClipboardIs(line[0], line[1])),
// Test trying to arrow down past end of buffer (arrowing past top of buffer covered above)
_.CtrlZ, Enumerable.Repeat(_.DownArrow, Console.BufferHeight), _.Escape,
// Test that we ding input that doesn't do anything
_.CtrlZ,
'c', CheckThat(() => { Assert.IsTrue(ding); ding = false; }),
'g', CheckThat(() => { Assert.IsTrue(ding); ding = false; }),
'a', CheckThat(() => { Assert.IsTrue(ding); ding = false; }),
_.Escape,
_.Enter),
resetCursor: false);
}
// To test:
// * Selected lines are inverted
// * Rtf output
// * Rtf special characters
}
}
}