[runtime] Fix Empty generic enumerator equality
[mono.git] / mcs / class / corlib / Test / System / ArrayTest.cs
index 351d312c92d63c5d217d3f9df04524402671680b..36db33d6352b9ac3efc47122a7897ed4289ea21d 100644 (file)
@@ -779,6 +779,14 @@ public class ArrayTest
                Array.CreateInstance (typeof (Int32), (long[])null);
        }
 
+       [Test]
+       public void CreateInstanceVoid ()
+       {
+               Assert.Throws<NotSupportedException> (delegate () {
+                               Array.CreateInstance (typeof (void), 1);
+                       });
+       }
+
        [Test]
        public void TestGetEnumerator() {
                String[] s1 = {"this", "is", "a", "test"};
@@ -995,7 +1003,6 @@ public class ArrayTest
                int[] myBoundArray = new int[1] { Int32.MinValue };
                Array myExtremeArray=Array.CreateInstance ( typeof(String), myLengthArray, myBoundArray );
                Assert.AreEqual (Int32.MaxValue, ((IList)myExtremeArray).IndexOf (42), "AD04");
-
        }
 
        [Test]
@@ -2575,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()
        {
@@ -3358,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];
 
@@ -3642,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 ()
@@ -3660,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");
+       }
 }
 }