Pārlūkot izejas kodu

2003-06-07 Ben Maurer <[email protected]>
* Stack.cs: Contains (null) works correctly.
* StackTest.cs: Added test for Contains (null)

svn path=/trunk/mcs/; revision=15177

Ben Maurer 22 gadi atpakaļ
vecāks
revīzija
54c4ccfe2c

+ 3 - 0
mcs/class/corlib/System.Collections/ChangeLog

@@ -1,3 +1,6 @@
+2003-06-07  Ben Maurer <[email protected]>
+	* Stack.cs: Contains (null) works correctly.
+
 2003-06-07  Gonzalo Paniagua Javier <[email protected]>
 
 	* Stack.cs: fixed Clone ().

+ 12 - 5
mcs/class/corlib/System.Collections/Stack.cs

@@ -167,11 +167,18 @@ namespace System.Collections {
 
 		public virtual bool Contains(object obj) {
 			if (count == 0)
-				return false;
-
-			for (int i = 0; i < count; i++) {
-				if (contents[i].Equals(obj))
-					return true; 
+				return false;
+			
+			if (obj == null) {
+					for (int i = 0; i < count; i++) {
+						if (contents[i] == null)
+							return true; 
+					}
+			} else {
+					for (int i = 0; i < count; i++) {
+						if (contents[i].Equals(obj))
+							return true; 
+					}
 			}
 
 			return false;

+ 3 - 0
mcs/class/corlib/Test/System.Collections/ChangeLog

@@ -1,3 +1,6 @@
+2003-06-07  Ben Maurer <[email protected]>
+	* StackTest.cs: Added test for Contains (null)
+
 2003-05-13 Nick Drochak <[email protected]>
 
 	* DictionaryEntry.cs: Added test

+ 7 - 0
mcs/class/corlib/Test/System.Collections/StackTest.cs

@@ -118,6 +118,13 @@ namespace MonoTests.System.Collections
                         stackInt.Pop();
 
                         Assert(!stackInt.Contains(toLocate));
+			
+			stackInt.Push(null);
+			Assert(stackInt.Contains(null));
+			stackInt.Pop();
+			Assert(!stackInt.Contains(null));
+			
+			
                 }
 
                 public void TestCopyTo()