Adds optional function to get the display string for TextPrompt choices

This commit is contained in:
Thomas Freudenberg
2020-12-26 18:17:46 +01:00
committed by GitHub
parent 041aea2ae5
commit 0bbf9b81a9
4 changed files with 92 additions and 16 deletions

View File

@ -0,0 +1 @@
Favorite fruit? [Apple/Banana]: Banana

View File

@ -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);
}
}
}