2 using System.Collections;
3 using System.Globalization;
7 namespace Mono.Globalization.Unicode
9 public class NormalizationTestGenerator
11 public static void Main ()
13 new NormalizationTestGenerator ().Run ();
18 ArrayList tests = new ArrayList ();
23 using (StreamReader sr = new StreamReader ("downloaded/NormalizationTest.txt")) {
24 for (line = 1; sr.Peek () >= 0; line++) {
25 ProcessLine (sr.ReadLine ());
29 Console.Error.WriteLine ("Error at line {0}", line);
33 TextWriter Output = new StringWriter ();
34 foreach (Testcase test in tests) {
35 Output.Write ("tests.Add (new Testcase (");
36 foreach (string data in test.Data) {
38 foreach (char c in data)
39 Output.Write ("\\u{0:X04}", (int) c);
40 Output.Write ("\", ");
42 Output.WriteLine ("{0}));", test.TestType);
45 StreamReader template = new StreamReader ("StringNormalizationTestSource.cs");
46 string ret = template.ReadToEnd ();
47 ret = ret.Replace ("@@@@@@ Replace Here @@@@@@", Output.ToString ());
48 Console.WriteLine (ret);
54 public string [] Data;
56 public Testcase (int type, string [] data)
63 void ProcessLine (string s)
65 int idx = s.IndexOf ('#');
67 s = s.Substring (0, idx);
70 if (s [0] == '@') { // @Part0-3
75 string [] parts = s.Split (';');
76 string [] data = new string [5];
78 for (int form = 0; form < 5; form++) {
79 string [] values = parts [form].Split (' ');
80 char [] raw = new char [values.Length];
81 for (int i = 0; i < raw.Length; i++) {
82 int x = int.Parse (values [i].Trim (),
83 NumberStyles.HexNumber);
84 if (x > char.MaxValue) {
85 Console.Error.WriteLine ("at line {0} test contains character {1:X} that is larger than char.MaxValue. Ignored.", line, x);
93 data [form] = new string (raw);
97 tests.Add (new Testcase (type, data));