mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-07-02 19:08:15 +08:00
Adds optional function to get the display string for TextPrompt choices
This commit is contained in:

committed by
GitHub

parent
041aea2ae5
commit
0bbf9b81a9
@ -0,0 +1 @@
|
||||
Favorite fruit? [Apple/Banana]: Banana
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Shouldly;
|
||||
using VerifyXunit;
|
||||
using Xunit;
|
||||
|
||||
@ -168,5 +169,24 @@ namespace Spectre.Console.Tests.Unit
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task Should_Use_Custom_Converter()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
console.Input.PushTextWithEnter("Banana");
|
||||
|
||||
// When
|
||||
var result = console.Prompt(
|
||||
new TextPrompt<(int, string)>("Favorite fruit?")
|
||||
.AddChoice((1, "Apple"))
|
||||
.AddChoice((2, "Banana"))
|
||||
.WithConverter(testData => testData.Item2));
|
||||
|
||||
// Then
|
||||
result.Item1.ShouldBe(2);
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user