Path: blob/master/test/jdk/java/text/Collator/Regression.java
41149 views
/*1* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 4048446 4051866 4053636 4054238 4054734 4054736 4058613 4059820 406015426* 4062418 4065540 4066189 4066696 4076676 4078588 4079231 4081866 408724127* 4087243 4092260 4095316 4101940 4103436 4114076 4114077 4124632 413273628* 4133509 4139572 4141640 4179126 4179686 4244884 466322029* @library /java/text/testlib30* @summary Regression tests for Collation and associated classes31* @modules jdk.localedata32*/33/*34(C) Copyright Taligent, Inc. 1996 - All Rights Reserved35(C) Copyright IBM Corp. 1996 - All Rights Reserved3637The original version of this source code and documentation is copyrighted and38owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These materials are39provided under terms of a License Agreement between Taligent and Sun. This40technology is protected by multiple US and International patents. This notice and41attribution to Taligent may not be removed.42Taligent is a registered trademark of Taligent, Inc.43*/4445import java.text.*;46import java.util.Locale;47import java.util.Vector;484950public class Regression extends CollatorTest {5152public static void main(String[] args) throws Exception {53new Regression().run(args);54}5556// CollationElementIterator.reset() doesn't work57//58public void Test4048446() {59CollationElementIterator i1 = en_us.getCollationElementIterator(test1);60CollationElementIterator i2 = en_us.getCollationElementIterator(test1);6162while ( i1.next() != CollationElementIterator.NULLORDER ) {63}64i1.reset();6566assertEqual(i1, i2);67}686970// Collator -> rules -> Collator round-trip broken for expanding characters71//72public void Test4051866() throws ParseException {73// Build a collator containing expanding characters74RuleBasedCollator c1 = new RuleBasedCollator("< o "75+"& oe ,o\u3080"76+"& oe ,\u1530 ,O"77+"& OE ,O\u3080"78+"& OE ,\u1520"79+"< p ,P");8081// Build another using the rules from the first82RuleBasedCollator c2 = new RuleBasedCollator(c1.getRules());8384// Make sure they're the same85if (!c1.getRules().equals(c2.getRules())) {86errln("Rules are not equal");87}88}8990// Collator thinks "black-bird" == "black"91//92public void Test4053636() {93if (en_us.equals("black-bird","black")) {94errln("black-bird == black");95}96}979899// CollationElementIterator will not work correctly if the associated100// Collator object's mode is changed101//102public void Test4054238() {103RuleBasedCollator c = (RuleBasedCollator) en_us.clone();104105c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);106CollationElementIterator i1 = en_us.getCollationElementIterator(test3);107108c.setDecomposition(Collator.NO_DECOMPOSITION);109CollationElementIterator i2 = en_us.getCollationElementIterator(test3);110111// At this point, BOTH iterators should use NO_DECOMPOSITION, since the112// collator itself is in that mode113assertEqual(i1, i2);114}115116// Collator.IDENTICAL documented but not implemented117//118public void Test4054734() {119RuleBasedCollator c = (RuleBasedCollator) en_us.clone();120try {121c.setStrength(Collator.IDENTICAL);122}123catch (Exception e) {124errln("Caught " + e.toString() + " setting Collator.IDENTICAL");125}126127String[] decomp = {128"\u0001", "<", "\u0002",129"\u0001", "=", "\u0001",130"A\u0001", ">", "~\u0002", // Ensure A and ~ are not compared bitwise131"\u00C0", "=", "A\u0300" // Decomp should make these equal132};133c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);134compareArray(c, decomp);135136String[] nodecomp = {137"\u00C0", ">", "A\u0300" // A-grave vs. A combining-grave138};139c.setDecomposition(Collator.NO_DECOMPOSITION);140compareArray(c, nodecomp);141}142143// Full Decomposition mode not implemented144//145public void Test4054736() {146RuleBasedCollator c = (RuleBasedCollator) en_us.clone();147c.setDecomposition(Collator.FULL_DECOMPOSITION);148149String[] tests = {150"\uFB4f", "=", "\u05D0\u05DC", // Alef-Lamed vs. Alef, Lamed151};152153compareArray(c, tests);154}155156// Collator.getInstance() causes an ArrayIndexOutofBoundsException for Korean157//158public void Test4058613() {159// Creating a default collator doesn't work when Korean is the default160// locale161162Locale oldDefault = Locale.getDefault();163164Locale.setDefault( Locale.KOREAN );165try {166Collator c = Collator.getInstance();167168// Since the fix to this bug was to turn of decomposition for Korean collators,169// ensure that's what we got170if (c.getDecomposition() != Collator.NO_DECOMPOSITION) {171errln("Decomposition is not set to NO_DECOMPOSITION");172}173}174finally {175Locale.setDefault(oldDefault);176}177}178179// RuleBasedCollator.getRules does not return the exact pattern as input180// for expanding character sequences181//182public void Test4059820() {183RuleBasedCollator c = null;184try {185c = new RuleBasedCollator("< a < b , c/a < d < z");186} catch (ParseException e) {187errln("Exception building collator: " + e.toString());188return;189}190if ( c.getRules().indexOf("c/a") == -1) {191errln("returned rules do not contain 'c/a'");192}193}194195// MergeCollation::fixEntry broken for "& H < \u0131, \u0130, i, I"196//197public void Test4060154() {198RuleBasedCollator c = null;199try {200c = new RuleBasedCollator("< g, G < h, H < i, I < j, J"201+ " & H < \u0131, \u0130, i, I" );202} catch (ParseException e) {203errln("Exception building collator: " + e.toString());204return;205}206c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);207208String[] tertiary = {209"A", "<", "B",210"H", "<", "\u0131",211"H", "<", "I",212"\u0131", "<", "\u0130",213"\u0130", "<", "i",214"\u0130", ">", "H",215};216c.setStrength(Collator.TERTIARY);217compareArray(c, tertiary);218219String[] secondary = {220"H", "<", "I",221"\u0131", "=", "\u0130",222};223c.setStrength(Collator.PRIMARY);224compareArray(c, secondary);225};226227// Secondary/Tertiary comparison incorrect in French Secondary228//229public void Test4062418() throws ParseException {230RuleBasedCollator c = (RuleBasedCollator) Collator.getInstance(Locale.FRANCE);231c.setStrength(Collator.SECONDARY);232233String[] tests = {234"p\u00eache", "<", "p\u00e9ch\u00e9", // Comparing accents from end, p\u00e9ch\u00e9 is greater235};236237compareArray(c, tests);238}239240// Collator.compare() method broken if either string contains spaces241//242public void Test4065540() {243if (en_us.compare("abcd e", "abcd f") == 0) {244errln("'abcd e' == 'abcd f'");245}246}247248// Unicode characters need to be recursively decomposed to get the249// correct result. For example,250// u1EB1 -> \u0103 + \u0300 -> a + \u0306 + \u0300.251//252public void Test4066189() {253String test1 = "\u1EB1";254String test2 = "a\u0306\u0300";255256RuleBasedCollator c1 = (RuleBasedCollator) en_us.clone();257c1.setDecomposition(Collator.FULL_DECOMPOSITION);258CollationElementIterator i1 = en_us.getCollationElementIterator(test1);259260RuleBasedCollator c2 = (RuleBasedCollator) en_us.clone();261c2.setDecomposition(Collator.NO_DECOMPOSITION);262CollationElementIterator i2 = en_us.getCollationElementIterator(test2);263264assertEqual(i1, i2);265}266267// French secondary collation checking at the end of compare iteration fails268//269public void Test4066696() {270RuleBasedCollator c = (RuleBasedCollator) Collator.getInstance(Locale.FRANCE);271c.setStrength(Collator.SECONDARY);272273String[] tests = {274"\u00e0", "<", "\u01fa", // a-grave < A-ring-acute275};276277compareArray(c, tests);278}279280281// Bad canonicalization of same-class combining characters282//283public void Test4076676() {284// These combining characters are all in the same class, so they should not285// be reordered, and they should compare as unequal.286String s1 = "A\u0301\u0302\u0300";287String s2 = "A\u0302\u0300\u0301";288289RuleBasedCollator c = (RuleBasedCollator) en_us.clone();290c.setStrength(Collator.TERTIARY);291292if (c.compare(s1,s2) == 0) {293errln("Same-class combining chars were reordered");294}295}296297298// RuleBasedCollator.equals(null) throws NullPointerException299//300public void Test4079231() {301try {302if (en_us.equals(null)) {303errln("en_us.equals(null) returned true");304}305}306catch (Exception e) {307errln("en_us.equals(null) threw " + e.toString());308}309}310311// RuleBasedCollator breaks on "< a < bb" rule312//313public void Test4078588() throws ParseException {314RuleBasedCollator rbc=new RuleBasedCollator("< a < bb");315316int result = rbc.compare("a","bb");317318if (result != -1) {319errln("Compare(a,bb) returned " + result + "; expected -1");320}321}322323// Combining characters in different classes not reordered properly.324//325public void Test4081866() throws ParseException {326// These combining characters are all in different classes,327// so they should be reordered and the strings should compare as equal.328String s1 = "A\u0300\u0316\u0327\u0315";329String s2 = "A\u0327\u0316\u0315\u0300";330331RuleBasedCollator c = (RuleBasedCollator) en_us.clone();332c.setStrength(Collator.TERTIARY);333334// Now that the default collators are set to NO_DECOMPOSITION335// (as a result of fixing bug 4114077), we must set it explicitly336// when we're testing reordering behavior. -- lwerner, 5/5/98337c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);338339if (c.compare(s1,s2) != 0) {340errln("Combining chars were not reordered");341}342}343344// string comparison errors in Scandinavian collators345//346public void Test4087241() {347RuleBasedCollator c = (RuleBasedCollator) Collator.getInstance(348new Locale("da", "DK"));349c.setStrength(Collator.SECONDARY);350351String[] tests = {352"\u007a", "<", "\u00e6", // z < ae353"a\u0308", "<", "a\u030a", // a-unlaut < a-ring354"Y", "<", "u\u0308", // Y < u-umlaut355};356357compareArray(c, tests);358}359360// CollationKey takes ignorable strings into account when it shouldn't361//362public void Test4087243() {363RuleBasedCollator c = (RuleBasedCollator) en_us.clone();364c.setStrength(Collator.TERTIARY);365366String[] tests = {367"123", "=", "123\u0001", // 1 2 3 = 1 2 3 ctrl-A368};369370compareArray(c, tests);371}372373// Mu/micro conflict374// Micro symbol and greek lowercase letter Mu should sort identically375//376public void Test4092260() {377Collator c = Collator.getInstance(new Locale("el", ""));378379// will only be equal when FULL_DECOMPOSITION is used380c.setDecomposition(Collator.FULL_DECOMPOSITION);381382String[] tests = {383"\u00B5", "=", "\u03BC",384};385386compareArray(c, tests);387}388389void Test4095316() {390Collator c = Collator.getInstance(new Locale("el", "GR"));391c.setStrength(Collator.TERTIARY);392// javadocs for RuleBasedCollator clearly specify that characters containing compatability393// chars MUST use FULL_DECOMPOSITION to get accurate comparisons.394c.setDecomposition(Collator.FULL_DECOMPOSITION);395396String[] tests = {397"\u03D4", "=", "\u03AB",398};399400compareArray(c, tests);401}402403public void Test4101940() {404try {405RuleBasedCollator c = new RuleBasedCollator("< a < b");406CollationElementIterator i = c.getCollationElementIterator("");407i.reset();408409if (i.next() != i.NULLORDER) {410errln("next did not return NULLORDER");411}412}413catch (Exception e) {414errln("Caught " + e );415}416}417418// Collator.compare not handling spaces properly419//420public void Test4103436() {421RuleBasedCollator c = (RuleBasedCollator) en_us.clone();422c.setStrength(Collator.TERTIARY);423424String[] tests = {425"file", "<", "file access",426"file", "<", "fileaccess",427};428429compareArray(c, tests);430}431432// Collation not Unicode conformant with Hangul syllables433//434public void Test4114076() {435RuleBasedCollator c = (RuleBasedCollator) en_us.clone();436c.setStrength(Collator.TERTIARY);437438//439// With Canonical decomposition, Hangul syllables should get decomposed440// into Jamo, but Jamo characters should not be decomposed into441// conjoining Jamo442//443c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);444String[] test1 = {445"\ud4db", "=", "\u1111\u1171\u11b6",446};447compareArray(c, test1);448449// Full decomposition result should be the same as canonical decomposition450// for all hangul.451c.setDecomposition(Collator.FULL_DECOMPOSITION);452compareArray(c, test1);453454}455456457// Collator.getCollationKey was hanging on certain character sequences458//459public void Test4124632() throws Exception {460Collator coll = Collator.getInstance(Locale.JAPAN);461462try {463coll.getCollationKey("A\u0308bc");464} catch (OutOfMemoryError e) {465errln("Ran out of memory -- probably an infinite loop");466}467}468469// sort order of french words with multiple accents has errors470//471public void Test4132736() {472Collator c = Collator.getInstance(Locale.FRANCE);473474String[] test1 = {475"e\u0300e\u0301", "<", "e\u0301e\u0300",476"e\u0300\u0301", ">", "e\u0301\u0300",477};478compareArray(c, test1);479}480481// The sorting using java.text.CollationKey is not in the exact order482//483public void Test4133509() {484String[] test1 = {485"Exception", "<", "ExceptionInInitializerError",486"Graphics", "<", "GraphicsEnvironment",487"String", "<", "StringBuffer",488};489compareArray(en_us, test1);490}491492// Collation with decomposition off doesn't work for Europe493//494public void Test4114077() {495// Ensure that we get the same results with decomposition off496// as we do with it on....497498RuleBasedCollator c = (RuleBasedCollator) en_us.clone();499c.setStrength(Collator.TERTIARY);500501String[] test1 = {502"\u00C0", "=", "A\u0300", // Should be equivalent503"p\u00eache", ">", "p\u00e9ch\u00e9",504"\u0204", "=", "E\u030F",505"\u01fa", "=", "A\u030a\u0301", // a-ring-acute -> a-ring, acute506// -> a, ring, acute507"A\u0300\u0316", "<", "A\u0316\u0300", // No reordering --> unequal508};509c.setDecomposition(Collator.NO_DECOMPOSITION);510compareArray(c, test1);511512String[] test2 = {513"A\u0300\u0316", "=", "A\u0316\u0300", // Reordering --> equal514};515c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);516compareArray(c, test2);517}518519// Support for Swedish gone in 1.1.6 (Can't create Swedish collator)520//521public void Test4141640() {522//523// Rather than just creating a Swedish collator, we might as well524// try to instantiate one for every locale available on the system525// in order to prevent this sort of bug from cropping up in the future526//527Locale[] locales = Collator.getAvailableLocales();528529for (int i = 0; i < locales.length; i++) {530try {531Collator c = Collator.getInstance(locales[i]);532} catch (Exception e) {533errln("Caught " + e + " creating collator for " + locales[i]);534}535}536}537538// getCollationKey throws exception for spanish text539// Cannot reproduce this bug on 1.2, however it DOES fail on 1.1.6540//541public void Test4139572() {542//543// Code pasted straight from the bug report544//545// create spanish locale and collator546Locale l = new Locale("es", "es");547Collator col = Collator.getInstance(l);548549// this spanish phrase kills it!550col.getCollationKey("Nombre De Objeto");551}552553// RuleBasedCollator doesn't use getCollationElementIterator internally554//555public void Test4146160() throws ParseException {556//557// Use a custom collator class whose getCollationElementIterator558// methods increment a count....559//560My4146160Collator.count = 0;561new My4146160Collator().getCollationKey("1");562if (My4146160Collator.count < 1) {563errln("getCollationElementIterator not called");564}565566My4146160Collator.count = 0;567new My4146160Collator().compare("1", "2");568if (My4146160Collator.count < 1) {569errln("getCollationElementIterator not called");570}571}572573static class My4146160Collator extends RuleBasedCollator {574public My4146160Collator() throws ParseException {575super(Regression.en_us.getRules());576}577578public CollationElementIterator getCollationElementIterator(579String text) {580count++;581return super.getCollationElementIterator(text);582}583public CollationElementIterator getCollationElementIterator(584CharacterIterator text) {585count++;586return super.getCollationElementIterator(text);587}588589public static int count = 0;590};591592// CollationElementIterator.previous broken for expanding char sequences593//594public void Test4179686() throws ParseException {595596// Create a collator with a few expanding character sequences in it....597RuleBasedCollator coll = new RuleBasedCollator(en_us.getRules()598+ " & ae ; \u00e4 & AE ; \u00c4"599+ " & oe ; \u00f6 & OE ; \u00d6"600+ " & ue ; \u00fc & UE ; \u00dc");601602String text = "T\u00f6ne"; // o-umlaut603604CollationElementIterator iter = coll.getCollationElementIterator(text);605Vector elements = new Vector();606int elem;607608// Iterate forward and collect all of the elements into a Vector609while ((elem = iter.next()) != iter.NULLORDER) {610elements.addElement(new Integer(elem));611}612613// Now iterate backward and make sure they're the same614int index = elements.size() - 1;615while ((elem = iter.previous()) != iter.NULLORDER) {616int expect = ((Integer)elements.elementAt(index)).intValue();617618if (elem != expect) {619errln("Mismatch at index " + index620+ ": got " + Integer.toString(elem,16)621+ ", expected " + Integer.toString(expect,16));622}623index--;624}625}626627public void Test4244884() throws ParseException {628RuleBasedCollator coll = (RuleBasedCollator)Collator.getInstance(Locale.US);629coll = new RuleBasedCollator(coll.getRules()630+ " & C < ch , cH , Ch , CH < cat < crunchy");631632String[] testStrings = new String[] {633"car",634"cave",635"clamp",636"cramp",637"czar",638"church",639"catalogue",640"crunchy",641"dog"642};643644for (int i = 1; i < testStrings.length; i++) {645if (coll.compare(testStrings[i - 1], testStrings[i]) >= 0) {646errln("error: \"" + testStrings[i - 1]647+ "\" is greater than or equal to \"" + testStrings[i]648+ "\".");649}650}651}652653public void Test4179216() throws ParseException {654// you can position a CollationElementIterator in the middle of655// a contracting character sequence, yielding a bogus collation656// element657RuleBasedCollator coll = (RuleBasedCollator)Collator.getInstance(Locale.US);658coll = new RuleBasedCollator(coll.getRules()659+ " & C < ch , cH , Ch , CH < cat < crunchy");660String testText = "church church catcatcher runcrunchynchy";661CollationElementIterator iter = coll.getCollationElementIterator(662testText);663664// test that the "ch" combination works properly665iter.setOffset(4);666int elt4 = CollationElementIterator.primaryOrder(iter.next());667668iter.reset();669int elt0 = CollationElementIterator.primaryOrder(iter.next());670671iter.setOffset(5);672int elt5 = CollationElementIterator.primaryOrder(iter.next());673674if (elt4 != elt0 || elt5 != elt0)675errln("The collation elements at positions 0 (" + elt0 + "), 4 ("676+ elt4 + "), and 5 (" + elt5 + ") don't match.");677678// test that the "cat" combination works properly679iter.setOffset(14);680int elt14 = CollationElementIterator.primaryOrder(iter.next());681682iter.setOffset(15);683int elt15 = CollationElementIterator.primaryOrder(iter.next());684685iter.setOffset(16);686int elt16 = CollationElementIterator.primaryOrder(iter.next());687688iter.setOffset(17);689int elt17 = CollationElementIterator.primaryOrder(iter.next());690691iter.setOffset(18);692int elt18 = CollationElementIterator.primaryOrder(iter.next());693694iter.setOffset(19);695int elt19 = CollationElementIterator.primaryOrder(iter.next());696697if (elt14 != elt15 || elt14 != elt16 || elt14 != elt17698|| elt14 != elt18 || elt14 != elt19)699errln("\"cat\" elements don't match: elt14 = " + elt14 + ", elt15 = "700+ elt15 + ", elt16 = " + elt16 + ", elt17 = " + elt17701+ ", elt18 = " + elt18 + ", elt19 = " + elt19);702703// now generate a complete list of the collation elements,704// first using next() and then using setOffset(), and705// make sure both interfaces return the same set of elements706iter.reset();707708int elt = iter.next();709int count = 0;710while (elt != CollationElementIterator.NULLORDER) {711++count;712elt = iter.next();713}714715String[] nextElements = new String[count];716String[] setOffsetElements = new String[count];717int lastPos = 0;718719iter.reset();720elt = iter.next();721count = 0;722while (elt != CollationElementIterator.NULLORDER) {723nextElements[count++] = testText.substring(lastPos, iter.getOffset());724lastPos = iter.getOffset();725elt = iter.next();726}727count = 0;728for (int i = 0; i < testText.length(); ) {729iter.setOffset(i);730lastPos = iter.getOffset();731elt = iter.next();732setOffsetElements[count++] = testText.substring(lastPos, iter.getOffset());733i = iter.getOffset();734}735for (int i = 0; i < nextElements.length; i++) {736if (nextElements[i].equals(setOffsetElements[i])) {737logln(nextElements[i]);738} else {739errln("Error: next() yielded " + nextElements[i] + ", but setOffset() yielded "740+ setOffsetElements[i]);741}742}743}744745public void Test4216006() throws Exception {746// rule parser barfs on "<\u00e0=a\u0300", and on other cases747// where the same token (after normalization) appears twice in a row748boolean caughtException = false;749try {750RuleBasedCollator dummy = new RuleBasedCollator("\u00e0<a\u0300");751}752catch (ParseException e) {753caughtException = true;754}755if (!caughtException) {756throw new Exception("\"a<a\" collation sequence didn't cause parse error!");757}758759RuleBasedCollator collator = new RuleBasedCollator("<\u00e0=a\u0300");760collator.setDecomposition(Collator.FULL_DECOMPOSITION);761collator.setStrength(Collator.IDENTICAL);762763String[] tests = {764"a\u0300", "=", "\u00e0",765"\u00e0", "=", "a\u0300"766};767768compareArray(collator, tests);769}770771public void Test4171974() {772// test French accent ordering more thoroughly773String[] frenchList = {774"\u0075\u0075", // u u775"\u00fc\u0075", // u-umlaut u776"\u01d6\u0075", // u-umlaut-macron u777"\u016b\u0075", // u-macron u778"\u1e7b\u0075", // u-macron-umlaut u779"\u0075\u00fc", // u u-umlaut780"\u00fc\u00fc", // u-umlaut u-umlaut781"\u01d6\u00fc", // u-umlaut-macron u-umlaut782"\u016b\u00fc", // u-macron u-umlaut783"\u1e7b\u00fc", // u-macron-umlaut u-umlaut784"\u0075\u01d6", // u u-umlaut-macron785"\u00fc\u01d6", // u-umlaut u-umlaut-macron786"\u01d6\u01d6", // u-umlaut-macron u-umlaut-macron787"\u016b\u01d6", // u-macron u-umlaut-macron788"\u1e7b\u01d6", // u-macron-umlaut u-umlaut-macron789"\u0075\u016b", // u u-macron790"\u00fc\u016b", // u-umlaut u-macron791"\u01d6\u016b", // u-umlaut-macron u-macron792"\u016b\u016b", // u-macron u-macron793"\u1e7b\u016b", // u-macron-umlaut u-macron794"\u0075\u1e7b", // u u-macron-umlaut795"\u00fc\u1e7b", // u-umlaut u-macron-umlaut796"\u01d6\u1e7b", // u-umlaut-macron u-macron-umlaut797"\u016b\u1e7b", // u-macron u-macron-umlaut798"\u1e7b\u1e7b" // u-macron-umlaut u-macron-umlaut799};800Collator french = Collator.getInstance(Locale.FRENCH);801802logln("Testing French order...");803checkListOrder(frenchList, french);804805logln("Testing French order without decomposition...");806french.setDecomposition(Collator.NO_DECOMPOSITION);807checkListOrder(frenchList, french);808809String[] englishList = {810"\u0075\u0075", // u u811"\u0075\u00fc", // u u-umlaut812"\u0075\u01d6", // u u-umlaut-macron813"\u0075\u016b", // u u-macron814"\u0075\u1e7b", // u u-macron-umlaut815"\u00fc\u0075", // u-umlaut u816"\u00fc\u00fc", // u-umlaut u-umlaut817"\u00fc\u01d6", // u-umlaut u-umlaut-macron818"\u00fc\u016b", // u-umlaut u-macron819"\u00fc\u1e7b", // u-umlaut u-macron-umlaut820"\u01d6\u0075", // u-umlaut-macron u821"\u01d6\u00fc", // u-umlaut-macron u-umlaut822"\u01d6\u01d6", // u-umlaut-macron u-umlaut-macron823"\u01d6\u016b", // u-umlaut-macron u-macron824"\u01d6\u1e7b", // u-umlaut-macron u-macron-umlaut825"\u016b\u0075", // u-macron u826"\u016b\u00fc", // u-macron u-umlaut827"\u016b\u01d6", // u-macron u-umlaut-macron828"\u016b\u016b", // u-macron u-macron829"\u016b\u1e7b", // u-macron u-macron-umlaut830"\u1e7b\u0075", // u-macron-umlaut u831"\u1e7b\u00fc", // u-macron-umlaut u-umlaut832"\u1e7b\u01d6", // u-macron-umlaut u-umlaut-macron833"\u1e7b\u016b", // u-macron-umlaut u-macron834"\u1e7b\u1e7b" // u-macron-umlaut u-macron-umlaut835};836Collator english = Collator.getInstance(Locale.ENGLISH);837838logln("Testing English order...");839checkListOrder(englishList, english);840841logln("Testing English order without decomposition...");842english.setDecomposition(Collator.NO_DECOMPOSITION);843checkListOrder(englishList, english);844}845846private void checkListOrder(String[] sortedList, Collator c) {847// this function uses the specified Collator to make sure the848// passed-in list is already sorted into ascending order849for (int i = 0; i < sortedList.length - 1; i++) {850if (c.compare(sortedList[i], sortedList[i + 1]) >= 0) {851errln("List out of order at element #" + i + ": "852+ prettify(sortedList[i]) + " >= "853+ prettify(sortedList[i + 1]));854}855}856}857858// CollationElementIterator set doesn't work propertly with next/prev859public void Test4663220() {860RuleBasedCollator collator = (RuleBasedCollator)Collator.getInstance(Locale.US);861CharacterIterator stringIter = new StringCharacterIterator("fox");862CollationElementIterator iter = collator.getCollationElementIterator(stringIter);863864int[] elements_next = new int[3];865logln("calling next:");866for (int i = 0; i < 3; ++i) {867logln("[" + i + "] " + (elements_next[i] = iter.next()));868}869870int[] elements_fwd = new int[3];871logln("calling set/next:");872for (int i = 0; i < 3; ++i) {873iter.setOffset(i);874logln("[" + i + "] " + (elements_fwd[i] = iter.next()));875}876877for (int i = 0; i < 3; ++i) {878if (elements_next[i] != elements_fwd[i]) {879errln("mismatch at position " + i +880": " + elements_next[i] +881" != " + elements_fwd[i]);882}883}884}885886//------------------------------------------------------------------------887// Internal utilities888//889private void compareArray(Collator c, String[] tests) {890for (int i = 0; i < tests.length; i += 3) {891892int expect = 0;893if (tests[i+1].equals("<")) {894expect = -1;895} else if (tests[i+1].equals(">")) {896expect = 1;897} else if (tests[i+1].equals("=")) {898expect = 0;899} else {900expect = Integer.decode(tests[i+1]).intValue();901}902903int result = c.compare(tests[i], tests[i+2]);904if (sign(result) != sign(expect))905{906errln( i/3 + ": compare(" + prettify(tests[i])907+ " , " + prettify(tests[i+2])908+ ") got " + result + "; expected " + expect);909}910else911{912// Collator.compare worked OK; now try the collation keys913CollationKey k1 = c.getCollationKey(tests[i]);914CollationKey k2 = c.getCollationKey(tests[i+2]);915916result = k1.compareTo(k2);917if (sign(result) != sign(expect)) {918errln( i/3 + ": key(" + prettify(tests[i])919+ ").compareTo(key(" + prettify(tests[i+2])920+ ")) got " + result + "; expected " + expect);921922errln(" " + prettify(k1) + " vs. " + prettify(k2));923}924}925}926}927928private static final int sign(int i) {929if (i < 0) return -1;930if (i > 0) return 1;931return 0;932}933934935static RuleBasedCollator en_us = (RuleBasedCollator)Collator.getInstance(Locale.US);936937String test1 = "XFILE What subset of all possible test cases has the highest probability of detecting the most errors?";938String test2 = "Xf ile What subset of all possible test cases has the lowest probability of detecting the least errors?";939String test3 = "a\u00FCbeck Gr\u00F6\u00DFe L\u00FCbeck";940}941942943