Skip to content
2 changes: 1 addition & 1 deletion src/Spectre.Console/Prompts/TextPrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ 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;
_comparer = comparer ?? StringComparer.OrdinalIgnoreCase;
}

/// <summary>
Expand Down
20 changes: 20 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,24 @@ 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)
{
// Given
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.

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

// Then
result.ShouldBe("Yes");
}
}