mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 00:42:51 +08:00
parent
9c9eb04f91
commit
e86f9d3c5a
@ -96,6 +96,21 @@ namespace Spectre.Console
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (int.TryParse(part, out var number))
|
||||
{
|
||||
if (number < 0)
|
||||
{
|
||||
error = $"Color number must be greater than or equal to 0 (was {number})";
|
||||
return null;
|
||||
}
|
||||
else if (number > 255)
|
||||
{
|
||||
error = $"Color number must be less than or equal to 255 (was {number})";
|
||||
return null;
|
||||
}
|
||||
|
||||
color = number;
|
||||
}
|
||||
else
|
||||
{
|
||||
error = !foreground
|
||||
|
@ -275,6 +275,31 @@ namespace Spectre.Console.Tests.Unit
|
||||
result.Background.ShouldBe(Color.Blue);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("12 on 24")]
|
||||
public void Should_Parse_Colors_Numbers_Correctly(string style)
|
||||
{
|
||||
// Given, When
|
||||
var result = Style.Parse(style);
|
||||
|
||||
// Then
|
||||
result.Foreground.ShouldBe(Color.Blue);
|
||||
result.Background.ShouldBe(Color.DeepSkyBlue4_1);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("-12", "Color number must be greater than or equal to 0 (was -12)")]
|
||||
[InlineData("256", "Color number must be less than or equal to 255 (was 256)")]
|
||||
public void Should_Return_Error_If_Color_Number_Is_Invalid(string style, string expected)
|
||||
{
|
||||
// Given, When
|
||||
var result = Record.Exception(() => Style.Parse(style));
|
||||
|
||||
// Then
|
||||
result.ShouldNotBeNull();
|
||||
result.Message.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("rgb()", "Invalid RGB color 'rgb()'.")]
|
||||
[InlineData("rgb(", "Invalid RGB color 'rgb('.")]
|
||||
|
Loading…
x
Reference in New Issue
Block a user