23
23
24
24
/*
25
25
* @test
26
- * @bug 8054307 8311906
26
+ * @bug 8054307 8311906 8321514
27
27
* @summary test String chars() and codePoints()
28
+ * @run main/othervm -XX:+CompactStrings Chars
29
+ * @run main/othervm -XX:-CompactStrings Chars
28
30
*/
29
31
30
32
import java .util .Arrays ;
@@ -45,6 +47,7 @@ public static void main(String[] args) {
45
47
}
46
48
testChars (cc , ccExp );
47
49
testCharsSubrange (cc , ccExp );
50
+ testIntsSubrange (ccExp );
48
51
testCPs (cc , cpExp );
49
52
50
53
// bmp without surrogates
@@ -72,6 +75,7 @@ public static void main(String[] args) {
72
75
cpExp = Arrays .copyOf (cpExp , k );
73
76
testChars (cc , ccExp );
74
77
testCharsSubrange (cc , ccExp );
78
+ testIntsSubrange (ccExp );
75
79
testCPs (cc , cpExp );
76
80
}
77
81
}
@@ -104,6 +108,27 @@ static void testCharsSubrange(char[] cc, int[] expected) {
104
108
}
105
109
}
106
110
111
+ static void testIntsSubrange (int [] expected ) {
112
+ int [] offsets = { 7 , 31 }; // offsets to test
113
+ int LENGTH = 13 ;
114
+ for (int i = 0 ; i < offsets .length ; i ++) {
115
+ int offset = Math .max (0 , offsets [i ]); // confine to the input array
116
+ int count = Math .min (LENGTH , expected .length - offset );
117
+ String str = new String (expected , offset , count );
118
+ int [] actual = str .chars ().toArray ();
119
+ int errOffset = Arrays .mismatch (actual , 0 , actual .length ,
120
+ expected , offset , offset + count );
121
+ if (errOffset >= 0 ) {
122
+ System .err .printf ("expected[%d] (%d) != actual[%d] (%d)%n" ,
123
+ offset + errOffset , expected [offset + errOffset ],
124
+ errOffset , actual [errOffset ]);
125
+ System .err .println ("expected: " + Arrays .toString (expected ));
126
+ System .err .println ("actual: " + Arrays .toString (actual ));
127
+ throw new RuntimeException ("testIntsSubrange failed!" );
128
+ }
129
+ }
130
+ }
131
+
107
132
static void testCPs (char [] cc , int [] expected ) {
108
133
String str = new String (cc );
109
134
if (!Arrays .equals (expected , str .codePoints ().toArray ())) {
1 commit comments
openjdk-notifier[bot] commentedon Dec 14, 2023
Review
Issues