forked from PowerShell/PSReadLine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptionsTest.cs
More file actions
114 lines (105 loc) · 4.96 KB
/
Copy pathOptionsTest.cs
File metadata and controls
114 lines (105 loc) · 4.96 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.PowerShell;
namespace UnitTestPSReadLine
{
// Disgusting language hack to make it easier to read a sequence of keys.
using _ = Keys;
public partial class UnitTest
{
[TestMethod]
public void TestContinuationPrompt()
{
TestSetup(KeyMode.Cmd);
Test("", Keys(
"{\n}",
CheckThat(() =>
AssertScreenIs(2,
TokenClassification.None, '{',
NextLine,
Tuple.Create(_console.ForegroundColor, _console.BackgroundColor),
PSConsoleReadlineOptions.DefaultContinuationPrompt,
TokenClassification.None, '}')),
_.CtrlC,
InputAcceptedNow
));
PSConsoleReadLine.SetOptions(new SetPSReadlineOption{ ContinuationPrompt = ""});
Test("", Keys(
"{\n}",
CheckThat(() => AssertScreenIs(2, TokenClassification.None, '{', NextLine, '}' )),
_.CtrlC,
InputAcceptedNow
));
var continuationPrompt = "::::: ";
PSConsoleReadLine.SetOptions(new SetPSReadlineOption{
ContinuationPrompt = continuationPrompt,
ContinuationPromptForegroundColor = ConsoleColor.Magenta,
ContinuationPromptBackgroundColor = ConsoleColor.DarkYellow,
});
Test("", Keys(
"{\n}",
CheckThat(() =>
AssertScreenIs(2,
TokenClassification.None, '{',
NextLine,
Tuple.Create(ConsoleColor.Magenta, ConsoleColor.DarkYellow),
continuationPrompt,
TokenClassification.None, '}')),
_.CtrlC,
InputAcceptedNow
));
}
[TestMethod]
public void TestGetKeyHandlers()
{
foreach (var keymode in new[] {KeyMode.Cmd, KeyMode.Emacs})
{
TestSetup(keymode);
foreach (var handler in PSConsoleReadLine.GetKeyHandlers(includeBound: false, includeUnbound: true))
{
Assert.AreEqual("Unbound", handler.Key);
Assert.IsFalse(string.IsNullOrWhiteSpace(handler.Function));
Assert.IsFalse(string.IsNullOrWhiteSpace(handler.Description));
}
foreach (var handler in PSConsoleReadLine.GetKeyHandlers(includeBound: true, includeUnbound: false))
{
Assert.AreNotEqual("Unbound", handler.Key);
Assert.IsFalse(string.IsNullOrWhiteSpace(handler.Function));
Assert.IsFalse(string.IsNullOrWhiteSpace(handler.Description));
}
}
}
[TestMethod]
[ExcludeFromCodeCoverage]
public void TestUselessStuffForBetterCoverage()
{
// Useless test to just make sure coverage numbers are better, written
// in the first way I could think of that doesn't warn about doing something useless.
var options = new SetPSReadlineOption();
var getKeyHandlerCommand = new GetKeyHandlerCommand();
var useless = ((object)options.AddToHistoryHandler ?? options).GetHashCode()
+ options.EditMode.GetHashCode()
+ ((object)options.ContinuationPrompt ?? options).GetHashCode()
+ options.ContinuationPromptBackgroundColor.GetHashCode()
+ options.ContinuationPromptForegroundColor.GetHashCode()
+ options.HistoryNoDuplicates.GetHashCode()
+ options.HistorySearchCursorMovesToEnd.GetHashCode()
+ options.MaximumHistoryCount.GetHashCode()
+ options.MaximumKillRingCount.GetHashCode()
+ options.DingDuration.GetHashCode()
+ options.DingTone.GetHashCode()
+ options.BellStyle.GetHashCode()
+ options.ExtraPromptLineCount.GetHashCode()
+ options.ShowToolTips.GetHashCode()
+ options.CompletionQueryItems.GetHashCode()
+ options.EmphasisBackgroundColor.GetHashCode()
+ options.EmphasisForegroundColor.GetHashCode()
+ options.HistorySearchCaseSensitive.GetHashCode()
+ getKeyHandlerCommand.Bound.GetHashCode()
+ getKeyHandlerCommand.Unbound.GetHashCode();
// This assertion just avoids annoying warnings about unused variables.
Assert.AreNotEqual(Math.PI, useless);
}
}
}