Add this for backwards compatibility
[mono.git] / mcs / class / System / Test / System.Text.RegularExpressions / RegexTrial.cs
1 using System;
2 using System.Text.RegularExpressions;
3
4 namespace MonoTests.System.Text.RegularExpressions {
5
6         class RegexTrial {
7                 public string pattern;
8                 public RegexOptions options;
9                 public string input;
10
11                 public string expected;
12                 public string error = "";
13
14                 public RegexTrial (string pattern, RegexOptions options, string input, string expected) {
15                         this.pattern = pattern;
16                         this.options = options;
17                         this.input = input;
18                         this.expected = expected;
19                 }
20
21                 public string Expected {
22                         get { return expected; }
23                 }
24                 
25                 public string Error {
26                         get {
27                                 return this.error;
28                         }
29                 }
30
31                 public string Execute () {
32                         string result;
33                         try {
34                                 Regex re = new Regex (pattern, options);
35                                 Match m = re.Match (input);
36
37                                 if (m.Success) {
38                                         result = "Pass.";
39
40                                         for (int i = 0; i < m.Groups.Count; ++ i) {
41                                                 Group group = m.Groups[i];
42                                                 
43                                                 result += " Group[" + i + "]=";
44                                                 foreach (Capture cap in group.Captures) {
45                                                         result += "(" + cap.Index + "," + cap.Length + ")";
46                                                 }
47                                         }
48                                 }
49                                 else
50                                         result = "Fail.";
51                         }
52                         catch (Exception e) {
53                                 
54                                 error = e.Message + "\n" + e.StackTrace + "\n\n";
55                                 
56                                 result = "Error.";
57                         }
58
59                         return result;
60                 }
61
62                 public override string ToString () {
63                         return
64                                 "Matching input '" + input +
65                                 "' against pattern '" + pattern +
66                                 "' with options '" + options + "'.";
67                 }
68         }
69
70         class Checksum {
71                 public Checksum () {
72                         this.sum = 0;
73                 }
74
75                 public uint Value {
76                         get { return sum; }
77                 }
78
79                 public void Add (string str) {
80                         for (int i = 0; i < str.Length; ++ i)
81                                 Add (str[i], 16);
82                 }
83
84                 public void Add (uint n) {
85                         Add (n, 32);
86                 }
87
88                 public void Add (ulong n, int bits) {
89                         ulong mask = 1ul << (bits - 1);
90                         for (int i = 0; i < bits; ++ i) {
91                                 Add ((n & mask) != 0);
92                                 mask >>= 1;
93                         }
94                 }
95
96                 public void Add (bool bit) {
97                         bool top = (sum & 0x80000000) != 0;
98                         sum <<= 1;
99                         sum ^= bit ? (uint)1 : (uint)0;
100
101                         if (top)
102                                 sum ^= key;
103                 }
104
105                 private uint sum;
106                 private readonly uint key = 0x04c11db7;
107         }
108 }