|
1 | 1 | using System;
|
| 2 | +using System.Globalization; |
| 3 | +using System.Threading; |
2 | 4 | using Eto.Drawing;
|
3 | 5 | using NUnit.Framework;
|
4 | 6 |
|
@@ -158,18 +160,40 @@ public void ColorToCmykShouldNotHaveNan(uint rgb)
|
158 | 160 | [TestCase("4294967295", 255, 255, 255, 255, ColorStyles.AlphaLast)] // #FFFFFFFF
|
159 | 161 | [TestCase("16777215", 255, 0, 255, 255, ColorStyles.AlphaLast)] // #FFFFFF
|
160 | 162 | [TestCase("305419896", 120, 18, 52, 86, ColorStyles.AlphaLast)] // #12345678 A = 78
|
161 |
| - public void ColorShouldParse(string text, int a, int r, int g, int b, ColorStyles? style = null) |
| 163 | + |
| 164 | + [TestCase("#0000", 0, 0, 0, 0, ColorStyles.AlphaLast, true)] |
| 165 | + [TestCase("#1234", 68, 17, 34, 51, ColorStyles.AlphaLast, true)] |
| 166 | + [TestCase("#00000000", 0, 0, 0, 0, ColorStyles.AlphaLast, true)] |
| 167 | + [TestCase("#12345678", 120, 18, 52, 86, ColorStyles.AlphaLast, true)] |
| 168 | + [TestCase("0, 0, 0, 0", 0, 0, 0, 0, ColorStyles.AlphaLast, true)] |
| 169 | + [TestCase("12, 34, 56, 78", 78, 12, 34, 56, ColorStyles.AlphaLast, true)] |
| 170 | + [TestCase("255, 255, 255, 255", 255, 255, 255, 255, ColorStyles.AlphaLast, true)] |
| 171 | + [TestCase("rgba(12,34,56,0.3)", 76, 12, 34, 56, ColorStyles.AlphaLast, true)] |
| 172 | + [TestCase("rgba(50%,20%,100%,0.3)", 76, 127, 51, 255, ColorStyles.AlphaLast, true)] |
| 173 | + [TestCase("rgba(50%,20.5%,100%,0.3)", 76, 127, 52, 255, ColorStyles.AlphaLast, true)] |
| 174 | + [TestCase("0", 0, 0, 0, 0, ColorStyles.AlphaLast, true)] |
| 175 | + [TestCase("4294967295", 255, 255, 255, 255, ColorStyles.AlphaLast, true)] // #FFFFFFFF |
| 176 | + [TestCase("16777215", 255, 0, 255, 255, ColorStyles.AlphaLast, true)] // #FFFFFF |
| 177 | + [TestCase("305419896", 120, 18, 52, 86, ColorStyles.AlphaLast, true)] // #12345678 A = 78 |
| 178 | + public void ColorShouldParse(string text, int a, int r, int g, int b, ColorStyles? style = null, bool? useDifferentCulture = null) |
162 | 179 | {
|
| 180 | + var systemCulture = CultureInfo.CurrentCulture; |
| 181 | + bool shouldSwitchCulture = useDifferentCulture != null && useDifferentCulture.Value; |
| 182 | + if (shouldSwitchCulture) |
| 183 | + Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); |
163 | 184 | Color color;
|
164 | 185 | var result = style == null ? Color.TryParse(text, out color) : Color.TryParse(text, out color, style.Value);
|
| 186 | + |
| 187 | + Thread.CurrentThread.CurrentCulture = systemCulture; |
| 188 | + |
165 | 189 | Assert.IsTrue(result, "#1 - Color could not be parsed from text");
|
166 | 190 |
|
167 | 191 | Assert.AreEqual(a, color.Ab, "#2.1 - Alpha component is incorrect");
|
168 | 192 | Assert.AreEqual(r, color.Rb, "#2.2 - Red component is incorrect");
|
169 | 193 | Assert.AreEqual(g, color.Gb, "#2.3 - Green component is incorrect");
|
170 | 194 | Assert.AreEqual(b, color.Bb, "#2.4 - Blue component is incorrect");
|
171 | 195 | }
|
172 |
| - |
| 196 | + |
173 | 197 | [TestCase("#0000", 0, 0, 0, 0, ColorStyles.ShortHex)]
|
174 | 198 | [TestCase("#1234", 17, 34, 51, 68, ColorStyles.ShortHex)]
|
175 | 199 | [TestCase("#FFFF", 255, 255, 255, 255, ColorStyles.ShortHex)]
|
|
0 commit comments