* MonoTouch/MonoPInvokeCallbackAttribute.cs: Added.
[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 () { tests [0].Execute (); }
87                 [Test]
88                 public void ResultTest_001 () { tests [1].Execute (); }
89                 [Test]
90                 public void ResultTest_002 () { tests [2].Execute (); }
91                 [Test]
92                 public void ResultTest_003 () { tests [3].Execute (); }
93                 [Test]
94                 public void ResultTest_004 () { tests [4].Execute (); }
95                 [Test]
96                 public void ResultTest_005 () { tests [5].Execute (); }
97                 [Test]
98                 public void ResultTest_006 () { tests [6].Execute (); }
99                 [Test]
100                 public void ResultTest_007 () { tests [7].Execute (); }
101                 [Test]
102                 public void ResultTest_008 () { tests [8].Execute (); }
103                 [Test]
104                 public void ResultTest_009 () { tests [9].Execute (); }
105                 [Test]
106                 public void ResultTest_010 () { tests [10].Execute (); }
107                 [Test]
108                 public void ResultTest_011 () { tests [11].Execute (); }
109                 [Test]
110                 public void ResultTest_012 () { tests [12].Execute (); }
111                 [Test]
112                 public void ResultTest_013 () { tests [13].Execute (); }
113                 [Test]
114                 public void ResultTest_014 () { tests [14].Execute (); }
115                 [Test]
116                 public void ResultTest_015 () { tests [15].Execute (); }
117                 [Test]
118                 public void ResultTest_016 () { tests [16].Execute (); }
119                 [Test]
120                 public void ResultTest_017 () { tests [17].Execute (); }
121                 [Test]
122                 public void ResultTest_018 () { tests [18].Execute (); }
123                 [Test]
124                 public void ResultTest_019 () { tests [19].Execute (); }
125                 [Test]
126                 public void ResultTest_020 () { tests [20].Execute (); }
127                 [Test]
128                 public void ResultTest_021 () { tests [21].Execute (); }
129                 [Test]
130                 public void ResultTest_022 () { tests [22].Execute (); }
131                 [Test]
132                 public void ResultTest_023 () { tests [23].Execute (); }
133                 [Test]
134                 public void ResultTest_024 () { tests [24].Execute (); }
135                 [Test]
136                 public void ResultTest_025 () { tests [25].Execute (); }
137                 [Test]
138                 public void ResultTest_026 () { tests [26].Execute (); }
139                 [Test]
140                 public void ResultTest_027 () { tests [27].Execute (); }
141                 [Test]
142                 public void ResultTest_028 () { tests [28].Execute (); }
143                 [Test]
144                 public void ResultTest_029 () { tests [29].Execute (); }
145                 [Test]
146                 public void ResultTest_030 () { tests [30].Execute (); }
147                 [Test]
148                 public void ResultTest_031 () { tests [31].Execute (); }
149                 [Test]
150                 public void ResultTest_032 () { tests [32].Execute (); }
151                 [Test]
152                 public void ResultTest_033 () { tests [33].Execute (); }
153                 [Test]
154                 public void ResultTest_034 () { tests [34].Execute (); }
155                 [Test]
156                 public void ResultTest_035 () { tests [35].Execute (); }
157                 [Test]
158                 public void ResultTest_036 () { tests [36].Execute (); }
159                 [Test]
160                 public void ResultTest_037 () { tests [37].Execute (); }
161                 [Test]
162                 public void ResultTest_038 () { tests [38].Execute (); }
163                 [Test]
164                 public void ResultTest_039 () { tests [39].Execute (); }
165                 [Test]
166                 public void ResultTest_040 () { tests [40].Execute (); }
167                 [Test]
168                 public void ResultTest_041 () { tests [41].Execute (); }
169                 [Test]
170                 public void ResultTest_042 () { tests [42].Execute (); }
171                 [Test]
172                 public void ResultTest_043 () { tests [43].Execute (); }
173                 [Test]
174                 [Category("NotWorking")]
175                 public void ResultTest_044 () { tests [44].Execute (); }
176                 [Test]
177                 public void ResultTest_045 () { tests [45].Execute (); }
178         }
179 }