Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,6 @@ namespace Spectre.Console.Tests.Unit;

public sealed class MultiSelectionPromptTests
{
private class CustomItem
{
public int X { get; set; }
public int Y { get; set; }

public class Comparer : IEqualityComparer<CustomItem>
{
public bool Equals(CustomItem x, CustomItem y)
{
return x.X == y.X && x.Y == y.Y;
}

public int GetHashCode(CustomItem obj)
{
throw new NotSupportedException();
}
}
}

[Fact]
public void Should_Not_Mark_Item_As_Selected_By_Default()
{
Expand Down Expand Up @@ -147,3 +128,22 @@ public void Should_Throw_When_Getting_Parents_Of_Non_Existing_Node()
action.ShouldThrow<ArgumentOutOfRangeException>();
}
}

file sealed class CustomItem
{
public int X { get; set; }
public int Y { get; set; }

public class Comparer : IEqualityComparer<CustomItem>
{
public bool Equals(CustomItem x, CustomItem y)
{
return x.X == y.X && x.Y == y.Y;
}

public int GetHashCode(CustomItem obj)
{
throw new NotSupportedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,45 @@ public void Should_Highlight_Search_Term()
// Then
console.Output.ShouldContain($"{ESC}[38;5;12m> Item {ESC}[0m{ESC}[1;38;5;12;48;5;11m1{ESC}[0m");
}

[Fact]
public void Should_Search_In_Remapped_Result()
{
// Given
var console = new TestConsole();
console.Profile.Capabilities.Interactive = true;
console.EmitAnsiSequences();
console.Input.PushText("2");
console.Input.PushKey(ConsoleKey.Enter);

var choices = new List<CustomSelectionItem>
{
new(33, "Item 1"),
new(34, "Item 2"),
};

var prompt = new SelectionPrompt<CustomSelectionItem>()
.Title("Select one")
.EnableSearch()
.UseConverter(o => o.Name)
.AddChoices(choices);

// When
var selection = prompt.Show(console);

// Then
selection.ShouldBe(choices[1]);
}
}

file sealed class CustomSelectionItem
{
public int Value { get; }
public string Name { get; }

public CustomSelectionItem(int value, string name)
{
Value = value;
Name = name ?? throw new ArgumentNullException(nameof(name));
}
}
41 changes: 0 additions & 41 deletions src/Tests/Spectre.Console.Tests/Unit/Prompts/TextPromptTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,45 +410,4 @@ public Task Uses_the_specified_choices_style()
// Then
return Verifier.Verify(console.Output);
}

[Fact]
public void Should_Search_In_Remapped_Result()
{
// Given
var console = new TestConsole();
console.Profile.Capabilities.Interactive = true;
console.EmitAnsiSequences();
console.Input.PushText("2");
console.Input.PushKey(ConsoleKey.Enter);

var choices = new List<CustomSelectionItem>
{
new(33, "Item 1"),
new(34, "Item 2"),
};

var prompt = new SelectionPrompt<CustomSelectionItem>()
.Title("Select one")
.EnableSearch()
.UseConverter(o => o.Name)
.AddChoices(choices);

// When
var selection = prompt.Show(console);

// Then
selection.ShouldBe(choices[1]);
}
}

file sealed class CustomSelectionItem
{
public int Value { get; }
public string Name { get; }

public CustomSelectionItem(int value, string name)
{
Value = value;
Name = name ?? throw new ArgumentNullException(nameof(name));
}
}