[Mono.Posix] Add Syscall.getgrouplist().
[mono.git] / mcs / class / System / Test / System.Text.RegularExpressions / RegexTrial.cs
1 using System;
2 using System.Text.RegularExpressions;
3
4 using NUnit.Framework;
5
6 namespace MonoTests.System.Text.RegularExpressions {
7
8         class RegexTrial {
9                 public string pattern;
10                 public RegexOptions options;
11                 public string input;
12
13                 public string expected;
14                 public string error = "";
15
16                 public RegexTrial (string pattern, RegexOptions options, string input, string expected)
17                 {
18                         this.pattern = pattern;
19                         this.options = options;
20                         this.input = input;
21                         this.expected = expected;
22                 }
23
24                 public string Expected {
25                         get { return expected; }
26                 }
27                 
28                 public string Error {
29                         get { return this.error; }
30                 }
31
32                 public void Execute ()
33                 {
34                         string result;
35
36                         for (int compiled = 0; compiled < 2; ++compiled) {
37                                 RegexOptions real_options = (compiled == 1) ? (options | RegexOptions.Compiled) : options;
38                                 try {
39                                         Regex re = new Regex (pattern, real_options);
40                                         int [] group_nums = re.GetGroupNumbers ();
41                                         Match m = re.Match (input);
42
43                                         if (m.Success) {
44                                                 result = "Pass.";
45
46                                                 for (int i = 0; i < m.Groups.Count; ++ i) {
47                                                         int gid = group_nums [i];
48                                                         Group group = m.Groups [gid];
49
50                                                         result += " Group[" + gid + "]=";
51                                                         foreach (Capture cap in group.Captures)
52                                                                 result += "(" + cap.Index + "," + cap.Length + ")";
53                                                 }
54                                         } else {
55                                                 result = "Fail.";
56                                         }
57                                 }
58                                 catch (Exception e) {
59                                         error = e.Message + "\n" + e.StackTrace + "\n\n";
60
61                                         result = "Error.";
62                                 }
63
64                                 Assert.AreEqual (expected, result,
65                                                                  "Matching input '{0}' against pattern '{1}' with options '{2}'", input, pattern, real_options);
66                         }
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 }