mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-07-02 10:58:17 +08:00

committed by
Patrik Svensson

parent
e280b82679
commit
1cf30f62fc
@ -0,0 +1 @@
|
||||
Favorite fruit? [Banana/Bandana/Orange]: Band Bandana
|
@ -0,0 +1 @@
|
||||
Favorite fruit? [Banana/Orange] (Banana): Banana
|
@ -0,0 +1 @@
|
||||
Favorite fruit? [Apple/Banana/Orange]: Apple Banana
|
@ -23,7 +23,11 @@ namespace Spectre.Console.Tests
|
||||
{
|
||||
PushCharacter(character);
|
||||
}
|
||||
}
|
||||
|
||||
public void PushTextWithEnter(string input)
|
||||
{
|
||||
PushText(input);
|
||||
PushKey(ConsoleKey.Enter);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Shouldly;
|
||||
using Spectre.Console.Rendering;
|
||||
using VerifyXunit;
|
||||
using Xunit;
|
||||
|
@ -13,8 +13,8 @@ namespace Spectre.Console.Tests.Unit
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
console.Input.PushText("ninety-nine");
|
||||
console.Input.PushText("99");
|
||||
console.Input.PushTextWithEnter("ninety-nine");
|
||||
console.Input.PushTextWithEnter("99");
|
||||
|
||||
// When
|
||||
console.Prompt(new TextPrompt<int>("Age?"));
|
||||
@ -46,8 +46,8 @@ namespace Spectre.Console.Tests.Unit
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
console.Input.PushText("Apple");
|
||||
console.Input.PushText("Banana");
|
||||
console.Input.PushTextWithEnter("Apple");
|
||||
console.Input.PushTextWithEnter("Banana");
|
||||
|
||||
// When
|
||||
console.Prompt(
|
||||
@ -65,7 +65,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
console.Input.PushText("Orange");
|
||||
console.Input.PushTextWithEnter("Orange");
|
||||
|
||||
// When
|
||||
console.Prompt(
|
||||
@ -78,15 +78,74 @@ namespace Spectre.Console.Tests.Unit
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task Should_Auto_Complete_To_First_Choice_If_Pressing_Tab_On_Empty_String()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
console.Input.PushKey(ConsoleKey.Tab);
|
||||
console.Input.PushKey(ConsoleKey.Enter);
|
||||
|
||||
// When
|
||||
console.Prompt(
|
||||
new TextPrompt<string>("Favorite fruit?")
|
||||
.AddChoice("Banana")
|
||||
.AddChoice("Orange")
|
||||
.DefaultValue("Banana"));
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task Should_Auto_Complete_To_Best_Match()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
console.Input.PushText("Band");
|
||||
console.Input.PushKey(ConsoleKey.Tab);
|
||||
console.Input.PushKey(ConsoleKey.Enter);
|
||||
|
||||
// When
|
||||
console.Prompt(
|
||||
new TextPrompt<string>("Favorite fruit?")
|
||||
.AddChoice("Banana")
|
||||
.AddChoice("Bandana")
|
||||
.AddChoice("Orange"));
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task Should_Auto_Complete_To_Next_Choice_When_Pressing_Tab_On_A_Match()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
console.Input.PushText("Apple");
|
||||
console.Input.PushKey(ConsoleKey.Tab);
|
||||
console.Input.PushKey(ConsoleKey.Enter);
|
||||
|
||||
// When
|
||||
console.Prompt(
|
||||
new TextPrompt<string>("Favorite fruit?")
|
||||
.AddChoice("Apple")
|
||||
.AddChoice("Banana")
|
||||
.AddChoice("Orange"));
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task Should_Return_Error_If_Custom_Validation_Fails()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
console.Input.PushText("22");
|
||||
console.Input.PushText("102");
|
||||
console.Input.PushText("ABC");
|
||||
console.Input.PushText("99");
|
||||
console.Input.PushTextWithEnter("22");
|
||||
console.Input.PushTextWithEnter("102");
|
||||
console.Input.PushTextWithEnter("ABC");
|
||||
console.Input.PushTextWithEnter("99");
|
||||
|
||||
// When
|
||||
console.Prompt(
|
||||
|
Reference in New Issue
Block a user