Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/CharSequence/DefaultTest.java
38813 views
1
/*
2
* Copyright (c) 2012, 2013, 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
import java.util.Arrays;
25
import java.util.List;
26
import java.util.NoSuchElementException;
27
import java.util.PrimitiveIterator;
28
import java.util.Spliterator;
29
import java.util.stream.Collectors;
30
31
import org.testng.annotations.Test;
32
33
import static org.testng.Assert.*;
34
35
/*
36
* @test
37
* @summary Unit test for CharSequence default methods
38
* @bug 8012665 8025002
39
* @run testng DefaultTest
40
*/
41
42
@Test(groups = "lib")
43
public class DefaultTest {
44
45
@Test(expectedExceptions = NoSuchElementException.class)
46
public void testEmptyChars() {
47
PrimitiveIterator.OfInt s = "".chars().iterator();
48
assertFalse(s.hasNext());
49
int ch = s.nextInt();
50
}
51
52
public void testSimpleChars() {
53
List<Integer> list = "abc".chars().boxed().collect(Collectors.toList());
54
assertEquals(list, Arrays.asList((int) 'a', (int) 'b', (int) 'c'));
55
}
56
57
public void testCodePointsCharacteristics() {
58
Spliterator.OfInt s = "".codePoints().spliterator();
59
assertFalse(s.hasCharacteristics(Spliterator.SIZED | Spliterator.SUBSIZED));
60
assertTrue(s.hasCharacteristics(Spliterator.ORDERED));
61
}
62
63
@Test(expectedExceptions = NoSuchElementException.class)
64
public void testEmptyCodePoints() {
65
PrimitiveIterator.OfInt s = "".codePoints().iterator();
66
assertFalse(s.hasNext());
67
int cp = s.nextInt();
68
}
69
70
public void testSimpleCodePoints() {
71
List<Integer> list = "abc".codePoints().boxed().collect(Collectors.toList());
72
assertEquals(list, Arrays.asList((int)'a', (int)'b', (int)'c'));
73
}
74
75
public void testUndefCodePoints() {
76
List<Integer> list = "X\ufffeY".codePoints().boxed().collect(Collectors.toList());
77
assertEquals(list, Arrays.asList((int)'X', 0xFFFE, (int)'Y'));
78
}
79
80
public void testSurrogatePairing() {
81
// U+1D11E = MUSICAL SYMBOL G CLEF
82
// equivalent to surrogate pair U+D834 U+DD1E
83
List<Integer> list;
84
final int GCLEF = 0x1d11e;
85
86
list = "\ud834\udd1e".codePoints().boxed().collect(Collectors.toList());
87
assertEquals(list, Arrays.asList(GCLEF));
88
list = "A\ud834\udd1e".codePoints().boxed().collect(Collectors.toList());
89
assertEquals(list, Arrays.asList((int)'A', GCLEF));
90
list = "\ud834\udd1eB".codePoints().boxed().collect(Collectors.toList());
91
assertEquals(list, Arrays.asList(GCLEF, (int)'B'));
92
list = "X\ud834\udd1eY".codePoints().boxed().collect(Collectors.toList());
93
assertEquals(list, Arrays.asList((int)'X', GCLEF, (int)'Y'));
94
}
95
96
public void testUndefUnpaired() {
97
List<Integer> list = "W\udd1eX\ud834Y\ufffeZ".codePoints().boxed().collect(Collectors.toList());
98
assertEquals(list, Arrays.asList(
99
(int)'W', 0xdd1e, (int)'X', 0xd834, (int)'Y', 0xfffe, (int)'Z'));
100
}
101
}
102
103