[bcl]Add test for CultureInfo.DefaultThreadCurrentCulture
[mono.git] / mcs / class / corlib / Test / System.Globalization / StringInfoTest.cs
1 //
2 // StringInfoTest.cs
3 //
4 // Author:
5 //      Atsushi Enomoto  <atsushi@ximian.com>
6 //
7 // Copyright (C) 2007 Novell, Inc (http://www.novell.com)
8 //
9
10 using NUnit.Framework;
11 using System;
12 using System.Globalization;
13 using System.IO;
14 using System.Runtime.Serialization;
15 using System.Runtime.Serialization.Formatters.Binary;
16
17 namespace MonoTests.System.Globalization
18 {
19
20         [TestFixture]
21         public class StringInfoTest
22         {
23                 [Test]
24                 public void GetNextTextElement ()
25                 {
26                         Assert.AreEqual ("A", StringInfo.GetNextTextElement ("ABC", 0), "#1");
27                         Assert.AreEqual ("C", StringInfo.GetNextTextElement ("ABC", 2), "#2");
28                         Assert.AreEqual ("A\u0330", StringInfo.GetNextTextElement ("A\u0330BC", 0), "#3");
29                         Assert.AreEqual ("B", StringInfo.GetNextTextElement ("A\u0330BC", 2), "#4");
30
31                         // hmm ...
32 #if NET_2_0 // it causes ArgumentOutOfRangeException in 1.x, not worthy to test it anymore
33                         Assert.AreEqual (String.Empty, StringInfo.GetNextTextElement ("A\u0330BC", 4), "#4");
34 #endif
35                 }
36
37                 [Test]
38                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
39                 public void GetNextTextElementOutOfRange1 ()
40                 {
41                         StringInfo.GetNextTextElement ("ABC", -1);
42                 }
43
44 #if NET_2_0
45                 [Test]
46                 public void LengthInTextElements ()
47                 {
48                         Assert.AreEqual (3, new StringInfo ("ABC").LengthInTextElements, "#1");
49                         Assert.AreEqual (5, new StringInfo (" ABC ").LengthInTextElements, "#2");
50                         Assert.AreEqual (3, new StringInfo ("A\u0330BC\u0330").LengthInTextElements, "#3");
51                         Assert.AreEqual (3, new StringInfo ("A\u0330\u0331BC\u0330").LengthInTextElements, "#4");
52                 }
53
54                 [Test]
55                 public void SubstringByTextElements ()
56                 {
57                         StringInfo si = new StringInfo ("A\u0330BC\u0330");
58                         Assert.AreEqual ("A\u0330BC\u0330", si.SubstringByTextElements (0), "#1");
59                         Assert.AreEqual ("BC\u0330", si.SubstringByTextElements (1), "#2");
60                         Assert.AreEqual ("C\u0330", si.SubstringByTextElements (2), "#3");
61                 }
62
63                 [Test]
64                 public void DefaultConstructor ()
65                 {
66                         var info = new StringInfo ();
67                         Assert.AreEqual (string.Empty, info.String);
68                 }
69
70                 [Test]
71                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
72                 public void SubstringByTextElementsOutOfRange1 ()
73                 {
74                         new StringInfo ("A\u0330BC\u0330").SubstringByTextElements (-1);
75                 }
76
77                 [Test]
78                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
79                 public void SubstringByTextElementsOutOfRange2 ()
80                 {
81                         new StringInfo ("A\u0330BC\u0330").SubstringByTextElements (4);
82                 }
83
84                 [Test]
85                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
86                 public void SubstringByTextElementsOutOfRange3 ()
87                 {
88                         new StringInfo (String.Empty).SubstringByTextElements (0);
89                 }
90 #endif
91         }
92
93 }