[runtime] Fix Empty generic enumerator equality
[mono.git] / mcs / class / corlib / Test / System / ArrayTest.cs
index 443b6874e6a519ed308f667f204c927f2234ec4a..36db33d6352b9ac3efc47122a7897ed4289ea21d 100644 (file)
@@ -2582,6 +2582,26 @@ public class ArrayTest
                }
        }
 
+       [Test]
+       public void TestSortComparableMixed()
+       {
+               var m = new TestSortComparableMixed_Comparer ();
+               var arr = new object [] { 1, 2, m, 4, 5, 6, 7, 8, 9, 10 };
+
+               Array.Sort (arr);
+
+               var expected = new object [] { m, 1, 2, 4, 5, 6, 7, 8, 9, 10 };
+               Assert.AreEqual (expected, arr);
+       }
+
+       class TestSortComparableMixed_Comparer : IComparable
+       {
+               public int CompareTo (object other)
+               {
+                       return -1;
+               }
+       }
+
        [Test]
        public void TestInitializeEmpty()
        {
@@ -3365,6 +3385,30 @@ public class ArrayTest
                }
        }
 
+       [Test]
+       public void IEnumerator_Dispose ()
+       {
+               IEnumerable<int> e = new int[] { 1 };
+               var en = e.GetEnumerator ();
+               Assert.IsTrue (en.MoveNext (), "#1");
+               Assert.IsFalse (en.MoveNext (), "#2");
+               en.Dispose ();
+               Assert.IsFalse (en.MoveNext (), "#3");
+       }
+
+       [Test]
+       public void IEnumerator_ZeroSize ()
+       {
+               IEnumerable<int> e = Array.Empty<int> ();
+               var en = e.GetEnumerator ();
+               Assert.IsFalse (en.MoveNext (), "#1");
+
+               e = Array.Empty<int> ();
+               en = e.GetEnumerator ();
+               Assert.IsFalse (en.MoveNext (), "#2");
+       }
+
+       [Test]
        public void ICollection_IsReadOnly() {
                ICollection<string> arr = new string [10];
 
@@ -3649,6 +3693,20 @@ public class ArrayTest
                Assert.AreEqual (3, c.Counter);         
        }
 
+       [Test]
+       public void EnumeratorsEquality ()
+       {
+               int [] normalBase = new int [0];
+               IEnumerable<int> specialBase = new int [0];
+
+               var firstSpecial = specialBase.GetEnumerator ();
+               var secondSpecial = specialBase.GetEnumerator ();
+               var firstNormal = normalBase.GetEnumerator ();
+               var secondNormal = normalBase.GetEnumerator ();
+
+               Assert.IsFalse (object.ReferenceEquals (firstNormal, secondNormal));
+               Assert.IsTrue (object.ReferenceEquals (firstSpecial, secondSpecial));
+       }
 
        [Test]
        public void JaggedArrayCtor ()
@@ -3667,5 +3725,17 @@ public class ArrayTest
                        Assert.AreEqual (10, ((object[])arr [i]).Length);
                }
        }
+
+       [Test]
+       public unsafe void PointerArraysBoxing ()
+       {
+               var x = new int*[10];
+               var e = x.GetEnumerator ();
+               e.MoveNext ();
+
+               Assert.Throws<NotSupportedException> (() => { var _ = e.Current; }, "#1");
+               Assert.Throws<NotSupportedException> (() => { var _ = x.GetValue (0); }, "#2");
+               Assert.Throws<NotSupportedException> (() => { x.SetValue (0, 0); }, "#3");
+       }
 }
 }