test/jdk/java/text/Collator/RuleBasedCollatorTest.java
author tschatzl
Wed, 24 Jul 2019 11:49:39 +0200
changeset 57508 28ab01c06755
parent 54837 6b06de11e78e
permissions -rw-r--r--
8228388: Add information about dirty/skipped card for Merge HCC in G1 log Summary: Collect and print informatio about the number of processed cards during the Merge HCC phase to improve log output. Reviewed-by: kbarrett, sangheki
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54837
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
     1
/*
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
     4
 *
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
     8
 *
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    13
 * accompanied this code).
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    14
 *
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    18
 *
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    21
 * questions.
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    22
 */
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    23
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    24
/*
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    25
 * @test
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    26
 * @bug 4406815 8222969
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    27
 * @summary RuleBasedCollatorTest uses very limited but selected test data
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    28
 *  to test basic functionalities provided by RuleBasedCollator.
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    29
 * @run testng/othervm RuleBasedCollatorTest
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    30
 */
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    31
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    32
import java.text.CollationElementIterator;
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    33
import java.text.CollationKey;
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    34
import java.text.RuleBasedCollator;
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    35
import java.text.Collator;
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    36
import java.text.ParseException;
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    37
import java.util.Arrays;
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    38
import java.util.Locale;
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    39
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    40
import org.testng.annotations.BeforeGroups;
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    41
import org.testng.annotations.DataProvider;
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    42
import org.testng.annotations.Test;
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    43
import org.testng.SkipException;
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    44
import static org.testng.Assert.*;
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    45
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    46
public class RuleBasedCollatorTest {
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    47
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    48
    static RuleBasedCollator USC;
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    49
    static String US_RULES;
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    50
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    51
    @BeforeGroups("USC")
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    52
    public void setup() {
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    53
        Collator c = Collator.getInstance(Locale.US);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    54
        if (!(c instanceof RuleBasedCollator)) {
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    55
            throw new SkipException("skip tests.");
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    56
        }
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    57
        USC = (RuleBasedCollator) c;
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    58
        US_RULES = USC.getRules();
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    59
    }
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    60
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    61
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    62
    @DataProvider(name = "rulesData")
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    63
    Object[][] rulesData() {
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    64
        //Basic Tailor
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    65
        String BASIC_TAILOR_RULES = "< b=c<\u00e6;A,a";
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    66
        String[] BASIC_TAILOR_DATA = {"\u00e6", "b", "a", "c", "A"};
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    67
        String[] BASIC_TAILOR_EXPECTED = {"b", "c", "\u00e6", "A", "a"};
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    68
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    69
        //Contraction
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    70
        String CONTRACTION_RULES = US_RULES + "& b < ch ,cH, Ch, CH < c ";
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    71
        String[] CONTRACTION_DATA = {"b", "c", "ch", "CH", "Ch", "cH"};
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    72
        String[] CONTRACTION_EXPECTED = {"b", "ch", "cH", "Ch", "CH", "c"};
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    73
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    74
        //Expansion
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    75
        String EXPANSION_RULES = US_RULES + "& ae = \u00e4 < b";
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    76
        String[] EXPANSION_DATA = {"ad", "af", "\u00e4"};
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    77
        String[] EXPANSION_EXPECTED = {"ad", "\u00e4", "af"};
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    78
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    79
        //Punctuation
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    80
        String PUNCTUATION_RULES = US_RULES + "< ' ' < '-'";
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    81
        String[] PUNCTUATION_DATA = {"b-w", "b-W", "B-w", "B-W", "bW", "bw",
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    82
                "Bw", "BW", "b w", "b W", "B w", "B W"};
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    83
        String[] PUNCTUATION_EXPECTED = {"bw", "bW", "Bw", "BW", "b w", "b W",
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    84
                "B w", "B W", "b-w", "b-W", "B-w", "B-W"};
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    85
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    86
        return new Object[][] {
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    87
                {BASIC_TAILOR_RULES, BASIC_TAILOR_DATA, BASIC_TAILOR_EXPECTED},
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    88
                {CONTRACTION_RULES, CONTRACTION_DATA, CONTRACTION_EXPECTED},
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    89
                {EXPANSION_RULES, EXPANSION_DATA, EXPANSION_EXPECTED},
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    90
                {PUNCTUATION_RULES, PUNCTUATION_DATA, PUNCTUATION_EXPECTED}
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    91
        };
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    92
    }
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    93
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    94
    @Test(dataProvider = "rulesData", groups = "USC")
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    95
    public void testRules(String rules, String[] testData, String[] expected)
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    96
            throws ParseException {
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    97
        Arrays.sort(testData, new RuleBasedCollator(rules));
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    98
        assertEquals(testData, expected);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
    99
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   100
    }
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   101
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   102
    @DataProvider(name = "FrenchSecondarySort")
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   103
    Object[][] FrenchSecondarySort() {
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   104
        return new Object[][] {
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   105
                { "\u0061\u00e1\u0061", "\u00e1\u0061\u0061", 1 },
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   106
                //{"\u0061\u00e1", "\u00e1\u0041", 1},  //JDK-4406815
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   107
                //{"\u00e1\u0041", "\u0061\u00e1", -1}, //JDK-4406815
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   108
                {"\u1ea0a", "\u1ea2A", -1}, //case ignore
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   109
                { "\u1ea0b", "\u1ea2A", 1 },  //primary overwrite
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   110
                { "\u1e15", "\u1e1d", -1 },   //ignore sec diacritic
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   111
                { "a", "\u1ea1", -1 } };
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   112
    }
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   113
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   114
    @Test(dataProvider = "FrenchSecondarySort", groups = "USC")
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   115
    public void testFrenchSecondarySort(String sData, String tData,
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   116
            int expected) throws ParseException {
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   117
        String french_rule = "@";
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   118
        String rules = US_RULES + french_rule;
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   119
        RuleBasedCollator rc = new RuleBasedCollator(rules);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   120
        int result = rc.compare(sData, tData);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   121
        assertEquals(expected, result);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   122
    }
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   123
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   124
    @DataProvider(name = "ThaiLaoVowelConsonantSwapping")
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   125
    Object[][] ThaiLaoVowelConsonantSwapping() {
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   126
        return new Object[][] {{"\u0e44\u0e01", "\u0e40\u0e2e", -1},//swap
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   127
                {"\u0e2e\u0e40", "\u0e01\u0e44", 1},//no swap
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   128
                {"\u0e44\u0061", "\u0e40\u0081", 1}//no swap
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   129
        };
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   130
    }
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   131
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   132
    @Test(dataProvider = "ThaiLaoVowelConsonantSwapping", groups = "USC")
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   133
    public void testThaiLaoVowelConsonantSwapping(String sData, String tData,
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   134
            int expected) throws ParseException {
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   135
        String thai_rule = "& Z < \u0e01 < \u0e2e <\u0e40 < \u0e44!";
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   136
        String rules = US_RULES + thai_rule;
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   137
        RuleBasedCollator rc = new RuleBasedCollator(rules);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   138
        int result = rc.compare(sData, tData);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   139
        assertEquals(expected, result);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   140
    }
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   141
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   142
    @Test
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   143
    public void testIgnorableCharacter() throws ParseException {
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   144
        String rule = "=f<a<c";
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   145
        RuleBasedCollator rc = new RuleBasedCollator(rule);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   146
        CollationElementIterator iter = rc.getCollationElementIterator("f");
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   147
        int element = iter.next();
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   148
        int primary = iter.primaryOrder(element);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   149
        assertEquals(primary, 0);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   150
    }
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   151
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   152
    @DataProvider(name = "Normalization")
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   153
    Object[][] Normalization() {
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   154
        return new Object[][] {
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   155
                //micro sign has no canonical decomp mapping
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   156
                // 0:NO_Decomposition;
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   157
                // 1:CANONICAL_Decomposition;
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   158
                // 2:FULL_Decomposition
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   159
                {"\u00b5", "\u03BC", 0, -1},
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   160
                {"\u00b5", "\u03BC", 1, -1},
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   161
                {"\u00b5", "\u03BC", 2, 0}
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   162
        };
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   163
    }
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   164
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   165
    @Test(dataProvider = "Normalization", groups = "USC")
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   166
    public void testNormalization(String sData, String tData, int decomp,
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   167
            int result) {
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   168
        RuleBasedCollator rc = (RuleBasedCollator)USC.clone();
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   169
        rc.setDecomposition(decomp);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   170
        assertEquals(rc.compare(sData, tData), result);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   171
    }
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   172
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   173
    @Test
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   174
    public void testEquality() throws ParseException {
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   175
        String rule1 = "<a=b";
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   176
        RuleBasedCollator rc1= new RuleBasedCollator(rule1);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   177
        //test equals()
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   178
        assertTrue(rc1.equals(new RuleBasedCollator(rule1)));
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   179
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   180
        //test semantic equality
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   181
        String[] array1 = {"b", "c", "a"};
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   182
        String[] array2 = Arrays.copyOf(array1, array1.length);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   183
        String[] expected = {"b", "a", "c"};
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   184
        String rule2 = "<b=a";
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   185
        RuleBasedCollator rc2= new RuleBasedCollator(rule2);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   186
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   187
        Arrays.sort(array1, rc1);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   188
        Arrays.sort(array2, rc2);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   189
        assertEquals(array1, array2);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   190
        assertEquals(array1, expected);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   191
    }
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   192
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   193
    @Test
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   194
    public void testBasicParsingOrder() throws ParseException {
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   195
        String rule1 = "< a < b & a < c";
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   196
        String rule2 = "< a < c & a < b";
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   197
        String rule3 = "< a < b < c";
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   198
        String s = "abc";
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   199
        RuleBasedCollator c1 = new RuleBasedCollator(rule1);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   200
        RuleBasedCollator c2 = new RuleBasedCollator(rule2);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   201
        RuleBasedCollator c3 = new RuleBasedCollator(rule3);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   202
        CollationKey k1 = c1.getCollationKey(s);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   203
        CollationKey k2 = c2.getCollationKey(s);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   204
        CollationKey k3 = c3.getCollationKey(s);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   205
        //rule1 should not equals to rule2
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   206
        assertEquals(k1.compareTo(k2) == 0, false);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   207
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   208
        //rule2 should equals to rule3
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   209
        assertEquals(k2.compareTo(k3) == 0, true);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   210
    }
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   211
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   212
    @DataProvider(name = "ParseData")
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   213
    Object[][] ParseData() {
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   214
        return new Object[][] {
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   215
                {""},
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   216
                {"a < b"},
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   217
                {"< a-b < c"},
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   218
                {"< ,a"},
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   219
                {"< a < b & c < d"}
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   220
        };
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   221
    }
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   222
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   223
    @Test(dataProvider = "ParseData",
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   224
            expectedExceptions = ParseException.class)
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   225
    public void testParseException(String rule) throws ParseException{
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   226
        new RuleBasedCollator(rule);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   227
    }
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   228
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   229
    @Test(expectedExceptions = NullPointerException.class)
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   230
    public void testNullParseException() throws ParseException{
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   231
        new RuleBasedCollator(null);
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   232
    }
6b06de11e78e 8222969: Migrate RuleBasedCollatorTest to JDK Repo
yzhou
parents:
diff changeset
   233
}