mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-11-04 02:25:28 +08:00 
			
		
		
		
	Add an implicit operator to convert from Color to Style (#1160)
This commit is contained in:
		@@ -247,42 +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]
 | 
			
		||||
    [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]
 | 
			
		||||
@@ -337,7 +337,7 @@ public sealed class TextPromptTests
 | 
			
		||||
        var prompt = new TextPrompt<string>("Enter Value:")
 | 
			
		||||
                .ShowDefaultValue()
 | 
			
		||||
                .DefaultValue("default")
 | 
			
		||||
                .DefaultValueStyle(new Style(foreground: Color.Red));
 | 
			
		||||
                .DefaultValueStyle(Color.Red);
 | 
			
		||||
 | 
			
		||||
        // When
 | 
			
		||||
        console.Prompt(prompt);
 | 
			
		||||
@@ -384,7 +384,7 @@ public sealed class TextPromptTests
 | 
			
		||||
                .ShowChoices()
 | 
			
		||||
                .AddChoice("Choice 1")
 | 
			
		||||
                .AddChoice("Choice 2")
 | 
			
		||||
                .ChoicesStyle(new Style(foreground: Color.Red));
 | 
			
		||||
                .ChoicesStyle(Color.Red);
 | 
			
		||||
 | 
			
		||||
        // When
 | 
			
		||||
        console.Prompt(prompt);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,20 @@
 | 
			
		||||
namespace Spectre.Console.Tests.Unit;
 | 
			
		||||
 | 
			
		||||
public sealed class StyleTests
 | 
			
		||||
{
 | 
			
		||||
{
 | 
			
		||||
    [Fact]
 | 
			
		||||
    public void Should_Convert_From_Color_As_Expected()
 | 
			
		||||
    {
 | 
			
		||||
        // Given
 | 
			
		||||
        Style style;
 | 
			
		||||
 | 
			
		||||
        // When
 | 
			
		||||
        style = Color.Red;
 | 
			
		||||
 | 
			
		||||
        // Then
 | 
			
		||||
        style.Foreground.ShouldBe(Color.Red);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [Fact]
 | 
			
		||||
    public void Should_Combine_Two_Styles_As_Expected()
 | 
			
		||||
    {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user