mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-11-04 02:25:28 +08:00 
			
		
		
		
	Custom mask for secret (#970)
* Masking Character added, not yet used. * Setting the masking character can be chained with other extensions. * Added string extension for masking, and replaced hardcoded asterisks. * Check if mask is null first. * Fixed Typo in previous test and added new test for custom masks. * Added tests for masking with null character * Added docs and example. * Adjusted extensions so that Mask is integrated into Secret extension. Updated Exampls and Tests accordingly
This commit is contained in:
		@@ -0,0 +1 @@
 | 
			
		||||
Favorite fruit? (------): ------
 | 
			
		||||
@@ -0,0 +1 @@
 | 
			
		||||
Favorite fruit? (): 
 | 
			
		||||
@@ -233,7 +233,7 @@ public sealed class TextPromptTests
 | 
			
		||||
 | 
			
		||||
    [Fact]
 | 
			
		||||
    [Expectation("SecretDefaultValue")]
 | 
			
		||||
    public Task Should_Chose_Masked_Default_Value_If_Nothing_Is_Entered_And_Prompt_Is_Secret()
 | 
			
		||||
    public Task Should_Choose_Masked_Default_Value_If_Nothing_Is_Entered_And_Prompt_Is_Secret()
 | 
			
		||||
    {
 | 
			
		||||
        // Given
 | 
			
		||||
        var console = new TestConsole();
 | 
			
		||||
@@ -247,6 +247,42 @@ public sealed class TextPromptTests
 | 
			
		||||
 | 
			
		||||
        // Then
 | 
			
		||||
        return Verifier.Verify(console.Output);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [Fact]
 | 
			
		||||
    [Expectation("SecretDefaultValueCustomMask")]
 | 
			
		||||
    public Task Should_Choose_Custom_Masked_Default_Value_If_Nothing_Is_Entered_And_Prompt_Is_Secret_And_Mask_Is_Custom()
 | 
			
		||||
    {
 | 
			
		||||
        // Given
 | 
			
		||||
        var console = new TestConsole();
 | 
			
		||||
        console.Input.PushKey(ConsoleKey.Enter);
 | 
			
		||||
 | 
			
		||||
        // When
 | 
			
		||||
        console.Prompt(
 | 
			
		||||
            new TextPrompt<string>("Favorite fruit?")
 | 
			
		||||
                .Secret('-')
 | 
			
		||||
                .DefaultValue("Banana"));
 | 
			
		||||
 | 
			
		||||
        // Then
 | 
			
		||||
        return Verifier.Verify(console.Output);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [Fact]
 | 
			
		||||
    [Expectation("SecretDefaultValueNullMask")]
 | 
			
		||||
    public Task Should_Choose_Empty_Masked_Default_Value_If_Nothing_Is_Entered_And_Prompt_Is_Secret_And_Mask_Is_Null()
 | 
			
		||||
    {
 | 
			
		||||
        // Given
 | 
			
		||||
        var console = new TestConsole();
 | 
			
		||||
        console.Input.PushKey(ConsoleKey.Enter);
 | 
			
		||||
 | 
			
		||||
        // When
 | 
			
		||||
        console.Prompt(
 | 
			
		||||
            new TextPrompt<string>("Favorite fruit?")
 | 
			
		||||
                .Secret(null)
 | 
			
		||||
                .DefaultValue("Banana"));
 | 
			
		||||
 | 
			
		||||
        // Then
 | 
			
		||||
        return Verifier.Verify(console.Output);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [Fact]
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user