Skip to content

Commit 32361d3

Browse files
authored
Cleanup prompt tests (#1635)
* Move Should_Search_In_Remapped_Result into the SelectionPromptTests class where it belongs * Use file sealed class for CustomItem, like it's done with CustomSelectionItem in the selection prompt tests
1 parent b9d2d2d commit 32361d3

File tree

3 files changed

+60
-60
lines changed

3 files changed

+60
-60
lines changed

src/Tests/Spectre.Console.Tests/Unit/Prompts/MultiSelectionPromptTests.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,6 @@ namespace Spectre.Console.Tests.Unit;
22

33
public sealed class MultiSelectionPromptTests
44
{
5-
private class CustomItem
6-
{
7-
public int X { get; set; }
8-
public int Y { get; set; }
9-
10-
public class Comparer : IEqualityComparer<CustomItem>
11-
{
12-
public bool Equals(CustomItem x, CustomItem y)
13-
{
14-
return x.X == y.X && x.Y == y.Y;
15-
}
16-
17-
public int GetHashCode(CustomItem obj)
18-
{
19-
throw new NotSupportedException();
20-
}
21-
}
22-
}
23-
245
[Fact]
256
public void Should_Not_Mark_Item_As_Selected_By_Default()
267
{
@@ -147,3 +128,22 @@ public void Should_Throw_When_Getting_Parents_Of_Non_Existing_Node()
147128
action.ShouldThrow<ArgumentOutOfRangeException>();
148129
}
149130
}
131+
132+
file sealed class CustomItem
133+
{
134+
public int X { get; set; }
135+
public int Y { get; set; }
136+
137+
public class Comparer : IEqualityComparer<CustomItem>
138+
{
139+
public bool Equals(CustomItem x, CustomItem y)
140+
{
141+
return x.X == y.X && x.Y == y.Y;
142+
}
143+
144+
public int GetHashCode(CustomItem obj)
145+
{
146+
throw new NotSupportedException();
147+
}
148+
}
149+
}

src/Tests/Spectre.Console.Tests/Unit/Prompts/SelectionPromptTests.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,45 @@ public void Should_Highlight_Search_Term()
8585
// Then
8686
console.Output.ShouldContain($"{ESC}[38;5;12m> Item {ESC}[0m{ESC}[1;38;5;12;48;5;11m1{ESC}[0m");
8787
}
88+
89+
[Fact]
90+
public void Should_Search_In_Remapped_Result()
91+
{
92+
// Given
93+
var console = new TestConsole();
94+
console.Profile.Capabilities.Interactive = true;
95+
console.EmitAnsiSequences();
96+
console.Input.PushText("2");
97+
console.Input.PushKey(ConsoleKey.Enter);
98+
99+
var choices = new List<CustomSelectionItem>
100+
{
101+
new(33, "Item 1"),
102+
new(34, "Item 2"),
103+
};
104+
105+
var prompt = new SelectionPrompt<CustomSelectionItem>()
106+
.Title("Select one")
107+
.EnableSearch()
108+
.UseConverter(o => o.Name)
109+
.AddChoices(choices);
110+
111+
// When
112+
var selection = prompt.Show(console);
113+
114+
// Then
115+
selection.ShouldBe(choices[1]);
116+
}
117+
}
118+
119+
file sealed class CustomSelectionItem
120+
{
121+
public int Value { get; }
122+
public string Name { get; }
123+
124+
public CustomSelectionItem(int value, string name)
125+
{
126+
Value = value;
127+
Name = name ?? throw new ArgumentNullException(nameof(name));
128+
}
88129
}

src/Tests/Spectre.Console.Tests/Unit/Prompts/TextPromptTests.cs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -410,45 +410,4 @@ public Task Uses_the_specified_choices_style()
410410
// Then
411411
return Verifier.Verify(console.Output);
412412
}
413-
414-
[Fact]
415-
public void Should_Search_In_Remapped_Result()
416-
{
417-
// Given
418-
var console = new TestConsole();
419-
console.Profile.Capabilities.Interactive = true;
420-
console.EmitAnsiSequences();
421-
console.Input.PushText("2");
422-
console.Input.PushKey(ConsoleKey.Enter);
423-
424-
var choices = new List<CustomSelectionItem>
425-
{
426-
new(33, "Item 1"),
427-
new(34, "Item 2"),
428-
};
429-
430-
var prompt = new SelectionPrompt<CustomSelectionItem>()
431-
.Title("Select one")
432-
.EnableSearch()
433-
.UseConverter(o => o.Name)
434-
.AddChoices(choices);
435-
436-
// When
437-
var selection = prompt.Show(console);
438-
439-
// Then
440-
selection.ShouldBe(choices[1]);
441-
}
442-
}
443-
444-
file sealed class CustomSelectionItem
445-
{
446-
public int Value { get; }
447-
public string Name { get; }
448-
449-
public CustomSelectionItem(int value, string name)
450-
{
451-
Value = value;
452-
Name = name ?? throw new ArgumentNullException(nameof(name));
453-
}
454413
}

0 commit comments

Comments
 (0)