Browse Source
Merge branch 'master' into fixes/FluentTextBox
pull/4251/head
danwalmsley
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
30 additions and
5 deletions
-
src/Avalonia.Visuals/Media/Color.cs
-
tests/Avalonia.Visuals.UnitTests/Media/ColorTests.cs
|
|
|
@ -89,6 +89,11 @@ namespace Avalonia.Media |
|
|
|
/// <returns>The <see cref="Color"/>.</returns>
|
|
|
|
public static Color Parse(string s) |
|
|
|
{ |
|
|
|
if (s is null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException(nameof(s)); |
|
|
|
} |
|
|
|
|
|
|
|
if (TryParse(s, out Color color)) |
|
|
|
{ |
|
|
|
return color; |
|
|
|
@ -120,14 +125,16 @@ namespace Avalonia.Media |
|
|
|
/// <returns>The status of the operation.</returns>
|
|
|
|
public static bool TryParse(string s, out Color color) |
|
|
|
{ |
|
|
|
if (s == null) |
|
|
|
color = default; |
|
|
|
|
|
|
|
if (s is null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException(nameof(s)); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (s.Length == 0) |
|
|
|
{ |
|
|
|
throw new FormatException(); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (s[0] == '#' && TryParseInternal(s.AsSpan(), out color)) |
|
|
|
@ -144,8 +151,6 @@ namespace Avalonia.Media |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
color = default; |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -179,5 +179,25 @@ namespace Avalonia.Visuals.UnitTests.Media |
|
|
|
{ |
|
|
|
Assert.False(Color.TryParse("#ff808g80", out _)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Parse_Throws_ArgumentNullException_For_Null_Input() |
|
|
|
{ |
|
|
|
Assert.Throws<ArgumentNullException>(() => Color.Parse((string)null)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Parse_Throws_FormatException_For_Invalid_Input() |
|
|
|
{ |
|
|
|
Assert.Throws<FormatException>(() => Color.Parse(string.Empty)); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[InlineData("")] |
|
|
|
[InlineData(null)] |
|
|
|
public void TryParse_Returns_False_For_Invalid_Input(string input) |
|
|
|
{ |
|
|
|
Assert.False(Color.TryParse(input, out _)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|