private void doTestComposedChars(bool compat) { int options = Normalizer.IGNORE_HANGUL; ComposedCharIter iter = new ComposedCharIter(compat, options); char lastChar = (char)0; while (iter.HasNext) { char ch = iter.Next(); // Test all characters between the last one and this one to make // sure that they don't have decompositions assertNoDecomp(lastChar, ch, compat, options); lastChar = ch; // Now make sure that the decompositions for this character // make sense String chString = new StringBuffer().Append(ch).ToString(); String iterDecomp = iter.Decomposition(); String normDecomp = Normalizer.Decompose(chString, compat); if (iterDecomp.Equals(chString)) { Errln("ERROR: " + Hex(ch) + " has identical decomp"); } else if (!iterDecomp.Equals(normDecomp)) { Errln("ERROR: Normalizer decomp for " + Hex(ch) + " (" + Hex(normDecomp) + ")" + " != iter decomp (" + Hex(iterDecomp) + ")"); } } assertNoDecomp(lastChar, '\uFFFF', compat, options); }
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); }
void assertNoDecomp(char start, char limit, bool compat, int options) { for (char x = ++start; x < limit; x++) { String xString = new StringBuffer().Append(x).ToString(); String decomp = Normalizer.Decompose(xString, compat); if (!decomp.Equals(xString)) { Errln("ERROR: " + Hex(x) + " has decomposition (" + Hex(decomp) + ")" + " but was not returned by iterator"); } } }
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(""); } }
public void TestJB1401() { Collator myCollator = null; char[] NFD_UnsafeStartChars = { (char)0x0f73, // Tibetan Vowel Sign II (char)0x0f75, // Tibetan Vowel Sign UU (char)0x0f81, // Tibetan Vowel Sign Reversed II (char)0 }; int i; try { myCollator = Collator.GetInstance(new CultureInfo("en") /* Locale.ENGLISH */); } catch (Exception e) { Errln("ERROR: Failed to create the collator for ENGLISH"); return; } myCollator.Decomposition = (Collator.CANONICAL_DECOMPOSITION); for (i = 0; ; i++) { // Get the next funny character to be tested, and set up the // three test strings X, Y, Z, consisting of an A-grave + test char, // in original form, NFD, and then NFC form. char c = NFD_UnsafeStartChars[i]; if (c == 0) { break; } String x = "\u00C0" + c; // \u00C0 is A Grave String y; String z; try { y = Normalizer.Decompose(x, false); z = Normalizer.Decompose(y, true); } catch (Exception e) { Errln("ERROR: Failed to normalize test of character" + c); return; } // Collation test. All three strings should be equal. // doTest does both strcoll and sort keys, with params in both orders. DoTest(myCollator, x, y, 0); DoTest(myCollator, x, z, 0); DoTest(myCollator, y, z, 0); // Run collation element iterators over the three strings. Results should be same for each. { CollationElementIterator ceiX, ceiY, ceiZ; int ceX, ceY, ceZ; int j; try { ceiX = ((RuleBasedCollator)myCollator).GetCollationElementIterator(x); ceiY = ((RuleBasedCollator)myCollator).GetCollationElementIterator(y); ceiZ = ((RuleBasedCollator)myCollator).GetCollationElementIterator(z); } catch (Exception e) { Errln("ERROR: getCollationElementIterator failed"); return; } for (j = 0; ; j++) { try { ceX = ceiX.Next(); ceY = ceiY.Next(); ceZ = ceiZ.Next(); } catch (Exception e) { Errln("ERROR: CollationElementIterator.next failed for iteration " + j); break; } if (ceX != ceY || ceY != ceZ) { Errln("ERROR: ucol_next failed for iteration " + j); break; } if (ceX == CollationElementIterator.NULLORDER) { break; } } } } }