processed with astyle
[mono.git] / mcs / class / System / Test / System.Text.RegularExpressions / RegexResultTests.cs
1 using System;
2 using System.Text;
3 using System.Text.RegularExpressions;
4 using NUnit.Framework;
5
6 namespace MonoTests.System.Text.RegularExpressions
7 {
8 [TestFixture]
9 public class RegexResultTests
10 {
11
12     struct testcase
13     {
14         public string original, pattern, replacement, expected;
15         public testcase (string o, string p, string r, string e) {
16             original = o;
17             pattern = p;
18             replacement = r;
19             expected = e;
20         }
21         public void Execute () {
22             string result;
23             try {
24                 Match match = Regex.Match (original, pattern);
25                 result = match.Result (replacement);
26             }
27             catch (Exception e) {
28                 result = "Error.";
29             }
30             Assert.AreEqual (expected, result, "rr#: {0} ~ s,{1},{2},",
31                              original, pattern, replacement);
32
33         }
34     }
35     static testcase [] tests = {
36         //      original        pattern                 replacement             expected
37         new testcase ("F2345678910L71", @"(F)(2)(3)(4)(5)(6)(7)(8)(9)(10)(L)\11",       "${S}$11$1", "Error."   ),//0
38         new testcase ("F2345678910LL1", @"(F)(2)(3)(4)(5)(6)(7)(8)(9)(10)(L)\11",       "${S}$11$1", "${S}LF"   ),//1
39         new testcase ("texts",  "(?<foo>e)(x)",         "${foo}$1$2$&",         "exeex"         ),//2
40         new testcase ("texts",  "(?<foo>e)(x)",         "${foo}$1$2$_",         "exetexts"      ),//3
41         new testcase ("texts",  "(?<foo>e)(x)",         "${foo}$1$2$`",         "exet"  ),//4
42         new testcase ("texts",  "(?<foo>e)(x)",         "${foo}$1$2$'",         "exets"         ),//5
43         new testcase ("text",   "x",                    "y",                    "y"             ),//6
44         new testcase ("text",   "x",                    "$",                    "$"             ),//7
45         new testcase ("text",   "x",                    "$1",                   "$1"            ),//8
46         new testcase ("text",   "x",                    "${1}",                 "${1}"  ),//9
47         new testcase ("text",   "x",                    "$5",                   "$5"            ),//10
48         new testcase ("te(x)t", "x",                    "$5",                   "$5"    ),//11
49         new testcase ("text",   "x",                    "${5",                  "${5"   ),//12
50         new testcase ("text",   "x",                    "${foo",                "${foo" ),//13
51         new testcase ("text",   "(x)",                  "$5",                   "$5"            ),//14
52         new testcase ("text",   "(x)",                  "$1",                   "x"             ),//15
53         new testcase ("text",   "e(x)",                 "$1",                   "x"             ),//16
54         new testcase ("text",   "e(x)",                 "$5",                   "$5"            ),//17
55         new testcase ("text",   "e(x)",                 "$4",                   "$4"            ),//18
56         new testcase ("text",   "e(x)",                 "$3",                   "$3"            ),//19
57         new testcase ("text",   "e(x)",                 "${1}",                 "x"             ),//20
58         new testcase ("text",   "e(x)",                 "${3}",                 "${3}"  ),//21
59         new testcase ("text",   "e(x)",                 "${1}${3}",             "x${3}" ),//22
60         new testcase ("text",   "e(x)",                 "${1}${name}",          "x${name}"      ),//23
61         new testcase ("text",   "e(?<foo>x)",           "${1}${name}",          "x${name}"      ),//24
62         new testcase ("text",   "e(?<foo>x)",           "${1}${foo}",           "xx"            ),//25
63         new testcase ("text",   "e(?<foo>x)",           "${goll}${foo}",        "${goll}x"      ),//26
64         new testcase ("text",   "e(?<foo>x)",           "${goll${foo}",         "${gollx"       ),//27
65         new testcase ("text",   "e(?<foo>x)",           "${goll${foo}}",        "${gollx}"      ),//28
66         new testcase ("text",   "e(?<foo>x)",           "$${foo}}",             "${foo}}"       ),//29
67         new testcase ("text",   "e(?<foo>x)",           "${${foo}}",            "${x}"  ),//30
68         new testcase ("text",   "e(?<foo>x)",           "$${foo}}",             "${foo}}"       ),//31
69         new testcase ("text",   "e(?<foo>x)",           "$${bfoo}}",            "${bfoo}}"      ),//32
70         new testcase ("text",   "e(?<foo>x)",           "$${foo}}",             "${foo}}"       ),//33
71         new testcase ("text",   "e(?<foo>x)",           "$${foo}",              "${foo}"        ),//34
72         new testcase ("text",   "e(?<foo>x)",           "$$",                   "$"             ),//35
73         new testcase ("text",   "(?<foo>e)(?<foo>x)",   "${foo}$1$2",           "xx$2"  ),//36
74         new testcase ("text",   "(e)(?<foo>x)",         "${foo}$1$2",           "xex"   ),//37
75         new testcase ("text",   "(?<foo>e)(x)",         "${foo}$1$2",           "exe"   ),//38
76         new testcase ("text",   "(e)(?<foo>x)",         "${foo}$1$2$+",         "xexx"  ),//39
77         new testcase ("text",   "(?<foo>e)(x)",         "${foo}$1$2$+",         "exee"  ),//40
78         new testcase ("314 1592 65358",         @"\d\d\d\d|\d\d\d", "a",        "a"     ),//41
79         new testcase ("2 314 1592 65358",       @"\d\d\d\d|\d\d\d", "a",        "a"     ),//42
80         new testcase ("<i>am not</i>",          "<(.+?)>",      "[$0:$1]",      "[<i>:i]"),//43
81         new testcase ("F2345678910L71", @"(F)(2)(3)(4)(5)(6)(?<S>7)(8)(9)(10)(L)\11",   "${S}$11$1", "77F"      ),//44
82         new testcase ("a", "a", @"\\", @"\\"), // bug #317092 //45
83     };
84
85     [Test]
86     public void ResultTest_000 () {
87         tests [0].Execute ();
88     }
89     [Test]
90     public void ResultTest_001 () {
91         tests [1].Execute ();
92     }
93     [Test]
94     public void ResultTest_002 () {
95         tests [2].Execute ();
96     }
97     [Test]
98     public void ResultTest_003 () {
99         tests [3].Execute ();
100     }
101     [Test]
102     public void ResultTest_004 () {
103         tests [4].Execute ();
104     }
105     [Test]
106     public void ResultTest_005 () {
107         tests [5].Execute ();
108     }
109     [Test]
110     public void ResultTest_006 () {
111         tests [6].Execute ();
112     }
113     [Test]
114     public void ResultTest_007 () {
115         tests [7].Execute ();
116     }
117     [Test]
118     public void ResultTest_008 () {
119         tests [8].Execute ();
120     }
121     [Test]
122     public void ResultTest_009 () {
123         tests [9].Execute ();
124     }
125     [Test]
126     public void ResultTest_010 () {
127         tests [10].Execute ();
128     }
129     [Test]
130     public void ResultTest_011 () {
131         tests [11].Execute ();
132     }
133     [Test]
134     public void ResultTest_012 () {
135         tests [12].Execute ();
136     }
137     [Test]
138     public void ResultTest_013 () {
139         tests [13].Execute ();
140     }
141     [Test]
142     public void ResultTest_014 () {
143         tests [14].Execute ();
144     }
145     [Test]
146     public void ResultTest_015 () {
147         tests [15].Execute ();
148     }
149     [Test]
150     public void ResultTest_016 () {
151         tests [16].Execute ();
152     }
153     [Test]
154     public void ResultTest_017 () {
155         tests [17].Execute ();
156     }
157     [Test]
158     public void ResultTest_018 () {
159         tests [18].Execute ();
160     }
161     [Test]
162     public void ResultTest_019 () {
163         tests [19].Execute ();
164     }
165     [Test]
166     public void ResultTest_020 () {
167         tests [20].Execute ();
168     }
169     [Test]
170     public void ResultTest_021 () {
171         tests [21].Execute ();
172     }
173     [Test]
174     public void ResultTest_022 () {
175         tests [22].Execute ();
176     }
177     [Test]
178     public void ResultTest_023 () {
179         tests [23].Execute ();
180     }
181     [Test]
182     public void ResultTest_024 () {
183         tests [24].Execute ();
184     }
185     [Test]
186     public void ResultTest_025 () {
187         tests [25].Execute ();
188     }
189     [Test]
190     public void ResultTest_026 () {
191         tests [26].Execute ();
192     }
193     [Test]
194     public void ResultTest_027 () {
195         tests [27].Execute ();
196     }
197     [Test]
198     public void ResultTest_028 () {
199         tests [28].Execute ();
200     }
201     [Test]
202     public void ResultTest_029 () {
203         tests [29].Execute ();
204     }
205     [Test]
206     public void ResultTest_030 () {
207         tests [30].Execute ();
208     }
209     [Test]
210     public void ResultTest_031 () {
211         tests [31].Execute ();
212     }
213     [Test]
214     public void ResultTest_032 () {
215         tests [32].Execute ();
216     }
217     [Test]
218     public void ResultTest_033 () {
219         tests [33].Execute ();
220     }
221     [Test]
222     public void ResultTest_034 () {
223         tests [34].Execute ();
224     }
225     [Test]
226     public void ResultTest_035 () {
227         tests [35].Execute ();
228     }
229     [Test]
230     public void ResultTest_036 () {
231         tests [36].Execute ();
232     }
233     [Test]
234     public void ResultTest_037 () {
235         tests [37].Execute ();
236     }
237     [Test]
238     public void ResultTest_038 () {
239         tests [38].Execute ();
240     }
241     [Test]
242     public void ResultTest_039 () {
243         tests [39].Execute ();
244     }
245     [Test]
246     public void ResultTest_040 () {
247         tests [40].Execute ();
248     }
249     [Test]
250     public void ResultTest_041 () {
251         tests [41].Execute ();
252     }
253     [Test]
254     public void ResultTest_042 () {
255         tests [42].Execute ();
256     }
257     [Test]
258     public void ResultTest_043 () {
259         tests [43].Execute ();
260     }
261     [Test]
262     [Category("NotWorking")]
263     public void ResultTest_044 () {
264         tests [44].Execute ();
265     }
266     [Test]
267     public void ResultTest_045 () {
268         tests [45].Execute ();
269     }
270 }
271 }