mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-11-04 10:35:27 +08:00 
			
		
		
		
	
				
					committed by
					
						
						Patrik Svensson
					
				
			
			
				
	
			
			
			
						parent
						
							753894de94
						
					
				
				
					commit
					fd69ad0b01
				
			@@ -3,7 +3,10 @@ namespace Spectre.Console.Tests.Unit;
 | 
			
		||||
public sealed class ListPromptStateTests
 | 
			
		||||
{
 | 
			
		||||
    private ListPromptState<string> CreateListPromptState(int count, int pageSize, bool shouldWrap, bool searchEnabled)
 | 
			
		||||
        => new(Enumerable.Range(0, count).Select(i => new ListPromptItem<string>(i.ToString())).ToList(), pageSize, shouldWrap, SelectionMode.Independent, true, searchEnabled);
 | 
			
		||||
        => new(
 | 
			
		||||
            Enumerable.Range(0, count).Select(i => new ListPromptItem<string>(i.ToString())).ToList(),
 | 
			
		||||
            text => text,
 | 
			
		||||
            pageSize, shouldWrap, SelectionMode.Independent, true, searchEnabled);
 | 
			
		||||
 | 
			
		||||
    [Fact]
 | 
			
		||||
    public void Should_Have_Start_Index_Zero()
 | 
			
		||||
 
 | 
			
		||||
@@ -410,4 +410,45 @@ public sealed class TextPromptTests
 | 
			
		||||
        // 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));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user