Merge pull request #819 from brendanzagaeski/patch-1
[mono.git] / mcs / class / corlib / Test / System / DecimalTest.cs
index 3133ebf8d06684f892b186ced974e783e3ac163f..8419857df40583b95c61f7bc52508ac89980c344 100644 (file)
@@ -335,7 +335,10 @@ namespace MonoTests.System
                                new ParseTest("-000000000000001922816251426433759354395033.300000000000000", -1922816251426433759354395033.3m),
                                new ParseTest("-7922816251426433759354395033.150000000000", -7922816251426433759354395033.2m),
                                new ParseTest("-7922816251426433759354395033.2400000000000", -7922816251426433759354395033.2m),
-                               new ParseTest("-7922816251426433759354395033.2600000000000", -7922816251426433759354395033.3m)
+                               new ParseTest("-7922816251426433759354395033.2600000000000", -7922816251426433759354395033.3m),
+                               new ParseTest("987654321098765432109876543.25999", 987654321098765432109876543.3m, NumberStyles.Float),
+                               new ParseTest("987654321098765432109876543.25199", 987654321098765432109876543.3m, NumberStyles.Float),
+                               new ParseTest("2.22222222222222222222222222225", 2.2222222222222222222222222222m, NumberStyles.Float)
                };
 
                [Test]
@@ -1129,6 +1132,13 @@ namespace MonoTests.System
                        }
                }
 */
+
+               [Test]
+               public void ParseCultureSeparator ()
+               {
+                       Assert.AreEqual (2.2m, decimal.Parse ("2.2", new CultureInfo("es-MX")));
+               }
+
                [Test]
                [Category ("TargetJvmNotWorking")]
                public void TryParse ()
@@ -1454,5 +1464,102 @@ namespace MonoTests.System
                        Assert.AreEqual (-2.1M, Math.Round (-2.08M, 1, m), "#15");
                        Assert.AreEqual (-3.1M, Math.Round (-3.05M, 1, m), "#16");
                }
+
+               [Test] // bug #4814
+               [SetCulture("")]
+               public void Parse_NumberGroupSeparatorIsEmpty_DoNotThrowIndexOutOfRangeException ()
+               {
+                       NumberFormatInfo nf = new NumberFormatInfo ();
+                       nf.NumberGroupSeparator = "";
+                       Decimal.Parse ("1.5", nf);
+               }
+
+               [Test] // bug #4814
+               [SetCulture("")]
+               public void Parse_CurrencyGroupSeparatorIsEmpty_DoNotThrowIndexOutOfRangeException ()
+               {
+                       NumberFormatInfo nf = new NumberFormatInfo ();
+                       nf.CurrencyGroupSeparator = "";
+                       Decimal.Parse ("\u00A41.5", NumberStyles.Currency, nf);
+               }
+
+               [Test] // bug #4814
+               [SetCulture("")]
+               public void Parse_LeadingSign_PositiveSignIsEmpty_DoNotThrowIndexOutOfRangeException ()
+               {
+                       NumberFormatInfo nf = new NumberFormatInfo ();
+                       nf.PositiveSign = "";
+                       try {
+                               Decimal.Parse ("+15", nf);
+                       } catch (FormatException) {
+                               return;
+                       }
+
+                       Assert.Fail ("Expected FormatException");
+               }
+
+               [Test] // bug #4814
+               [SetCulture("")]
+               public void Parse_LeadingSign_NegativeSignIsEmpty_DoNotThrowIndexOutOfRangeException ()
+               {
+                       NumberFormatInfo nf = new NumberFormatInfo ();
+                       nf.NegativeSign = "";
+                       try {
+                               Decimal.Parse ("-15", nf);
+                       } catch (FormatException) {
+                               return;
+                       }
+
+                       Assert.Fail ("Expected FormatException");
+               }
+
+               [Test] // bug #4814
+               [SetCulture("")]
+               public void Parse_TrailingSign_PositiveSignIsEmpty_DoNotThrowIndexOutOfRangeException ()
+               {
+                       NumberFormatInfo nf = new NumberFormatInfo ();
+                       nf.PositiveSign = "";
+                       try {
+                               Decimal.Parse ("15+", nf);
+                       } catch (FormatException) {
+                               return;
+                       }
+
+                       Assert.Fail ("Expected FormatException");
+               }
+
+               [Test] // bug #4814
+               [SetCulture("")]
+               public void Parse_TrailingSign_NegativeSignIsEmpty_DoNotThrowIndexOutOfRangeException ()
+               {
+                       NumberFormatInfo nf = new NumberFormatInfo ();
+                       nf.NegativeSign = "";
+                       try {
+                               Decimal.Parse ("15-", nf);
+                       } catch (FormatException) {
+                               return;
+                       }
+
+                       Assert.Fail ("Expected FormatException");
+               }
+
+               [Test]
+               [SetCulture("en-US")]
+               public void ParseZeros ()
+               {
+                       var d = Decimal.Parse ("0.000");
+                       var bits = Decimal.GetBits (d);
+                       Assert.AreEqual (0, bits[0], "#1");
+                       Assert.AreEqual (0, bits[1], "#2");
+                       Assert.AreEqual (0, bits[2], "#3");
+                       Assert.AreEqual (196608, bits[3], "#4");
+                       Assert.AreEqual ("0.000", d.ToString (), "#5");
+
+                       d = Decimal.Parse("0.000000000000000000000000000000000000000000000000000000000000000000");
+                       Assert.AreEqual ("0.0000000000000000000000000000", d.ToString (), "#10");
+
+                       d = Decimal.Parse ("0.");
+                       Assert.AreEqual ("0", d.ToString (), "#11");
+               }
        }
 }