[System] UriKind.RelativeOrAbsolute workaround.
[mono.git] / mcs / class / corlib / Test / System / StringTest.cs
1 // StringTest.cs - NUnit Test Cases for the System.String class
2 //
3 // Authors:
4 //   Jeffrey Stedfast <fejj@ximian.com>
5 //   David Brandt <bucky@keystreams.com>
6 //   Kornel Pal <http://www.kornelpal.hu/>
7 //
8 // (C) Ximian, Inc.  http://www.ximian.com
9 // Copyright (C) 2006 Kornel Pal
10 // Copyright (C) 2006 Novell (http://www.novell.com)
11 //
12
13 using System;
14 using System.Text;
15 using System.Globalization;
16 using System.Reflection;
17 using System.Threading;
18
19 using NUnit.Framework;
20
21 namespace MonoTests.System
22 {
23
24 [TestFixture]
25 public class StringTest
26 {
27         class NullFormatter : IFormatProvider, ICustomFormatter
28         {
29                 public string Format (string format, object arg, IFormatProvider provider)
30                 {
31                         return null;
32                 }
33
34                 public object GetFormat (Type formatType)
35                 {
36                         return this;
37                 }
38         }
39
40         class ToNullStringer
41         {
42                 public override string ToString()
43                 {
44                         return null;
45                 }
46         }
47
48         private CultureInfo orgCulture;
49
50         [SetUp]
51         public void SetUp ()
52         {
53                 // save current culture
54                 orgCulture = CultureInfo.CurrentCulture;
55         }
56
57         [TearDown]
58         public void TearDown ()
59         {
60                 // restore original culture
61                 Thread.CurrentThread.CurrentCulture = orgCulture;
62         }
63
64
65         [Test] // ctor (Char [])
66         public unsafe void Constructor2 ()
67         {
68                 Assert.AreEqual (String.Empty, new String ((char[]) null), "#1");
69                 Assert.AreEqual (String.Empty, new String (new Char [0]), "#2");
70                 Assert.AreEqual ("A", new String (new Char [1] {'A'}), "#3");
71         }
72
73         [Test] // ctor (Char, Int32)
74         public void Constructor4 ()
75         {
76                 Assert.AreEqual (string.Empty, new String ('A', 0));
77                 Assert.AreEqual (new String ('A', 3), "AAA");
78         }
79
80         [Test] // ctor (Char, Int32)
81         public void Constructor4_Count_Negative ()
82         {
83                 try {
84                         new String ('A', -1);
85                         Assert.Fail ("#1");
86                 } catch (ArgumentOutOfRangeException ex) {
87                         // 'count' must be non-negative
88                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
89                         Assert.IsNull (ex.InnerException, "#3");
90                         Assert.IsNotNull (ex.Message, "#4");
91                         Assert.AreEqual ("count", ex.ParamName, "#5");
92                 }
93         }
94
95         [Test] // ctor (Char [], Int32, Int32)
96         public void Constructor6 ()
97         {
98                 char [] arr = new char [3] { 'A', 'B', 'C' };
99                 Assert.AreEqual ("ABC", new String (arr, 0, arr.Length), "#1");
100                 Assert.AreEqual ("BC", new String (arr, 1, 2), "#2");
101                 Assert.AreEqual (string.Empty, new String (arr, 2, 0), "#3");
102         }
103
104         [Test] // ctor (Char [], Int32, Int32)
105         public void Constructor6_Length_Negative ()
106         {
107                 char [] arr = new char [3] { 'A', 'B', 'C' };
108
109                 try {
110                         new String (arr, 0, -1);
111                         Assert.Fail ("#1");
112                 } catch (ArgumentOutOfRangeException ex) {
113                         // Length cannot be less than zero
114                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
115                         Assert.IsNull (ex.InnerException, "#3");
116                         Assert.IsNotNull (ex.Message, "#4");
117                         Assert.AreEqual ("length", ex.ParamName, "#5");
118                 }
119         }
120
121         [Test] // ctor (Char [], Int32, Int32)
122         public void Constructor6_Length_Overflow ()
123         {
124                 char [] arr = new char [3] { 'A', 'B', 'C' };
125
126                 try {
127                         new String (arr, 1, 3);
128                         Assert.Fail ("#1");
129                 } catch (ArgumentOutOfRangeException ex) {
130                         // Index was out of range. Must be non-negative and
131                         // less than the size of the collection
132                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
133                         Assert.IsNull (ex.InnerException, "#3");
134                         Assert.IsNotNull (ex.Message, "#4");
135                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
136                 }
137         }
138
139         [Test] // ctor (Char [], Int32, Int32)
140         public void Constructor6_StartIndex_Negative ()
141         {
142                 char [] arr = new char [3] { 'A', 'B', 'C' };
143
144                 try {
145                         new String (arr, -1, 0);
146                         Assert.Fail ("#1");
147                 } catch (ArgumentOutOfRangeException ex) {
148                         // StartIndex cannot be less than zero
149                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
150                         Assert.IsNull (ex.InnerException, "#3");
151                         Assert.IsNotNull (ex.Message, "#4");
152                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
153                 }
154         }
155
156         [Test] // ctor (Char [], Int32, Int32)
157         public void Constructor6_Value_Null ()
158         {
159                 try {
160                         new String ((char []) null, 0, 0);
161                         Assert.Fail ("#1");
162                 } catch (ArgumentNullException ex) {
163                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
164                         Assert.IsNull (ex.InnerException, "#3");
165                         Assert.IsNotNull (ex.Message, "#4");
166                         Assert.AreEqual ("value", ex.ParamName, "#5");
167                 }
168         }
169
170         [Test]
171         public unsafe void CharPtrConstructor ()
172         {
173                 Assert.AreEqual (String.Empty, new String ((char*) null), "char*");
174                 Assert.AreEqual (String.Empty, new String ((char*) null, 0, 0), "char*,int,int");
175         }
176
177         [Test]
178         public unsafe void TestSbytePtrConstructorASCII ()
179         {
180                 Encoding encoding = Encoding.ASCII;
181                 String s = "ASCII*\0";
182                 byte[] bytes = encoding.GetBytes (s);
183
184                 fixed (byte* bytePtr = bytes)
185                         Assert.AreEqual (s, new String ((sbyte*) bytePtr, 0, bytes.Length, encoding));
186         }
187
188         [Test]
189         public unsafe void TestSbytePtrConstructorDefault ()
190         {
191                 Encoding encoding = Encoding.Default;
192                 byte [] bytes = new byte [256];
193                 
194                 for (int i = 0; i < 255; i++)
195                         bytes [i] = (byte) (i + 1);
196                 bytes [255] = (byte) 0;
197
198                 // Ensure that bytes are valid for Encoding.Default
199                 bytes = encoding.GetBytes (encoding.GetChars (bytes));
200                 String s = encoding.GetString(bytes);
201
202                 // Ensure null terminated array
203                 bytes [bytes.Length - 1] = (byte) 0;
204
205                 fixed (byte* bytePtr = bytes) 
206                 {
207                         Assert.AreEqual (s.Substring (0, s.Length - 1), new String ((sbyte*) bytePtr));
208                         Assert.AreEqual (s, new String ((sbyte*) bytePtr, 0, bytes.Length));
209                         Assert.AreEqual (s, new String ((sbyte*) bytePtr, 0, bytes.Length, null));
210                         Assert.AreEqual (s, new String ((sbyte*) bytePtr, 0, bytes.Length, encoding));
211                 }
212         }
213
214         [Test] // ctor (SByte*)
215         public unsafe void Constructor3_Value_Null ()
216         {
217                 Assert.AreEqual (String.Empty, new String ((sbyte*) null));
218         }
219
220         [Test] // ctor (SByte*)
221         [Ignore ("invalid test")]
222         public unsafe void Constructor3_Value_Invalid ()
223         {
224                 try {
225                         new String ((sbyte*) (-1));
226                         Assert.Fail ("#1");
227                 } catch (ArgumentOutOfRangeException ex) {
228                         // Pointer startIndex and length do not refer to a
229                         // valid string
230                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
231                         Assert.IsNull (ex.InnerException, "#3");
232                         Assert.IsNotNull (ex.Message, "#4");
233                         Assert.AreEqual ("ptr", ex.ParamName, "#5");
234                 }
235         }
236
237         [Test] // ctor (SByte*, Int32, Int32)
238         public unsafe void Constructor7_Length_Negative ()
239         {
240                 try {
241                         new String ((sbyte*) null, 0, -1);
242                         Assert.Fail ("#1");
243                 } catch (ArgumentOutOfRangeException ex) {
244                         // Length cannot be less than zero
245                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
246                         Assert.IsNull (ex.InnerException, "#3");
247                         Assert.IsNotNull (ex.Message, "#4");
248                         Assert.AreEqual ("length", ex.ParamName, "#5");
249                 }
250         }
251
252         [Test] // ctor (SByte*, Int32, Int32)
253         public unsafe void Constructor7_StartIndex_Negative ()
254         {
255                 try {
256                         new String ((sbyte*) null, -1, 0);
257                         Assert.Fail ("#1");
258                 } catch (ArgumentOutOfRangeException ex) {
259                         // StartIndex cannot be less than zero
260                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
261                         Assert.IsNull (ex.InnerException, "#3");
262                         Assert.IsNotNull (ex.Message, "#4");
263                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
264                 }
265         }
266
267         [Test]
268         public unsafe void Constructor7_StartIndex_Overflow ()
269         {
270                 try {
271                         new String ((sbyte*) (-1), 1, 0);
272                         Assert.Fail ("#A1");
273                 } catch (ArgumentOutOfRangeException ex) {
274                         // Pointer startIndex and length do not refer to a
275                         // valid string
276                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
277                         Assert.IsNull (ex.InnerException, "#A3");
278                         Assert.IsNotNull (ex.Message, "#A4");
279                         Assert.AreEqual ("startIndex", ex.ParamName, "#A5");
280                 }
281
282                 try {
283                         new String ((sbyte*) (-1), 1, 1);
284                         Assert.Fail ("#B1");
285                 } catch (ArgumentOutOfRangeException ex) {
286                         // Pointer startIndex and length do not refer to a
287                         // valid string
288                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
289                         Assert.IsNull (ex.InnerException, "#B3");
290                         Assert.IsNotNull (ex.Message, "#B4");
291                         Assert.AreEqual ("startIndex", ex.ParamName, "#B5");
292                 }
293         }
294
295         [Test] // ctor (SByte*, Int32, Int32)
296         [Ignore ("invalid test")]
297         public unsafe void Constructor7_Value_Invalid ()
298         {
299                 try {
300                         new String ((sbyte*) (-1), 0, 1);
301                         Assert.Fail ("#1");
302                 } catch (ArgumentOutOfRangeException ex) {
303                         // Pointer startIndex and length do not refer to a
304                         // valid string
305                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
306                         Assert.IsNull (ex.InnerException, "#3");
307                         Assert.IsNotNull (ex.Message, "#4");
308                         Assert.AreEqual ("ptr", ex.ParamName, "#5");
309                 }
310         }
311
312         [Test] // ctor (SByte*, Int32, Int32)
313         public unsafe void Constructor7_Value_Null ()
314         {
315                 try {
316                         new String ((sbyte*) null, 0, 0);
317                         Assert.Fail ("#A1");
318                 } catch (ArgumentNullException ex) {
319                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
320                         Assert.IsNull (ex.InnerException, "#A3");
321                         Assert.IsNotNull (ex.Message, "#A4");
322                         Assert.AreEqual ("value", ex.ParamName, "#A5");
323                 }
324
325                 try {
326                         new String ((sbyte*) null, 0, 1);
327                         Assert.Fail ("#B1");
328                 } catch (ArgumentNullException ex) {
329                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
330                         Assert.IsNull (ex.InnerException, "#B3");
331                         Assert.IsNotNull (ex.Message, "#B4");
332                         Assert.AreEqual ("value", ex.ParamName, "#B5");
333                 }
334
335                 try {
336                         new String ((sbyte*) null, 1, 0);
337                         Assert.Fail ("#C1");
338                 } catch (ArgumentNullException ex) {
339                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#C2");
340                         Assert.IsNull (ex.InnerException, "#C3");
341                         Assert.IsNotNull (ex.Message, "#C4");
342                         Assert.AreEqual ("value", ex.ParamName, "#C5");
343                 }
344         }
345
346         [Test] // ctor (SByte*, Int32, Int32, Encoding)
347         public unsafe void Constructor8_Length_Negative ()
348         {
349                 try {
350                         new String ((sbyte*) null, 0, -1, null);
351                         Assert.Fail ("#A1");
352                 } catch (ArgumentOutOfRangeException ex) {
353                         // Length cannot be less than zero
354                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
355                         Assert.IsNull (ex.InnerException, "#A3");
356                         Assert.IsNotNull (ex.Message, "#A4");
357                         Assert.AreEqual ("length", ex.ParamName, "#A5");
358                 }
359
360                 try {
361                         new String ((sbyte*) null, 0, -1, Encoding.Default);
362                         Assert.Fail ("#B1");
363                 } catch (ArgumentOutOfRangeException ex) {
364                         // Non-negative number required
365                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
366                         Assert.IsNull (ex.InnerException, "#B3");
367                         Assert.IsNotNull (ex.Message, "#B4");
368                         Assert.AreEqual ("length", ex.ParamName, "#B5");
369                 }
370         }
371
372         [Test] // ctor (SByte*, Int32, Int32, Encoding)
373         public unsafe void Constructor8_StartIndex_Negative ()
374         {
375                 try {
376                         new String ((sbyte*) null, -1, 0, null);
377                         Assert.Fail ("#A1");
378                 } catch (ArgumentOutOfRangeException ex) {
379                         // StartIndex cannot be less than zero
380                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
381                         Assert.IsNull (ex.InnerException, "#A3");
382                         Assert.IsNotNull (ex.Message, "#A4");
383                         Assert.AreEqual ("startIndex", ex.ParamName, "#A5");
384                 }
385
386                 try {
387                         new String ((sbyte*) null, -1, 0, Encoding.Default);
388                         Assert.Fail ("#B1");
389                 } catch (ArgumentOutOfRangeException ex) {
390                         // StartIndex cannot be less than zero
391                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
392                         Assert.IsNull (ex.InnerException, "#B3");
393                         Assert.IsNotNull (ex.Message, "#B4");
394                         Assert.AreEqual ("startIndex", ex.ParamName, "#B5");
395                 }
396         }
397
398         [Test]
399         public unsafe void Constructor8_StartIndex_Overflow ()
400         {
401                 try {
402                         new String ((sbyte*) (-1), 1, 0, null);
403                         Assert.Fail ("#A1");
404                 } catch (ArgumentOutOfRangeException ex) {
405                         // Pointer startIndex and length do not refer to a
406                         // valid string
407                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
408                         Assert.IsNull (ex.InnerException, "#A3");
409                         Assert.IsNotNull (ex.Message, "#A4");
410                         Assert.AreEqual ("startIndex", ex.ParamName, "#A5");
411                 }
412
413                 try {
414                         new String ((sbyte*) (-1), 1, 1, null);
415                         Assert.Fail ("#B1");
416                 } catch (ArgumentOutOfRangeException ex) {
417                         // Pointer startIndex and length do not refer to a
418                         // valid string
419                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
420                         Assert.IsNull (ex.InnerException, "#B3");
421                         Assert.IsNotNull (ex.Message, "#B4");
422                         Assert.AreEqual ("startIndex", ex.ParamName, "#B5");
423                 }
424
425                 try {
426                         new String ((sbyte*) (-1), 1, 0, Encoding.Default);
427                         Assert.Fail ("#C1");
428                 } catch (ArgumentOutOfRangeException ex) {
429                         // Pointer startIndex and length do not refer to a
430                         // valid string
431                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#C2");
432                         Assert.IsNull (ex.InnerException, "#C3");
433                         Assert.IsNotNull (ex.Message, "#C4");
434                         Assert.AreEqual ("startIndex", ex.ParamName, "#C5");
435                 }
436
437                 try {
438                         new String ((sbyte*) (-1), 1, 1, Encoding.Default);
439                         Assert.Fail ("#D1");
440                 } catch (ArgumentOutOfRangeException ex) {
441                         // Pointer startIndex and length do not refer to a
442                         // valid string
443                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#D2");
444                         Assert.IsNull (ex.InnerException, "#D3");
445                         Assert.IsNotNull (ex.Message, "#D4");
446                         Assert.AreEqual ("startIndex", ex.ParamName, "#D5");
447                 }
448         }
449
450         [Test] // ctor (SByte*, Int32, Int32, Encoding)
451         [Ignore ("invalid test")]
452         public unsafe void Constructor8_Value_Invalid ()
453         {
454                 try {
455                         new String ((sbyte*) (-1), 0, 1, null);
456                         Assert.Fail ("#1");
457                 } catch (ArgumentOutOfRangeException ex) {
458                         // Pointer startIndex and length do not refer to a
459                         // valid string
460                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
461                         Assert.IsNull (ex.InnerException, "#3");
462                         Assert.IsNotNull (ex.Message, "#4");
463                         Assert.AreEqual ("ptr", ex.ParamName, "#5");
464                 }
465         }
466
467         [Test]
468         [Ignore ("Runtime throws NullReferenceException instead of AccessViolationException")]
469         [ExpectedException (typeof (AccessViolationException))]
470         public unsafe void Constructor8_Value_Invalid2 ()
471         {
472                 new String ((sbyte*) (-1), 0, 1, Encoding.Default);
473         }
474
475         [Test] // ctor (SByte*, Int32, Int32, Encoding)
476         public unsafe void Constructor8_Value_Null ()
477         {
478                 try {
479                         new String ((sbyte*) null, 0, 0, null);
480                         Assert.Fail ("#A1");
481                 } catch (ArgumentNullException ex) {
482                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
483                         Assert.IsNull (ex.InnerException, "#A3");
484                         Assert.IsNotNull (ex.Message, "#A4");
485                         Assert.AreEqual ("value", ex.ParamName, "#A5");
486                 }
487
488                 try {
489                         new String ((sbyte*) null, 0, 1, null);
490                         Assert.Fail ("#B1");
491                 } catch (ArgumentNullException ex) {
492                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
493                         Assert.IsNull (ex.InnerException, "#B3");
494                         Assert.IsNotNull (ex.Message, "#B4");
495                         Assert.AreEqual ("value", ex.ParamName, "#B5");
496                 }
497
498                 try {
499                         new String ((sbyte*) null, 1, 0, null);
500                         Assert.Fail ("#C1");
501                 } catch (ArgumentNullException ex) {
502                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#C2");
503                         Assert.IsNull (ex.InnerException, "#C3");
504                         Assert.IsNotNull (ex.Message, "#C4");
505                         Assert.AreEqual ("value", ex.ParamName, "#C5");
506                 }
507
508                 Assert.AreEqual (String.Empty, new String ((sbyte*) null, 0, 0, Encoding.Default), "#D");
509
510                 try {
511                         new String ((sbyte*) null, 0, 1, Encoding.Default);
512                         Assert.Fail ("#E1");
513                 } catch (ArgumentOutOfRangeException ex) {
514                         // Pointer startIndex and length do not refer to a
515                         // valid string
516                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#E2");
517                         Assert.IsNull (ex.InnerException, "#E3");
518                         Assert.IsNotNull (ex.Message, "#E4");
519                         //Assert.AreEqual ("value", ex.ParamName, "#E5");
520                 }
521
522                 Assert.AreEqual (String.Empty, new String ((sbyte*) null, 1, 0, Encoding.Default), "#F");
523         }
524         [Test]
525         public void Length ()
526         {
527                 string str = "test string";
528
529                 Assert.AreEqual (11, str.Length, "wrong length");
530         }
531
532         [Test]
533         public void Clone ()
534         {
535                 string s1 = "oRiGiNal";
536                 Assert.AreEqual (s1, s1.Clone (), "#A1");
537                 Assert.AreSame (s1, s1.Clone (), "#A2");
538
539                 string s2 = new DateTime (2000, 6, 3).ToString ();
540                 Assert.AreEqual (s2, s2.Clone (), "#B1");
541                 Assert.AreSame (s2, s2.Clone (), "#B2");
542         }
543
544         [Test] // bug #316666
545         public void CompareNotWorking ()
546         {
547                 Assert.AreEqual (String.Compare ("A", "a"), 1, "A03");
548                 Assert.AreEqual (String.Compare ("a", "A"), -1, "A04");
549         }
550
551         [Test]
552         public void CompareNotWorking2 ()
553         {
554                 string needle = "ab";
555                 string haystack = "abbcbacab";
556                 Assert.AreEqual (0, String.Compare(needle, 0, haystack, 0, 2, false), "basic substring check #9");
557                 for (int i = 1; i <= (haystack.Length - needle.Length); i++) {
558                         if (i != 7) {
559                                 Assert.AreEqual (-1, String.Compare(needle, 0, haystack, i, 2, false), "loop substring check #8/" + i);
560                         }
561                 }
562         }
563
564         [Test]
565         public void Compare ()
566         {
567                 string lesser = "abc";
568                 string medium = "abcd";
569                 string greater = "xyz";
570                 string caps = "ABC";
571
572                 Assert.AreEqual (0, String.Compare (null, null));
573                 Assert.AreEqual (1, String.Compare (lesser, null));
574
575                 Assert.IsTrue (String.Compare (lesser, greater) < 0);
576                 Assert.IsTrue (String.Compare (greater, lesser) > 0);
577                 Assert.IsTrue (String.Compare (lesser, lesser) == 0);
578                 Assert.IsTrue (String.Compare (lesser, medium) < 0);
579
580                 Assert.IsTrue (String.Compare (lesser, caps, true) == 0);
581                 Assert.IsTrue (String.Compare (lesser, caps, false) != 0);
582                 Assert.AreEqual (String.Compare ("a", "b"), -1, "A01");
583                 Assert.AreEqual (String.Compare ("b", "a"), 1, "A02");
584
585
586                 // TODO - test with CultureInfo
587
588                 string needle = "ab";
589                 string haystack = "abbcbacab";
590                 Assert.AreEqual (0, String.Compare(needle, 0, haystack, 0, 2), "basic substring check #1");
591                 Assert.AreEqual (-1, String.Compare(needle, 0, haystack, 0, 3), "basic substring check #2");
592                 Assert.AreEqual (0, String.Compare("ab", 0, "ab", 0, 2), "basic substring check #3");
593                 Assert.AreEqual (0, String.Compare("ab", 0, "ab", 0, 3), "basic substring check #4");
594                 Assert.AreEqual (0, String.Compare("abc", 0, "ab", 0, 2), "basic substring check #5");
595                 Assert.AreEqual (1, String.Compare("abc", 0, "ab", 0, 5), "basic substring check #6");
596                 Assert.AreEqual (-1, String.Compare("ab", 0, "abc", 0, 5), "basic substring check #7");
597
598                 for (int i = 1; i <= (haystack.Length - needle.Length); i++) {
599                         if (i != 7) {
600                                 Assert.IsTrue (String.Compare(needle, 0, haystack, i, 2) != 0, "loop substring check #1/" + i);
601                                 Assert.IsTrue (String.Compare(needle, 0, haystack, i, 3) != 0, "loop substring check #2/" + i);
602                         } else {
603                                 Assert.AreEqual (0, String.Compare(needle, 0, haystack, i, 2), "loop substring check #3/" + i);
604                                 Assert.AreEqual (0, String.Compare(needle, 0, haystack, i, 3), "loop substring check #4/" + i);
605                         }
606                 }
607
608                 needle = "AB";
609                 Assert.AreEqual (0, String.Compare(needle, 0, haystack, 0, 2, true), "basic substring check #8");
610                 for (int i = 1; i <= (haystack.Length - needle.Length); i++) {
611                         if (i != 7) {
612                                 Assert.IsTrue (String.Compare(needle, 0, haystack, i, 2, true) != 0, "loop substring check #5/" + i);
613                                 Assert.IsTrue (String.Compare(needle, 0, haystack, i, 2, false) != 0, "loop substring check #6/" + i);
614                         } else {
615                                 Assert.AreEqual (0, String.Compare(needle, 0, haystack, i, 2, true), "loop substring check #7/" + i);
616                         }
617                 }
618
619                 Assert.AreEqual (0, String.Compare (needle, 0, haystack, 0, 0), "Compare with 0 length");
620
621                 // TODO - extended format call with CultureInfo
622         }
623
624         [Test]
625         public void CompareOrdinal ()
626         {
627                 string lesser = "abc";
628                 string medium = "abcd";
629                 string greater = "xyz";
630
631                 Assert.AreEqual (0, String.CompareOrdinal (null, null));
632                 Assert.AreEqual (1, String.CompareOrdinal (lesser, null));
633
634                 Assert.IsTrue (String.CompareOrdinal (lesser, greater) < 0, "#1");
635                 Assert.IsTrue (String.CompareOrdinal (greater, lesser) > 0, "#2");
636                 Assert.IsTrue (String.CompareOrdinal (lesser, lesser) == 0, "#3");
637                 Assert.IsTrue (String.CompareOrdinal (lesser, medium) < 0, "#4");
638
639                 string needle = "ab";
640                 string haystack = "abbcbacab";
641                 Assert.AreEqual (0, String.CompareOrdinal(needle, 0, haystack, 0, 2), "basic substring check");
642                 Assert.AreEqual (-1, String.CompareOrdinal(needle, 0, haystack, 0, 3), "basic substring miss");
643                 for (int i = 1; i <= (haystack.Length - needle.Length); i++) {
644                         if (i != 7) {
645                                 Assert.IsTrue (String.CompareOrdinal(needle, 0, haystack, i, 2) != 0, "loop substring check " + i);
646                                 Assert.IsTrue (String.CompareOrdinal(needle, 0, haystack, i, 3) != 0, "loop substring check " + i);
647                         } else {
648                                 Assert.AreEqual (0, String.CompareOrdinal(needle, 0, haystack, i, 2), "loop substring check " + i);
649                                 Assert.AreEqual (0, String.CompareOrdinal(needle, 0, haystack, i, 3), "loop substring check " + i);
650                         }
651                 }
652         }
653
654         [Test]
655         [ExpectedException (typeof (ArgumentOutOfRangeException))]
656         public void CompareOrdinal_InvalidCount()
657         {
658                 string.CompareOrdinal ("a", 0, "b", 0, -1);
659         }
660
661         [Test]
662         public void CompareOrdinalWithOffset ()
663         {
664                 string ab1 = "ab";
665                 string ab2 = "a" + new string ('b', 1);
666                 
667                 Assert.IsTrue (string.CompareOrdinal (ab1, 0, ab1, 1, 1) < 0, "#1");
668                 Assert.IsTrue (string.CompareOrdinal (ab2, 0, ab1, 1, 1) < 0, "#2");
669         }
670
671         [Test]
672         public void CompareOrdinalSubstringWithNull ()
673         {
674                 string lesser = "abc";
675                 string greater = "xyz";
676
677                 Assert.AreEqual (0, string.CompareOrdinal (null, 0, null, 0, 0), "substring both null");
678                 Assert.AreEqual (-1, string.CompareOrdinal (null, 0, greater, 0, 0), "substring strA null");
679                 Assert.AreEqual (-1, string.CompareOrdinal (null, 4, greater, 0, 0), "substring strA null; indexA greater than strA.Length");
680                 Assert.AreEqual (-1, string.CompareOrdinal (null, 0, greater, 4, 0), "substring strA null; indexB greater than strB.Length");
681                 Assert.AreEqual (-1, string.CompareOrdinal (null, -1, greater, -1, -1), "substring strA null; indexA, indexB, length negative");
682                 Assert.AreEqual (1, string.CompareOrdinal (lesser, 0, null, 0, 0), "substring strB null");
683                 Assert.AreEqual (1, string.CompareOrdinal (lesser, 4, null, 0, 0), "substring strB null; indexA greater than strA.Length");
684                 Assert.AreEqual (1, string.CompareOrdinal (lesser, 0, null, 4, 0), "substring strB null; indexB greater than strB.Length");
685                 Assert.AreEqual (1, string.CompareOrdinal (lesser, -1, null, -1, -1), "substring strB null; indexA, indexB, length negative");
686         }
687
688         [Test]
689         public void CompareTo ()
690         {
691                 string lower = "abc";
692                 string greater = "xyz";
693                 string lesser = "abc";
694                 
695                 Assert.IsTrue (lower.CompareTo (greater) < 0);
696                 Assert.IsTrue (lower.CompareTo (lower) == 0);
697                 Assert.IsTrue (greater.CompareTo (lesser) > 0);
698         }
699         
700         class WeirdToString
701         {
702                 public override string ToString ()
703                 {
704                         return null;
705                 }
706         }
707
708         [Test]
709         public void Concat ()
710         {
711                 string string1 = "string1";
712                 string string2 = "string2";
713                 string concat = "string1string2";
714
715                 Assert.IsTrue (String.Concat (string1, string2) == concat);
716                 
717                 Assert.AreEqual (string1, String.Concat (string1, null));
718                 Assert.AreEqual (string1, String.Concat (null, string1));
719                 Assert.AreEqual (string.Empty, String.Concat (null, null));
720                 
721                 WeirdToString wts = new WeirdToString ();
722                 Assert.AreEqual (string1, String.Concat (string1, wts));
723                 Assert.AreEqual (string1, String.Concat (wts, string1));
724                 Assert.AreEqual (string.Empty, String.Concat (wts, wts));
725                 string [] allstr = new string []{ string1, null, string2, concat };
726                 object [] allobj = new object []{ string1, null, string2, concat };
727                 string astr = String.Concat (allstr);
728                 Assert.AreEqual ("string1string2string1string2", astr);
729                 string ostr = String.Concat (allobj);
730                 Assert.AreEqual (astr, ostr);
731         }
732
733         [Test]
734         public void Copy ()
735         {
736                 string s1 = "original";
737                 string s2 = String.Copy(s1);
738                 Assert.AreEqual (s1, s2, "#1");
739                 Assert.IsTrue (!object.ReferenceEquals (s1, s2), "#2");
740         }
741
742         [Test]
743         public void Copy_Str_Null ()
744         {
745                 try {
746                         String.Copy ((string) null);
747                         Assert.Fail ("#1");
748                 } catch (ArgumentNullException ex) {
749                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
750                         Assert.IsNull (ex.InnerException, "#3");
751                         Assert.IsNotNull (ex.Message, "#4");
752                         Assert.AreEqual ("str", ex.ParamName, "#5");
753                 }
754         }
755
756         [Test]
757         public void CopyTo ()
758         {
759                 string s1 = "original";
760                 char[] c1 = new char[s1.Length];
761                 string s2 = new String(c1);
762                 Assert.IsTrue (!s1.Equals(s2), "#1");
763                 for (int i = 0; i < s1.Length; i++) {
764                         s1.CopyTo(i, c1, i, 1);
765                 }
766                 s2 = new String(c1);
767                 Assert.AreEqual (s1, s2, "#2");
768         }
769
770         [Test]
771         public void CopyTo_Count_Negative ()
772         {
773                 char [] dest = new char [4];
774                 try {
775                         "Mono".CopyTo (0, dest, 0, -1);
776                         Assert.Fail ("#1");
777                 } catch (ArgumentOutOfRangeException ex) {
778                         // Count cannot be less than zero
779                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
780                         Assert.IsNull (ex.InnerException, "#3");
781                         Assert.IsNotNull (ex.Message, "#4");
782                         Assert.AreEqual ("count", ex.ParamName, "#5");
783                 }
784         }
785
786         [Test]
787         public void CopyTo_Count_Overflow ()
788         {
789                 char [] dest = new char [4];
790                 try {
791                         "Mono".CopyTo (0, dest, 0, Int32.MaxValue);
792                         Assert.Fail ("#1");
793                 } catch (ArgumentOutOfRangeException ex) {
794                         // Index and count must refer to a location within the
795                         // string
796                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
797                         Assert.IsNull (ex.InnerException, "#3");
798                         Assert.IsNotNull (ex.Message, "#4");
799                         Assert.AreEqual ("sourceIndex", ex.ParamName, "#5");
800                 }
801         }
802
803         [Test]
804         public void CopyTo_Destination_Null ()
805         {
806                 string s = "original";
807
808                 try {
809                         s.CopyTo (0, (char []) null, 0, s.Length);
810                         Assert.Fail ("#1");
811                 } catch (ArgumentNullException ex) {
812                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
813                         Assert.IsNull (ex.InnerException, "#3");
814                         Assert.IsNotNull (ex.Message, "#4");
815                         Assert.AreEqual ("destination", ex.ParamName, "#5");
816                 }
817         }
818
819         [Test]
820         public void CopyTo_DestinationIndex_Negative ()
821         {
822                 char [] dest = new char [4];
823                 try {
824                         "Mono".CopyTo (0, dest, -1, 4);
825                         Assert.Fail ("#1");
826                 } catch (ArgumentOutOfRangeException ex) {
827                         // Index and count must refer to a location within the
828                         // string
829                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
830                         Assert.IsNull (ex.InnerException, "#3");
831                         Assert.IsNotNull (ex.Message, "#4");
832                         Assert.AreEqual ("destinationIndex", ex.ParamName, "#5");
833                 }
834         }
835
836         [Test]
837         public void CopyTo_DestinationIndex_Overflow ()
838         {
839                 char [] dest = new char [4];
840                 try {
841                         "Mono".CopyTo (0, dest, Int32.MaxValue, 4);
842                         Assert.Fail ("#1");
843                 } catch (ArgumentOutOfRangeException ex) {
844                         // Index and count must refer to a location within the
845                         // string
846                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
847                         Assert.IsNull (ex.InnerException, "#3");
848                         Assert.IsNotNull (ex.Message, "#4");
849                         Assert.AreEqual ("destinationIndex", ex.ParamName, "#5");
850                 }
851         }
852
853         [Test]
854         public void CopyTo_SourceIndex_Negative ()
855         {
856                 char [] dest = new char [4];
857                 try {
858                         "Mono".CopyTo (-1, dest, 0, 4);
859                         Assert.Fail ("#1");
860                 } catch (ArgumentOutOfRangeException ex) {
861                         // Index was out of range. Must be non-negative and
862                         // less than the size of the collection
863                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
864                         Assert.IsNull (ex.InnerException, "#3");
865                         Assert.IsNotNull (ex.Message, "#4");
866                         Assert.AreEqual ("sourceIndex", ex.ParamName, "#5");
867                 }
868         }
869
870         [Test]
871         public void CopyTo_SourceIndex_Overflow ()
872         {
873                 char[] dest = new char [4];
874                 try {
875                         "Mono".CopyTo (Int32.MaxValue, dest, 0, 4);
876                         Assert.Fail ("#1");
877                 } catch (ArgumentOutOfRangeException ex) {
878                         // Index and count must refer to a location within the
879                         // string
880                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
881                         Assert.IsNull (ex.InnerException, "#3");
882                         Assert.IsNotNull (ex.Message, "#4");
883                         Assert.AreEqual ("sourceIndex", ex.ParamName, "#5");
884                 }
885         }
886
887         [Test] // EndsWith (String)
888         public void EndsWith1 ()
889         {
890                 string s;
891
892                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
893                 s = "AbC";
894
895                 Assert.IsTrue (s.EndsWith ("bC"), "#A1");
896                 Assert.IsTrue (!s.EndsWith ("bc"), "#A1");
897                 Assert.IsTrue (!s.EndsWith ("dc"), "#A2");
898                 Assert.IsTrue (!s.EndsWith ("LAbC"), "#A3");
899                 Assert.IsTrue (s.EndsWith (string.Empty), "#A4");
900                 Assert.IsTrue (!s.EndsWith ("Ab"), "#A5");
901                 Assert.IsTrue (!s.EndsWith ("Abc"), "#A6");
902                 Assert.IsTrue (s.EndsWith ("AbC"), "#A7");
903
904                 s = "Tai";
905
906                 Assert.IsTrue (s.EndsWith ("ai"), "#B1");
907                 Assert.IsTrue (!s.EndsWith ("AI"), "#B2");
908                 Assert.IsTrue (!s.EndsWith ("LTai"), "#B3");
909                 Assert.IsTrue (s.EndsWith (string.Empty), "#B4");
910                 Assert.IsTrue (!s.EndsWith ("Ta"), "#B5");
911                 Assert.IsTrue (!s.EndsWith ("tai"), "#B6");
912                 Assert.IsTrue (s.EndsWith ("Tai"), "#B7");
913
914                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
915
916                 Assert.IsTrue (s.EndsWith ("ai"), "#C1");
917                 Assert.IsTrue (!s.EndsWith ("AI"), "#C2");
918                 Assert.IsTrue (!s.EndsWith ("LTai"), "#C3");
919                 Assert.IsTrue (s.EndsWith (string.Empty), "#C4");
920                 Assert.IsTrue (!s.EndsWith ("Ta"), "#C5");
921                 Assert.IsTrue (!s.EndsWith ("tai"), "#C6");
922                 Assert.IsTrue (s.EndsWith ("Tai"), "#C7");
923         }
924
925         [Test] // EndsWith (String)
926         public void EndsWith1_Value_Null ()
927         {
928                 try {
929                         "ABC".EndsWith ((string) null);
930                         Assert.Fail ("#1");
931                 } catch (ArgumentNullException ex) {
932                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
933                         Assert.IsNull (ex.InnerException, "#3");
934                         Assert.IsNotNull (ex.Message, "#4");
935                         Assert.AreEqual ("value", ex.ParamName, "#5");
936                 }
937         }
938
939         [Test] // EndsWith (String, StringComparison)
940         public void EndsWith2_ComparisonType_Invalid ()
941         {
942                 try {
943                         "ABC".EndsWith ("C", (StringComparison) 80);
944                         Assert.Fail ("#1");
945                 } catch (ArgumentException ex) {
946                         // The string comparison type passed in is currently
947                         // not supported
948                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
949                         Assert.IsNull (ex.InnerException, "#3");
950                         Assert.IsNotNull (ex.Message, "#4");
951                         Assert.AreEqual ("comparisonType", ex.ParamName, "#5");
952                 }
953         }
954
955         [Test] // EndsWith (String, StringComparison)
956         public void EndsWith2_Value_Null ()
957         {
958                 try {
959                         "ABC".EndsWith ((string) null, StringComparison.CurrentCulture);
960                         Assert.Fail ("#1");
961                 } catch (ArgumentNullException ex) {
962                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
963                         Assert.IsNull (ex.InnerException, "#3");
964                         Assert.IsNotNull (ex.Message, "#4");
965                         Assert.AreEqual ("value", ex.ParamName, "#5");
966                 }
967         }
968
969         [Test] // EndsWith (String, Boolean, CultureInfo)
970         public void EndsWith3 ()
971         {
972                 string s;
973                 bool ignorecase;
974                 CultureInfo culture;
975
976                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
977                 s = "AbC";
978                 culture = null;
979
980                 ignorecase = false;
981                 Assert.IsTrue (!s.EndsWith ("bc", ignorecase, culture), "#A1");
982                 Assert.IsTrue (!s.EndsWith ("dc", ignorecase, culture), "#A2");
983                 Assert.IsTrue (!s.EndsWith ("LAbC", ignorecase, culture), "#A3");
984                 Assert.IsTrue (s.EndsWith (string.Empty, ignorecase, culture), "#A4");
985                 Assert.IsTrue (!s.EndsWith ("Ab", ignorecase, culture), "#A5");
986                 Assert.IsTrue (!s.EndsWith ("Abc", ignorecase, culture), "#A6");
987                 Assert.IsTrue (s.EndsWith ("AbC", ignorecase, culture), "#A7");
988
989                 ignorecase = true;
990                 Assert.IsTrue (s.EndsWith ("bc", ignorecase, culture), "#B1");
991                 Assert.IsTrue (!s.EndsWith ("dc", ignorecase, culture), "#B2");
992                 Assert.IsTrue (!s.EndsWith ("LAbC", ignorecase, culture), "#B3");
993                 Assert.IsTrue (s.EndsWith (string.Empty, ignorecase, culture), "#B4");
994                 Assert.IsTrue (!s.EndsWith ("Ab", ignorecase, culture), "#B5");
995                 Assert.IsTrue (s.EndsWith ("Abc", ignorecase, culture), "#B6");
996                 Assert.IsTrue (s.EndsWith ("AbC", ignorecase, culture), "#B7");
997
998                 s = "Tai";
999                 culture = null;
1000
1001                 ignorecase = false;
1002                 Assert.IsTrue (s.EndsWith ("ai", ignorecase, culture), "#C1");
1003                 Assert.IsTrue (!s.EndsWith ("AI", ignorecase, culture), "#C2");
1004                 Assert.IsTrue (!s.EndsWith ("LTai", ignorecase, culture), "#C3");
1005                 Assert.IsTrue (s.EndsWith (string.Empty, ignorecase, culture), "#C4");
1006                 Assert.IsTrue (!s.EndsWith ("Ta", ignorecase, culture), "#C5");
1007                 Assert.IsTrue (!s.EndsWith ("tai", ignorecase, culture), "#C6");
1008                 Assert.IsTrue (s.EndsWith ("Tai", ignorecase, culture), "#C7");
1009
1010                 ignorecase = true;
1011                 Assert.IsTrue (s.EndsWith ("ai", ignorecase, culture), "#D1");
1012                 Assert.IsTrue (!s.EndsWith ("AI", ignorecase, culture), "#D2");
1013                 Assert.IsTrue (!s.EndsWith ("LTai", ignorecase, culture), "#D3");
1014                 Assert.IsTrue (s.EndsWith (string.Empty, ignorecase, culture), "#D4");
1015                 Assert.IsTrue (!s.EndsWith ("Ta", ignorecase, culture), "#D5");
1016                 Assert.IsTrue (s.EndsWith ("tai", ignorecase, culture), "#D6");
1017                 Assert.IsTrue (s.EndsWith ("Tai", ignorecase, culture), "#D7");
1018
1019                 s = "Tai";
1020                 culture = new CultureInfo ("en-US");
1021
1022                 ignorecase = false;
1023                 Assert.IsTrue (s.EndsWith ("ai", ignorecase, culture), "#E1");
1024                 Assert.IsTrue (!s.EndsWith ("AI", ignorecase, culture), "#E2");
1025                 Assert.IsTrue (!s.EndsWith ("LTai", ignorecase, culture), "#E3");
1026                 Assert.IsTrue (s.EndsWith (string.Empty, ignorecase, culture), "#E4");
1027                 Assert.IsTrue (!s.EndsWith ("Ta", ignorecase, culture), "#E5");
1028                 Assert.IsTrue (!s.EndsWith ("tai", ignorecase, culture), "#E6");
1029                 Assert.IsTrue (s.EndsWith ("Tai", ignorecase, culture), "#E7");
1030
1031                 ignorecase = true;
1032                 Assert.IsTrue (s.EndsWith ("ai", ignorecase, culture), "#F1");
1033                 Assert.IsTrue (s.EndsWith ("AI", ignorecase, culture), "#F2");
1034                 Assert.IsTrue (!s.EndsWith ("LTai", ignorecase, culture), "#F3");
1035                 Assert.IsTrue (s.EndsWith (string.Empty, ignorecase, culture), "#F4");
1036                 Assert.IsTrue (!s.EndsWith ("Ta", ignorecase, culture), "#F5");
1037                 Assert.IsTrue (s.EndsWith ("tai", ignorecase, culture), "#F6");
1038                 Assert.IsTrue (s.EndsWith ("Tai", ignorecase, culture), "#F7");
1039
1040                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
1041                 culture = null;
1042
1043                 ignorecase = false;
1044                 Assert.IsTrue (s.EndsWith ("ai", ignorecase, culture), "#G1");
1045                 Assert.IsTrue (!s.EndsWith ("AI", ignorecase, culture), "#G2");
1046                 Assert.IsTrue (!s.EndsWith ("LTai", ignorecase, culture), "#G3");
1047                 Assert.IsTrue (s.EndsWith (string.Empty, ignorecase, culture), "#G4");
1048                 Assert.IsTrue (!s.EndsWith ("Ta", ignorecase, culture), "#G5");
1049                 Assert.IsTrue (!s.EndsWith ("tai", ignorecase, culture), "#G6");
1050                 Assert.IsTrue (s.EndsWith ("Tai", ignorecase, culture), "#G7");
1051
1052                 ignorecase = true;
1053                 Assert.IsTrue (s.EndsWith ("ai", ignorecase, culture), "#H1");
1054                 Assert.IsTrue (s.EndsWith ("AI", ignorecase, culture), "#H2");
1055                 Assert.IsTrue (!s.EndsWith ("LTai", ignorecase, culture), "#H3");
1056                 Assert.IsTrue (s.EndsWith (string.Empty, ignorecase, culture), "#H4");
1057                 Assert.IsTrue (!s.EndsWith ("Ta", ignorecase, culture), "#H5");
1058                 Assert.IsTrue (s.EndsWith ("tai", ignorecase, culture), "#H6");
1059                 Assert.IsTrue (s.EndsWith ("Tai", ignorecase, culture), "#H7");
1060         }
1061
1062         [Test] // EndsWith (String, Boolean, CultureInfo)
1063         public void EndsWith3_Value_Null ()
1064         {
1065                 try {
1066                         "ABC".EndsWith ((string) null, true, null);
1067                         Assert.Fail ("#1");
1068                 } catch (ArgumentNullException ex) {
1069                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1070                         Assert.IsNull (ex.InnerException, "#3");
1071                         Assert.IsNotNull (ex.Message, "#4");
1072                         Assert.AreEqual ("value", ex.ParamName, "#5");
1073                 }
1074         }
1075
1076         [Test]
1077         public void TestEquals ()
1078         {
1079                 string s1 = "original";
1080                 string yes = "original";
1081                 object y = yes;
1082                 string no = "copy";
1083                 string s1s1 = s1 + s1;
1084
1085                 Assert.IsTrue (!s1.Equals (null), "No match for null");
1086                 Assert.IsTrue (s1.Equals (y), "Should match object");
1087                 Assert.IsTrue (s1.Equals (yes), "Should match");
1088                 Assert.IsTrue (!s1.Equals (no), "Shouldn't match");
1089
1090                 Assert.IsTrue (String.Equals (null, null), "Static nulls should match");
1091                 Assert.IsTrue (String.Equals (s1, yes), "Should match");
1092                 Assert.IsTrue (!String.Equals (s1, no), "Shouldn't match");
1093
1094                 Assert.AreEqual (false, s1s1.Equals (y), "Equals (object)");
1095         }
1096
1097         [Test]
1098         public void TestFormat ()
1099         {
1100                 Assert.AreEqual (string.Empty, String.Format (string.Empty, 0), "Empty format string.");
1101                 Assert.AreEqual ("100", String.Format ("{0}", 100), "Single argument.");
1102                 Assert.AreEqual ("X   37X", String.Format ("X{0,5}X", 37), "Single argument, right justified.");
1103                 Assert.AreEqual ("X37   X", String.Format ("X{0,-5}X", 37), "Single argument, left justified.");
1104                 Assert.AreEqual ("  7d", String.Format ("{0, 4:x}", 125), "Whitespace in specifier");
1105                 Assert.AreEqual ("The 3 wise men.", String.Format ("The {0} wise {1}.", 3, "men"), "Two arguments.");
1106                 Assert.AreEqual ("do re me fa so.", String.Format ("{0} re {1} fa {2}.", "do", "me", "so"), "Three arguments.");
1107                 Assert.AreEqual ("###00c0ffee#", String.Format ("###{0:x8}#", 0xc0ffee), "Formatted argument.");
1108                 Assert.AreEqual ("#  033#", String.Format ("#{0,5:x3}#", 0x33), "Formatted argument, right justified.");
1109                 Assert.AreEqual ("#033  #", String.Format ("#{0,-5:x3}#", 0x33), "Formatted argument, left justified.");
1110                 Assert.AreEqual ("typedef struct _MonoObject { ... } MonoObject;", String.Format ("typedef struct _{0} {{ ... }} MonoObject;", "MonoObject"), "Escaped bracket");
1111                 Assert.AreEqual ("Could not find file \"a/b\"", String.Format ("Could not find file \"{0}\"", "a/b"), "With Slash");
1112                 Assert.AreEqual ("Could not find file \"a\\b\"", String.Format ("Could not find file \"{0}\"", "a\\b"), "With BackSlash");
1113                 Assert.AreEqual ("{d} ", string.Format ("{{{0:d}} }", 100));
1114         }
1115
1116         [Test] // Format (String, Object)
1117         public void Format1_Format_Null ()
1118         {
1119                 try {
1120                         String.Format (null, 1);
1121                         Assert.Fail ("#1");
1122                 } catch (ArgumentNullException ex) {
1123                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1124                         Assert.IsNull (ex.InnerException, "#3");
1125                         Assert.IsNotNull (ex.Message, "#4");
1126                         Assert.AreEqual ("format", ex.ParamName, "#5");
1127                 }
1128         }
1129
1130         [Test] // Format (String, Object [])
1131         public void Format2_Format_Null ()
1132         {
1133                 try {
1134                         String.Format (null, new object [] { 2 });
1135                         Assert.Fail ("#1");
1136                 } catch (ArgumentNullException ex) {
1137                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1138                         Assert.IsNull (ex.InnerException, "#3");
1139                         Assert.IsNotNull (ex.Message, "#4");
1140                         Assert.AreEqual ("format", ex.ParamName, "#5");
1141                 }
1142         }
1143
1144         [Test] // Format (String, Object [])
1145         public void Format2_Args_Null ()
1146         {
1147                 try {
1148                         String.Format ("text", (object []) null);
1149                         Assert.Fail ("#1");
1150                 } catch (ArgumentNullException ex) {
1151                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1152                         Assert.IsNull (ex.InnerException, "#3");
1153                         Assert.IsNotNull (ex.Message, "#4");
1154                         Assert.AreEqual ("args", ex.ParamName, "#5");
1155                 }
1156         }
1157
1158         [Test] // Format (IFormatProvider, String, Object [])
1159         public void Format3_Format_Null ()
1160         {
1161                 try {
1162                         String.Format (CultureInfo.InvariantCulture, null,
1163                                 new object [] { 3 });
1164                         Assert.Fail ("#1");
1165                 } catch (ArgumentNullException ex) {
1166                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1167                         Assert.IsNull (ex.InnerException, "#3");
1168                         Assert.IsNotNull (ex.Message, "#4");
1169                         Assert.AreEqual ("format", ex.ParamName, "#5");
1170                 }
1171         }
1172
1173         [Test] // Format (IFormatProvider, String, Object [])
1174         public void Format3_Args_Null ()
1175         {
1176                 try {
1177                         String.Format (CultureInfo.InvariantCulture, "text",
1178                                 (object []) null);
1179                         Assert.Fail ("#1");
1180                 } catch (ArgumentNullException ex) {
1181                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1182                         Assert.IsNull (ex.InnerException, "#3");
1183                         Assert.IsNotNull (ex.Message, "#4");
1184                         Assert.AreEqual ("args", ex.ParamName, "#5");
1185                 }
1186         }
1187
1188         [Test] // Format (String, Object, Object)
1189         public void Format4_Format_Null ()
1190         {
1191                 try {
1192                         String.Format (null, 4, 5);
1193                         Assert.Fail ("#1");
1194                 } catch (ArgumentNullException ex) {
1195                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1196                         Assert.IsNull (ex.InnerException, "#3");
1197                         Assert.IsNotNull (ex.Message, "#4");
1198                         Assert.AreEqual ("format", ex.ParamName, "#5");
1199                 }
1200         }
1201
1202         [Test] // Format (String, Object, Object, Object)
1203         public void Format5_Format_Null ()
1204         {
1205                 try {
1206                         String.Format (null, 4, 5, 6);
1207                         Assert.Fail ("#1");
1208                 } catch (ArgumentNullException ex) {
1209                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1210                         Assert.IsNull (ex.InnerException, "#3");
1211                         Assert.IsNotNull (ex.Message, "#4");
1212                         Assert.AreEqual ("format", ex.ParamName, "#5");
1213                 }
1214         }
1215
1216         [Test]
1217         public void Format ()
1218         {
1219                 var s = String.Format (new NullFormatter (), "{0:}", "test");
1220                 Assert.AreEqual ("test", s);
1221         }
1222
1223         [Test]
1224         public void Format_Arg_ToNullStringer ()
1225         {
1226                 var s = String.Format ("{0}", new ToNullStringer ());
1227                 Assert.AreEqual ("", s);
1228         }
1229
1230         [Test]
1231         public void TestGetEnumerator ()
1232         {
1233                 string s1 = "original";
1234                 char[] c1 = new char[s1.Length];
1235                 string s2 = new String(c1);
1236                 Assert.IsTrue (!s1.Equals(s2), "pre-enumerated string should not match");
1237                 CharEnumerator en = s1.GetEnumerator();
1238                 Assert.IsNotNull (en, "null enumerator");
1239                 
1240                 for (int i = 0; i < s1.Length; i++) {
1241                         en.MoveNext();
1242                         c1[i] = en.Current;
1243                 }
1244                 s2 = new String(c1);
1245                 Assert.AreEqual (s1, s2, "enumerated string should match");
1246         }
1247
1248         [Test]
1249         public void TestGetHashCode ()
1250         {
1251                 string s1 = "original";
1252                 // TODO - weak test, currently.  Just verifies determinicity.
1253                 Assert.AreEqual (s1.GetHashCode(), s1.GetHashCode(), "same string, same hash code");
1254         }
1255
1256         [Test]
1257         public void TestGetType ()
1258         {
1259                 string s1 = "original";
1260                 Assert.AreEqual ("System.String", s1.GetType().ToString(), "String type");
1261         }
1262
1263         [Test]
1264         public void TestGetTypeCode ()
1265         {
1266                 string s1 = "original";
1267                 Assert.IsTrue (s1.GetTypeCode().Equals(TypeCode.String));
1268         }
1269
1270         [Test]
1271         public void IndexOf ()
1272         {
1273                 string s1 = "original";
1274
1275                 try {
1276                         s1.IndexOf ('q', s1.Length + 1);
1277                         Assert.Fail ("#A1");
1278                 } catch (ArgumentOutOfRangeException ex) {
1279                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
1280                         Assert.IsNull (ex.InnerException, "#A3");
1281                         Assert.IsNotNull (ex.Message, "#A4");
1282                         Assert.AreEqual ("startIndex", ex.ParamName, "#A5");
1283                 }
1284
1285                 try {
1286                         s1.IndexOf ('q', s1.Length + 1, 1);
1287                         Assert.Fail ("#B1");
1288                 } catch (ArgumentOutOfRangeException ex) {
1289                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
1290                         Assert.IsNull (ex.InnerException, "#B3");
1291                         Assert.IsNotNull (ex.Message, "#B4");
1292                         Assert.AreEqual ("startIndex", ex.ParamName, "#B5");
1293                 }
1294
1295                 try {
1296                         s1.IndexOf ("huh", s1.Length + 1);
1297                         Assert.Fail ("#C1");
1298                 } catch (ArgumentOutOfRangeException ex) {
1299                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#C2");
1300                         Assert.IsNull (ex.InnerException, "#C3");
1301                         Assert.IsNotNull (ex.Message, "#C4");
1302                         Assert.AreEqual ("startIndex", ex.ParamName, "#C5");
1303                 }
1304
1305                 Assert.AreEqual (1, s1.IndexOf('r'), "basic char index");
1306                 Assert.AreEqual (2, s1.IndexOf('i'), "basic char index 2");
1307                 Assert.AreEqual (-1, s1.IndexOf('q'), "basic char index - no");
1308                 
1309                 Assert.AreEqual (1, s1.IndexOf("rig"), "basic string index");
1310                 Assert.AreEqual (2, s1.IndexOf("i"), "basic string index 2");
1311                 Assert.AreEqual (0, string.Empty.IndexOf(string.Empty), "basic string index 3");
1312                 Assert.AreEqual (0, "ABC".IndexOf(string.Empty), "basic string index 4");
1313                 Assert.AreEqual (-1, s1.IndexOf("rag"), "basic string index - no");
1314
1315                 Assert.AreEqual (1, s1.IndexOf('r', 1), "stepped char index");
1316                 Assert.AreEqual (2, s1.IndexOf('i', 1), "stepped char index 2");
1317                 Assert.AreEqual (4, s1.IndexOf('i', 3), "stepped char index 3");
1318                 Assert.AreEqual (-1, s1.IndexOf('i', 5), "stepped char index 4");
1319                 Assert.AreEqual (-1, s1.IndexOf('l', s1.Length), "stepped char index 5");
1320
1321                 Assert.AreEqual (1, s1.IndexOf('r', 1, 1), "stepped limited char index");
1322                 Assert.AreEqual (-1, s1.IndexOf('r', 0, 1), "stepped limited char index");
1323                 Assert.AreEqual (2, s1.IndexOf('i', 1, 3), "stepped limited char index");
1324                 Assert.AreEqual (4, s1.IndexOf('i', 3, 3), "stepped limited char index");
1325                 Assert.AreEqual (-1, s1.IndexOf('i', 5, 3), "stepped limited char index");
1326
1327                 s1 = "original original";
1328                 Assert.AreEqual (0, s1.IndexOf("original", 0), "stepped string index 1");
1329                 Assert.AreEqual (9, s1.IndexOf("original", 1), "stepped string index 2");
1330                 Assert.AreEqual (-1, s1.IndexOf("original", 10), "stepped string index 3");
1331                 Assert.AreEqual (3, s1.IndexOf(string.Empty, 3), "stepped string index 4");
1332                 Assert.AreEqual (1, s1.IndexOf("rig", 0, 5), "stepped limited string index 1");
1333                 Assert.AreEqual (-1, s1.IndexOf("rig", 0, 3), "stepped limited string index 2");
1334                 Assert.AreEqual (10, s1.IndexOf("rig", 2, 15), "stepped limited string index 3");
1335                 Assert.AreEqual (-1, s1.IndexOf("rig", 2, 3), "stepped limited string index 4");
1336                 Assert.AreEqual (2, s1.IndexOf(string.Empty, 2, 3), "stepped limited string index 5");
1337                 
1338                 string s2 = "QBitArray::bitarr_data"; 
1339                 Assert.AreEqual (9, s2.IndexOf ("::"), "bug #62160");
1340         }
1341
1342         [Test] // IndexOf (String)
1343         public void IndexOf2_Value_Null ()
1344         {
1345                 try {
1346                         "Mono".IndexOf ((string) null);
1347                         Assert.Fail ("#1");
1348                 } catch (ArgumentNullException ex) {
1349                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1350                         Assert.IsNull (ex.InnerException, "#3");
1351                         Assert.IsNotNull (ex.Message, "#4");
1352                         Assert.AreEqual ("value", ex.ParamName, "#5");
1353                 }
1354         }
1355
1356         [Test] // IndexOf (Char, Int32)
1357         public void IndexOf3 ()
1358         {
1359                 string s = "testing123456";
1360
1361                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
1362
1363                 Assert.AreEqual (-1, s.IndexOf ('a', s.Length), "#A1");
1364                 Assert.AreEqual (-1, s.IndexOf ('6', s.Length), "#A2");
1365                 Assert.AreEqual (-1, s.IndexOf ('t', s.Length), "#A3");
1366                 Assert.AreEqual (-1, s.IndexOf ('T', s.Length), "#A4");
1367                 Assert.AreEqual (-1, s.IndexOf ('i', s.Length), "#A5");
1368                 Assert.AreEqual (-1, s.IndexOf ('I', s.Length), "#A6");
1369                 Assert.AreEqual (-1, s.IndexOf ('q', s.Length), "#A7");
1370                 Assert.AreEqual (-1, s.IndexOf ('3', s.Length), "#A8");
1371
1372                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
1373
1374                 Assert.AreEqual (-1, s.IndexOf ('a', s.Length), "#B1");
1375                 Assert.AreEqual (-1, s.IndexOf ('6', s.Length), "#B2");
1376                 Assert.AreEqual (-1, s.IndexOf ('t', s.Length), "#B3");
1377                 Assert.AreEqual (-1, s.IndexOf ('T', s.Length), "#B4");
1378                 Assert.AreEqual (-1, s.IndexOf ('i', s.Length), "#B5");
1379                 Assert.AreEqual (-1, s.IndexOf ('I', s.Length), "#B6");
1380                 Assert.AreEqual (-1, s.IndexOf ('q', s.Length), "#B7");
1381                 Assert.AreEqual (-1, s.IndexOf ('3', s.Length), "#B8");
1382         }
1383
1384         [Test] // IndexOf (String, Int32)
1385         public void IndexOf4 ()
1386         {
1387                 string s = "testing123456";
1388
1389                 Assert.AreEqual (-1, s.IndexOf ("IN", 3), "#1");
1390                 Assert.AreEqual (4, s.IndexOf ("in", 3), "#2");
1391                 Assert.AreEqual (-1, s.IndexOf ("in", 5), "#3");
1392                 Assert.AreEqual (7, s.IndexOf ("1", 5), "#4");
1393                 Assert.AreEqual (12, s.IndexOf ("6", 12), "#5");
1394                 Assert.AreEqual (0, s.IndexOf ("testing123456", 0), "#6");
1395                 Assert.AreEqual (-1, s.IndexOf ("testing123456", 1), "#7");
1396                 Assert.AreEqual (5, s.IndexOf (string.Empty, 5), "#8");
1397                 Assert.AreEqual (0, s.IndexOf (string.Empty, 0), "#9");
1398         }
1399
1400         [Test] // IndexOf (String, Int32)
1401         public void IndexOf4_Value_Null ()
1402         {
1403                 try {
1404                         "Mono".IndexOf ((string) null, 1);
1405                         Assert.Fail ("#1");
1406                 } catch (ArgumentNullException ex) {
1407                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1408                         Assert.IsNull (ex.InnerException, "#3");
1409                         Assert.IsNotNull (ex.Message, "#4");
1410                         Assert.AreEqual ("value", ex.ParamName, "#5");
1411                 }
1412         }
1413
1414         [Test] // IndexOf (String, StringComparison)
1415         public void IndexOf5 ()
1416         {
1417                 string s = "testing123456";
1418                 StringComparison comparison_type;
1419
1420                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
1421
1422                 comparison_type = StringComparison.CurrentCulture;
1423                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#A1");
1424                 Assert.AreEqual (-1, s.IndexOf ("NG", comparison_type), "#A2");
1425                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#A3");
1426                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#A4");
1427                 Assert.AreEqual (-1, s.IndexOf ("T", comparison_type), "#A5");
1428                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#A6");
1429                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#A7");
1430                 Assert.AreEqual (-1, s.IndexOf ("TIN", comparison_type), "#A8");
1431                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#A9");
1432
1433                 comparison_type = StringComparison.CurrentCultureIgnoreCase;
1434                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#B1");
1435                 Assert.AreEqual (5, s.IndexOf ("NG", comparison_type), "#B2");
1436                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#B3");
1437                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#B4");
1438                 Assert.AreEqual (0, s.IndexOf ("T", comparison_type), "#B5");
1439                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#B6");
1440                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#B7");
1441                 Assert.AreEqual (-1, s.IndexOf ("TIN", comparison_type), "#B8");
1442                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#B9");
1443
1444                 comparison_type = StringComparison.InvariantCulture;
1445                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#C1");
1446                 Assert.AreEqual (-1, s.IndexOf ("NG", comparison_type), "#C2");
1447                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#C3");
1448                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#C4");
1449                 Assert.AreEqual (-1, s.IndexOf ("T", comparison_type), "#C5");
1450                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#C6");
1451                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#C7");
1452                 Assert.AreEqual (-1, s.IndexOf ("TIN", comparison_type), "#C8");
1453                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#C9");
1454
1455                 comparison_type = StringComparison.InvariantCultureIgnoreCase;
1456                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#D1");
1457                 Assert.AreEqual (5, s.IndexOf ("NG", comparison_type), "#D2");
1458                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#D3");
1459                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#D4");
1460                 Assert.AreEqual (0, s.IndexOf ("T", comparison_type), "#D5");
1461                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#D6");
1462                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#D7");
1463                 Assert.AreEqual (3, s.IndexOf ("TIN", comparison_type), "#D8");
1464                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#D9");
1465
1466                 comparison_type = StringComparison.Ordinal;
1467                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#E1");
1468                 Assert.AreEqual (-1, s.IndexOf ("NG", comparison_type), "#E2");
1469                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#E3");
1470                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#E4");
1471                 Assert.AreEqual (-1, s.IndexOf ("T", comparison_type), "#E5");
1472                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#E6");
1473                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#E7");
1474                 Assert.AreEqual (-1, s.IndexOf ("TIN", comparison_type), "#E8");
1475                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#E9");
1476
1477                 comparison_type = StringComparison.OrdinalIgnoreCase;
1478                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#F1");
1479                 Assert.AreEqual (5, s.IndexOf ("NG", comparison_type), "#F2");
1480                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#F3");
1481                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#F4");
1482                 Assert.AreEqual (0, s.IndexOf ("T", comparison_type), "#F5");
1483                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#F6");
1484                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#F7");
1485                 Assert.AreEqual (3, s.IndexOf ("TIN", comparison_type), "#F8");
1486                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#F9");
1487
1488                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
1489
1490                 comparison_type = StringComparison.CurrentCulture;
1491                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#G1");
1492                 Assert.AreEqual (-1, s.IndexOf ("NG", comparison_type), "#G2");
1493                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#G3");
1494                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#G4");
1495                 Assert.AreEqual (-1, s.IndexOf ("T", comparison_type), "#G5");
1496                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#G6");
1497                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#G7");
1498                 Assert.AreEqual (-1, s.IndexOf ("TIN", comparison_type), "#G8");
1499                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#G9");
1500
1501                 comparison_type = StringComparison.CurrentCultureIgnoreCase;
1502                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#H1");
1503                 Assert.AreEqual (5, s.IndexOf ("NG", comparison_type), "#H2");
1504                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#H3");
1505                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#H4");
1506                 Assert.AreEqual (0, s.IndexOf ("T", comparison_type), "#H5");
1507                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#H6");
1508                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#H7");
1509                 Assert.AreEqual (3, s.IndexOf ("TIN", comparison_type), "#H8");
1510                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#H9");
1511
1512                 comparison_type = StringComparison.InvariantCulture;
1513                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#I1");
1514                 Assert.AreEqual (-1, s.IndexOf ("NG", comparison_type), "#I2");
1515                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#I3");
1516                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#I4");
1517                 Assert.AreEqual (-1, s.IndexOf ("T", comparison_type), "#I5");
1518                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#I6");
1519                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#I7");
1520                 Assert.AreEqual (-1, s.IndexOf ("TIN", comparison_type), "#I8");
1521                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#I9");
1522
1523                 comparison_type = StringComparison.InvariantCultureIgnoreCase;
1524                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#J1");
1525                 Assert.AreEqual (5, s.IndexOf ("NG", comparison_type), "#J2");
1526                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#J3");
1527                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#J4");
1528                 Assert.AreEqual (0, s.IndexOf ("T", comparison_type), "#J5");
1529                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#J6");
1530                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#J7");
1531                 Assert.AreEqual (3, s.IndexOf ("TIN", comparison_type), "#J8");
1532                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#J9");
1533
1534                 comparison_type = StringComparison.Ordinal;
1535                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#K1");
1536                 Assert.AreEqual (-1, s.IndexOf ("NG", comparison_type), "#K2");
1537                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#K3");
1538                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#K4");
1539                 Assert.AreEqual (-1, s.IndexOf ("T", comparison_type), "#K5");
1540                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#K6");
1541                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#K7");
1542                 Assert.AreEqual (-1, s.IndexOf ("TIN", comparison_type), "#K8");
1543                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#K9");
1544
1545                 comparison_type = StringComparison.OrdinalIgnoreCase;
1546                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#L1");
1547                 Assert.AreEqual (5, s.IndexOf ("NG", comparison_type), "#L2");
1548                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#L3");
1549                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#L4");
1550                 Assert.AreEqual (0, s.IndexOf ("T", comparison_type), "#L5");
1551                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#L6");
1552                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#L7");
1553                 Assert.AreEqual (3, s.IndexOf ("TIN", comparison_type), "#L8");
1554                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#L9");
1555
1556                 Assert.AreEqual (0, string.Empty.IndexOf (string.Empty, comparison_type), "#M");
1557         }
1558
1559         [Test] // IndexOf (String, StringComparison)
1560         public void IndexOf5_ComparisonType_Invalid ()
1561         {
1562                 try {
1563                         "Mono".IndexOf (string.Empty, (StringComparison) Int32.MinValue);
1564                         Assert.Fail ("#1");
1565                 } catch (ArgumentException ex) {
1566                         // The string comparison type passed in is currently
1567                         // not supported
1568                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1569                         Assert.IsNull (ex.InnerException, "#3");
1570                         Assert.IsNotNull (ex.Message, "#4");
1571                         Assert.AreEqual ("comparisonType", ex.ParamName, "#5");
1572                 }
1573         }
1574
1575         [Test] // IndexOf (String, StringComparison)
1576         public void IndexOf5_Value_Null ()
1577         {
1578                 try {
1579                         "Mono".IndexOf ((string) null, StringComparison.Ordinal);
1580                         Assert.Fail ("#1");
1581                 } catch (ArgumentNullException ex) {
1582                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1583                         Assert.IsNull (ex.InnerException, "#3");
1584                         Assert.IsNotNull (ex.Message, "#4");
1585                         Assert.AreEqual ("value", ex.ParamName, "#5");
1586                 }
1587         }
1588
1589         [Test]
1590         [ExpectedException (typeof (ArgumentOutOfRangeException))]
1591         public void IndexOfStringComparisonOrdinalRangeException1 ()
1592         {
1593                 "Mono".IndexOf ("no", 5, StringComparison.Ordinal);
1594         }
1595
1596         [Test]
1597         [ExpectedException (typeof (ArgumentOutOfRangeException))]
1598         public void IndexOfStringComparisonOrdinalRangeException2 ()
1599         {
1600                 "Mono".IndexOf ("no", 1, 5, StringComparison.Ordinal);
1601         }
1602
1603         [Test]
1604         [ExpectedException (typeof (ArgumentOutOfRangeException))]
1605         public void IndexOfStringComparisonOrdinalIgnoreCaseRangeException1 ()
1606         {
1607                 "Mono".IndexOf ("no", 5, StringComparison.OrdinalIgnoreCase);
1608         }
1609
1610         [Test]
1611         [ExpectedException (typeof (ArgumentOutOfRangeException))]
1612         public void IndexOfStringComparisonOrdinalIgnoreCaseRangeException2 ()
1613         {
1614                 "Mono".IndexOf ("no", 1, 5, StringComparison.OrdinalIgnoreCase);
1615         }
1616
1617         [Test]
1618         public void IndexOfStringComparisonCurrentCulture_Empty ()
1619         {
1620                 Assert.AreEqual (1, "Mono".IndexOf ("", 1, StringComparison.CurrentCultureIgnoreCase));
1621         }
1622
1623         [Test]
1624         public void IndexOfStringComparison ()
1625         {
1626                 string text = "testing123456";
1627                 string text2 = "123";
1628                 string text3 = "NG";
1629                 string text4 = "t";
1630                 Assert.AreEqual (7, text.IndexOf (text2, StringComparison.Ordinal), "#1-1");
1631                 Assert.AreEqual (5, text.IndexOf (text3, StringComparison.OrdinalIgnoreCase), "#2-1");
1632
1633                 Assert.AreEqual (7, text.IndexOf (text2, 0, StringComparison.Ordinal), "#1-2");
1634                 Assert.AreEqual (5, text.IndexOf (text3, 0, StringComparison.OrdinalIgnoreCase), "#2-2");
1635
1636                 Assert.AreEqual (7, text.IndexOf (text2, 1, StringComparison.Ordinal), "#1-3");
1637                 Assert.AreEqual (5, text.IndexOf (text3, 1, StringComparison.OrdinalIgnoreCase), "#2-3");
1638
1639                 Assert.AreEqual (7, text.IndexOf (text2, 6, StringComparison.Ordinal), "#1-4");
1640                 Assert.AreEqual (-1, text.IndexOf (text3, 6, StringComparison.OrdinalIgnoreCase), "#2-4");
1641
1642                 Assert.AreEqual (7, text.IndexOf (text2, 7, 3, StringComparison.Ordinal), "#1-5");
1643                 Assert.AreEqual (-1, text.IndexOf (text3, 7, 3, StringComparison.OrdinalIgnoreCase), "#2-5");
1644
1645                 Assert.AreEqual (-1, text.IndexOf (text2, 6, 0, StringComparison.Ordinal), "#1-6");
1646                 Assert.AreEqual (-1, text.IndexOf (text3, 5, 0, StringComparison.OrdinalIgnoreCase), "#2-6");
1647
1648                 Assert.AreEqual (-1, text.IndexOf (text2, 7, 1, StringComparison.Ordinal), "#1-7");
1649                 Assert.AreEqual (-1, text.IndexOf (text3, 5, 1, StringComparison.OrdinalIgnoreCase), "#2-7");
1650
1651                 Assert.AreEqual (0, text.IndexOf (text4, 0, StringComparison.Ordinal), "#3-1");
1652                 Assert.AreEqual (0, text.IndexOf (text4, 0, StringComparison.OrdinalIgnoreCase), "#3-2");
1653
1654                 Assert.AreEqual (-1, text.IndexOf (text4, 13, StringComparison.Ordinal), "#4-1");
1655                 Assert.AreEqual (-1, text.IndexOf (text4, 13, StringComparison.OrdinalIgnoreCase), "#4-2");
1656
1657                 Assert.AreEqual (-1, text.IndexOf (text4, 13, 0, StringComparison.Ordinal), "#4-1");
1658                 Assert.AreEqual (-1, text.IndexOf (text4, 13, 0, StringComparison.OrdinalIgnoreCase), "#4-2");
1659
1660                 Assert.AreEqual (12, text.IndexOf ("6", 12, 1, StringComparison.Ordinal), "#5-1");
1661                 Assert.AreEqual (12, text.IndexOf ("6", 12, 1, StringComparison.OrdinalIgnoreCase), "#5-2");
1662         }
1663
1664         [Test]
1665         public void IndexOfStringComparisonOrdinal ()
1666         {
1667                 string text = "testing123456";
1668                 Assert.AreEqual (10, text.IndexOf ("456", StringComparison.Ordinal), "#1");
1669                 Assert.AreEqual (-1, text.IndexOf ("4567", StringComparison.Ordinal), "#2");
1670                 Assert.AreEqual (0, text.IndexOf ("te", StringComparison.Ordinal), "#3");
1671                 Assert.AreEqual (2, text.IndexOf ("s", StringComparison.Ordinal), "#4");
1672                 Assert.AreEqual (-1, text.IndexOf ("ates", StringComparison.Ordinal), "#5");
1673                 Assert.AreEqual (-1, text.IndexOf ("S", StringComparison.Ordinal), "#6");
1674         }
1675
1676         [Test]
1677         public void IndexOfStringComparisonOrdinalIgnoreCase ()
1678         {
1679                 string text = "testing123456";
1680                 Assert.AreEqual (10, text.IndexOf ("456", StringComparison.OrdinalIgnoreCase), "#1");
1681                 Assert.AreEqual (-1, text.IndexOf ("4567", StringComparison.OrdinalIgnoreCase), "#2");
1682                 Assert.AreEqual (0, text.IndexOf ("te", StringComparison.OrdinalIgnoreCase), "#3");
1683                 Assert.AreEqual (2, text.IndexOf ("s", StringComparison.OrdinalIgnoreCase), "#4");
1684                 Assert.AreEqual (-1, text.IndexOf ("ates", StringComparison.OrdinalIgnoreCase), "#5");
1685                 Assert.AreEqual (2, text.IndexOf ("S", StringComparison.OrdinalIgnoreCase), "#6");
1686         }
1687
1688         [Test]
1689         public void IndexOfOrdinalCountSmallerThanValueString ()
1690         {
1691                 Assert.AreEqual (-1, "Test".IndexOf ("ST", 2, 1, StringComparison.Ordinal), "#1");
1692                 Assert.AreEqual (-1, "Test".IndexOf ("ST", 2, 1, StringComparison.OrdinalIgnoreCase), "#2");
1693                 Assert.AreEqual (-1, "Test".LastIndexOf ("ST", 2, 1, StringComparison.Ordinal), "#3");
1694                 Assert.AreEqual (-1, "Test".LastIndexOf ("ST", 2, 1, StringComparison.OrdinalIgnoreCase), "#4");
1695         }
1696
1697         [Test] // IndexOf (Char, Int32, Int32)
1698         public void IndexOf6_Count_Negative ()
1699         {
1700                 try {
1701                         "Mono".IndexOf ('o', 1, -1);
1702                         Assert.Fail ("#1");
1703                 } catch (ArgumentOutOfRangeException ex) {
1704                         // Count must be positive and count must refer to a
1705                         // location within the string/array/collection
1706                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
1707                         Assert.IsNull (ex.InnerException, "#3");
1708                         Assert.IsNotNull (ex.Message, "#4");
1709                         Assert.AreEqual ("count", ex.ParamName, "#5");
1710                 }
1711         }
1712
1713         [Test] // IndexOf (Char, Int32, Int32)
1714         public void IndexOf6_Count_Overflow ()
1715         {
1716                 try {
1717                         "Mono".IndexOf ('o', 1, Int32.MaxValue);
1718                         Assert.Fail ("#1");
1719                 } catch (ArgumentOutOfRangeException ex) {
1720                         // Count must be positive and count must refer to a
1721                         // location within the string/array/collection
1722                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
1723                         Assert.IsNull (ex.InnerException, "#3");
1724                         Assert.IsNotNull (ex.Message, "#4");
1725                         Assert.AreEqual ("count", ex.ParamName, "#5");
1726                 }
1727         }
1728
1729         [Test] // IndexOf (Char, Int32, Int32)
1730         public void IndexOf6_StartIndex_Negative ()
1731         {
1732                 try {
1733                         "Mono".IndexOf ('o', -1, 1);
1734                         Assert.Fail ("#1");
1735                 } catch (ArgumentOutOfRangeException ex) {
1736                         // Index was out of range. Must be non-negative and
1737                         // less than the size of the collection
1738                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
1739                         Assert.IsNull (ex.InnerException, "#3");
1740                         Assert.IsNotNull (ex.Message, "#4");
1741                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
1742                 }
1743         }
1744
1745         [Test] // IndexOf (Char, Int32, Int32)
1746         public void IndexOf6_StartIndex_Overflow ()
1747         {
1748                 string s = "testing123456";
1749
1750                 try {
1751                         s.IndexOf ('o', s.Length + 1, 1);
1752                         Assert.Fail ("#1");
1753                 } catch (ArgumentOutOfRangeException ex) {
1754                         // Index was out of range. Must be non-negative and
1755                         // less than the size of the collection
1756                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
1757                         Assert.IsNull (ex.InnerException, "#3");
1758                         Assert.IsNotNull (ex.Message, "#4");
1759                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
1760                 }
1761         }
1762
1763         [Test] // IndexOf (String, Int32, Int32)
1764         public void IndexOf7 ()
1765         {
1766                 string s = "testing123456test";
1767
1768                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
1769
1770                 Assert.AreEqual (-1, s.IndexOf ("123", 4, 5), "#A1");
1771                 Assert.AreEqual (7, s.IndexOf ("123", 4, 6), "#A2");
1772                 Assert.AreEqual (-1, s.IndexOf ("123", 5, 4), "#A3");
1773                 Assert.AreEqual (7, s.IndexOf ("123", 5, 5), "#A4");
1774                 Assert.AreEqual (7, s.IndexOf ("123", 0, s.Length), "#A5");
1775                 Assert.AreEqual (-1, s.IndexOf ("123", s.Length, 0), "#A6");
1776
1777                 Assert.AreEqual (-1, s.IndexOf ("tin", 2, 3), "#B1");
1778                 Assert.AreEqual (3, s.IndexOf ("tin", 3, 3), "#B2");
1779                 Assert.AreEqual (-1, s.IndexOf ("tin", 2, 2), "#B3");
1780                 Assert.AreEqual (-1, s.IndexOf ("tin", 1, 4), "#B4");
1781                 Assert.AreEqual (3, s.IndexOf ("tin", 0, s.Length), "#B5");
1782                 Assert.AreEqual (-1, s.IndexOf ("tin", s.Length, 0), "#B6");
1783
1784                 Assert.AreEqual (6, s.IndexOf ("g12", 4, 5), "#C1");
1785                 Assert.AreEqual (-1, s.IndexOf ("g12", 5, 2), "#C2");
1786                 Assert.AreEqual (-1, s.IndexOf ("g12", 5, 3), "#C3");
1787                 Assert.AreEqual (6, s.IndexOf ("g12", 6, 4), "#C4");
1788                 Assert.AreEqual (6, s.IndexOf ("g12", 0, s.Length), "#C5");
1789                 Assert.AreEqual (-1, s.IndexOf ("g12", s.Length, 0), "#C6");
1790
1791                 Assert.AreEqual (1, s.IndexOf ("est", 0, 5), "#D1");
1792                 Assert.AreEqual (-1, s.IndexOf ("est", 1, 2), "#D2");
1793                 Assert.AreEqual (-1, s.IndexOf ("est", 2, 10), "#D3");
1794                 Assert.AreEqual (14, s.IndexOf ("est", 7, 10), "#D4");
1795                 Assert.AreEqual (1, s.IndexOf ("est", 0, s.Length), "#D5");
1796                 Assert.AreEqual (-1, s.IndexOf ("est", s.Length, 0), "#D6");
1797
1798                 Assert.AreEqual (-1, s.IndexOf ("T", 0, s.Length), "#E1");
1799                 Assert.AreEqual (4, s.IndexOf ("i", 0, s.Length), "#E2");
1800                 Assert.AreEqual (-1, s.IndexOf ("I", 0, s.Length), "#E3");
1801                 Assert.AreEqual (12, s.IndexOf ("6", 0, s.Length), "#E4");
1802                 Assert.AreEqual (0, s.IndexOf ("testing123456", 0, s.Length), "#E5");
1803                 Assert.AreEqual (-1, s.IndexOf ("testing1234567", 0, s.Length), "#E6");
1804                 Assert.AreEqual (0, s.IndexOf (string.Empty, 0, 0), "#E7");
1805                 Assert.AreEqual (4, s.IndexOf (string.Empty, 4, 3), "#E8");
1806                 Assert.AreEqual (0, string.Empty.IndexOf (string.Empty, 0, 0), "#E9");
1807                 Assert.AreEqual (-1, string.Empty.IndexOf ("abc", 0, 0), "#E10");
1808
1809                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
1810
1811                 Assert.AreEqual (-1, s.IndexOf ("123", 4, 5), "#F1");
1812                 Assert.AreEqual (7, s.IndexOf ("123", 4, 6), "#F2");
1813                 Assert.AreEqual (-1, s.IndexOf ("123", 5, 4), "#F3");
1814                 Assert.AreEqual (7, s.IndexOf ("123", 5, 5), "#F4");
1815                 Assert.AreEqual (7, s.IndexOf ("123", 0, s.Length), "#F5");
1816                 Assert.AreEqual (-1, s.IndexOf ("123", s.Length, 0), "#F6");
1817
1818                 Assert.AreEqual (-1, s.IndexOf ("tin", 2, 3), "#G1");
1819                 Assert.AreEqual (3, s.IndexOf ("tin", 3, 3), "#G2");
1820                 Assert.AreEqual (-1, s.IndexOf ("tin", 2, 2), "#G3");
1821                 Assert.AreEqual (-1, s.IndexOf ("tin", 1, 4), "#G4");
1822                 Assert.AreEqual (3, s.IndexOf ("tin", 0, s.Length), "#G5");
1823                 Assert.AreEqual (-1, s.IndexOf ("tin", s.Length, 0), "#G6");
1824
1825                 Assert.AreEqual (6, s.IndexOf ("g12", 4, 5), "#H1");
1826                 Assert.AreEqual (-1, s.IndexOf ("g12", 5, 2), "#H2");
1827                 Assert.AreEqual (-1, s.IndexOf ("g12", 5, 3), "#H3");
1828                 Assert.AreEqual (6, s.IndexOf ("g12", 6, 4), "#H4");
1829                 Assert.AreEqual (6, s.IndexOf ("g12", 0, s.Length), "#H5");
1830                 Assert.AreEqual (-1, s.IndexOf ("g12", s.Length, 0), "#H6");
1831
1832                 Assert.AreEqual (1, s.IndexOf ("est", 0, 5), "#I1");
1833                 Assert.AreEqual (-1, s.IndexOf ("est", 1, 2), "#I2");
1834                 Assert.AreEqual (-1, s.IndexOf ("est", 2, 10), "#I3");
1835                 Assert.AreEqual (14, s.IndexOf ("est", 7, 10), "#I4");
1836                 Assert.AreEqual (1, s.IndexOf ("est", 0, s.Length), "#I5");
1837                 Assert.AreEqual (-1, s.IndexOf ("est", s.Length, 0), "#I6");
1838
1839                 Assert.AreEqual (-1, s.IndexOf ("T", 0, s.Length), "#J1");
1840                 Assert.AreEqual (4, s.IndexOf ("i", 0, s.Length), "#J2");
1841                 Assert.AreEqual (-1, s.IndexOf ("I", 0, s.Length), "#J3");
1842                 Assert.AreEqual (12, s.IndexOf ("6", 0, s.Length), "#J4");
1843                 Assert.AreEqual (0, s.IndexOf ("testing123456", 0, s.Length), "#J5");
1844                 Assert.AreEqual (-1, s.IndexOf ("testing1234567", 0, s.Length), "#J6");
1845                 Assert.AreEqual (0, s.IndexOf (string.Empty, 0, 0), "#J7");
1846                 Assert.AreEqual (4, s.IndexOf (string.Empty, 4, 3), "#J8");
1847                 Assert.AreEqual (0, string.Empty.IndexOf (string.Empty, 0, 0), "#J9");
1848                 Assert.AreEqual (-1, string.Empty.IndexOf ("abc", 0, 0), "#J10");
1849         }
1850
1851         [Test]
1852         public void IndexOf7_Empty ()
1853         {
1854                 Assert.AreEqual (1, "FOO".IndexOf ("", 1, 2, StringComparison.Ordinal));
1855                 Assert.AreEqual (1, "FOO".IndexOf ("", 1, 2, StringComparison.OrdinalIgnoreCase));
1856         }
1857
1858         [Test] // IndexOf (String, Int32, Int32)
1859         public void IndexOf7_Count_Negative ()
1860         {
1861                 try {
1862                         "Mono".IndexOf ("no", 1, -1);
1863                         Assert.Fail ("#1");
1864                 } catch (ArgumentOutOfRangeException ex) {
1865                         // Count must be positive and count must refer to a
1866                         // location within the string/array/collection
1867                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
1868                         Assert.IsNull (ex.InnerException, "#3");
1869                         Assert.IsNotNull (ex.Message, "#4");
1870                         Assert.AreEqual ("count", ex.ParamName, "#5");
1871                 }
1872         }
1873
1874         [Test] // IndexOf (String, Int32, Int32)
1875         public void IndexOf7_Count_Overflow ()
1876         {
1877                 string s = "testing123456";
1878
1879                 try {
1880                         s.IndexOf ("no", 1, s.Length);
1881                         Assert.Fail ("#A1");
1882                 } catch (ArgumentOutOfRangeException ex) {
1883                         // Count must be positive and count must refer to a
1884                         // location within the string/array/collection
1885                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
1886                         Assert.IsNull (ex.InnerException, "#A3");
1887                         Assert.IsNotNull (ex.Message, "#A4");
1888                         Assert.AreEqual ("count", ex.ParamName, "#A5");
1889                 }
1890
1891                 try {
1892                         s.IndexOf ("no", 1, s.Length + 1);
1893                         Assert.Fail ("#B1");
1894                 } catch (ArgumentOutOfRangeException ex) {
1895                         // Count must be positive and count must refer to a
1896                         // location within the string/array/collection
1897                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
1898                         Assert.IsNull (ex.InnerException, "#B3");
1899                         Assert.IsNotNull (ex.Message, "#B4");
1900                         Assert.AreEqual ("count", ex.ParamName, "#B5");
1901                 }
1902
1903                 try {
1904                         s.IndexOf ("no", 1, int.MaxValue);
1905                         Assert.Fail ("#C1");
1906                 } catch (ArgumentOutOfRangeException ex) {
1907                         // Count must be positive and count must refer to a
1908                         // location within the string/array/collection
1909                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#C2");
1910                         Assert.IsNull (ex.InnerException, "#C3");
1911                         Assert.IsNotNull (ex.Message, "#C4");
1912                         Assert.AreEqual ("count", ex.ParamName, "#C5");
1913                 }
1914         }
1915
1916         [Test] // IndexOf (String, Int32, Int32)
1917         public void IndexOf7_StartIndex_Negative ()
1918         {
1919                 try {
1920                         "Mono".IndexOf ("no", -1, 1);
1921                         Assert.Fail ("#1");
1922                 } catch (ArgumentOutOfRangeException ex) {
1923                         // Index was out of range. Must be non-negative and
1924                         // less than the size of the collection
1925                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
1926                         Assert.IsNull (ex.InnerException, "#3");
1927                         Assert.IsNotNull (ex.Message, "#4");
1928                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
1929                 }
1930         }
1931
1932         [Test] // IndexOf (String, Int32, Int32)
1933         public void IndexOf7_StartIndex_Overflow ()
1934         {
1935                 string s = "testing123456";
1936
1937                 try {
1938                         s.IndexOf ("no", s.Length + 1, 1);
1939                         Assert.Fail ("#A1");
1940                 } catch (ArgumentOutOfRangeException ex) {
1941                         // Index was out of range. Must be non-negative and
1942                         // less than the size of the collection
1943                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
1944                         Assert.IsNull (ex.InnerException, "#A3");
1945                         Assert.IsNotNull (ex.Message, "#A4");
1946                         Assert.AreEqual ("startIndex", ex.ParamName, "#A5");
1947                 }
1948
1949                 try {
1950                         s.IndexOf ("no", int.MaxValue, 1);
1951                         Assert.Fail ("#B1");
1952                 } catch (ArgumentOutOfRangeException ex) {
1953                         // Index was out of range. Must be non-negative and
1954                         // less than the size of the collection
1955                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
1956                         Assert.IsNull (ex.InnerException, "#B3");
1957                         Assert.IsNotNull (ex.Message, "#B4");
1958                         Assert.AreEqual ("startIndex", ex.ParamName, "#B5");
1959                 }
1960         }
1961
1962         [Test] // IndexOf (String, Int32, Int32)
1963         public void IndexOf7_Value_Null ()
1964         {
1965                 try {
1966                         "Mono".IndexOf ((string) null, 0, 1);
1967                         Assert.Fail ("#1");
1968                 } catch (ArgumentNullException ex) {
1969                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1970                         Assert.IsNull (ex.InnerException, "#3");
1971                         Assert.IsNotNull (ex.Message, "#4");
1972                         Assert.AreEqual ("value", ex.ParamName, "#5");
1973                 }
1974         }
1975
1976         [Test] // IndexOf (String, Int32, StringComparison)
1977         public void IndexOf8_ComparisonType_Invalid ()
1978         {
1979                 try {
1980                         "Mono".IndexOf (string.Empty, 1, (StringComparison) Int32.MinValue);
1981                         Assert.Fail ("#1");
1982                 } catch (ArgumentException ex) {
1983                         // The string comparison type passed in is currently
1984                         // not supported
1985                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1986                         Assert.IsNull (ex.InnerException, "#3");
1987                         Assert.IsNotNull (ex.Message, "#4");
1988                         Assert.AreEqual ("comparisonType", ex.ParamName, "#5");
1989                 }
1990         }
1991
1992         [Test] // IndexOf (String, Int32, StringComparison)
1993         public void IndexOf8_StartIndex_Negative ()
1994         {
1995                 try {
1996                         "Mono".IndexOf ("o", -1, StringComparison.Ordinal);
1997                         Assert.Fail ("#1");
1998                 } catch (ArgumentOutOfRangeException ex) {
1999                         // Index was out of range. Must be non-negative and
2000                         // less than the size of the collection
2001                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2002                         Assert.IsNull (ex.InnerException, "#3");
2003                         Assert.IsNotNull (ex.Message, "#4");
2004                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
2005                 }
2006         }
2007
2008         [Test] // IndexOf (String, Int32, Int32, StringComparison)
2009         public void IndexOf9_ComparisonType_Invalid ()
2010         {
2011                 try {
2012                         "Mono".IndexOf (string.Empty, 0, 1, (StringComparison) Int32.MinValue);
2013                         Assert.Fail ("#1");
2014                 } catch (ArgumentException ex) {
2015                         // The string comparison type passed in is currently
2016                         // not supported
2017                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
2018                         Assert.IsNull (ex.InnerException, "#3");
2019                         Assert.IsNotNull (ex.Message, "#4");
2020                         Assert.AreEqual ("comparisonType", ex.ParamName, "#5");
2021                 }
2022         }
2023
2024         [Test] // IndexOf (String, Int32, Int32, StringComparison)
2025         public void IndexOf9_Count_Negative ()
2026         {
2027                 try {
2028                         "Mono".IndexOf ("o", 1, -1, StringComparison.Ordinal);
2029                         Assert.Fail ("#1");
2030                         Assert.Fail ("#1");
2031                 } catch (ArgumentOutOfRangeException ex) {
2032                         // Count must be positive and count must refer to a
2033                         // location within the string/array/collection
2034                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2035                         Assert.IsNull (ex.InnerException, "#3");
2036                         Assert.IsNotNull (ex.Message, "#4");
2037                         Assert.AreEqual ("count", ex.ParamName, "#5");
2038                 }
2039         }
2040
2041         [Test] // IndexOf (String, Int32, Int32, StringComparison)
2042         public void IndexOf9_StartIndex_Negative ()
2043         {
2044                 try {
2045                         "Mono".IndexOf ("o", -1, 0, StringComparison.Ordinal);
2046                         Assert.Fail ("#1");
2047                 } catch (ArgumentOutOfRangeException ex) {
2048                         // Index was out of range. Must be non-negative and
2049                         // less than the size of the collection
2050                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2051                         Assert.IsNull (ex.InnerException, "#3");
2052                         Assert.IsNotNull (ex.Message, "#4");
2053                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
2054                 }
2055         }
2056
2057         [Test]
2058         public void IndexOfAny1 ()
2059         {
2060                 string s = "abcdefghijklmd";
2061                 char[] c;
2062
2063                 c = new char [] {'a', 'e', 'i', 'o', 'u'};
2064                 Assert.AreEqual (0, s.IndexOfAny (c), "#1");
2065                 c = new char [] { 'd', 'z' };
2066                 Assert.AreEqual (3, s.IndexOfAny (c), "#1");
2067                 c = new char [] { 'q', 'm', 'z' };
2068                 Assert.AreEqual (12, s.IndexOfAny (c), "#2");
2069                 c = new char [0];
2070                 Assert.AreEqual (-1, s.IndexOfAny (c), "#3");
2071
2072         }
2073
2074         [Test] // IndexOfAny (Char [])
2075         public void IndexOfAny1_AnyOf_Null ()
2076         {
2077                 try {
2078                         "mono".IndexOfAny ((char []) null);
2079                         Assert.Fail ("#1");
2080                 } catch (ArgumentNullException ex) {
2081                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2082                         Assert.IsNull (ex.InnerException, "#3");
2083                         Assert.IsNotNull (ex.Message, "#4");
2084                         Assert.IsNull (ex.ParamName, "#5");
2085                 }
2086         }
2087
2088         [Test] // IndexOfAny (Char [], Int32)
2089         public void IndexOfAny2 ()
2090         {
2091                 string s = "abcdefghijklmd";
2092                 char [] c;
2093
2094                 c = new char [] { 'a', 'e', 'i', 'o', 'u' };
2095                 Assert.AreEqual (0, s.IndexOfAny (c, 0), "#A1");
2096                 Assert.AreEqual (4, s.IndexOfAny (c, 1), "#A1");
2097                 Assert.AreEqual (-1, s.IndexOfAny (c, 9), "#A2");
2098                 Assert.AreEqual (-1, s.IndexOfAny (c, s.Length), "#A3");
2099
2100                 c = new char [] { 'd', 'z' };
2101                 Assert.AreEqual (3, s.IndexOfAny (c, 0), "#B1");
2102                 Assert.AreEqual (3, s.IndexOfAny (c, 3), "#B2");
2103                 Assert.AreEqual (13, s.IndexOfAny (c, 4), "#B3");
2104                 Assert.AreEqual (13, s.IndexOfAny (c, 9), "#B4");
2105                 Assert.AreEqual (-1, s.IndexOfAny (c, s.Length), "#B5");
2106                 Assert.AreEqual (13, s.IndexOfAny (c, s.Length - 1), "#B6");
2107
2108                 c = new char [] { 'q', 'm', 'z' };
2109                 Assert.AreEqual (12, s.IndexOfAny (c, 0), "#C1");
2110                 Assert.AreEqual (12, s.IndexOfAny (c, 4), "#C2");
2111                 Assert.AreEqual (12, s.IndexOfAny (c, 12), "#C3");
2112                 Assert.AreEqual (-1, s.IndexOfAny (c, s.Length), "#C4");
2113
2114                 c = new char [0];
2115                 Assert.AreEqual (-1, s.IndexOfAny (c, 0), "#D1");
2116                 Assert.AreEqual (-1, s.IndexOfAny (c, 4), "#D2");
2117                 Assert.AreEqual (-1, s.IndexOfAny (c, 9), "#D3");
2118                 Assert.AreEqual (-1, s.IndexOfAny (c, s.Length), "#D4");
2119         }
2120
2121         [Test] // IndexOfAny (Char [], Int32)
2122         public void IndexOfAny2_AnyOf_Null ()
2123         {
2124                 try {
2125                         "mono".IndexOfAny ((char []) null, 0);
2126                         Assert.Fail ("#1");
2127                 } catch (ArgumentNullException ex) {
2128                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2129                         Assert.IsNull (ex.InnerException, "#3");
2130                         Assert.IsNotNull (ex.Message, "#4");
2131                         Assert.IsNull (ex.ParamName, "#5");
2132                 }
2133         }
2134
2135         [Test] // IndexOfAny (Char [], Int32)
2136         public void IndexOfAny2_StartIndex_Negative ()
2137         {
2138                 string s = "abcdefghijklm";
2139
2140                 try {
2141                         s.IndexOfAny (new char [1] { 'd' }, -1, 1);
2142                         Assert.Fail ("#1");
2143                 } catch (ArgumentOutOfRangeException ex) {
2144                         // Specified argument was out of the range of valid
2145                         // values
2146                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2147                         Assert.IsNull (ex.InnerException, "#3");
2148                         Assert.IsNotNull (ex.Message, "#4");
2149                         Assert.IsNull (ex.ParamName, "#5");
2150                 }
2151         }
2152
2153         [Test] // IndexOfAny (Char [], Int32, Int32)
2154         public void IndexOfAny2_StartIndex_Overflow ()
2155         {
2156                 string s = "abcdefghijklm";
2157
2158                 try {
2159                         s.IndexOfAny (new char [1] { 'd' }, s.Length + 1);
2160                         Assert.Fail ("#1");
2161                 } catch (ArgumentOutOfRangeException ex) {
2162                         // Specified argument was out of the range of valid
2163                         // values
2164                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2165                         Assert.IsNull (ex.InnerException, "#3");
2166                         Assert.IsNotNull (ex.Message, "#4");
2167                         Assert.IsNull (ex.ParamName, "#5");
2168                 }
2169         }
2170
2171         [Test] // IndexOfAny (Char [], Int32, Int32)
2172         public void IndexOfAny3 ()
2173         {
2174                 string s = "abcdefghijklmd";
2175                 char [] c;
2176
2177                 c = new char [] { 'a', 'e', 'i', 'o', 'u' };
2178                 Assert.AreEqual (0, s.IndexOfAny (c, 0, 2), "#A1");
2179                 Assert.AreEqual (-1, s.IndexOfAny (c, 1, 2), "#A2");
2180                 Assert.AreEqual (-1, s.IndexOfAny (c, 1, 3), "#A3");
2181                 Assert.AreEqual (4, s.IndexOfAny (c, 1, 4), "#A3");
2182                 Assert.AreEqual (4, s.IndexOfAny (c, 1, s.Length - 1), "#A4");
2183
2184                 c = new char [] { 'd', 'z' };
2185                 Assert.AreEqual (-1, s.IndexOfAny (c, 0, 2), "#B1");
2186                 Assert.AreEqual (-1, s.IndexOfAny (c, 1, 2), "#B2");
2187                 Assert.AreEqual (3, s.IndexOfAny (c, 1, 3), "#B3");
2188                 Assert.AreEqual (3, s.IndexOfAny (c, 0, s.Length), "#B4");
2189                 Assert.AreEqual (3, s.IndexOfAny (c, 1, s.Length - 1), "#B5");
2190                 Assert.AreEqual (-1, s.IndexOfAny (c, s.Length, 0), "#B6");
2191
2192                 c = new char [] { 'q', 'm', 'z' };
2193                 Assert.AreEqual (-1, s.IndexOfAny (c, 0, 10), "#C1");
2194                 Assert.AreEqual (12, s.IndexOfAny (c, 10, 4), "#C2");
2195                 Assert.AreEqual (-1, s.IndexOfAny (c, 1, 3), "#C3");
2196                 Assert.AreEqual (12, s.IndexOfAny (c, 0, s.Length), "#C4");
2197                 Assert.AreEqual (12, s.IndexOfAny (c, 1, s.Length - 1), "#C5");
2198
2199                 c = new char [0];
2200                 Assert.AreEqual (-1, s.IndexOfAny (c, 0, 3), "#D1");
2201                 Assert.AreEqual (-1, s.IndexOfAny (c, 4, 9), "#D2");
2202                 Assert.AreEqual (-1, s.IndexOfAny (c, 9, 5), "#D3");
2203                 Assert.AreEqual (-1, s.IndexOfAny (c, 13, 1), "#D4");
2204         }
2205
2206         [Test] // IndexOfAny (Char [], Int32, Int32)
2207         public void IndexOfAny3_AnyOf_Null ()
2208         {
2209                 try {
2210                         "mono".IndexOfAny ((char []) null, 0, 0);
2211                         Assert.Fail ("#1");
2212                 } catch (ArgumentNullException ex) {
2213                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2214                         Assert.IsNull (ex.InnerException, "#3");
2215                         Assert.IsNotNull (ex.Message, "#4");
2216                         Assert.IsNull (ex.ParamName, "#5");
2217                 }
2218         }
2219
2220         [Test] // IndexOfAny (Char [], Int32, Int32)
2221         public void IndexOfAny3_Count_Negative ()
2222         {
2223                 try {
2224                         "Mono".IndexOfAny (new char [1] { 'o' }, 1, -1);
2225                         Assert.Fail ("#1");
2226                 } catch (ArgumentOutOfRangeException ex) {
2227                         // Count must be positive and count must refer to a
2228                         // location within the string/array/collection
2229                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2230                         Assert.IsNull (ex.InnerException, "#3");
2231                         Assert.IsNotNull (ex.Message, "#4");
2232                         Assert.AreEqual ("count", ex.ParamName, "#5");
2233                 }
2234         }
2235
2236         [Test] // IndexOfAny (Char [], Int32, Int32)
2237         public void IndexOfAny3_Length_Overflow ()
2238         {
2239                 string s = "abcdefghijklm";
2240
2241                 try {
2242                         s.IndexOfAny (new char [1] { 'd' }, 1, s.Length);
2243                         Assert.Fail ("#1");
2244                 } catch (ArgumentOutOfRangeException ex) {
2245                         // Count must be positive and count must refer to a
2246                         // location within the string/array/collection
2247                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2248                         Assert.IsNull (ex.InnerException, "#3");
2249                         Assert.IsNotNull (ex.Message, "#4");
2250                         Assert.AreEqual ("count", ex.ParamName, "#5");
2251                 }
2252         }
2253
2254         [Test] // IndexOfAny (Char [], Int32, Int32)
2255         public void IndexOfAny3_StartIndex_Negative ()
2256         {
2257                 try {
2258                         "Mono".IndexOfAny (new char [1] { 'o' }, -1, 1);
2259                         Assert.Fail ("#1");
2260                 } catch (ArgumentOutOfRangeException ex) {
2261                         // Specified argument was out of the range of valid
2262                         // values
2263                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2264                         Assert.IsNull (ex.InnerException, "#3");
2265                         Assert.IsNotNull (ex.Message, "#4");
2266                         Assert.IsNull (ex.ParamName, "#5");
2267                 }
2268         }
2269
2270         [Test] // IndexOfAny (Char [], Int32, Int32)
2271         public void IndexOfAny3_StartIndex_Overflow ()
2272         {
2273                 string s = "abcdefghijklm";
2274
2275                 try {
2276                         s.IndexOfAny (new char [1] { 'o' }, s.Length + 1, 1);
2277                         Assert.Fail ("#1");
2278                 } catch (ArgumentOutOfRangeException ex) {
2279                         // Specified argument was out of the range of valid
2280                         // values
2281                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2282                         Assert.IsNull (ex.InnerException, "#3");
2283                         Assert.IsNotNull (ex.Message, "#4");
2284                         Assert.IsNull (ex.ParamName, "#5");
2285                 }
2286         }
2287
2288         [Test]
2289         public void Contains ()
2290         {
2291                 Assert.IsTrue ("ABC".Contains (string.Empty));
2292                 Assert.IsTrue ("ABC".Contains ("ABC"));
2293                 Assert.IsTrue ("ABC".Contains ("AB"));
2294                 Assert.IsTrue (!"ABC".Contains ("AD"));
2295                 Assert.IsTrue (!"encyclopædia".Contains("encyclopaedia"));
2296         }
2297
2298         [Test]
2299         public void IndexOfIsCultureAwareWhileContainsIsNot ()
2300         {
2301                 string a = "encyclopædia";
2302                 string b = "encyclopaedia";
2303                 Assert.IsFalse (a.Contains (b), "#1");
2304                 Assert.IsTrue (a.Contains ("æ"), "#1.1");
2305                 Assert.IsFalse (b.Contains ("æ"), "#1.2");
2306                 Assert.AreEqual (0, a.IndexOf (b), "#2");
2307                 Assert.AreEqual (8, a.IndexOf ('æ'), "#3");
2308                 Assert.AreEqual (-1, b.IndexOf ('æ'), "#4");
2309                 Assert.AreEqual (8, a.IndexOf ("æ"), "#5");
2310                 Assert.AreEqual (8, b.IndexOf ("æ"), "#6");
2311
2312                 Assert.AreEqual (0, CultureInfo.CurrentCulture.CompareInfo.IndexOf (a, b, 0, a.Length, CompareOptions.None), "#7");
2313                 Assert.AreEqual (-1, CultureInfo.CurrentCulture.CompareInfo.IndexOf (a, b, 0, a.Length, CompareOptions.Ordinal), "#8");
2314         }
2315
2316         [Test]
2317         public void Contains_Value_Null ()
2318         {
2319                 try {
2320                         "ABC".Contains (null);
2321                         Assert.Fail ("#1");
2322                 } catch (ArgumentNullException ex) {
2323                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2324                         Assert.IsNull (ex.InnerException, "#3");
2325                         Assert.IsNotNull (ex.Message, "#4");
2326                         Assert.AreEqual ("value", ex.ParamName, "#5");
2327                 }
2328         }
2329
2330         [Test]
2331         public void IsNullOrEmpty ()
2332         {
2333                 Assert.IsTrue (String.IsNullOrEmpty (null));
2334                 Assert.IsTrue (String.IsNullOrEmpty (String.Empty));
2335                 Assert.IsTrue (String.IsNullOrEmpty (""));
2336                 Assert.IsTrue (!String.IsNullOrEmpty ("A"));
2337                 Assert.IsTrue (!String.IsNullOrEmpty (" "));
2338                 Assert.IsTrue (!String.IsNullOrEmpty ("\t"));
2339                 Assert.IsTrue (!String.IsNullOrEmpty ("\n"));
2340         }
2341
2342         [Test]
2343         public void TestInsert ()
2344         {
2345                 string s1 = "original";
2346                 
2347                 try {
2348                         s1.Insert (0, null);
2349                         Assert.Fail ("#A1");
2350                 } catch (ArgumentNullException ex) {
2351                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
2352                         Assert.IsNull (ex.InnerException, "#A3");
2353                         Assert.IsNotNull (ex.Message, "#A4");
2354                         Assert.AreEqual ("value", ex.ParamName, "#A5");
2355                 }
2356
2357                 try {
2358                         s1.Insert (s1.Length + 1, "Hi!");
2359                         Assert.Fail ("#B1");
2360                 } catch (ArgumentOutOfRangeException ex) {
2361                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
2362                         Assert.IsNull (ex.InnerException, "#B3");
2363                         Assert.IsNotNull (ex.Message, "#B4");
2364                         Assert.AreEqual ("startIndex", ex.ParamName, "#B5");
2365                 }
2366
2367                 Assert.AreEqual ("Hi!original", s1.Insert (0, "Hi!"), "#C1");
2368                 Assert.AreEqual ("originalHi!", s1.Insert (s1.Length, "Hi!"), "#C2");
2369                 Assert.AreEqual ("origHi!inal", s1.Insert (4, "Hi!"), "#C3");
2370         }
2371
2372         [Test]
2373         public void Intern ()
2374         {
2375                 string s1 = "original";
2376                 Assert.AreSame (s1, String.Intern (s1), "#A1");
2377                 Assert.AreSame (String.Intern(s1), String.Intern(s1), "#A2");
2378
2379                 string s2 = "originally";
2380                 Assert.AreSame (s2, String.Intern (s2), "#B1");
2381                 Assert.IsTrue (String.Intern(s1) != String.Intern(s2), "#B2");
2382
2383                 string s3 = new DateTime (2000, 3, 7).ToString ();
2384                 Assert.IsNull (String.IsInterned (s3), "#C1");
2385
2386                 string s4 = String.Intern (s3);
2387                 Assert.AreEqual (s3, s4, "#C2");
2388                 Assert.AreSame (s4, String.IsInterned (s4), "#C3");
2389                 Assert.AreSame (s4, String.IsInterned (new DateTime (2000, 3, 7).ToString ()), "#C4");
2390                 Assert.AreSame (s4, String.Intern (new DateTime (2000, 3, 7).ToString ()), "#C5");
2391         }
2392
2393         [Test]
2394         public void Intern_Str_Null ()
2395         {
2396                 try {
2397                         String.Intern (null);
2398                         Assert.Fail ("#1");
2399                 } catch (ArgumentNullException ex) {
2400                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2401                         Assert.IsNull (ex.InnerException, "#3");
2402                         Assert.IsNotNull (ex.Message, "#4");
2403                         Assert.AreEqual ("str", ex.ParamName, "#5");
2404                 }
2405         }
2406
2407         [Test]
2408         public void IsInterned ()
2409         {
2410                 Assert.IsNull (String.IsInterned (new DateTime (2000, 3, 6).ToString ()), "#1");
2411                 string s1 = "original";
2412                 Assert.AreSame (s1, String.IsInterned (s1), "#2");
2413         }
2414
2415         [Test]
2416         public void IsInterned_Str_Null ()
2417         {
2418                 try {
2419                         String.IsInterned (null);
2420                         Assert.Fail ("#1");
2421                 } catch (ArgumentNullException ex) {
2422                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2423                         Assert.IsNull (ex.InnerException, "#3");
2424                         Assert.IsNotNull (ex.Message, "#4");
2425                         Assert.AreEqual ("str", ex.ParamName, "#5");
2426                 }
2427         }
2428
2429         [Test]
2430         public void TestJoin ()
2431         {
2432                 try {
2433                         string s = String.Join(" ", null);
2434                         Assert.Fail ("#A1");
2435                 } catch (ArgumentNullException ex) {
2436                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
2437                         Assert.IsNull (ex.InnerException, "#A3");
2438                         Assert.IsNotNull (ex.Message, "#A4");
2439                         Assert.AreEqual ("value", ex.ParamName, "#A5");
2440                 }
2441
2442                 string[] chunks = {"this", "is", "a", "test"};
2443                 Assert.AreEqual ("this is a test", String.Join(" ", chunks), "Basic join");
2444                 Assert.AreEqual ("this.is.a.test", String.Join(".", chunks), "Basic join");
2445
2446                 Assert.AreEqual ("is a", String.Join(" ", chunks, 1, 2), "Subset join");
2447                 Assert.AreEqual ("is.a", String.Join(".", chunks, 1, 2), "Subset join");
2448                 Assert.AreEqual ("is a test", String.Join(" ", chunks, 1, 3), "Subset join");
2449
2450                 try {
2451                         string s = String.Join(" ", chunks, 2, 3);
2452                         Assert.Fail ("#C1");
2453                 } catch (ArgumentOutOfRangeException ex) {
2454                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#C2");
2455                         Assert.IsNull (ex.InnerException, "#C3");
2456                         Assert.IsNotNull (ex.Message, "#C4");
2457                         Assert.AreEqual ("startIndex", ex.ParamName, "#C5");
2458                 }
2459         }
2460
2461         [Test]
2462         public void Join_SeparatorNull ()
2463         {
2464                 string[] chunks = {"this", "is", "a", "test"};
2465                 Assert.AreEqual ("thisisatest", String.Join (null, chunks), "SeparatorNull");
2466         }
2467
2468         [Test]
2469         public void Join_ValuesNull ()
2470         {
2471                 string[] chunks1 = {null, "is", "a", null};
2472                 Assert.AreEqual (" is a ", String.Join (" ", chunks1), "SomeNull");
2473
2474                 string[] chunks2 = {null, "is", "a", null};
2475                 Assert.AreEqual ("isa", String.Join (null, chunks2), "Some+Sep=Null");
2476
2477                 string[] chunks3 = {null, null, null, null};
2478                 Assert.AreEqual ("   ", String.Join (" ", chunks3), "AllValuesNull");
2479         }
2480
2481         [Test]
2482         public void Join_AllNull ()
2483         {
2484                 string[] chunks = {null, null, null};
2485                 Assert.AreEqual (string.Empty, String.Join (null, chunks), "AllNull");
2486         }
2487
2488         [Test]
2489         public void Join_StartIndexNegative ()
2490         {
2491                 string[] values = { "Mo", "no" };
2492                 try {
2493                         String.Join ("o", values, -1, 1);
2494                         Assert.Fail ("#1");
2495                 } catch (ArgumentOutOfRangeException ex) {
2496                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2497                         Assert.IsNull (ex.InnerException, "#3");
2498                         Assert.IsNotNull (ex.Message, "#4");
2499                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
2500                 }
2501         }
2502
2503         [Test]
2504         public void Join_StartIndexOverflow ()
2505         {
2506                 string[] values = { "Mo", "no" };
2507                 try {
2508                         String.Join ("o", values, Int32.MaxValue, 1);
2509                         Assert.Fail ("#1");
2510                 } catch (ArgumentOutOfRangeException ex) {
2511                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2512                         Assert.IsNull (ex.InnerException, "#3");
2513                         Assert.IsNotNull (ex.Message, "#4");
2514                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
2515                 }
2516         }
2517
2518         [Test]
2519         public void Join_LengthNegative ()
2520         {
2521                 string[] values = { "Mo", "no" };
2522                 try {
2523                         String.Join ("o", values, 1, -1);
2524                         Assert.Fail ("#1");
2525                 } catch (ArgumentOutOfRangeException ex) {
2526                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2527                         Assert.IsNull (ex.InnerException, "#3");
2528                         Assert.IsNotNull (ex.Message, "#4");
2529                         Assert.AreEqual ("count", ex.ParamName, "#5");
2530                 }
2531         }
2532
2533         [Test]
2534         public void Join_LengthOverflow ()
2535         {
2536                 string[] values = { "Mo", "no" };
2537                 try {
2538                         String.Join ("o", values, 1, Int32.MaxValue);
2539                         Assert.Fail ("#1");
2540                 } catch (ArgumentOutOfRangeException ex) {
2541                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2542                         Assert.IsNull (ex.InnerException, "#3");
2543                         Assert.IsNotNull (ex.Message, "#4");
2544                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
2545                 }
2546         }
2547
2548         [Test]
2549         public void LastIndexOf ()
2550         {
2551                 string s1 = "original";
2552
2553                 try {
2554                         s1.LastIndexOf ('q', -1);
2555                         Assert.Fail ("#A1");
2556                 } catch (ArgumentOutOfRangeException ex) {
2557                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
2558                         Assert.IsNull (ex.InnerException, "#A3");
2559                         Assert.IsNotNull (ex.Message, "#A4");
2560                         Assert.AreEqual ("startIndex", ex.ParamName, "#A5");
2561                 }
2562
2563                 try {
2564                         s1.LastIndexOf ('q', -1, 1);
2565                         Assert.Fail ("#B1");
2566                 } catch (ArgumentOutOfRangeException ex) {
2567                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
2568                         Assert.IsNull (ex.InnerException, "#B3");
2569                         Assert.IsNotNull (ex.Message, "#B4");
2570                         Assert.AreEqual ("startIndex", ex.ParamName, "#B5");
2571                 }
2572
2573                 try {
2574                         s1.LastIndexOf ("huh", s1.Length + 1);
2575                         Assert.Fail ("#C1");
2576                 } catch (ArgumentOutOfRangeException ex) {
2577                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#C2");
2578                         Assert.IsNull (ex.InnerException, "#C3");
2579                         Assert.IsNotNull (ex.Message, "#C4");
2580                         Assert.AreEqual ("startIndex", ex.ParamName, "#C5");
2581                 }
2582
2583                 try {
2584                         int i = s1.LastIndexOf ("huh", s1.Length + 1, 3);
2585                         Assert.Fail ("#D1");
2586                 } catch (ArgumentOutOfRangeException ex) {
2587                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#D2");
2588                         Assert.IsNull (ex.InnerException, "#D3");
2589                         Assert.IsNotNull (ex.Message, "#D4");
2590                         Assert.AreEqual ("startIndex", ex.ParamName, "#D5");
2591                 }
2592
2593                 try {
2594                         s1.LastIndexOf (null);
2595                         Assert.Fail ("#E1");
2596                 } catch (ArgumentNullException ex) {
2597                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#E2");
2598                         Assert.IsNull (ex.InnerException, "#E3");
2599                         Assert.IsNotNull (ex.Message, "#E4");
2600                         Assert.AreEqual ("value", ex.ParamName, "#E5");
2601                 }
2602
2603                 try {
2604                         s1.LastIndexOf (null, 0);
2605                         Assert.Fail ("#F1");
2606                 } catch (ArgumentNullException ex) {
2607                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#F2");
2608                         Assert.IsNull (ex.InnerException, "#F3");
2609                         Assert.IsNotNull (ex.Message, "#F4");
2610                         Assert.AreEqual ("value", ex.ParamName, "#F5");
2611                 }
2612
2613                 try {
2614                         s1.LastIndexOf (null, 0, 1);
2615                         Assert.Fail ("#G1");
2616                 } catch (ArgumentNullException ex) {
2617                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#G2");
2618                         Assert.IsNull (ex.InnerException, "#G3");
2619                         Assert.IsNotNull (ex.Message, "#G4");
2620                         Assert.AreEqual ("value", ex.ParamName, "#G5");
2621                 }
2622
2623                 Assert.AreEqual (1, s1.LastIndexOf('r'), "basic char index");
2624                 Assert.AreEqual (4, s1.LastIndexOf('i'), "basic char index");
2625                 Assert.AreEqual (-1, s1.LastIndexOf('q'), "basic char index - no");
2626
2627                 Assert.AreEqual (7, s1.LastIndexOf(string.Empty), "basic string index");
2628                 Assert.AreEqual (1, s1.LastIndexOf("rig"), "basic string index");
2629                 Assert.AreEqual (4, s1.LastIndexOf("i"), "basic string index");
2630                 Assert.AreEqual (-1, s1.LastIndexOf("rag"), "basic string index - no");
2631
2632                 Assert.AreEqual (1, s1.LastIndexOf('r', s1.Length-1), "stepped char index");
2633                 Assert.AreEqual (4, s1.LastIndexOf('i', s1.Length-1), "stepped char index");
2634                 Assert.AreEqual (2, s1.LastIndexOf('i', 3), "stepped char index");
2635                 Assert.AreEqual (-1, s1.LastIndexOf('i', 1), "stepped char index");
2636
2637                 Assert.AreEqual (1, s1.LastIndexOf('r', 1, 1), "stepped limited char index");
2638                 Assert.AreEqual (-1, s1.LastIndexOf('r', 0, 1), "stepped limited char index");
2639                 Assert.AreEqual (4, s1.LastIndexOf('i', 6, 3), "stepped limited char index");
2640                 Assert.AreEqual (2, s1.LastIndexOf('i', 3, 3), "stepped limited char index");
2641                 Assert.AreEqual (-1, s1.LastIndexOf('i', 1, 2), "stepped limited char index");
2642
2643                 s1 = "original original";
2644                 Assert.AreEqual (9, s1.LastIndexOf("original", s1.Length), "stepped string index #1");
2645                 Assert.AreEqual (0, s1.LastIndexOf("original", s1.Length-2), "stepped string index #2");
2646                 Assert.AreEqual (-1, s1.LastIndexOf("original", s1.Length-11), "stepped string index #3");
2647                 Assert.AreEqual (-1, s1.LastIndexOf("translator", 2), "stepped string index #4");
2648                 Assert.AreEqual (0, string.Empty.LastIndexOf(string.Empty, 0), "stepped string index #5");
2649                 Assert.AreEqual (-1, string.Empty.LastIndexOf("A", -1), "stepped string index #6");
2650                 Assert.AreEqual (10, s1.LastIndexOf("rig", s1.Length-1, 10), "stepped limited string index #1");
2651                 Assert.AreEqual (-1, s1.LastIndexOf("rig", s1.Length, 3), "stepped limited string index #2");
2652                 Assert.AreEqual (10, s1.LastIndexOf("rig", s1.Length-2, 15), "stepped limited string index #3");
2653                 Assert.AreEqual (-1, s1.LastIndexOf("rig", s1.Length-2, 3), "stepped limited string index #4");
2654                              
2655                 string s2 = "QBitArray::bitarr_data"; 
2656                 Assert.AreEqual (9, s2.LastIndexOf ("::"), "bug #62160");
2657
2658                 string s3 = "test123";
2659                 Assert.AreEqual (0, s3.LastIndexOf ("test123"), "bug #77412");
2660
2661                 Assert.AreEqual (0, "\u267B RT \u30FC".LastIndexOf ("\u267B RT "), "bug #605094");
2662         }
2663
2664         [Test]
2665         [ExpectedException (typeof (ArgumentException))]
2666         public void LastIndexOf_StringComparison ()
2667         {
2668                 " ".LastIndexOf (string.Empty, 0, 1, (StringComparison)Int32.MinValue);
2669         }
2670
2671         [Test]
2672         [ExpectedException (typeof (ArgumentOutOfRangeException))]
2673         public void LastIndexOfStringComparisonOrdinalRangeException1 ()
2674         {
2675                 "Mono".LastIndexOf ("no", 5, StringComparison.Ordinal);
2676         }
2677
2678         [Test]
2679         [ExpectedException (typeof (ArgumentOutOfRangeException))]
2680         public void LastIndexOfStringComparisonOrdinalRangeException2 () 
2681         {
2682                 "Mono".LastIndexOf ("no", 1, 3, StringComparison.Ordinal);
2683         }
2684
2685         [Test]
2686         [ExpectedException (typeof (ArgumentOutOfRangeException))]
2687         public void LastIndexOfStringComparisonOrdinalIgnoreCaseRangeException1 ()
2688         {
2689                 "Mono".LastIndexOf ("no", 5, StringComparison.OrdinalIgnoreCase);
2690         }
2691
2692         [Test]
2693         [ExpectedException (typeof (ArgumentOutOfRangeException))]
2694         public void LastIndexOfStringComparisonOrdinalIgnoreCaseRangeException2 ()
2695         {
2696                 "Mono".LastIndexOf ("no", 1, 3, StringComparison.OrdinalIgnoreCase);
2697         }
2698
2699         [Test]
2700         public void LastIndexOfStringComparison ()
2701         {
2702                 string text = "testing123456";
2703                 string text2 = "123";
2704                 string text3 = "NG";
2705                 string text4 = "t";
2706                 Assert.AreEqual (7, text.LastIndexOf (text2, StringComparison.Ordinal), "#1-1");
2707                 Assert.AreEqual (5, text.LastIndexOf (text3, StringComparison.OrdinalIgnoreCase), "#2-1");
2708
2709                 Assert.AreEqual (7, text.LastIndexOf (text2, 12, StringComparison.Ordinal), "#1-2");
2710                 Assert.AreEqual (5, text.LastIndexOf (text3, 12, StringComparison.OrdinalIgnoreCase), "#2-2");
2711
2712                 Assert.AreEqual (-1, text.LastIndexOf (text2, 0, StringComparison.Ordinal), "#1-3");
2713                 Assert.AreEqual (-1, text.LastIndexOf (text3, 0, StringComparison.OrdinalIgnoreCase), "#2-3");
2714
2715                 Assert.AreEqual (-1, text.LastIndexOf (text2, 6, StringComparison.Ordinal), "#1-4");
2716                 Assert.AreEqual (5, text.LastIndexOf (text3, 6, StringComparison.OrdinalIgnoreCase), "#2-4");
2717
2718                 Assert.AreEqual (-1, text.LastIndexOf (text2, 7, 3, StringComparison.Ordinal), "#1-5");
2719                 Assert.AreEqual (5, text.LastIndexOf (text3, 7, 3, StringComparison.OrdinalIgnoreCase), "#2-5");
2720
2721                 Assert.AreEqual (-1, text.LastIndexOf (text2, 6, 0, StringComparison.Ordinal), "#1-6");
2722                 Assert.AreEqual (-1, text.LastIndexOf (text3, 5, 0, StringComparison.OrdinalIgnoreCase), "#2-6");
2723
2724                 Assert.AreEqual (-1, text.LastIndexOf (text2, 7, 1, StringComparison.Ordinal), "#1-7");
2725                 Assert.AreEqual (-1, text.LastIndexOf (text3, 5, 1, StringComparison.OrdinalIgnoreCase), "#2-7");
2726
2727                 Assert.AreEqual (0, text.LastIndexOf (text4, 0, StringComparison.Ordinal), "#3-1");
2728                 Assert.AreEqual (0, text.LastIndexOf (text4, 0, StringComparison.OrdinalIgnoreCase), "#3-2");
2729
2730                 Assert.AreEqual (3, text.LastIndexOf (text4, 13, StringComparison.Ordinal), "#4-1");
2731                 Assert.AreEqual (3, text.LastIndexOf (text4, 13, StringComparison.OrdinalIgnoreCase), "#4-2");
2732
2733                 Assert.AreEqual (3, text.LastIndexOf (text4, 13, 14, StringComparison.Ordinal), "#4-1");
2734                 Assert.AreEqual (3, text.LastIndexOf (text4, 13, 14, StringComparison.OrdinalIgnoreCase), "#4-2");
2735
2736                 Assert.AreEqual (0, text.LastIndexOf (text4, 1, 2, StringComparison.Ordinal), "#5-1");
2737                 Assert.AreEqual (0, text.LastIndexOf (text4, 1, 2, StringComparison.OrdinalIgnoreCase), "#5-2");
2738
2739                 Assert.AreEqual (-1, "".LastIndexOf ("FOO", StringComparison.Ordinal));
2740                 Assert.AreEqual (0, "".LastIndexOf ("", StringComparison.Ordinal));
2741         }
2742
2743         [Test]
2744         public void LastIndexOfStringComparisonOrdinal ()
2745         {
2746                 string text = "testing123456";
2747                 Assert.AreEqual (10, text.LastIndexOf ("456", StringComparison.Ordinal), "#1");
2748                 Assert.AreEqual (-1, text.LastIndexOf ("4567", StringComparison.Ordinal), "#2");
2749                 Assert.AreEqual (0, text.LastIndexOf ("te", StringComparison.Ordinal), "#3");
2750                 Assert.AreEqual (2, text.LastIndexOf ("s", StringComparison.Ordinal), "#4");
2751                 Assert.AreEqual (-1, text.LastIndexOf ("ates", StringComparison.Ordinal), "#5");
2752                 Assert.AreEqual (-1, text.LastIndexOf ("S", StringComparison.Ordinal), "#6");
2753         }
2754
2755         [Test]
2756         public void LastIndexOfStringComparisonOrdinalIgnoreCase ()
2757         {
2758                 string text = "testing123456";
2759                 Assert.AreEqual (10, text.LastIndexOf ("456", StringComparison.OrdinalIgnoreCase), "#1");
2760                 Assert.AreEqual (-1, text.LastIndexOf ("4567", StringComparison.OrdinalIgnoreCase), "#2");
2761                 Assert.AreEqual (0, text.LastIndexOf ("te", StringComparison.OrdinalIgnoreCase), "#3");
2762                 Assert.AreEqual (2, text.LastIndexOf ("s", StringComparison.OrdinalIgnoreCase), "#4");
2763                 Assert.AreEqual (-1, text.LastIndexOf ("ates", StringComparison.OrdinalIgnoreCase), "#5");
2764                 Assert.AreEqual (2, text.LastIndexOf ("S", StringComparison.OrdinalIgnoreCase), "#6");
2765         }
2766
2767         [Test]
2768         public void LastIndexOf_Char_StartIndexStringLength ()
2769         {
2770                 string s = "Mono";
2771                 try {
2772                         s.LastIndexOf ('n', s.Length, 1);
2773                         Assert.Fail ("#1");
2774                 } catch (ArgumentOutOfRangeException ex) {
2775                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2776                         Assert.IsNull (ex.InnerException, "#3");
2777                         Assert.IsNotNull (ex.Message, "#4");
2778                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
2779                 }
2780                 // this works for string but not for a char
2781         }
2782
2783         [Test]
2784         public void LastIndexOf_Char_StartIndexOverflow ()
2785         {
2786                 try {
2787                         "Mono".LastIndexOf ('o', Int32.MaxValue, 1);
2788                         Assert.Fail ("#1");
2789                 } catch (ArgumentOutOfRangeException ex) {
2790                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2791                         Assert.IsNull (ex.InnerException, "#3");
2792                         Assert.IsNotNull (ex.Message, "#4");
2793                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
2794                 }
2795         }
2796
2797         [Test]
2798         public void LastIndexOf_Char_LengthOverflow ()
2799         {
2800                 try {
2801                         "Mono".LastIndexOf ('o', 1, Int32.MaxValue);
2802                         Assert.Fail ("#1");
2803                 } catch (ArgumentOutOfRangeException ex) {
2804                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2805                         Assert.IsNull (ex.InnerException, "#3");
2806                         Assert.IsNotNull (ex.Message, "#4");
2807                         Assert.AreEqual ("count", ex.ParamName, "#5");
2808                 }
2809         }
2810
2811         [Test]
2812         public void LastIndexOf_String_StartIndexStringLength ()
2813         {
2814                 string s = "Mono";
2815                 Assert.AreEqual (-1, s.LastIndexOf ("n", s.Length, 1));
2816                 // this works for string but not for a char
2817         }
2818
2819         [Test]
2820         public void LastIndexOf_String_StartIndexStringLength_Plus1 ()
2821         {
2822                 string s = "Mono";
2823                 try {
2824                         s.LastIndexOf ("n", s.Length + 1, 1);
2825                         Assert.Fail ("#1");
2826                 } catch (ArgumentOutOfRangeException ex) {
2827                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2828                         Assert.IsNull (ex.InnerException, "#3");
2829                         Assert.IsNotNull (ex.Message, "#4");
2830                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
2831                 }
2832         }
2833
2834         [Test]
2835         public void LastIndexOf_String_StartIndexOverflow ()
2836         {
2837                 try {
2838                         "Mono".LastIndexOf ("no", Int32.MaxValue, 1);
2839                         Assert.Fail ("#1");
2840                 } catch (ArgumentOutOfRangeException ex) {
2841                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2842                         Assert.IsNull (ex.InnerException, "#3");
2843                         Assert.IsNotNull (ex.Message, "#4");
2844                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
2845                 }
2846         }
2847
2848         [Test]
2849         public void LastIndexOf_String_LengthOverflow ()
2850         {
2851                 try {
2852                         "Mono".LastIndexOf ("no", 1, Int32.MaxValue);
2853                         Assert.Fail ("#1");
2854                 } catch (ArgumentOutOfRangeException ex) {
2855                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2856                         Assert.IsNull (ex.InnerException, "#3");
2857                         Assert.IsNotNull (ex.Message, "#4");
2858                         Assert.AreEqual ("count", ex.ParamName, "#5");
2859                 }
2860         }
2861
2862         [Test]
2863         public void LastIndexOfAny ()
2864         {
2865                 string s1 = ".bcdefghijklm";
2866
2867                 try {
2868                         s1.LastIndexOfAny (null);
2869                         Assert.Fail ("#A1");
2870                 } catch (ArgumentNullException ex) {
2871                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
2872                         Assert.IsNull (ex.InnerException, "#A3");
2873                         Assert.IsNotNull (ex.Message, "#A4");
2874                         Assert.IsNull (ex.ParamName, "#A5");
2875                 }
2876
2877                 try {
2878                         s1.LastIndexOfAny (null, s1.Length);
2879                         Assert.Fail ("#B1");
2880                 } catch (ArgumentNullException ex) {
2881                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
2882                         Assert.IsNull (ex.InnerException, "#B3");
2883                         Assert.IsNotNull (ex.Message, "#B4");
2884                         Assert.IsNull (ex.ParamName, "#B5");
2885                 }
2886
2887                 try {
2888                         s1.LastIndexOfAny (null, s1.Length, 1);
2889                         Assert.Fail ("#C1");
2890                 } catch (ArgumentNullException ex) {
2891                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#C2");
2892                         Assert.IsNull (ex.InnerException, "#C3");
2893                         Assert.IsNotNull (ex.Message, "#C4");
2894                         Assert.IsNull (ex.ParamName, "#C5");
2895                 }
2896
2897                 char[] c1 = {'a', 'e', 'i', 'o', 'u'};
2898                 Assert.AreEqual (8, s1.LastIndexOfAny (c1), "#D1");
2899                 Assert.AreEqual (4, s1.LastIndexOfAny (c1, 7), "#D2");
2900                 Assert.AreEqual (-1, s1.LastIndexOfAny (c1, 3), "#D3");
2901                 Assert.AreEqual (4, s1.LastIndexOfAny (c1, s1.Length - 6, 4), "#D4");
2902                 Assert.AreEqual (-1, s1.LastIndexOfAny (c1, s1.Length - 6, 3), "#D5");
2903
2904                 try {
2905                         s1.LastIndexOfAny (c1, -1);
2906                         Assert.Fail ("#E1");
2907                 } catch (ArgumentOutOfRangeException ex) {
2908                         // Index was out of range. Must be non-negative and
2909                         // less than the size of the collection
2910                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#E2");
2911                         Assert.IsNull (ex.InnerException, "#E3");
2912                         Assert.IsNotNull (ex.Message, "#E4");
2913                         Assert.AreEqual ("startIndex", ex.ParamName, "#E5");
2914                 }
2915
2916                 try {
2917                         s1.LastIndexOfAny (c1, -1, 1);
2918                         Assert.Fail ("#F1");
2919                 } catch (ArgumentOutOfRangeException ex) {
2920                         // Index was out of range. Must be non-negative and
2921                         // less than the size of the collection
2922                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#F2");
2923                         Assert.IsNull (ex.InnerException, "#F3");
2924                         Assert.IsNotNull (ex.Message, "#F4");
2925                         Assert.AreEqual ("startIndex", ex.ParamName, "#F5");
2926                 }
2927         }
2928
2929         [Test]
2930         public void LastIndexOfAny_Length_Overflow ()
2931         {
2932                 try {
2933                         "Mono".LastIndexOfAny (new char [1] { 'o' }, 1, Int32.MaxValue);
2934                         Assert.Fail ("#1");
2935                 } catch (ArgumentOutOfRangeException ex) {
2936                         // Count must be positive and count must refer to a
2937                         // location within the string/array/collection
2938                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2939                         Assert.IsNull (ex.InnerException, "#3");
2940                         Assert.IsNotNull (ex.Message, "#4");
2941                         Assert.AreEqual ("count", ex.ParamName, "#5");
2942                 }
2943         }
2944
2945         [Test]
2946         public void LastIndexOfAny_StartIndex_Overflow ()
2947         {
2948                 try {
2949                         "Mono".LastIndexOfAny (new char [1] { 'o' }, Int32.MaxValue, 1);
2950                         Assert.Fail ("#1");
2951                 } catch (ArgumentOutOfRangeException ex) {
2952                         // Index was out of range. Must be non-negative and
2953                         // less than the size of the collection
2954                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2955                         Assert.IsNull (ex.InnerException, "#3");
2956                         Assert.IsNotNull (ex.Message, "#4");
2957                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
2958                 }
2959         }
2960
2961         [Test] // PadLeft (Int32)
2962         public void PadLeft1 ()
2963         {
2964                 string s1 = "Hi!";
2965                 string result;
2966
2967                 result = s1.PadLeft (0);
2968                 Assert.AreSame (s1, result, "#A");
2969
2970                 result = s1.PadLeft (s1.Length - 1);
2971                 Assert.AreSame (s1, result, "#B");
2972
2973                 result = s1.PadLeft (s1.Length);
2974                 Assert.AreEqual (s1, result, "#C1");
2975                 Assert.IsTrue (object.ReferenceEquals (s1, result), "#C2");
2976
2977                 result = s1.PadLeft (s1.Length + 1);
2978                 Assert.AreEqual (" Hi!", result, "#D");
2979         }
2980
2981         [Test] // PadLeft (Int32)
2982         public void PadLeft1_TotalWidth_Negative ()
2983         {
2984                 try {
2985                         "Mono".PadLeft (-1);
2986                         Assert.Fail ("#1");
2987                 } catch (ArgumentOutOfRangeException ex) {
2988                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2989                         Assert.IsNull (ex.InnerException, "#3");
2990                         Assert.IsNotNull (ex.Message, "#4");
2991                         Assert.AreEqual ("totalWidth", ex.ParamName, "#5");
2992                 }
2993         }
2994
2995         [Test]
2996         public void PadLeft_Overflow ()
2997         {
2998                 try {
2999                         "x".PadLeft (int.MaxValue, '-');
3000                 } catch (OutOfMemoryException) {
3001                 }
3002         }
3003
3004         [Test] // PadRight (Int32)
3005         public void PadRight1 ()
3006         {
3007                 string s1 = "Hi!";
3008                 string result;
3009
3010                 result = s1.PadRight (0);
3011                 Assert.AreSame (s1, result, "#A");
3012
3013                 result = s1.PadRight (s1.Length - 1);
3014                 Assert.AreSame (s1, result, "#B");
3015
3016                 result = s1.PadRight (s1.Length);
3017                 Assert.AreEqual (s1, result, "#C1");
3018                 Assert.IsTrue (object.ReferenceEquals (s1, result), "#C2");
3019
3020                 result = s1.PadRight (s1.Length + 1);
3021                 Assert.AreEqual ("Hi! ", result, "#D");
3022         }
3023
3024         [Test] // PadRight1 (Int32)
3025         public void PadRight1_TotalWidth_Negative ()
3026         {
3027                 try {
3028                         "Mono".PadRight (-1);
3029                         Assert.Fail ("#1");
3030                 } catch (ArgumentOutOfRangeException ex) {
3031                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3032                         Assert.IsNull (ex.InnerException, "#3");
3033                         Assert.IsNotNull (ex.Message, "#4");
3034                         Assert.AreEqual ("totalWidth", ex.ParamName, "#5");
3035                 }
3036         }
3037
3038         [Test]
3039         public void PadRight2 ()
3040         {
3041                 Assert.AreEqual ("100000000000", "1".PadRight (12, '0'), "#1");
3042                 Assert.AreEqual ("000000000000", "".PadRight (12, '0'), "#2");
3043         }
3044
3045         [Test]
3046         public void PadRight_Overflow ()
3047         {
3048                 try {
3049                         "x".PadRight (int.MaxValue, '-');
3050                 } catch (OutOfMemoryException) {
3051                 }
3052         }
3053
3054         [Test] // Remove (Int32, Int32)
3055         public void Remove2 ()
3056         {
3057                 string s1 = "original";
3058
3059                 try {
3060                         s1.Remove (-1, 1);
3061                         Assert.Fail ("#A1");
3062                 } catch (ArgumentOutOfRangeException ex) {
3063                         // StartIndex cannot be less than zero
3064                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
3065                         Assert.IsNull (ex.InnerException, "#A3");
3066                         Assert.IsNotNull (ex.Message, "#A4");
3067                         Assert.AreEqual ("startIndex", ex.ParamName, "#A5");
3068                 }
3069
3070                 try {
3071                         s1.Remove (1,-1);
3072                         Assert.Fail ("#B1");
3073                 } catch (ArgumentOutOfRangeException ex) {
3074                         // Count cannot be less than zero
3075                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
3076                         Assert.IsNull (ex.InnerException, "#B3");
3077                         Assert.IsNotNull (ex.Message, "#B4");
3078                         Assert.AreEqual ("count", ex.ParamName, "#B5");
3079                 }
3080
3081                 try {
3082                         s1.Remove (s1.Length, s1.Length);
3083                         Assert.Fail ("#C1");
3084                 } catch (ArgumentOutOfRangeException ex) {
3085                         // Index and count must refer to a location within the
3086                         // string
3087                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#C2");
3088                         Assert.IsNull (ex.InnerException, "#C3");
3089                         Assert.IsNotNull (ex.Message, "#C4");
3090                         Assert.AreEqual ("count", ex.ParamName, "#C5");
3091                 }
3092
3093                 Assert.AreEqual ("oinal", s1.Remove(1, 3), "#D1");
3094                 Assert.AreEqual (s1, s1.Remove (0, 0), "#D2");
3095                 Assert.IsTrue (!object.ReferenceEquals (s1, s1.Remove (0, 0)), "#D3");
3096                 Assert.AreEqual ("riginal", s1.Remove (0, 1), "#D4");
3097                 Assert.AreEqual ("origina", s1.Remove (7, 1), "#D5");
3098         }
3099
3100         [Test] // Remove (Int32, Int32)
3101         public void Remove2_Length_Overflow ()
3102         {
3103                 try {
3104                         "Mono".Remove (1, Int32.MaxValue);
3105                         Assert.Fail ("#1");
3106                 } catch (ArgumentOutOfRangeException ex) {
3107                         // Index and count must refer to a location within the
3108                         // string
3109                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3110                         Assert.IsNull (ex.InnerException, "#3");
3111                         Assert.IsNotNull (ex.Message, "#4");
3112                         Assert.AreEqual ("count", ex.ParamName, "#5");
3113                 }
3114         }
3115
3116         [Test] // Remove (Int32, Int32)
3117         public void Remove2_StartIndex_Overflow ()
3118         {
3119                 try {
3120                         "Mono".Remove (Int32.MaxValue, 1);
3121                         Assert.Fail ("#1");
3122                 } catch (ArgumentOutOfRangeException ex) {
3123                         // Index and count must refer to a location within the
3124                         // string
3125                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3126                         Assert.IsNull (ex.InnerException, "#3");
3127                         Assert.IsNotNull (ex.Message, "#4");
3128                         Assert.AreEqual ("count", ex.ParamName, "#5");
3129                 }
3130         }
3131
3132         [Test] // Remove (Int32)
3133         public void Remove1_StartIndex_Negative ()
3134         {
3135                 try {
3136                         "ABC".Remove (-1);
3137                         Assert.Fail ("#1");
3138                 } catch (ArgumentOutOfRangeException ex) {
3139                         // StartIndex cannot be less than zero
3140                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3141                         Assert.IsNull (ex.InnerException, "#3");
3142                         Assert.IsNotNull (ex.Message, "#4");
3143                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
3144                 }
3145         }
3146
3147         [Test] // Remove (Int32)
3148         public void Remove1_StartIndex_Overflow ()
3149         {
3150                 try {
3151                         "ABC".Remove (3);
3152                         Assert.Fail ("#1");
3153                 } catch (ArgumentOutOfRangeException ex) {
3154                         // startIndex must be less than length of string
3155                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3156                         Assert.IsNull (ex.InnerException, "#3");
3157                         Assert.IsNotNull (ex.Message, "#4");
3158                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
3159                 }
3160         }
3161
3162         [Test] // Remove (Int32)
3163         public void Remove1 ()
3164         {
3165                 string s = "ABC";
3166
3167                 Assert.AreEqual ("AB", s.Remove (2), "#1");
3168                 Assert.AreEqual (string.Empty, s.Remove (0), "#2");
3169                 Assert.AreEqual ("A", s.Remove (1), "#3");
3170         }
3171
3172         [Test]
3173         public void Replace()
3174         {
3175                 string s1 = "original";
3176
3177                 Assert.AreEqual (s1, s1.Replace('q', 's'), "non-hit char");
3178                 Assert.AreEqual ("oxiginal", s1.Replace('r', 'x'), "single char");
3179                 Assert.AreEqual ("orxgxnal", s1.Replace('i', 'x'), "double char");
3180
3181                 bool errorThrown = false;
3182                 try {
3183                         string s = s1.Replace(null, "feh");
3184                 } catch (ArgumentNullException) {
3185                         errorThrown = true;
3186                 }
3187                 Assert.IsTrue (errorThrown, "should get null arg exception");
3188
3189                 Assert.AreEqual ("ornal", s1.Replace("igi", null), "replace as remove");
3190                 Assert.AreEqual (s1, s1.Replace("spam", "eggs"), "non-hit string");
3191                 Assert.AreEqual ("orirumal", s1.Replace("gin", "rum"), "single string");
3192                 Assert.AreEqual ("oreigeinal", s1.Replace("i", "ei"), "double string");
3193
3194                 Assert.AreEqual ("ooriginal", s1.Replace("o", "oo"), "start");
3195                 Assert.AreEqual ("originall", s1.Replace("l", "ll"), "end");
3196
3197                 Assert.AreEqual ("riginal", s1.Replace("o", string.Empty), "start empty");
3198                 Assert.AreEqual ("origina", s1.Replace("l", string.Empty), "end empty");
3199
3200                 Assert.AreEqual ("original", s1.Replace("original2", "original3"), "replace bigger that original");
3201
3202                 Assert.AreEqual (":!:", "::".Replace ("::", ":!:"), "result longer");
3203
3204                 // Test overlapping matches (bug #54988)
3205                 string s2 = "...aaaaaaa.bbbbbbbbb,............ccccccc.u...";
3206                 Assert.AreEqual (s2.Replace("..", "."), "..aaaaaaa.bbbbbbbbb,......ccccccc.u..");
3207
3208                 // Test replacing null characters (bug #67395)
3209                 Assert.AreEqual ("is this ok ?", "is \0 ok ?".Replace ("\0", "this"), "should not strip content after nullchar");
3210         }
3211
3212         [Test]
3213         public void ReplaceStringBeginEndTest ()
3214         {
3215                 string s1 = "original";
3216
3217                 Assert.AreEqual ("riginal", s1.Replace ("o", ""), "#1");
3218                 Assert.AreEqual ("origina", s1.Replace ("l", ""), "#2");
3219                 Assert.AreEqual ("ariginal", s1.Replace ("o", "a"), "#3");
3220                 Assert.AreEqual ("originaa", s1.Replace ("l", "a"), "#4");
3221                 Assert.AreEqual ("aariginal", s1.Replace ("o", "aa"), "#5");
3222                 Assert.AreEqual ("originaaa", s1.Replace ("l", "aa"), "#6");
3223                 Assert.AreEqual ("original", s1.Replace ("o", "o"), "#7");
3224                 Assert.AreEqual ("original", s1.Replace ("l", "l"), "#8");
3225                 Assert.AreEqual ("original", s1.Replace ("original", "original"), "#9");
3226                 Assert.AreEqual ("", s1.Replace ("original", ""), "#10");
3227         }
3228
3229         [Test]
3230         public void ReplaceStringBeginEndTestFallback ()
3231         {
3232                 string prev = new String ('o', 300);
3233                 string s1 = prev + "riginal";
3234
3235                 Assert.AreEqual ("riginal", s1.Replace ("o", ""), "#1");
3236                 Assert.AreEqual (prev + "rigina", s1.Replace ("l", ""), "#2");
3237                 Assert.AreEqual (new String ('a', 300) + "riginal", s1.Replace ("o", "a"), "#3");
3238                 Assert.AreEqual (prev + "riginaa", s1.Replace ("l", "a"), "#4");
3239                 Assert.AreEqual (new String ('a', 600) + "riginal", s1.Replace ("o", "aa"), "#5");
3240                 Assert.AreEqual (prev + "riginaaa", s1.Replace ("l", "aa"), "#6");
3241                 Assert.AreEqual (s1, s1.Replace ("o", "o"), "#7");
3242                 Assert.AreEqual (s1, s1.Replace ("l", "l"), "#8");
3243                 Assert.AreEqual (s1, s1.Replace (s1, s1), "#9");
3244                 Assert.AreEqual ("", s1.Replace (prev + "riginal", ""), "#10");
3245         }
3246
3247         [Test]
3248         public void ReplaceStringOffByOne ()
3249         {
3250                 Assert.AreEqual ("", new String ('o', 199).Replace ("o", ""), "#-1");
3251                 Assert.AreEqual ("", new String ('o', 200).Replace ("o", ""), "#0");
3252                 Assert.AreEqual ("", new String ('o', 201).Replace ("o", ""), "#+1");
3253         }
3254
3255         [Test]
3256         public void ReplaceStringCultureTests ()
3257         {
3258                 // LAMESPEC: According to MSDN Replace with String parameter is culture-senstive.
3259                 // However this does not currently seem to be the case. Otherwise following code should
3260                 // produce "check" instead of "AE"
3261
3262                 CultureInfo old = Thread.CurrentThread.CurrentCulture;
3263                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
3264                 Assert.AreEqual ("AE", "AE".Replace ("\u00C6", "check"), "#1");
3265                 Thread.CurrentThread.CurrentCulture = old;
3266         }
3267
3268         [Test] // StartsWith (String)
3269         public void StartsWith1 ()
3270         {
3271                 string s1 = "original";
3272                 
3273                 Assert.IsTrue (s1.StartsWith ("o"), "#1");
3274                 Assert.IsTrue (s1.StartsWith ("orig"), "#2");
3275                 Assert.IsTrue (!s1.StartsWith ("rig"), "#3");
3276                 Assert.IsTrue (s1.StartsWith (String.Empty), "#4");
3277                 Assert.IsTrue (String.Empty.StartsWith (String.Empty), "#5");
3278                 Assert.IsTrue (!String.Empty.StartsWith ("rig"), "#6");
3279         }
3280
3281         [Test] // StartsWith (String)
3282         public void StartsWith1_Value_Null ()
3283         {
3284                 try {
3285                         "A".StartsWith (null);
3286                         Assert.Fail ("#1");
3287                 } catch (ArgumentNullException ex) {
3288                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
3289                         Assert.IsNull (ex.InnerException, "#3");
3290                         Assert.IsNotNull (ex.Message, "#4");
3291                         Assert.AreEqual ("value", ex.ParamName, "#5");
3292                 }
3293         }
3294
3295         [Test] // StartsWith (String, StringComparison)
3296         public void StartsWith2_ComparisonType_Invalid ()
3297         {
3298                 try {
3299                         "ABC".StartsWith ("A", (StringComparison) 80);
3300                         Assert.Fail ("#1");
3301                 } catch (ArgumentException ex) {
3302                         // The string comparison type passed in is currently
3303                         // not supported
3304                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
3305                         Assert.IsNull (ex.InnerException, "#3");
3306                         Assert.IsNotNull (ex.Message, "#4");
3307                         Assert.AreEqual ("comparisonType", ex.ParamName, "#5");
3308                 }
3309         }
3310
3311         [Test] // StartsWith (String, StringComparison)
3312         public void StartsWith2_Value_Null ()
3313         {
3314                 try {
3315                         "A".StartsWith (null, StringComparison.CurrentCulture);
3316                         Assert.Fail ("#1");
3317                 } catch (ArgumentNullException ex) {
3318                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
3319                         Assert.IsNull (ex.InnerException, "#3");
3320                         Assert.IsNotNull (ex.Message, "#4");
3321                         Assert.AreEqual ("value", ex.ParamName, "#5");
3322                 }
3323         }
3324
3325         [Test] // StartsWith (String, Boolean, CultureInfo)
3326         public void StartsWith3_Culture_Null ()
3327         {
3328                 // This should not crash
3329                 string s = "boo";
3330
3331                 s.StartsWith ("this", true, null);
3332         }
3333
3334         [Test] // SubString (Int32)
3335         public void Substring1 ()
3336         {
3337                 string s = "original";
3338
3339                 Assert.AreEqual ("inal", s.Substring (4), "#1");
3340                 Assert.AreEqual (string.Empty, s.Substring (s.Length), "#2");
3341                 Assert.AreSame (s, s.Substring (0), "#3");
3342         }
3343
3344         [Test] // SubString (Int32)
3345         public void SubString1_StartIndex_Negative ()
3346         {
3347                 string s = "original";
3348
3349                 try {
3350                         s.Substring (-1);
3351                         Assert.Fail ("#1");
3352                 } catch (ArgumentOutOfRangeException ex) {
3353                         // StartIndex cannot be less than zero
3354                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3355                         Assert.IsNull (ex.InnerException, "#3");
3356                         Assert.IsNotNull (ex.Message, "#4");
3357                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
3358                 }
3359         }
3360
3361         [Test] // SubString (Int32)
3362         public void SubString1_StartIndex_Overflow ()
3363         {
3364                 string s = "original";
3365
3366                 try {
3367                         s.Substring (s.Length + 1);
3368                         Assert.Fail ("#1");
3369                 } catch (ArgumentOutOfRangeException ex) {
3370                         // startIndex cannot be larger than length of string
3371                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3372                         Assert.IsNull (ex.InnerException, "#3");
3373                         Assert.IsNotNull (ex.Message, "#4");
3374                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
3375                 }
3376         }
3377
3378         [Test] // SubString (Int32, Int32)
3379         public void Substring2 ()
3380         {
3381                 string s = "original";
3382
3383                 Assert.AreEqual ("igin", s.Substring (2, 4), "#1");
3384                 Assert.AreEqual (string.Empty, s.Substring (s.Length, 0), "#2");
3385                 Assert.AreEqual ("origina", s.Substring (0, s.Length - 1), "#3");
3386                 Assert.AreEqual (s, s.Substring (0, s.Length), "#4");
3387                 Assert.AreSame (s, s.Substring (0, s.Length), "#5");
3388         }
3389
3390         [Test] // SubString (Int32, Int32)
3391         public void SubString2_Length_Negative ()
3392         {
3393                 string s = "original";
3394
3395                 try {
3396                         s.Substring (1, -1);
3397                         Assert.Fail ("#1");
3398                 } catch (ArgumentOutOfRangeException ex) {
3399                         // Length cannot be less than zero
3400                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3401                         Assert.IsNull (ex.InnerException, "#3");
3402                         Assert.IsNotNull (ex.Message, "#4");
3403                         Assert.AreEqual ("length", ex.ParamName, "#5");
3404                 }
3405         }
3406         
3407         [Test] // SubString (Int32, Int32)
3408         public void Substring2_Length_Overflow ()
3409         {
3410                 string s = "original";
3411
3412                 try {
3413                         s.Substring (s.Length, 1);
3414                         Assert.Fail ("#A1");
3415                 } catch (ArgumentOutOfRangeException ex) {
3416                         // Index and length must refer to a location within
3417                         // the string
3418                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
3419                         Assert.IsNull (ex.InnerException, "#A3");
3420                         Assert.IsNotNull (ex.Message, "#A4");
3421                         Assert.AreEqual ("length", ex.ParamName, "#A5");
3422                 }
3423
3424                 try {
3425                         s.Substring (1, s.Length);
3426                         Assert.Fail ("#B1");
3427                 } catch (ArgumentOutOfRangeException ex) {
3428                         // Index and length must refer to a location within
3429                         // the string
3430                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
3431                         Assert.IsNull (ex.InnerException, "#B3");
3432                         Assert.IsNotNull (ex.Message, "#B4");
3433                         Assert.AreEqual ("length", ex.ParamName, "#B5");
3434                 }
3435
3436                 try {
3437                         s.Substring (1, Int32.MaxValue);
3438                         Assert.Fail ("#C1");
3439                 } catch (ArgumentOutOfRangeException ex) {
3440                         // Index and length must refer to a location within
3441                         // the string
3442                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#C2");
3443                         Assert.IsNull (ex.InnerException, "#C3");
3444                         Assert.IsNotNull (ex.Message, "#C4");
3445                         Assert.AreEqual ("length", ex.ParamName, "#C5");
3446                 }
3447         }
3448
3449         [Test] // SubString (Int32, Int32)
3450         public void SubString2_StartIndex_Negative ()
3451         {
3452                 string s = "original";
3453
3454                 try {
3455                         s.Substring (-1, 1);
3456                         Assert.Fail ("#1");
3457                 } catch (ArgumentOutOfRangeException ex) {
3458                         // StartIndex cannot be less than zero
3459                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3460                         Assert.IsNull (ex.InnerException, "#3");
3461                         Assert.IsNotNull (ex.Message, "#4");
3462                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
3463                 }
3464         }
3465
3466         [Test] // SubString (Int32, Int32)
3467         public void Substring2_StartIndex_Overflow ()
3468         {
3469                 string s = "original";
3470
3471                 try {
3472                         s.Substring (s.Length + 1, 0);
3473                         Assert.Fail ("#A1");
3474                 } catch (ArgumentOutOfRangeException ex) {
3475                         // startIndex cannot be larger than length of string
3476                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
3477                         Assert.IsNull (ex.InnerException, "#A3");
3478                         Assert.IsNotNull (ex.Message, "#A4");
3479                         Assert.AreEqual ("startIndex", ex.ParamName, "#A5");
3480                 }
3481
3482                 try {
3483                         "Mono".Substring (Int32.MaxValue, 1);
3484                         Assert.Fail ("#B1");
3485                 } catch (ArgumentOutOfRangeException ex) {
3486                         // startIndex cannot be larger than length of string
3487                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
3488                         Assert.IsNull (ex.InnerException, "#B3");
3489                         Assert.IsNotNull (ex.Message, "#B4");
3490                         Assert.AreEqual ("startIndex", ex.ParamName, "#B5");
3491                 }
3492         }
3493
3494         [Test]
3495         public void ToCharArray ()
3496         {
3497                 const string s = "original";
3498                 char [] c;
3499
3500                 c = s.ToCharArray ();
3501                 Assert.AreEqual (s.Length, c.Length, "#A1");
3502                 Assert.AreEqual (s, new String (c), "#A2");
3503
3504                 c = s.ToCharArray (0, s.Length);
3505                 Assert.AreEqual (s.Length, c.Length, "#B1");
3506                 Assert.AreEqual (s, new String (c), "#B2");
3507
3508                 c = s.ToCharArray (1, s.Length - 1);
3509                 Assert.AreEqual (7, c.Length, "#C1");
3510                 Assert.AreEqual ("riginal", new String (c), "#C2");
3511
3512                 c = s.ToCharArray (0, 3);
3513                 Assert.AreEqual (3, c.Length, "#D1");
3514                 Assert.AreEqual ("ori", new String (c), "#D2");
3515
3516                 c = s.ToCharArray (2, 0);
3517                 Assert.AreEqual (0, c.Length, "#E1");
3518                 Assert.AreEqual (string.Empty, new String (c), "#E2");
3519
3520                 c = s.ToCharArray (3, 2);
3521                 Assert.AreEqual (2, c.Length, "#F1");
3522                 Assert.AreEqual ("gi", new String (c), "#F2");
3523
3524                 c = s.ToCharArray (s.Length, 0);
3525                 Assert.AreEqual (0, c.Length, "#G1");
3526                 Assert.AreEqual (string.Empty, new String (c), "#G2");
3527         }
3528
3529         [Test]
3530         public void ToCharArray_Length_Negative ()
3531         {
3532                 const string s = "original";
3533
3534                 try {
3535                         s.ToCharArray (1, -1);
3536                         Assert.Fail ("#1");
3537                 } catch (ArgumentOutOfRangeException ex) {
3538                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3539                         Assert.IsNull (ex.InnerException, "#3");
3540                         Assert.IsNotNull (ex.Message, "#4");
3541                         Assert.AreEqual ("length", ex.ParamName, "#5");
3542                 }
3543         }
3544
3545         [Test]
3546         public void ToCharArray_Length_Overflow ()
3547         {
3548                 const string s = "original";
3549
3550                 try {
3551                         s.ToCharArray (1, s.Length);
3552                         Assert.Fail ("#A1");
3553                 } catch (ArgumentOutOfRangeException ex) {
3554                         // Index was out of range. Must be non-negative and
3555                         // less than the size of the collection
3556                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
3557                         Assert.IsNull (ex.InnerException, "#A3");
3558                         Assert.IsNotNull (ex.Message, "#A4");
3559                         Assert.AreEqual ("startIndex", ex.ParamName, "#A5");
3560                 }
3561
3562                 try {
3563                         s.ToCharArray (1, Int32.MaxValue);
3564                         Assert.Fail ("#B1");
3565                 } catch (ArgumentOutOfRangeException ex) {
3566                         // Index was out of range. Must be non-negative and
3567                         // less than the size of the collection
3568                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
3569                         Assert.IsNull (ex.InnerException, "#B3");
3570                         Assert.IsNotNull (ex.Message, "#B4");
3571                         Assert.AreEqual ("startIndex", ex.ParamName, "#B5");
3572                 }
3573         }
3574
3575         [Test]
3576         public void ToCharArray_StartIndex_Negative ()
3577         {
3578                 const string s = "original";
3579
3580                 try {
3581                         s.ToCharArray (-1, 1);
3582                         Assert.Fail ("#1");
3583                 } catch (ArgumentOutOfRangeException ex) {
3584                         // Index was out of range. Must be non-negative and
3585                         // less than the size of the collection
3586                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3587                         Assert.IsNull (ex.InnerException, "#3");
3588                         Assert.IsNotNull (ex.Message, "#4");
3589                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
3590                 }
3591         }
3592
3593         [Test]
3594         public void ToCharArray_StartIndex_Overflow ()
3595         {
3596                 const string s = "original";
3597
3598                 try {
3599                         s.ToCharArray (s.Length, 1);
3600                         Assert.Fail ("#A1");
3601                 } catch (ArgumentOutOfRangeException ex) {
3602                         // Index was out of range. Must be non-negative and
3603                         // less than the size of the collection
3604                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
3605                         Assert.IsNull (ex.InnerException, "#A3");
3606                         Assert.IsNotNull (ex.Message, "#A4");
3607                         Assert.AreEqual ("startIndex", ex.ParamName, "#A5");
3608                 }
3609
3610                 try {
3611                         s.ToCharArray (Int32.MaxValue, 1);
3612                         Assert.Fail ("#B1");
3613                 } catch (ArgumentOutOfRangeException ex) {
3614                         // Index was out of range. Must be non-negative and
3615                         // less than the size of the collection
3616                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
3617                         Assert.IsNull (ex.InnerException, "#B3");
3618                         Assert.IsNotNull (ex.Message, "#B4");
3619                         Assert.AreEqual ("startIndex", ex.ParamName, "#B5");
3620                 }
3621         }
3622
3623         [Test] // ToLower ()
3624         public void ToLower1 ()
3625         {
3626                 string s = "OrIgInAli";
3627
3628                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
3629
3630                 Assert.AreEqual ("\u006f\u0072\u0131\u0067\u0131\u006e\u0061\u006c\u0069", s.ToLower(), "#1");
3631
3632                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
3633
3634                 Assert.AreEqual ("originali", s.ToLower (), "#2");
3635         }
3636
3637         [Test] // ToLower (CultureInfo)
3638         public void ToLower2 ()
3639         {
3640                 string s = "OrIgInAli";
3641
3642                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
3643
3644                 Assert.AreEqual ("originali", s.ToLower (new CultureInfo ("en-US")), "#A1");
3645                 Assert.AreEqual ("\u006f\u0072\u0131\u0067\u0131\u006e\u0061\u006c\u0069", s.ToLower (new CultureInfo ("tr-TR")), "#A2");
3646                 Assert.AreEqual (string.Empty, string.Empty.ToLower (new CultureInfo ("en-US")), "#A3");
3647                 Assert.AreEqual (string.Empty, string.Empty.ToLower (new CultureInfo ("tr-TR")), "#A4");
3648
3649                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
3650
3651                 Assert.AreEqual ("originali", s.ToLower (new CultureInfo ("en-US")), "#B1");
3652                 Assert.AreEqual ("\u006f\u0072\u0131\u0067\u0131\u006e\u0061\u006c\u0069", s.ToLower (new CultureInfo ("tr-TR")), "#B2");
3653                 Assert.AreEqual (string.Empty, string.Empty.ToLower (new CultureInfo ("en-US")), "#B3");
3654                 Assert.AreEqual (string.Empty, string.Empty.ToLower (new CultureInfo ("tr-TR")), "#B4");
3655         }
3656
3657         [Test] // ToLower (CultureInfo)
3658         public void ToLower2_Culture_Null ()
3659         {
3660                 string s = "OrIgInAl";
3661
3662                 try {
3663                         s.ToLower ((CultureInfo) null);
3664                         Assert.Fail ("#A1");
3665                 } catch (ArgumentNullException ex) {
3666                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
3667                         Assert.IsNull (ex.InnerException, "#A3");
3668                         Assert.IsNotNull (ex.Message, "#A4");
3669                         Assert.AreEqual ("culture", ex.ParamName, "#A5");
3670                 }
3671
3672                 try {
3673                         string.Empty.ToLower ((CultureInfo) null);
3674                         Assert.Fail ("#B1");
3675                 } catch (ArgumentNullException ex) {
3676                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
3677                         Assert.IsNull (ex.InnerException, "#B3");
3678                         Assert.IsNotNull (ex.Message, "#B4");
3679                         Assert.AreEqual ("culture", ex.ParamName, "#B5");
3680                 }
3681         }
3682
3683         [Test]
3684         public void TestToString ()
3685         {
3686                 string s1 = "OrIgInAli";
3687                 Assert.AreEqual (s1, s1.ToString(), "ToString failed!");
3688         }
3689
3690         [Test] // ToUpper ()
3691         public void ToUpper1 ()
3692         {
3693                 string s = "OrIgInAli";
3694
3695                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
3696
3697                 Assert.AreEqual ("ORIGINAL\u0130", s.ToUpper (), "#1");
3698
3699                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
3700
3701                 Assert.AreEqual ("ORIGINALI", s.ToUpper (), "#2");
3702         }
3703
3704         [Test] // ToUpper (CultureInfo)
3705         public void ToUpper2 ()
3706         {
3707                 string s = "OrIgInAli";
3708
3709                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
3710
3711                 Assert.AreEqual ("ORIGINALI", s.ToUpper (new CultureInfo ("en-US")), "#A1");
3712                 Assert.AreEqual ("ORIGINAL\u0130", s.ToUpper (new CultureInfo ("tr-TR")), "#A2");
3713                 Assert.AreEqual (string.Empty, string.Empty.ToUpper (new CultureInfo ("en-US")), "#A3");
3714                 Assert.AreEqual (string.Empty, string.Empty.ToUpper (new CultureInfo ("tr-TR")), "#A4");
3715
3716                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
3717
3718                 Assert.AreEqual ("ORIGINALI", s.ToUpper (new CultureInfo ("en-US")), "#B1");
3719                 Assert.AreEqual ("ORIGINAL\u0130", s.ToUpper (new CultureInfo ("tr-TR")), "#B2");
3720                 Assert.AreEqual (string.Empty, string.Empty.ToUpper (new CultureInfo ("en-US")), "#B3");
3721                 Assert.AreEqual (string.Empty, string.Empty.ToUpper (new CultureInfo ("tr-TR")), "#B4");
3722         }
3723
3724         [Test] // ToUpper (CultureInfo)
3725         public void ToUpper2_Culture_Null ()
3726         {
3727                 string s = "OrIgInAl";
3728
3729                 try {
3730                         s.ToUpper ((CultureInfo) null);
3731                         Assert.Fail ("#A1");
3732                 } catch (ArgumentNullException ex) {
3733                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
3734                         Assert.IsNull (ex.InnerException, "#A3");
3735                         Assert.IsNotNull (ex.Message, "#A4");
3736                         Assert.AreEqual ("culture", ex.ParamName, "#A5");
3737                 }
3738
3739                 try {
3740                         string.Empty.ToUpper ((CultureInfo) null);
3741                         Assert.Fail ("#B1");
3742                 } catch (ArgumentNullException ex) {
3743                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
3744                         Assert.IsNull (ex.InnerException, "#B3");
3745                         Assert.IsNotNull (ex.Message, "#B4");
3746                         Assert.AreEqual ("culture", ex.ParamName, "#B5");
3747                 }
3748         }
3749
3750         [Test]
3751         public void TestTrim ()
3752         {
3753                 string s1 = "  original\t\n";
3754                 Assert.AreEqual ("original", s1.Trim(), "basic trim failed");
3755                 Assert.AreEqual ("original", s1.Trim(null), "basic trim failed");
3756
3757                 s1 = "original";
3758                 Assert.AreEqual ("original", s1.Trim(), "basic trim failed");
3759                 Assert.AreEqual ("original", s1.Trim(null), "basic trim failed");
3760
3761                 s1 = "   \t \n  ";
3762                 Assert.AreEqual (string.Empty, s1.Trim(), "empty trim failed");
3763                 Assert.AreEqual (string.Empty, s1.Trim(null), "empty trim failed");
3764
3765                 s1 = "aaaoriginalbbb";
3766                 char[] delims = {'a', 'b'};
3767                 Assert.AreEqual ("original", s1.Trim(delims), "custom trim failed");
3768
3769                 Assert.AreEqual ("original", "\u2028original\u2029".Trim (), "net_2_0 additional char#1");
3770                 Assert.AreEqual ("original", "\u0085original\u1680".Trim (), "net_2_0 additional char#2");
3771
3772 #if NET_4_0
3773                 Assert.AreEqual ("", "\x9\xa\xb\xc\xd\x20\x85\xa0\x1680\x2000\x2001\x2002\x2003\x2004\x2005\x2006\x2007\x2008\x2009\x200a\x2028\x2029\x202f\x205f\x3000".Trim (), "net_4_0 changes #1");
3774 #endif
3775         }
3776
3777         [Test]
3778         public void TestTrimEnd ()
3779         {
3780                 string s1 = "  original\t\n";
3781                 Assert.AreEqual ("  original", s1.TrimEnd(null), "basic TrimEnd failed");
3782
3783                 s1 = "  original";
3784                 Assert.AreEqual ("  original", s1.TrimEnd(null), "basic TrimEnd failed");
3785
3786                 s1 = "  \t  \n  \n    ";
3787                 Assert.AreEqual (string.Empty, s1.TrimEnd(null), "empty TrimEnd failed");
3788
3789                 s1 = "aaaoriginalbbb";
3790                 char[] delims = {'a', 'b'};
3791                 Assert.AreEqual ("aaaoriginal", s1.TrimEnd(delims), "custom TrimEnd failed");
3792         }
3793
3794         [Test]
3795         public void TestTrimStart ()
3796         {
3797                 string s1 = "  original\t\n";
3798                 Assert.AreEqual ("original\t\n", s1.TrimStart(null), "basic TrimStart failed");
3799
3800                 s1 = "original\t\n";
3801                 Assert.AreEqual ("original\t\n", s1.TrimStart(null), "basic TrimStart failed");
3802
3803                 s1 = "    \t \n \n  ";
3804                 Assert.AreEqual (string.Empty, s1.TrimStart(null), "empty TrimStart failed");
3805
3806                 s1 = "aaaoriginalbbb";
3807                 char[] delims = {'a', 'b'};
3808                 Assert.AreEqual ("originalbbb", s1.TrimStart(delims), "custom TrimStart failed");
3809         }
3810
3811         [Test]
3812         public void TestChars ()
3813         {
3814                 string s;
3815
3816                 s = string.Empty;
3817                 try {
3818                         char c = s [0];
3819                         Assert.Fail ("#A1:" + c);
3820                 } catch (IndexOutOfRangeException ex) {
3821                         Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#A2");
3822                         Assert.IsNull (ex.InnerException, "#A3");
3823                         Assert.IsNotNull (ex.Message, "#A4");
3824                 }
3825
3826                 s = "A";
3827                 try {
3828                         char c = s [-1];
3829                         Assert.Fail ("#B1:" + c);
3830                 } catch (IndexOutOfRangeException ex) {
3831                         Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#B2");
3832                         Assert.IsNull (ex.InnerException, "#B3");
3833                         Assert.IsNotNull (ex.Message, "#B4");
3834                 }
3835         }
3836
3837         [Test]
3838         public void TestComparePeriod ()
3839         {
3840                 // according to bug 63981, this behavior is for all cultures
3841                 Assert.AreEqual (-1, String.Compare ("foo.obj", "foobar.obj", false), "#1");
3842         }
3843
3844         [Test]
3845         public void LastIndexOfAnyBounds1 ()
3846         {
3847                 string mono = "Mono";
3848                 char [] k = { 'M' };
3849                 try {
3850                         mono.LastIndexOfAny (k, mono.Length, 1);
3851                         Assert.Fail ("#1");
3852                 } catch (ArgumentOutOfRangeException ex) {
3853                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3854                         Assert.IsNull (ex.InnerException, "#3");
3855                         Assert.IsNotNull (ex.Message, "#4");
3856                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
3857                 }
3858         }
3859
3860         [Test]
3861         public void TestSplit ()
3862         {
3863                 string s1 = "abcdefghijklm";
3864                 char[] c1 = {'q', 'r'};
3865                 Assert.AreEqual (s1, (s1.Split(c1))[0], "No splitters");
3866
3867                 char[] c2 = {'a', 'e', 'i', 'o', 'u'};
3868                 string[] chunks = s1.Split(c2);
3869                 Assert.AreEqual (string.Empty, chunks[0], "First chunk");
3870                 Assert.AreEqual ("bcd", chunks[1], "Second chunk");
3871                 Assert.AreEqual ("fgh", chunks[2], "Third chunk");
3872                 Assert.AreEqual ("jklm", chunks[3], "Fourth chunk");
3873
3874                 {
3875                         bool errorThrown = false;
3876                         try {
3877                                 chunks = s1.Split(c2, -1);
3878                         } catch (ArgumentOutOfRangeException) {
3879                                 errorThrown = true;
3880                         }
3881                         Assert.IsTrue (errorThrown, "Split out of range");
3882                 }
3883
3884                 chunks = s1.Split(c2, 2);
3885                 Assert.AreEqual (2, chunks.Length, "Limited chunk");
3886                 Assert.AreEqual (string.Empty, chunks[0], "First limited chunk");
3887                 Assert.AreEqual ("bcdefghijklm", chunks[1], "Second limited chunk");
3888
3889                 string s3 = "1.0";
3890                 char[] c3 = {'.'};
3891                 chunks = s3.Split(c3,2);
3892                 Assert.AreEqual (2, chunks.Length, "1.0 split length");
3893                 Assert.AreEqual ("1", chunks[0], "1.0 split first chunk");
3894                 Assert.AreEqual ("0", chunks[1], "1.0 split second chunk");
3895
3896                 string s4 = "1.0.0";
3897                 char[] c4 = {'.'};
3898                 chunks = s4.Split(c4,2);
3899                 Assert.AreEqual (2, chunks.Length, "1.0.0 split length");
3900                 Assert.AreEqual ("1", chunks[0], "1.0.0 split first chunk");
3901                 Assert.AreEqual ("0.0", chunks[1], "1.0.0 split second chunk");
3902
3903                 string s5 = ".0.0";
3904                 char[] c5 = {'.'};
3905                 chunks = s5.Split (c5, 2);
3906                 Assert.AreEqual (2, chunks.Length, ".0.0 split length");
3907                 Assert.AreEqual (string.Empty, chunks[0], ".0.0 split first chunk");
3908                 Assert.AreEqual ("0.0", chunks[1], ".0.0 split second chunk");
3909
3910                 string s6 = ".0";
3911                 char[] c6 = {'.'};
3912                 chunks = s6.Split (c6, 2);
3913                 Assert.AreEqual (2, chunks.Length, ".0 split length");
3914                 Assert.AreEqual (string.Empty, chunks[0], ".0 split first chunk");
3915                 Assert.AreEqual ("0", chunks[1], ".0 split second chunk");
3916
3917                 string s7 = "0.";
3918                 char[] c7 = {'.'};
3919                 chunks = s7.Split (c7, 2);
3920                 Assert.AreEqual (2, chunks.Length, "0. split length");
3921                 Assert.AreEqual ("0", chunks[0], "0. split first chunk");
3922                 Assert.AreEqual (string.Empty, chunks[1], "0. split second chunk");
3923
3924                 string s8 = "0.0000";
3925                 char[] c8 = {'.'};
3926                 chunks = s8.Split (c8, 2);
3927                 Assert.AreEqual (2, chunks.Length, "0.0000/2 split length");
3928                 Assert.AreEqual ("0", chunks[0], "0.0000/2 split first chunk");
3929                 Assert.AreEqual ("0000", chunks[1], "0.0000/2 split second chunk");
3930
3931                 chunks = s8.Split (c8, 3);
3932                 Assert.AreEqual (2, chunks.Length, "0.0000/3 split length");
3933                 Assert.AreEqual ("0", chunks[0], "0.0000/3 split first chunk");
3934                 Assert.AreEqual ("0000", chunks[1], "0.0000/3 split second chunk");
3935
3936                 chunks = s8.Split (c8, 1);
3937                 Assert.AreEqual (1, chunks.Length, "0.0000/1 split length");
3938                 Assert.AreEqual ("0.0000", chunks[0], "0.0000/1 split first chunk");
3939
3940                 chunks = s1.Split(c2, 1);
3941                 Assert.AreEqual (1, chunks.Length, "Single split");
3942                 Assert.AreEqual (s1, chunks[0], "Single chunk");
3943
3944                 chunks = s1.Split(c2, 0);
3945                 Assert.AreEqual (0, chunks.Length, "Zero split");
3946
3947 #if NET_4_0
3948                 Assert.AreEqual (0, "\x9\xa\xb\xc\xd\x20\x85\xa0\x1680\x2000\x2001\x2002\x2003\x2004\x2005\x2006\x2007\x2008\x2009\x200a\x2028\x2029\x202f\x205f\x3000".Split ((char[]) null, StringSplitOptions.RemoveEmptyEntries).Length, "net_4_0 changes");
3949 #endif
3950         }
3951
3952         [Test]
3953         public void MoreSplit ()
3954         {
3955                 string test = "123 456 789";
3956                 string [] st = test.Split ();
3957                 Assert.AreEqual ("123", st [0], "#01");
3958                 st = test.Split (null);
3959                 Assert.AreEqual ("123", st [0], "#02");
3960
3961                 Assert.AreEqual (1, "encyclopædia".Split (new[] { "ae" }, StringSplitOptions.None).Length, "#03");
3962         }
3963
3964         [Test] // Split (Char [], StringSplitOptions)
3965         public void Split3_Options_Invalid ()
3966         {
3967                 try {
3968                         "A B".Split (new Char [] { 'A' }, (StringSplitOptions) 4096);
3969                         Assert.Fail ("#1");
3970                 } catch (ArgumentException ex) {
3971                         // Illegal enum value: 4096
3972                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
3973                         Assert.IsNull (ex.InnerException, "#3");
3974                         Assert.IsNotNull (ex.Message, "#4");
3975                         Assert.IsTrue (ex.Message.IndexOf ("4096") != 1, "#5");
3976                         Assert.IsNull (ex.ParamName, "#6");
3977                 }
3978         }
3979
3980         [Test] // Split (Char [], StringSplitOptions)
3981         public void Split4_Options_Invalid ()
3982         {
3983                 try {
3984                         "A B".Split (new String [] { "A" }, (StringSplitOptions) 4096);
3985                         Assert.Fail ("#1");
3986                 } catch (ArgumentException ex) {
3987                         // Illegal enum value: 4096
3988                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
3989                         Assert.IsNull (ex.InnerException, "#3");
3990                         Assert.IsNotNull (ex.Message, "#4");
3991                         Assert.IsTrue (ex.Message.IndexOf ("4096") != 1, "#5");
3992                         Assert.IsNull (ex.ParamName, "#6");
3993                 }
3994         }
3995
3996         [Test] // Split (Char [], StringSplitOptions)
3997         public void Split5_Options_Invalid ()
3998         {
3999                 try {
4000                         "A B".Split (new Char [] { 'A' }, 0, (StringSplitOptions) 4096);
4001                         Assert.Fail ("#1");
4002                 } catch (ArgumentException ex) {
4003                         // Illegal enum value: 4096
4004                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
4005                         Assert.IsNull (ex.InnerException, "#3");
4006                         Assert.IsNotNull (ex.Message, "#4");
4007                         Assert.IsTrue (ex.Message.IndexOf ("4096") != 1, "#5");
4008                         Assert.IsNull (ex.ParamName, "#6");
4009                 }
4010         }
4011
4012         [Test] // Split (String [], Int32, StringSplitOptions)
4013         public void Split6_Count_Negative ()
4014         {
4015                 try {
4016                         "A B".Split (new String [] { "A" }, -1, StringSplitOptions.None);
4017                         Assert.Fail ("#1");
4018                 } catch (ArgumentOutOfRangeException ex) {
4019                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
4020                         Assert.IsNull (ex.InnerException, "#3");
4021                         Assert.IsNotNull (ex.Message, "#4");
4022                         Assert.AreEqual ("count", ex.ParamName, "#5");
4023                 }
4024         }
4025
4026         [Test] // Split (String [], Int32, StringSplitOptions)
4027         public void Split6_Options_Invalid ()
4028         {
4029                 try {
4030                         "A B".Split (new String [] { "A" }, 0, (StringSplitOptions) 4096);
4031                         Assert.Fail ("#1");
4032                 } catch (ArgumentException ex) {
4033                         // Illegal enum value: 4096
4034                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
4035                         Assert.IsNull (ex.InnerException, "#3");
4036                         Assert.IsNotNull (ex.Message, "#4");
4037                         Assert.IsTrue (ex.Message.IndexOf ("4096") != 1, "#5");
4038                         Assert.IsNull (ex.ParamName, "#6");
4039                 }
4040         }
4041
4042         [Test]
4043         public void SplitString ()
4044         {
4045                 String[] res;
4046                 
4047                 // count == 0
4048                 res = "A B C".Split (new String [] { "A" }, 0, StringSplitOptions.None);
4049                 Assert.AreEqual (0, res.Length);
4050
4051                 // empty and RemoveEmpty
4052                 res = string.Empty.Split (new String [] { "A" }, StringSplitOptions.RemoveEmptyEntries);
4053                 Assert.AreEqual (0, res.Length);
4054
4055                 // Not found
4056                 res = "A B C".Split (new String [] { "D" }, StringSplitOptions.None);
4057                 Assert.AreEqual (1, res.Length);
4058                 Assert.AreEqual ("A B C", res [0]);
4059
4060                 // A normal test
4061                 res = "A B C DD E".Split (new String[] { "B", "D" }, StringSplitOptions.None);
4062                 Assert.AreEqual (4, res.Length);
4063                 Assert.AreEqual ("A ", res [0]);
4064                 Assert.AreEqual (" C ", res [1]);
4065                 Assert.AreEqual (string.Empty, res [2]);
4066                 Assert.AreEqual (" E", res [3]);
4067
4068                 // Same with RemoveEmptyEntries
4069                 res = "A B C DD E".Split (new String[] { "B", "D" }, StringSplitOptions.RemoveEmptyEntries);
4070                 Assert.AreEqual (3, res.Length);
4071                 Assert.AreEqual ("A ", res [0]);
4072                 Assert.AreEqual (" C ", res [1]);
4073                 Assert.AreEqual (" E", res [2]);
4074
4075                 // Delimiter matches once at the beginning of the string
4076                 res = "A B".Split (new String [] { "A" }, StringSplitOptions.RemoveEmptyEntries);
4077                 Assert.AreEqual (1, res.Length);
4078                 Assert.AreEqual (" B", res [0]);
4079
4080                 // Delimiter at the beginning and at the end
4081                 res = "B C DD B".Split (new String[] { "B" }, StringSplitOptions.None);
4082                 Assert.AreEqual (3, res.Length);
4083                 Assert.AreEqual (string.Empty, res [0]);
4084                 Assert.AreEqual (" C DD ", res [1]);
4085                 Assert.AreEqual (string.Empty, res [2]);
4086
4087                 res = "B C DD B".Split (new String[] { "B" }, StringSplitOptions.RemoveEmptyEntries);
4088                 Assert.AreEqual (1, res.Length);
4089                 Assert.AreEqual (" C DD ", res [0]);
4090
4091                 // count
4092                 res = "A B C DD E".Split (new String[] { "B", "D" }, 2, StringSplitOptions.None);
4093                 Assert.AreEqual (2, res.Length);
4094                 Assert.AreEqual ("A ", res [0]);
4095                 Assert.AreEqual (" C DD E", res [1]);
4096
4097                 // Ordering
4098                 res = "ABCDEF".Split (new String[] { "EF", "BCDE" }, StringSplitOptions.None);
4099                 Assert.AreEqual (2, res.Length);
4100                 Assert.AreEqual ("A", res [0]);
4101                 Assert.AreEqual ("F", res [1]);
4102
4103                 res = "ABCDEF".Split (new String[] { "BCD", "BC" }, StringSplitOptions.None);
4104                 Assert.AreEqual (2, res.Length);
4105                 Assert.AreEqual ("A", res [0]);
4106                 Assert.AreEqual ("EF", res [1]);
4107
4108                 // Whitespace
4109                 res = "A B\nC".Split ((String[])null, StringSplitOptions.None);
4110                 Assert.AreEqual (3, res.Length);
4111                 Assert.AreEqual ("A", res [0]);
4112                 Assert.AreEqual ("B", res [1]);
4113                 Assert.AreEqual ("C", res [2]);
4114
4115                 res = "A B\nC".Split (new String [0], StringSplitOptions.None);
4116                 Assert.AreEqual (3, res.Length);
4117                 Assert.AreEqual ("A", res [0]);
4118                 Assert.AreEqual ("B", res [1]);
4119                 Assert.AreEqual ("C", res [2]);
4120         }
4121         
4122         [Test]
4123         public void SplitStringChars ()
4124         {
4125                 String[] res;
4126
4127                 // empty
4128                 res = string.Empty.Split (new Char [] { 'A' });
4129                 Assert.AreEqual (1, res.Length);
4130                 Assert.AreEqual (string.Empty, res [0]);
4131
4132                 // empty and RemoveEmpty
4133                 res = string.Empty.Split (new Char [] { 'A' }, StringSplitOptions.RemoveEmptyEntries);
4134                 Assert.AreEqual (0, res.Length);
4135
4136                 // count == 0
4137                 res = "..A..B..".Split (new Char[] { '.' }, 0, StringSplitOptions.None);
4138                 Assert.AreEqual (0, res.Length, "#01-01");
4139
4140                 // count == 1
4141                 res = "..A..B..".Split (new Char[] { '.' }, 1, StringSplitOptions.None);
4142                 Assert.AreEqual (1, res.Length, "#02-01");
4143                 Assert.AreEqual ("..A..B..", res [0], "#02-02");
4144
4145                 // count == 1 + RemoveEmpty
4146                 res = "..A..B..".Split (new Char[] { '.' }, 1, StringSplitOptions.RemoveEmptyEntries);
4147                 Assert.AreEqual (1, res.Length, "#03-01");
4148                 Assert.AreEqual ("..A..B..", res [0], "#03-02");
4149                 
4150                 // Strange Case A+B A
4151                 res = "...".Split (new Char[] { '.' }, 1, StringSplitOptions.RemoveEmptyEntries);
4152                 Assert.AreEqual (1, res.Length, "#ABA-01");
4153                 Assert.AreEqual ("...", res [0], "#ABA-02");
4154
4155                 // Strange Case A+B B
4156                 res = "...".Split (new Char[] { '.' }, 2, StringSplitOptions.RemoveEmptyEntries);
4157                 Assert.AreEqual (0, res.Length, "#ABB-01");
4158
4159                 // Keeping Empties and multipe split chars
4160                 res = "..A;.B.;".Split (new Char[] { '.', ';' }, StringSplitOptions.None);
4161                 Assert.AreEqual (7, res.Length, "#04-01");
4162                 Assert.AreEqual (string.Empty, res [0], "#04-02");
4163                 Assert.AreEqual (string.Empty, res [1], "#04-03");
4164                 Assert.AreEqual ("A", res [2], "#04-04");
4165                 Assert.AreEqual (string.Empty, res [3], "#04-05");
4166                 Assert.AreEqual ("B", res [4], "#04-06");
4167                 Assert.AreEqual (string.Empty, res [5], "#04-07");
4168                 Assert.AreEqual (string.Empty, res [6], "#04-08");
4169
4170                 // Trimming (3 tests)
4171                 res = "..A".Split (new Char[] { '.' }, 2, StringSplitOptions.RemoveEmptyEntries);
4172                 Assert.AreEqual (1, res.Length, "#05-01");
4173                 Assert.AreEqual ("A", res [0], "#05-02");
4174                 
4175                 res = "A..".Split (new Char[] { '.' }, 2, StringSplitOptions.RemoveEmptyEntries);
4176                 Assert.AreEqual (1, res.Length, "#06-01");
4177                 Assert.AreEqual ("A", res [0], "#06-02");
4178                 
4179                 res = "..A..".Split (new Char[] { '.' }, 2, StringSplitOptions.RemoveEmptyEntries);
4180                 Assert.AreEqual (1, res.Length, "#07-01");
4181                 Assert.AreEqual ("A", res [0], "#07-02");
4182
4183                 // Lingering Tail
4184                 res = "..A..B..".Split (new Char[] { '.' }, 2, StringSplitOptions.RemoveEmptyEntries);
4185                 Assert.AreEqual (2, res.Length, "#08-01");
4186                 Assert.AreEqual ("A", res [0], "#08-02");
4187                 Assert.AreEqual ("B..", res [1], "#08-03");
4188
4189                 // Whitespace and Long split chain (removing empty chars)
4190                 res = "  A\tBC\n\rDEF    GHI  ".Split ((Char[])null, StringSplitOptions.RemoveEmptyEntries);
4191                 Assert.AreEqual (4, res.Length, "#09-01");
4192                 Assert.AreEqual ("A", res [0], "#09-02");
4193                 Assert.AreEqual ("BC", res [1], "#09-03");
4194                 Assert.AreEqual ("DEF", res [2], "#09-04");
4195                 Assert.AreEqual ("GHI", res [3], "#09-05");
4196
4197                 // Nothing but separators
4198                 res = "..,.;.,".Split (new Char[]{'.',',',';'},2,StringSplitOptions.RemoveEmptyEntries);
4199                 Assert.AreEqual (0, res.Length, "#10-01");
4200
4201                 // Complete testseries
4202                 char[] dash = new Char[] { '/' };
4203                 StringSplitOptions o = StringSplitOptions.RemoveEmptyEntries;
4204                 Assert.AreEqual ("hi", "hi".Split (dash, o)[0], "#11-01");
4205                 Assert.AreEqual ("hi", "hi/".Split (dash, o)[0], "#11-02");
4206                 Assert.AreEqual ("hi", "/hi".Split (dash, o)[0], "#11-03");
4207
4208                 Assert.AreEqual ("hi..", "hi../".Split (dash, o)[0], "#11-04-1");
4209                 Assert.AreEqual ("hi..", "/hi..".Split (dash, o)[0], "#11-04-2");
4210
4211                 res = "/hi/..".Split (dash, o);
4212                 Assert.AreEqual ("hi", res[0], "#11-05-1");
4213                 Assert.AreEqual ("..", res[1], "#11-05-2");
4214                 Assert.AreEqual (2, res.Length, "#11-09-3");
4215
4216                 res = "hi/..".Split (dash, o);
4217                 Assert.AreEqual ("hi", res[0], "#11-06-1");
4218                 Assert.AreEqual ("..", res[1], "#11-06-2");
4219                 Assert.AreEqual (2, res.Length, "#11-09-3");
4220
4221                 res = "hi/../".Split (dash, o);
4222                 Assert.AreEqual ("hi", res[0], "#11-07-1");
4223                 Assert.AreEqual ("..", res[1], "#11-07-2");
4224                 Assert.AreEqual (2, res.Length, "#11-07-3");
4225
4226                 res = "/hi../".Split (dash, o);
4227                 Assert.AreEqual ("hi..", res[0], "#11-08-1");
4228                 Assert.AreEqual (1, res.Length, "#11-08-2");
4229
4230                 res = "/hi/../".Split (dash, o);
4231                 Assert.AreEqual ("hi", res[0], "#11-09-1");
4232                 Assert.AreEqual ("..", res[1], "#11-09-2");
4233                 Assert.AreEqual (2, res.Length, "#11-09-3");
4234
4235                 Assert.AreEqual (0, "    ".Split ((char[]) null, 2, StringSplitOptions.RemoveEmptyEntries).Length, "#12-00-0");
4236                 
4237                 res = "not found".Split (new char[2]);
4238                 Assert.AreEqual ("not found", res[0], "#12-04-27");
4239                 Assert.AreEqual (1, res.Length, "#12-04-27-A");
4240         }
4241         
4242         [Test]
4243         public void SplitStringStrings ()
4244         {
4245                 String[] res;
4246
4247                 // count == 0
4248                 res = "..A..B..".Split (new String[] { "." }, 0, StringSplitOptions.None);
4249                 Assert.AreEqual (0, res.Length, "#01-01");
4250
4251                 // count == 1
4252                 res = "..A..B..".Split (new String[] { "." }, 1, StringSplitOptions.None);
4253                 Assert.AreEqual (1, res.Length, "#02-01");
4254                 Assert.AreEqual ("..A..B..", res [0], "#02-02");
4255
4256                 // count == 1 + RemoveEmpty
4257                 res = "..A..B..".Split (new String[] { "." }, 1, StringSplitOptions.RemoveEmptyEntries);
4258                 Assert.AreEqual (1, res.Length, "#03-01");
4259                 Assert.AreEqual ("..A..B..", res [0], "#03-02");
4260                 
4261                 // Strange Case A+B A
4262                 res = "...".Split (new String[] { "." }, 1, StringSplitOptions.RemoveEmptyEntries);
4263                 Assert.AreEqual (1, res.Length, "#ABA-01");
4264                 Assert.AreEqual ("...", res [0], "#ABA-02");
4265
4266                 // Strange Case A+B B
4267                 res = "...".Split (new String[] { "." }, 2, StringSplitOptions.RemoveEmptyEntries);
4268                 Assert.AreEqual (0, res.Length, "#ABB-01");
4269
4270                 // Keeping Empties and multipe split chars
4271                 res = "..A;.B.;".Split (new String[] { ".", ";" }, StringSplitOptions.None);
4272                 Assert.AreEqual (7, res.Length, "#04-01");
4273                 Assert.AreEqual (string.Empty, res [0], "#04-02");
4274                 Assert.AreEqual (string.Empty, res [1], "#04-03");
4275                 Assert.AreEqual ("A", res [2], "#04-04");
4276                 Assert.AreEqual (string.Empty, res [3], "#04-05");
4277                 Assert.AreEqual ("B", res [4], "#04-06");
4278                 Assert.AreEqual (string.Empty, res [5], "#04-07");
4279                 Assert.AreEqual (string.Empty, res [6], "#04-08");
4280
4281                 // Trimming (3 tests)
4282                 res = "..A".Split (new String[] { "." }, 2, StringSplitOptions.RemoveEmptyEntries);
4283                 Assert.AreEqual (1, res.Length, "#05-01");
4284                 Assert.AreEqual ("A", res [0], "#05-02");
4285                 
4286                 res = "A..".Split (new String[] { "." }, 2, StringSplitOptions.RemoveEmptyEntries);
4287                 Assert.AreEqual (1, res.Length, "#06-01");
4288                 Assert.AreEqual ("A", res [0], "#06-02");
4289                 
4290                 res = "..A..".Split (new String[] { "." }, 2, StringSplitOptions.RemoveEmptyEntries);
4291                 Assert.AreEqual (1, res.Length, "#07-01");
4292                 Assert.AreEqual ("A", res [0], "#07-02");
4293
4294                 // Lingering Tail
4295                 res = "..A..B..".Split (new String[] { "." }, 2, StringSplitOptions.RemoveEmptyEntries);
4296                 Assert.AreEqual (2, res.Length, "#08-01");
4297                 Assert.AreEqual ("A", res [0], "#08-02");
4298                 Assert.AreEqual ("B..", res [1], "#08-03");
4299
4300                 // Whitespace and Long split chain (removing empty chars)
4301                 res = "  A\tBC\n\rDEF    GHI  ".Split ((String[])null, StringSplitOptions.RemoveEmptyEntries);
4302                 Assert.AreEqual (4, res.Length, "#09-01");
4303                 Assert.AreEqual ("A", res [0], "#09-02");
4304                 Assert.AreEqual ("BC", res [1], "#09-03");
4305                 Assert.AreEqual ("DEF", res [2], "#09-04");
4306                 Assert.AreEqual ("GHI", res [3], "#09-05");
4307
4308                 // Nothing but separators
4309                 res = "..,.;.,".Split (new String[]{".",",",";"},2,StringSplitOptions.RemoveEmptyEntries);
4310                 Assert.AreEqual (0, res.Length, "#10-01");
4311
4312                 // Complete testseries
4313                 String[] dash = new String[] { "/" };
4314                 StringSplitOptions o = StringSplitOptions.RemoveEmptyEntries;
4315                 Assert.AreEqual ("hi", "hi".Split (dash, o)[0], "#11-01");
4316                 Assert.AreEqual ("hi", "hi/".Split (dash, o)[0], "#11-02");
4317                 Assert.AreEqual ("hi", "/hi".Split (dash, o)[0], "#11-03");
4318
4319                 Assert.AreEqual ("hi..", "hi../".Split (dash, o)[0], "#11-04-1");
4320                 Assert.AreEqual ("hi..", "/hi..".Split (dash, o)[0], "#11-04-2");
4321
4322                 res = "/hi/..".Split (dash, o);
4323                 Assert.AreEqual ("hi", res[0], "#11-05-1");
4324                 Assert.AreEqual ("..", res[1], "#11-05-2");
4325                 Assert.AreEqual (2, res.Length, "#11-09-3");
4326
4327                 res = "hi/..".Split (dash, o);
4328                 Assert.AreEqual ("hi", res[0], "#11-06-1");
4329                 Assert.AreEqual ("..", res[1], "#11-06-2");
4330                 Assert.AreEqual (2, res.Length, "#11-09-3");
4331
4332                 res = "hi/../".Split (dash, o);
4333                 Assert.AreEqual ("hi", res[0], "#11-07-1");
4334                 Assert.AreEqual ("..", res[1], "#11-07-2");
4335                 Assert.AreEqual (2, res.Length, "#11-07-3");
4336
4337                 res = "/hi../".Split (dash, o);
4338                 Assert.AreEqual ("hi..", res[0], "#11-08-1");
4339                 Assert.AreEqual (1, res.Length, "#11-08-2");
4340
4341                 res = "/hi/../".Split (dash, o);
4342                 Assert.AreEqual ("hi", res[0], "#11-09-1");
4343                 Assert.AreEqual ("..", res[1], "#11-09-2");
4344                 Assert.AreEqual (2, res.Length, "#11-09-3");
4345         }
4346
4347         [Test]
4348         [Category ("NotDotNet")]
4349         public void Normalize1 ()
4350         {
4351                 // .NET does not combine them into U+1F80
4352                 // seealso: http://demo.icu-project.org/icu-bin/nbrowser?t=\u03B1\u0313\u0345
4353                 string s = "\u03B1\u0313\u0345";
4354                 Assert.IsTrue (!s.IsNormalized (NormalizationForm.FormC), "#1");
4355                 Assert.IsTrue (!s.IsNormalized (NormalizationForm.FormKC), "#2");
4356                 Assert.AreEqual ("\u1F80", s.Normalize (NormalizationForm.FormC), "#3");
4357                 Assert.AreEqual ("\u1F80", s.Normalize (NormalizationForm.FormKC), "#4");
4358         }
4359
4360         [Test]
4361         [Category ("NotDotNet")]
4362         public void Normalize2 ()
4363         {
4364                 string s1 = "\u0061\u0301bc";
4365                 string s2 = "\u00e1bc";
4366                 // .NET does not combine \u0061\0301 into \u00E1
4367                 // seealso: http://demo.icu-project.org/icu-bin/nbrowser?t=\u0061\u0301bc
4368                 Assert.AreEqual (s2, s1.Normalize (NormalizationForm.FormC), "#1");
4369                 Assert.AreEqual (s2, s1.Normalize (NormalizationForm.FormKC), "#2");
4370         }
4371
4372         [Test]
4373         public void Normalize3 ()
4374         {
4375                 var s = new string (new char [] { '\u064A', '\u064F', '\u0648', '\u0654', '\u0652', '\u064A', '\u064F', '\u0648', '\u0654' });
4376
4377                 var formC = new string (new char [] { '\u064A', '\u064F', '\u0624', '\u0652', '\u064a', '\u064f', '\u0624' });
4378                 var formD = new string (new char [] { '\u064A', '\u064F', '\u0648', '\u0652', '\u0654', '\u064a', '\u064f', '\u0648', '\u0654' });
4379                 var formKC = new string (new char [] { '\u064A', '\u064F', '\u0624', '\u0652', '\u064a', '\u064f', '\u0624' });
4380                 var formKD = new string (new char [] { '\u064A', '\u064F', '\u0648', '\u0652', '\u0654', '\u064a', '\u064f', '\u0648', '\u0654' });
4381
4382                 Assert.AreEqual (formD, s.Normalize (NormalizationForm.FormD), "#1");
4383                 Assert.AreEqual (formC, s.Normalize (NormalizationForm.FormC), "#2");
4384                 Assert.AreEqual (formKD, s.Normalize (NormalizationForm.FormKD), "#3");
4385                 Assert.AreEqual (formKC, s.Normalize (NormalizationForm.FormKC), "#4");
4386         }
4387
4388         [Test] // bug #480152, test cases by David Mitchell
4389         public void NormalizeFormD ()
4390         {
4391                 Assert.AreEqual ("\u212B".Normalize (NormalizationForm.FormD), "\u0041\u030A", "#1");
4392                 Assert.AreEqual ("\u1E69".Normalize (NormalizationForm.FormD), "\u0073\u0323\u0307", "#2");
4393                 Assert.AreEqual ("\u1e4e".Normalize (NormalizationForm.FormD), "\u004f\u0303\u0308", "#3");
4394                 Assert.AreEqual ("\u1e2f".Normalize (NormalizationForm.FormD), "\u0069\u0308\u0301", "#4");
4395         }
4396
4397         [Test] // bug #480152, test cases by David Mitchell
4398         public void NormalizeFormC ()
4399         {
4400                 Assert.AreEqual ("\u0041\u030a\u0061\u030a".Normalize (NormalizationForm.FormC), "\u00c5\u00e5", "#1");
4401                 Assert.AreEqual ("\u006E\u0303".Normalize (NormalizationForm.FormC), "\u00F1", "#2");
4402                 Assert.AreEqual ("\u03B7\u0313\u0300\u0345".Normalize (NormalizationForm.FormC), "\u1F92", "#3");
4403         }
4404
4405         [Test] // bug #480152, test cases by Tom Philpot
4406         public void NormalizeFormCCrashers ()
4407         {
4408                 string[][] entries = new string[][] {
4409                         new string[] { "\u05d0\u0307\u05dc", "#1" },
4410                         new string[] { "\u05d0\u0307\u05dc\u05d9\u05d9\u05df", "#2" },
4411                         new string[] { "\u05d4\u05d0\u0307\u05dc\u0307\u05d9\u0307\u05df\u0307", "#3" },
4412                         new string[] { "\u05d9\u05e9\u05de\u05e2\u0307\u05d0\u0307\u05dc\u0307", "#4" },
4413                         new string[] { "\u05d9\u05e9\u05e8\u05d0\u0307\u05dc\u0307", "#5" },
4414                 };
4415
4416                 foreach (string[] entry in entries)
4417                         entry [0].Normalize (NormalizationForm.FormC);
4418         }
4419
4420         [Test]
4421         public void NormalizeFormCHangul ()
4422         {
4423                 Assert.AreEqual ("\u1100\u116C".Normalize (NormalizationForm.FormC), "\uAD34", "#1");
4424                 Assert.AreEqual ("\u1100\u116B\u11C2".Normalize (NormalizationForm.FormC), "\uAD33", "#2");
4425                 Assert.AreEqual ("\u1100!".Normalize (NormalizationForm.FormC), "\u1100!", "#3");
4426                 Assert.AreEqual ("\u1100\u116B!".Normalize (NormalizationForm.FormC), "\uAD18\u0021", "#4");
4427                 Assert.AreEqual ("!\u116C".Normalize (NormalizationForm.FormC), "!\u116C", "#5");
4428                 Assert.AreEqual ("!\u116B\u11C2".Normalize (NormalizationForm.FormC), "!\u116B\u11C2", "#6");
4429         }
4430
4431         [Test]
4432         public void MoreNormalizeFormC ()
4433         {
4434                 Assert.AreEqual ("\u1E0A\u0323".Normalize (NormalizationForm.FormC), "\u1E0C\u0307", "#1");
4435                 Assert.AreEqual ("\u0044\u0323\u0307".Normalize (NormalizationForm.FormC), "\u1E0C\u0307", "#2");
4436         }
4437
4438         [Test]
4439         public void Emptiness ()
4440         {
4441                 // note: entries using AreEqual are in reality AreNotSame on MS FX
4442                 // but I prefer Mono implementation ;-) and it minimize the changes
4443                 Assert.AreSame (String.Empty, "", "Empty");
4444
4445                 Assert.AreSame (String.Empty, String.Concat ((object) null), "Concat(null)");
4446                 Assert.AreSame (String.Empty, String.Concat ((object) String.Empty), "Concat(empty)");
4447                 Assert.AreSame (String.Empty, String.Concat ((object) String.Empty, (object) String.Empty), "Concat(object,object)");
4448                 Assert.AreSame (String.Empty, String.Concat (String.Empty, String.Empty), "Concat(string,string)");
4449                 Assert.AreEqual (String.Empty, String.Concat (String.Empty, String.Empty, String.Empty), "Concat(string,string,string)");
4450                 Assert.AreEqual (String.Empty, String.Concat ((object) null, (object) (object) null, (object) null, (object) null), "Concat(null,null,null,null)-object");
4451                 Assert.AreSame (String.Empty, String.Concat ((string) null, (string) (string) null, (string) null, (string) null), "Concat(null,null,null,null)-string");
4452                 Assert.AreNotSame (String.Empty, String.Concat (String.Empty, String.Empty, String.Empty, String.Empty), "Concat(string,string,string,string)");
4453                 Assert.AreEqual (String.Empty, String.Concat (new object [] { String.Empty, String.Empty }), "Concat(object[])");
4454                 Assert.AreEqual (String.Empty, String.Concat (new string [] { String.Empty, String.Empty }), "Concat(string[])");
4455
4456                 Assert.AreNotSame (String.Empty, String.Copy (String.Empty), "Copy");
4457
4458                 Assert.AreEqual (String.Empty, "".Insert (0, String.Empty), "Insert(Empty)");
4459                 Assert.AreEqual (String.Empty, String.Empty.Insert (0, ""), "Empty.Insert");
4460
4461                 Assert.AreSame (String.Empty, String.Empty.PadLeft (0), "PadLeft(int)");
4462                 Assert.AreSame (String.Empty, String.Empty.PadLeft (0, '.'), "PadLeft(int.char)");
4463                 Assert.AreSame (String.Empty, String.Empty.PadRight (0), "PadRight(int)");
4464                 Assert.AreSame (String.Empty, String.Empty.PadRight (0, '.'), "PadRight(int.char)");
4465
4466                 Assert.AreSame (String.Empty, "".Substring (0), "Substring(int)");
4467                 Assert.AreSame (String.Empty, "ab".Substring (1, 0), "Substring(int,int)");
4468
4469                 Assert.AreSame (String.Empty, "".ToLower (), "ToLower");
4470                 Assert.AreSame (String.Empty, "".ToUpper (), "ToUpper");
4471                 Assert.AreSame (String.Empty, "".ToLower (CultureInfo.CurrentCulture), "ToLower(CultureInfo)");
4472                 Assert.AreSame (String.Empty, "".ToUpper (CultureInfo.CurrentCulture), "ToUpper(CultureInfo)");
4473                 Assert.AreSame (String.Empty, "".ToLowerInvariant (), "ToLowerInvariant");
4474                 Assert.AreSame (String.Empty, "".ToUpperInvariant (), "ToUpperInvariant");
4475
4476                 Assert.AreSame (String.Empty, "".Trim (), "Trim()");
4477                 Assert.AreSame (String.Empty, "a".Trim ('a'), "Trim(char)");
4478                 Assert.AreSame (String.Empty, "a".TrimEnd ('a'), "TrimEnd(char)");
4479                 Assert.AreSame (String.Empty, "a".TrimStart ('a'), "TrimStart(char)");
4480         }
4481         
4482         [Test]
4483         public void LastIndexOfAndEmptiness () {
4484                 Assert.AreEqual (-1, "".LastIndexOf('.'), "#1");
4485                 Assert.AreEqual (-1, "".LastIndexOf('.', -1), "#2");
4486                 Assert.AreEqual (-1, "".LastIndexOf('.', -1, -1), "#3");
4487                 Assert.AreEqual (0, "x".LastIndexOf('x', 0), "#4");
4488                 Assert.AreEqual (0 , "x".LastIndexOf('x', 0, 1), "#5");
4489                 Assert.AreEqual (-1 , "x".LastIndexOf('z', 0, 1), "#6");
4490
4491                 try {
4492                         "".LastIndexOf(null);
4493                         Assert.Fail ("#7");
4494                 } catch (ArgumentNullException) {}
4495
4496                 Assert.AreEqual (0, "".LastIndexOf(""), "#8");
4497                 Assert.AreEqual (0, "".LastIndexOf("", -1), "#9");
4498                 Assert.AreEqual (0, "".LastIndexOf("", -1, 1), "#10");
4499                 Assert.AreEqual (0, "".LastIndexOf("", StringComparison.Ordinal), "#11");
4500                 Assert.AreEqual (0, "".LastIndexOf("", -1, StringComparison.Ordinal), "#12");
4501                 Assert.AreEqual (0, "".LastIndexOf("", -1, -1, StringComparison.Ordinal), "#13");
4502                 Assert.AreEqual (0, "x".LastIndexOf(""), "#14");
4503
4504                 Assert.AreEqual (0, "x".LastIndexOf("x", 0), "#15");
4505                 Assert.AreEqual (0, "x".LastIndexOf("", 0), "#16");
4506                 Assert.AreEqual (0, "xxxx".LastIndexOf("", 0), "#17");
4507                 Assert.AreEqual (1, "xxxx".LastIndexOf("", 1), "#18");
4508
4509                 Assert.AreEqual (1, "xy".LastIndexOf(""), "#19");
4510                 Assert.AreEqual (2, "xyz".LastIndexOf(""), "#20");
4511                 Assert.AreEqual (1, "xy".LastIndexOf(""), "#21");
4512                 Assert.AreEqual (1, "xy".LastIndexOf("", 2), "#22");
4513                 Assert.AreEqual (2, "xyz".LastIndexOf("", 2), "#23");
4514                 Assert.AreEqual (2, "xyz".LastIndexOf("", 2, 2), "#24");
4515                 Assert.AreEqual (2, "xyz".LastIndexOf("", 3, 3), "#25");
4516
4517                 try {
4518                         "xy".LastIndexOf("", 29);
4519                         Assert.Fail ("#26");
4520                 }catch (ArgumentOutOfRangeException){}
4521
4522                 Assert.AreEqual (-1, "".LastIndexOf("x"), "#27");
4523                 Assert.AreEqual (-1, "".LastIndexOf("x", -1), "#28");
4524                 Assert.AreEqual (-1, "".LastIndexOf("x", -1), "#29");
4525                 Assert.AreEqual (-1, "".LastIndexOf("x", StringComparison.Ordinal), "#30");
4526                 Assert.AreEqual (-1, "".LastIndexOf("x", -1, StringComparison.Ordinal), "#31");
4527                 Assert.AreEqual (-1, "".LastIndexOf("x", -1, -1, StringComparison.Ordinal), "#32");
4528
4529                 Assert.AreEqual (1, "xx".LastIndexOf("", StringComparison.Ordinal), "#33");
4530                 Assert.AreEqual (1, "xx".LastIndexOf("", 2, StringComparison.Ordinal), "#34");
4531                 Assert.AreEqual (1, "xx".LastIndexOf("", 2, 2, StringComparison.Ordinal), "#35");
4532
4533                 Assert.AreEqual (3, "xxxx".LastIndexOf("", StringComparison.Ordinal), "#36");
4534                 Assert.AreEqual (2, "xxxx".LastIndexOf("", 2, StringComparison.Ordinal), "#37");
4535                 Assert.AreEqual (2, "xxxx".LastIndexOf("", 2, 2, StringComparison.Ordinal), "#38");
4536
4537                 Assert.AreEqual (3, "xxxx".LastIndexOf("", 3, StringComparison.Ordinal), "#39");
4538                 Assert.AreEqual (3, "xxxx".LastIndexOf("", 3, 3, StringComparison.Ordinal), "#40");
4539         }
4540         
4541         
4542         [Test]
4543         public void LastIndexOfAnyAndEmptiness () {
4544                 Assert.AreEqual (-1, "".LastIndexOfAny(new char[] {'.', 'x'}), "#1");
4545                 Assert.AreEqual (-1, "".LastIndexOfAny(new char[] {'.', 'x'}, -1), "#2");
4546                 Assert.AreEqual (-1, "".LastIndexOfAny(new char[] {'.', 'x'}, -1, -1), "#3");
4547         }
4548 }
4549
4550 }