summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.UnitTests
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2017-03-01 19:45:26 +0100
committerJason Smith <jason.smith@xamarin.com>2017-03-01 10:45:26 -0800
commit837929478ed9ebb0e006ba8413cc147748619ef9 (patch)
tree29adeaa48876584e063dc4fd3cc409e23779df11 /Xamarin.Forms.Core.UnitTests
parentbadc2e03782e3e266ad03313fed1c7ab14f0cacb (diff)
downloadxamarin-forms-837929478ed9ebb0e006ba8413cc147748619ef9.tar.gz
xamarin-forms-837929478ed9ebb0e006ba8413cc147748619ef9.tar.bz2
xamarin-forms-837929478ed9ebb0e006ba8413cc147748619ef9.zip
[C] support more color format in ColorTypeConverter (#784)
* [C] support more color format in ColorTypeConverter * [C] Parse numbers in InvariantCulture * more tests
Diffstat (limited to 'Xamarin.Forms.Core.UnitTests')
-rw-r--r--Xamarin.Forms.Core.UnitTests/ColorUnitTests.cs41
1 files changed, 27 insertions, 14 deletions
diff --git a/Xamarin.Forms.Core.UnitTests/ColorUnitTests.cs b/Xamarin.Forms.Core.UnitTests/ColorUnitTests.cs
index b29a9680..43554784 100644
--- a/Xamarin.Forms.Core.UnitTests/ColorUnitTests.cs
+++ b/Xamarin.Forms.Core.UnitTests/ColorUnitTests.cs
@@ -241,19 +241,34 @@ namespace Xamarin.Forms.Core.UnitTests
}
[Test]
- public void TestColorTypeConverter ()
+ public void TestColorTypeConverter()
{
- var converter = new ColorTypeConverter ();
- Assert.True (converter.CanConvertFrom (typeof(string)));
- Assert.AreEqual (Color.Blue, converter.ConvertFromInvariantString ("Color.Blue"));
- Assert.AreEqual (Color.Blue, converter.ConvertFromInvariantString ("Blue"));
- Assert.AreEqual (Color.Blue, converter.ConvertFromInvariantString ("#0000ff"));
- Assert.AreEqual (Color.Default, converter.ConvertFromInvariantString ("Color.Default"));
- Assert.AreEqual (Color.Accent, converter.ConvertFromInvariantString ("Accent"));
- var hotpink = Color.FromHex ("#FF69B4");
+ var converter = new ColorTypeConverter();
+ Assert.True(converter.CanConvertFrom(typeof(string)));
+ Assert.AreEqual(Color.Blue, converter.ConvertFromInvariantString("Color.Blue"));
+ Assert.AreEqual(Color.Blue, converter.ConvertFromInvariantString("Blue"));
+ Assert.AreEqual(Color.Blue, converter.ConvertFromInvariantString("blue"));
+ Assert.AreEqual(Color.Blue, converter.ConvertFromInvariantString("#0000ff"));
+ Assert.AreEqual(Color.Blue, converter.ConvertFromInvariantString("#00f"));
+ Assert.AreEqual(Color.Blue.MultiplyAlpha(2.0 / 3.0), converter.ConvertFromInvariantString("#a00f"));
+ Assert.AreEqual(Color.Blue, converter.ConvertFromInvariantString("rgb(0,0, 255)"));
+ Assert.AreEqual(Color.Blue, converter.ConvertFromInvariantString("rgb(0,0, 300)"));
+ Assert.AreEqual(Color.Blue, converter.ConvertFromInvariantString("rgb(0,0, 300)"));
+ Assert.AreEqual(Color.Blue.MultiplyAlpha(.8), converter.ConvertFromInvariantString("rgba(0%,0%, 100%, .8)"));
+ Assert.AreEqual(Color.Blue, converter.ConvertFromInvariantString("rgb(0%,0%, 110%)"));
+ Assert.AreEqual(Color.Blue, converter.ConvertFromInvariantString("hsl(240,100%, 50%)"));
+ Assert.AreEqual(Color.Blue, converter.ConvertFromInvariantString("hsl(240,110%, 50%)"));
+ Assert.AreEqual(Color.Blue.MultiplyAlpha(.8), converter.ConvertFromInvariantString("hsla(240,100%, 50%, .8)"));
+ Assert.AreEqual(Color.Default, converter.ConvertFromInvariantString("Color.Default"));
+ Assert.AreEqual(Color.Accent, converter.ConvertFromInvariantString("Accent"));
+ var hotpink = Color.FromHex("#FF69B4");
Color.Accent = hotpink;
- Assert.AreEqual (Color.Accent, converter.ConvertFromInvariantString ("Accent"));
- Assert.Throws<InvalidOperationException> (() => converter.ConvertFromInvariantString (""));
+ Assert.AreEqual(Color.Accent, converter.ConvertFromInvariantString("Accent"));
+ Assert.AreEqual(Color.Default, converter.ConvertFromInvariantString("#12345"));
+ Assert.Throws<InvalidOperationException>(() => converter.ConvertFromInvariantString(""));
+ Assert.Throws<InvalidOperationException>(() => converter.ConvertFromInvariantString("rgb(0,0,255"));
+ Assert.Throws<InvalidOperationException>(() => converter.ConvertFromInvariantString("hsl(12, 100%)"));
+ Assert.Throws<InvalidOperationException>(() => converter.ConvertFromInvariantString("rgba(0,0,255)"));
}
[Test]
@@ -262,7 +277,5 @@ namespace Xamarin.Forms.Core.UnitTests
Assert.AreEqual (Color.Default, default(Color));
Assert.AreEqual (Color.Default, new Color ());
}
-
-
}
-}
+} \ No newline at end of file