public void TestNormalizerAPI() { // instantiate a Normalizer from a CharacterIterator string s = Utility.Unescape("a\u0308\uac00\\U0002f800"); // make s a bit longer and more interesting CharacterIterator iter = new StringCharacterIterator(s + s); //test deprecated constructors Normalizer norm = new Normalizer(iter, NormalizerMode.NFC, 0); if (norm.Next() != 0xe4) { Errln("error in Normalizer(CharacterIterator).next()"); } Normalizer norm2 = new Normalizer(s, NormalizerMode.NFC, 0); if (norm2.Next() != 0xe4) { Errln("error in Normalizer(CharacterIterator).next()"); } // test clone(), ==, and hashCode() Normalizer clone = (Normalizer)norm.Clone(); if (clone.GetBeginIndex() != norm.GetBeginIndex()) { Errln("error in Normalizer.getBeginIndex()"); } if (clone.GetEndIndex() != norm.GetEndIndex()) { Errln("error in Normalizer.getEndIndex()"); } // test setOption() and getOption() clone.SetOption(0xaa0000, true); clone.SetOption(0x20000, false); if (clone.GetOption(0x880000) == 0 || clone.GetOption(0x20000) == 1) { Errln("error in Normalizer::setOption() or Normalizer::getOption()"); } // ICU4N specific - test setting normalizer options via enum clone.UnicodeVersion = NormalizerUnicodeVersion.Unicode3_2; assertEquals("error in Normalizer.UnicodeVersion property", NormalizerUnicodeVersion.Unicode3_2, clone.UnicodeVersion); clone.UnicodeVersion = NormalizerUnicodeVersion.Default; assertEquals("error in Normalizer.UnicodeVersion property", NormalizerUnicodeVersion.Default, clone.UnicodeVersion); //test deprecated normalize method Normalizer.Normalize(s, NormalizerMode.NFC, 0); //test deprecated compose method Normalizer.Compose(s, false, 0); //test deprecated decompose method Normalizer.Decompose(s, false, 0); }
public void TestRoundTrip() { int options = Normalizer.IGNORE_HANGUL; bool compat = false; ComposedCharIter iter = new ComposedCharIter(false, options); while (iter.HasNext) { char ch = iter.Next(); string chStr = "" + ch; string decomp = iter.Decomposition(); string comp = Normalizer.Compose(decomp, compat); if (UChar.HasBinaryProperty(ch, UProperty.Full_Composition_Exclusion)) { Logln("Skipped excluded char " + Hex(ch) + " (" + UChar.GetName(ch) + ")"); continue; } // Avoid disparaged characters if (decomp.Length == 4) { continue; } if (!comp.Equals(chStr)) { Errln("ERROR: Round trip invalid: " + Hex(chStr) + " --> " + Hex(decomp) + " --> " + Hex(comp)); Errln(" char decomp is '" + decomp + "'"); } } }
private void CharacterTest(string s, int ch, CanonicalIterator it) { int mixedCounter = 0; int lastMixedCounter = -1; bool gotDecomp = false; bool gotComp = false; bool gotSource = false; string decomp = Normalizer.Decompose(s, false); string comp = Normalizer.Compose(s, false); // skip characters that don't have either decomp. // need quick test for this! if (s.Equals(decomp) && s.Equals(comp)) { return; } it.SetSource(s); while (true) { string item = it.Next(); if (item == null) { break; } if (item.Equals(s)) { gotSource = true; } if (item.Equals(decomp)) { gotDecomp = true; } if (item.Equals(comp)) { gotComp = true; } if ((mixedCounter & 0x7F) == 0 && (ch < 0xAD00 || ch > 0xAC00 + 11172)) { if (lastMixedCounter != mixedCounter) { Logln(""); lastMixedCounter = mixedCounter; } Logln("\t" + mixedCounter + "\t" + Hex(item) + (item.Equals(s) ? "\t(*original*)" : "") + (item.Equals(decomp) ? "\t(*decomp*)" : "") + (item.Equals(comp) ? "\t(*comp*)" : "") ); } } // check that zeros optimization doesn't mess up. /* * if (true) { * it.reset(); * itSet.clear(); * while (true) { * String item = it.next(); * if (item == null) break; * itSet.add(item); * } * slowIt.setSource(s); * slowItSet.clear(); * while (true) { * String item = slowIt.next(); * if (item == null) break; * slowItSet.add(item); * } * if (!itSet.equals(slowItSet)) { * errln("Zero optimization failure with " + getReadable(s)); * } * } */ mixedCounter++; if (!gotSource || !gotDecomp || !gotComp) { Errln("FAIL CanonicalIterator: " + s + " decomp: " + decomp + " comp: " + comp); it.Reset(); for (string item = it.Next(); item != null; item = it.Next()) { Err(item + " "); } Errln(""); } }