Skip to content
10 changes: 9 additions & 1 deletion src/Spectre.Console/Prompts/TextPrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,15 @@ public sealed class TextPrompt<T> : IPrompt<T>, IHasCulture
public TextPrompt(string prompt, StringComparer? comparer = null)
{
_prompt = prompt ?? throw new System.ArgumentNullException(nameof(prompt));
_comparer = comparer;

if (typeof(T) == typeof(string) && comparer is null)
{
_comparer = StringComparer.OrdinalIgnoreCase;
}
else
{
_comparer = comparer;
}
Comment thread
akinsmosu marked this conversation as resolved.
Outdated
}

/// <summary>
Expand Down
17 changes: 17 additions & 0 deletions src/Tests/Spectre.Console.Tests/Unit/Prompts/TextPromptTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,21 @@ public Task Uses_the_specified_choices_style()
// Then
return Verifier.Verify(console.Output);
}

[Theory]
[InlineData("yes")]
[InlineData("Yes")]
[InlineData("YES")]
public async Task Uses_case_insensitive_comparison_when_no_comparer_is_passed(string input)
{
var console = new TestConsole { EmitAnsiSequences = true, };
console.Input.PushTextWithEnter(input);

var prompt = new TextPrompt<string>("Was the tool helpful?")
.AddChoices(["Yes", "Partially", "No"]);
Comment thread
akinsmosu marked this conversation as resolved.

var result = await console.PromptAsync(prompt);
Comment thread
akinsmosu marked this conversation as resolved.

Assert.Equal("Yes", result);
Comment thread
akinsmosu marked this conversation as resolved.
Outdated
}
}