author | jbachorik |
Tue, 21 Jan 2014 13:04:55 +0100 | |
changeset 22353 | d09e3ff5fd63 |
parent 20182 | 7e90af95fc4e |
child 23010 | 6dadb192ad81 |
permissions | -rw-r--r-- |
17210
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
1 |
/* |
17333 | 2 |
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
17210
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
4 |
* |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
17333 | 7 |
* published by the Free Software Foundation. |
17210
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
8 |
* |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
13 |
* accompanied this code). |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
14 |
* |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
18 |
* |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
21 |
* questions. |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
22 |
*/ |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
23 |
|
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
24 |
import java.util.Arrays; |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
25 |
import java.util.List; |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
26 |
import java.util.NoSuchElementException; |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
27 |
import java.util.PrimitiveIterator; |
20182
7e90af95fc4e
8025002: "".codePoints().sorted().iterator().hasNext() causes NegativeArraySizeException
psandoz
parents:
17333
diff
changeset
|
28 |
import java.util.Spliterator; |
17210
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
29 |
import java.util.stream.Collectors; |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
30 |
|
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
31 |
import org.testng.annotations.Test; |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
32 |
|
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
33 |
import static org.testng.Assert.*; |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
34 |
|
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
35 |
/* |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
36 |
* @test |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
37 |
* @summary Unit test for CharSequence default methods |
20182
7e90af95fc4e
8025002: "".codePoints().sorted().iterator().hasNext() causes NegativeArraySizeException
psandoz
parents:
17333
diff
changeset
|
38 |
* @bug 8012665 8025002 |
17210
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
39 |
* @run testng DefaultTest |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
40 |
*/ |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
41 |
|
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
42 |
@Test(groups = "lib") |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
43 |
public class DefaultTest { |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
44 |
|
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
45 |
@Test(expectedExceptions = NoSuchElementException.class) |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
46 |
public void testEmptyChars() { |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
47 |
PrimitiveIterator.OfInt s = "".chars().iterator(); |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
48 |
assertFalse(s.hasNext()); |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
49 |
int ch = s.nextInt(); |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
50 |
} |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
51 |
|
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
52 |
public void testSimpleChars() { |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
53 |
List<Integer> list = "abc".chars().boxed().collect(Collectors.toList()); |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
54 |
assertEquals(list, Arrays.asList((int) 'a', (int) 'b', (int) 'c')); |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
55 |
} |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
56 |
|
20182
7e90af95fc4e
8025002: "".codePoints().sorted().iterator().hasNext() causes NegativeArraySizeException
psandoz
parents:
17333
diff
changeset
|
57 |
public void testCodePointsCharacteristics() { |
7e90af95fc4e
8025002: "".codePoints().sorted().iterator().hasNext() causes NegativeArraySizeException
psandoz
parents:
17333
diff
changeset
|
58 |
Spliterator.OfInt s = "".codePoints().spliterator(); |
7e90af95fc4e
8025002: "".codePoints().sorted().iterator().hasNext() causes NegativeArraySizeException
psandoz
parents:
17333
diff
changeset
|
59 |
assertFalse(s.hasCharacteristics(Spliterator.SIZED | Spliterator.SUBSIZED)); |
7e90af95fc4e
8025002: "".codePoints().sorted().iterator().hasNext() causes NegativeArraySizeException
psandoz
parents:
17333
diff
changeset
|
60 |
assertTrue(s.hasCharacteristics(Spliterator.ORDERED)); |
7e90af95fc4e
8025002: "".codePoints().sorted().iterator().hasNext() causes NegativeArraySizeException
psandoz
parents:
17333
diff
changeset
|
61 |
} |
7e90af95fc4e
8025002: "".codePoints().sorted().iterator().hasNext() causes NegativeArraySizeException
psandoz
parents:
17333
diff
changeset
|
62 |
|
17210
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
63 |
@Test(expectedExceptions = NoSuchElementException.class) |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
64 |
public void testEmptyCodePoints() { |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
65 |
PrimitiveIterator.OfInt s = "".codePoints().iterator(); |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
66 |
assertFalse(s.hasNext()); |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
67 |
int cp = s.nextInt(); |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
68 |
} |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
69 |
|
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
70 |
public void testSimpleCodePoints() { |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
71 |
List<Integer> list = "abc".codePoints().boxed().collect(Collectors.toList()); |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
72 |
assertEquals(list, Arrays.asList((int)'a', (int)'b', (int)'c')); |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
73 |
} |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
74 |
|
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
75 |
public void testUndefCodePoints() { |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
76 |
List<Integer> list = "X\ufffeY".codePoints().boxed().collect(Collectors.toList()); |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
77 |
assertEquals(list, Arrays.asList((int)'X', 0xFFFE, (int)'Y')); |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
78 |
} |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
79 |
|
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
80 |
public void testSurrogatePairing() { |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
81 |
// U+1D11E = MUSICAL SYMBOL G CLEF |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
82 |
// equivalent to surrogate pair U+D834 U+DD1E |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
83 |
List<Integer> list; |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
84 |
final int GCLEF = 0x1d11e; |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
85 |
|
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
86 |
list = "\ud834\udd1e".codePoints().boxed().collect(Collectors.toList()); |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
87 |
assertEquals(list, Arrays.asList(GCLEF)); |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
88 |
list = "A\ud834\udd1e".codePoints().boxed().collect(Collectors.toList()); |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
89 |
assertEquals(list, Arrays.asList((int)'A', GCLEF)); |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
90 |
list = "\ud834\udd1eB".codePoints().boxed().collect(Collectors.toList()); |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
91 |
assertEquals(list, Arrays.asList(GCLEF, (int)'B')); |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
92 |
list = "X\ud834\udd1eY".codePoints().boxed().collect(Collectors.toList()); |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
93 |
assertEquals(list, Arrays.asList((int)'X', GCLEF, (int)'Y')); |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
94 |
} |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
95 |
|
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
96 |
public void testUndefUnpaired() { |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
97 |
List<Integer> list = "W\udd1eX\ud834Y\ufffeZ".codePoints().boxed().collect(Collectors.toList()); |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
98 |
assertEquals(list, Arrays.asList( |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
99 |
(int)'W', 0xdd1e, (int)'X', 0xd834, (int)'Y', 0xfffe, (int)'Z')); |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
100 |
} |
8a90d05f28d8
8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents:
diff
changeset
|
101 |
} |