private string [] string_values;
private string [] string_values_fail = {
"", // empty
- "- 1.0" // Inner whitespace
+ "- 1.0", // Inner whitespace
+ "3 5" // Inner whitespace 2
};
private double [] double_values = {
};
[SetUp]
- public void GetReady ()
+ public void Setup ()
{
string sep = NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
string_values = new string [15];
}
[Test]
+ [SetCulture ("en-US")]
public void Parse ()
{
int i = 0;
try {
Assert.AreEqual (1234.5678, Double.Parse ("1,234.5678", NumberStyles.Float | NumberStyles.AllowThousands, Nfi), "#C1");
} catch (Exception e) {
- Assertion.Fail ("#C2: Parse Failed NumberStyles.AllowThousands with e = " + e.ToString ());
+ Assert.Fail ("#C2: Parse Failed NumberStyles.AllowThousands with e = " + e.ToString ());
}
try {
Double.Parse (null);
- Assertion.Fail ("#D1");
+ Assert.Fail ("#D1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#D2");
Assert.IsNull (ex.InnerException, "#D3");
try {
Double.Parse ("-1" + sep + "79769313486232e308");
- Assertion.Fail ("#G1");
+ Assert.Fail ("#G1");
} catch (OverflowException ex) {
Assert.AreEqual (typeof (OverflowException), ex.GetType (), "#G2");
Assert.IsNull (ex.InnerException, "#G3");
for (i = 0; i < string_values_fail.Length; ++i) {
try {
Double.Parse (string_values_fail [i]);
- Assertion.Fail ("#H1: " + string_values_fail [i]);
+ Assert.Fail ("#H1: " + string_values_fail [i]);
} catch (FormatException ex) {
Assert.AreEqual (typeof (FormatException), ex.GetType (), "#H2");
Assert.IsNull (ex.InnerException, "#H3");
Assert.IsNotNull (ex.Message, "#H4");
}
}
+ }
- try {
- Double.Parse (" ");
- Assert.Fail ("#I1");
- } catch (FormatException ex) {
- Assert.AreEqual (typeof (FormatException), ex.GetType (), "#I2");
- Assert.IsNull (ex.InnerException, "#I3");
- Assert.IsNotNull (ex.Message, "#I4");
- }
+ [Test]
+ public void ParseAllowWhitespaces ()
+ {
+ var nf = CultureInfo.CurrentCulture.NumberFormat;
+ NumberStyles style = NumberStyles.Float;
+ double.Parse (" 32 ");
+ double.Parse (string.Format (" {0} ", nf.PositiveInfinitySymbol));
+ double.Parse (string.Format (" {0} ", nf.NegativeInfinitySymbol));
+ double.Parse (string.Format (" {0} ", nf.NaNSymbol));
}
[Test] // bug #81630
- [Category ("NotWorking")]
public void Parse_Whitespace ()
{
try {
}
}
+ [Test] // //bug #81777
+ public void Parse_TrailingGarbage ()
+ {
+ try {
+ double.Parse ("22 foo");
+ Assert.Fail ("#1");
+ } catch (FormatException ex) {
+ Assert.AreEqual (typeof (FormatException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ }
+ }
+
+ [Test]
+ public void Parse_Infinity ()
+ {
+ double value;
+ IFormatProvider german = new CultureInfo ("de-DE");
+ var res = double.Parse ("+unendlich", NumberStyles.Float, german);
+ Assert.AreEqual (double.PositiveInfinity, res);
+ }
+
[Test]
public void TestToString ()
{
list.Add (new Element (0.086d, "00000", "00000"));
list.Add (new Element (0.086d, "(###) ### - ####", "() - "));
list.Add (new Element (0.086d, "#.##", ".09"));
+ list.Add (new Element (0.086d, "#.#", ".1"));
list.Add (new Element (0.086d, "0.00", "0.09"));
list.Add (new Element (0.086d, "00.00", "00.09"));
list.Add (new Element (0.086d, "#,#", ""));
}
}
+ [Test]
+ public void TestRoundtrip () // bug #320433
+ {
+ Assert.AreEqual ("10.78", 10.78.ToString ("R", NumberFormatInfo.InvariantInfo));
+ }
+
[Test] // bug #72955
public void LongLongValueRoundtrip ()
{
}
[Test]
-#if NET_2_0
[ExpectedException (typeof (ArgumentException))]
-#else
- [Category ("NotWorking")]
- // MS accept hex values under 1.x but the results neither match the long value
- // nor the value of a 64bits double
-#endif
public void HexNumber_WithHexToParse ()
{
// from bug #72221
}
[Test]
-#if NET_2_0
[ExpectedException (typeof (ArgumentException))]
-#else
- [Category ("NotWorking")]
- // MS accept hex values under 1.x but the results neither match the long value
- // nor the value of a 64bits double
-#endif
public void HexNumber_NoHexToParse ()
{
double d;
null, out value));
}
+ [Test]
+ public void TryParse_NonDigitStrings ()
+ {
+ double value;
+ Assert.IsFalse (Double.TryParse ("string", NumberStyles.Any, null, out value), "#1");
+ Assert.IsFalse (Double.TryParse ("with whitespace", NumberStyles.Any, null, out value), "#2");
+
+ Assert.IsFalse (Double.TryParse ("string", out value), "#3");
+ Assert.IsFalse (Double.TryParse ("with whitespace", out value), "#4");
+ }
+
+
[Test] // bug #77721
public void ParseCurrency ()
{
double d = double.Parse ("$4.56", NumberStyles.Currency, f);
Assert.AreEqual (4.56, d);
} finally {
- // restore original culture
Thread.CurrentThread.CurrentCulture = originalCulture;
}
+ }
+
+ [Test]
+ public void ParseEmptyNumberGroupSeparator ()
+ {
+ CultureInfo originalCulture = CultureInfo.CurrentCulture;
+ Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
+ try {
+ var nf = new NumberFormatInfo ();
+ nf.NumberDecimalSeparator = ".";
+ nf.NumberGroupSeparator = "";
+ double d = double.Parse ("4.5", nf);
+ Assert.AreEqual (4.5, d);
+ } finally {
+ Thread.CurrentThread.CurrentCulture = originalCulture;
+ }
+ }
+ [Test]
+ public void ParseAdvanced ()
+ {
+ Assert.AreEqual (-456, double.Parse("(456 ) ", NumberStyles.AllowParentheses | NumberStyles.AllowTrailingWhite, CultureInfo.InvariantCulture), "#1");
+ Assert.AreEqual (-456, double.Parse("(456)", NumberStyles.AllowParentheses, CultureInfo.InvariantCulture), "#2");
+ Assert.AreEqual (-3, double.Parse("3-", NumberStyles.AllowTrailingSign, CultureInfo.InvariantCulture), "#3");
+ Assert.AreEqual (-3.5, double.Parse("3.5-", NumberStyles.AllowTrailingSign | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture), "#4");
+ Assert.AreEqual (-0.5, double.Parse ("0.5 - ", NumberStyles.AllowTrailingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowTrailingWhite, CultureInfo.InvariantCulture), "#5");
+ Assert.AreEqual (-900000, double.Parse ("-9E5 " + CultureInfo.InvariantCulture.NumberFormat.CurrencySymbol + " ", NumberStyles.Any, CultureInfo.InvariantCulture), "#6");
}
}
}