1 /*
  2  * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 /*
 25  * @test
 26  * @library /java/text/testlib
 27  * @summary test English Collation
 28  * @run junit EnglishTest
 29  */
 30 
 31 import java.util.Locale;
 32 import java.text.Collator;
 33 
 34 import org.junit.jupiter.api.Test;
 35 
 36 import static org.junit.jupiter.api.Assertions.fail;
 37 
 38 /*
 39 (C) Copyright Taligent, Inc. 1996 - All Rights Reserved
 40 (C) Copyright IBM Corp. 1996 - All Rights Reserved
 41 
 42   The original version of this source code and documentation is copyrighted and
 43 owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These materials are
 44 provided under terms of a License Agreement between Taligent and Sun. This
 45 technology is protected by multiple US and International patents. This notice and
 46 attribution to Taligent may not be removed.
 47   Taligent is a registered trademark of Taligent, Inc.
 48 */
 49 
 50 public class EnglishTest {
 51 
 52     /*
 53      * Data for TestPrimary()
 54      */
 55     private static final String[] primarySourceData = {
 56         "p\u00EAche",
 57         "abc",
 58         "abc",
 59         "abc",
 60         "a\u00E6c"
 61     };
 62 
 63     private static final String[] primaryTargetData = {
 64         "p\u00E9ch\u00E9",
 65         "aBC",
 66         "abd",
 67         "\u00E4bc",
 68         "a\u00C6c"
 69     };
 70 
 71     private static final int[] primaryResults = {
 72          0,  0, -1,  0,  0,
 73     };
 74 
 75     /*
 76      * Data for TestSecondary()
 77      */
 78     private static final String[] secondarySourceData = {
 79         "abc",
 80         "abc",
 81         "a\u00E6c",
 82         "abc",
 83         "abc",
 84         "p\u00e9ch\u00e9"
 85     };
 86 
 87     private static final String[] secondaryTargetData = {
 88         "aBd",
 89         "\u00E4bc",
 90         "a\u00C6c",
 91         "aBd",
 92         "\u00E4bc",
 93         "p\u00eache"
 94     };
 95 
 96     private static final int[] secondaryResults = {
 97         -1, -1,  0, -1, -1, -1
 98     };
 99 
100     /*
101      * Data for TestTertiary() {
102      */
103     private static final String[] tertiarySourceData = {
104         "ab",
105         "black-bird",
106         "black bird",
107         "black-bird",
108         "Hello",
109         "ABC",
110         "abc",
111         "blackbird",
112         "black-bird",
113         "black-bird",
114         "p\u00EAche",
115         "p\u00E9ch\u00E9",
116         "\u00C4B\u0308C\u0308",
117         "a\u0308bc",
118         "p\u00E9cher",
119         "roles",
120         "abc",
121         "A",
122         "A",
123         "ab",
124         "tcompareplain",
125         "ab",
126         "a#b",
127         "a#b",
128         "abc",
129         "Abcda",
130         "abcda",
131         "abcda",
132         "\u00E6bcda",
133         "\u00E4bcda",
134         "abc",
135         "abc",
136         "abc",
137         "abc",
138         "abc",
139         "acHc",
140         "a\u0308bc",
141         "thi\u0302s"
142     };
143 
144     private static final String[] tertiaryTargetData = {
145         "abc",
146         "blackbird",
147         "black-bird",
148         "black",
149         "hello",
150         "ABC",
151         "ABC",
152         "blackbirds",
153         "blackbirds",
154         "blackbird",
155         "p\u00E9ch\u00E9",
156         "p\u00E9cher",
157         "\u00C4B\u0308C\u0308",
158         "A\u0308bc",
159         "p\u00E9che",
160         "ro\u0302le",
161         "A\u00E1cd",
162         "A\u00E1cd",
163         "abc",
164         "abc",
165         "TComparePlain",
166         "aBc",
167         "a#B",
168         "a&b",
169         "a#c",
170         "abcda",
171         "\u00C4bcda",
172         "\u00E4bcda",
173         "\u00C4bcda",
174         "\u00C4bcda",
175         "ab#c",
176         "abc",
177         "ab=c",
178         "abd",
179         "\u00E4bc",
180         "aCHc",
181         "\u00E4bc",
182         "th\u00EEs"
183     };
184 
185     private static final int[] tertiaryResults = {
186         -1,  1, -1,  1,  1,  0, -1, -1, -1,  1,
187          1, -1,  0, -1,  1,  1,  1, -1, -1, -1,
188         -1, -1, -1,  1,  1,  1, -1, -1,  1, -1,
189          1,  0,  1, -1, -1, -1,  0,  0
190     };
191 
192     private static final String testData[] = {
193         "a",
194         "A",
195         "e",
196         "E",
197         "\u00e9",
198         "\u00e8",
199         "\u00ea",
200         "\u00eb",
201         "ea",
202         "x"
203     };
204 
205     @Test
206     public void TestPrimary() {
207         TestUtils.doCollatorTest(myCollation, Collator.PRIMARY,
208                primarySourceData, primaryTargetData, primaryResults);
209     }
210 
211     @Test
212     public void TestSecondary() {
213         TestUtils.doCollatorTest(myCollation, Collator.SECONDARY,
214                secondarySourceData, secondaryTargetData, secondaryResults);
215     }
216 
217     @Test
218     public void TestTertiary() {
219         TestUtils.doCollatorTest(myCollation, Collator.TERTIARY,
220                tertiarySourceData, tertiaryTargetData, tertiaryResults);
221 
222         for (int i = 0; i < testData.length-1; i++) {
223             for (int j = i+1; j < testData.length; j++) {
224                 TestUtils.doCollatorTest(myCollation, testData[i], testData[j], -1);
225             }
226         }
227     }
228 
229     private final Collator myCollation = Collator.getInstance(Locale.ENGLISH);
230 }