public void TestReset() { String text = "abc"; CollationElementIterator iterator = coll .GetCollationElementIterator(text); int[] orders = new int[text.Length]; int order = iterator.Next(); int i = 0; while (order != CollationElementIterator.NULLORDER) { orders[i++] = order; order = iterator.Next(); } int offset = iterator.GetOffset(); NUnit.Framework.Assert.AreEqual(text.Length, offset); iterator.Reset(); NUnit.Framework.Assert.AreEqual(0, iterator.GetOffset()); }
public void TestDiscontiguous() { String rulestr = "&z < AB < X\u0300 < ABC < X\u0300\u0315"; String[] src = { "ADB", "ADBC", "A\u0315B", "A\u0315BC", // base character blocked "XD\u0300", "XD\u0300\u0315", // non blocking combining character "X\u0319\u0300", "X\u0319\u0300\u0315", // blocking combining character "X\u0314\u0300", "X\u0314\u0300\u0315", // contraction prefix "ABDC", "AB\u0315C", "X\u0300D\u0315", "X\u0300\u0319\u0315", "X\u0300\u031A\u0315", // ends not with a contraction character "X\u0319\u0300D", "X\u0319\u0300\u0315D", "X\u0300D\u0315D", "X\u0300\u0319\u0315D", "X\u0300\u031A\u0315D" }; String[] tgt = // non blocking combining character { "A D B", "A D BC", "A \u0315 B", "A \u0315 BC", // base character blocked "X D \u0300", "X D \u0300\u0315", // non blocking combining character "X\u0300 \u0319", "X\u0300\u0315 \u0319", // blocking combining character "X \u0314 \u0300", "X \u0314 \u0300\u0315", // contraction prefix "AB DC", "AB \u0315 C", "X\u0300 D \u0315", "X\u0300\u0315 \u0319", "X\u0300 \u031A \u0315", // ends not with a contraction character "X\u0300 \u0319D", "X\u0300\u0315 \u0319D", "X\u0300 D\u0315D", "X\u0300\u0315 \u0319D", "X\u0300 \u031A\u0315D" }; int count = 0; try { RuleBasedCollator coll = new RuleBasedCollator(rulestr); CollationElementIterator iter = coll.GetCollationElementIterator(""); CollationElementIterator resultiter = coll.GetCollationElementIterator(""); while (count < src.Length) { iter.SetText(src[count]); int s = 0; while (s < tgt[count].Length) { int e = tgt[count].IndexOf(' ', s); if (e < 0) { e = tgt[count].Length; } String resultstr = tgt[count].Substring(s, e - s); // ICU4N: Corrected 2nd parameter resultiter.SetText(resultstr); int ce = resultiter.Next(); while (ce != CollationElementIterator.NULLORDER) { if (ce != iter.Next()) { Errln("Discontiguos contraction test mismatch at" + count); return; } ce = resultiter.Next(); } s = e + 1; } iter.Reset(); CollationTest.BackAndForth(this, iter); count++; } } catch (Exception e) { Warnln("Error running discontiguous tests " + e.ToString()); } }
public void TestSetText(/* char* par */) { RuleBasedCollator en_us = (RuleBasedCollator)Collator.GetInstance(new CultureInfo("en-US")); CollationElementIterator iter1 = en_us.GetCollationElementIterator(test1); CollationElementIterator iter2 = en_us.GetCollationElementIterator(test2); // Run through the second iterator just to exercise it int c = iter2.Next(); int i = 0; while (++i < 10 && c != CollationElementIterator.NULLORDER) { try { c = iter2.Next(); } catch (Exception e) { Errln("iter2.Next() returned an error."); break; } } // Now set it to point to the same string as the first iterator try { iter2.SetText(test1); } catch (Exception e) { Errln("call to iter2->setText(test1) failed."); return; } assertEqual(iter1, iter2); iter1.Reset(); //now use the overloaded setText(ChracterIterator&, UErrorCode) function to set the text CharacterIterator chariter = new StringCharacterIterator(test1); try { iter2.SetText(chariter); } catch (Exception e) { Errln("call to iter2->setText(chariter(test1)) failed."); return; } assertEqual(iter1, iter2); iter1.Reset(); //now use the overloaded setText(ChracterIterator&, UErrorCode) function to set the text UCharacterIterator uchariter = UCharacterIterator.GetInstance(test1); try { iter2.SetText(uchariter); } catch (Exception e) { Errln("call to iter2->setText(uchariter(test1)) failed."); return; } assertEqual(iter1, iter2); }