static void runTrial (MatchCollectionTrial t, bool rtl) { int i; MatchCollection mc; string name = t.name; if (rtl) name += "-rtl"; int len = t.matches.Length; Regex r = new Regex (t.regex, rtl ? RegexOptions.RightToLeft : RegexOptions.None); // Incremental mode -- this access mc = r.Matches (t.text); for (i = 0; i < len; ++i) Assert.AreEqual (mc [i].Value, t.matches [rtl ? len - i - 1 : i], "{0}:this:{1}", name, i); Assert.AreEqual (i, mc.Count, "{0}:this:count", name); // Incremental mode -- enumerator mc = r.Matches (t.text); i = 0; foreach (Match m in mc) { Assert.AreEqual (m.Value, t.matches [rtl ? len - i - 1 : i], "{0}:enum:{1}", name, i); ++i; } Assert.AreEqual (i, len, "{0}:enum:count", name); // random mode Random rng = new Random (); for (int j = 0; j < len * 5; ++j) { i = rng.Next (len); Assert.AreEqual (mc [i].Value, t.matches [rtl ? len - i - 1 : i], "{0}:random{1}:{2}", name, j, i); } // Non-incremental mode mc = r.Matches (t.text); Assert.AreEqual (mc.Count, len); i = 0; foreach (Match m in mc) { Assert.AreEqual (m.Value, t.matches [rtl ? len - i - 1 : i], "{0}:nienum:{1}", name, i); ++i; } for (i = 0; i < len; ++i) Assert.AreEqual (mc [i].Value, t.matches [rtl ? len - i - 1 : i], "{0}:nithis:{1}", name, i); }
static void runTrial (MatchCollectionTrial t) { runTrial (t, false); runTrial (t, true); }
static void runTrial(MatchCollectionTrial t, bool rtl, bool compiled) { int i; MatchCollection mc; string name = t.name; if (rtl) { name += "-rtl"; } int len = t.matches.Length; RegexOptions options = rtl ? RegexOptions.RightToLeft : RegexOptions.None; if (compiled) { options |= RegexOptions.Compiled; } Regex r = new Regex(t.regex, options); // Incremental mode -- this access mc = r.Matches(t.text); for (i = 0; i < len; ++i) { Assert.AreEqual(mc [i].Value, t.matches [rtl ? len - i - 1 : i], "{0}:this:{1}", name, i); } Assert.AreEqual(i, mc.Count, "{0}:this:count", name); // Incremental mode -- enumerator mc = r.Matches(t.text); i = 0; foreach (Match m in mc) { Assert.AreEqual(m.Value, t.matches [rtl ? len - i - 1 : i], "{0}:enum:{1}", name, i); ++i; } Assert.AreEqual(i, len, "{0}:enum:count", name); // random mode Random rng = new Random(); for (int j = 0; j < len * 5; ++j) { i = rng.Next(len); Assert.AreEqual(mc [i].Value, t.matches [rtl ? len - i - 1 : i], "{0}:random{1}:{2}", name, j, i); } // Non-incremental mode mc = r.Matches(t.text); Assert.AreEqual(mc.Count, len); i = 0; foreach (Match m in mc) { Assert.AreEqual(m.Value, t.matches [rtl ? len - i - 1 : i], "{0}:nienum:{1}", name, i); ++i; } for (i = 0; i < len; ++i) { Assert.AreEqual(mc [i].Value, t.matches [rtl ? len - i - 1 : i], "{0}:nithis:{1}", name, i); } }
static void runTrial(MatchCollectionTrial t, bool compiled) { runTrial(t, false, compiled); runTrial(t, true, compiled); }
static void runTrial (MatchCollectionTrial t, bool compiled) { runTrial (t, false, compiled); runTrial (t, true, compiled); }
static void runTrial(MatchCollectionTrial t) { runTrial(t, false); runTrial(t, true); }