Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/CharSequence/DefaultTest.java
38813 views
/*1* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.util.Arrays;24import java.util.List;25import java.util.NoSuchElementException;26import java.util.PrimitiveIterator;27import java.util.Spliterator;28import java.util.stream.Collectors;2930import org.testng.annotations.Test;3132import static org.testng.Assert.*;3334/*35* @test36* @summary Unit test for CharSequence default methods37* @bug 8012665 802500238* @run testng DefaultTest39*/4041@Test(groups = "lib")42public class DefaultTest {4344@Test(expectedExceptions = NoSuchElementException.class)45public void testEmptyChars() {46PrimitiveIterator.OfInt s = "".chars().iterator();47assertFalse(s.hasNext());48int ch = s.nextInt();49}5051public void testSimpleChars() {52List<Integer> list = "abc".chars().boxed().collect(Collectors.toList());53assertEquals(list, Arrays.asList((int) 'a', (int) 'b', (int) 'c'));54}5556public void testCodePointsCharacteristics() {57Spliterator.OfInt s = "".codePoints().spliterator();58assertFalse(s.hasCharacteristics(Spliterator.SIZED | Spliterator.SUBSIZED));59assertTrue(s.hasCharacteristics(Spliterator.ORDERED));60}6162@Test(expectedExceptions = NoSuchElementException.class)63public void testEmptyCodePoints() {64PrimitiveIterator.OfInt s = "".codePoints().iterator();65assertFalse(s.hasNext());66int cp = s.nextInt();67}6869public void testSimpleCodePoints() {70List<Integer> list = "abc".codePoints().boxed().collect(Collectors.toList());71assertEquals(list, Arrays.asList((int)'a', (int)'b', (int)'c'));72}7374public void testUndefCodePoints() {75List<Integer> list = "X\ufffeY".codePoints().boxed().collect(Collectors.toList());76assertEquals(list, Arrays.asList((int)'X', 0xFFFE, (int)'Y'));77}7879public void testSurrogatePairing() {80// U+1D11E = MUSICAL SYMBOL G CLEF81// equivalent to surrogate pair U+D834 U+DD1E82List<Integer> list;83final int GCLEF = 0x1d11e;8485list = "\ud834\udd1e".codePoints().boxed().collect(Collectors.toList());86assertEquals(list, Arrays.asList(GCLEF));87list = "A\ud834\udd1e".codePoints().boxed().collect(Collectors.toList());88assertEquals(list, Arrays.asList((int)'A', GCLEF));89list = "\ud834\udd1eB".codePoints().boxed().collect(Collectors.toList());90assertEquals(list, Arrays.asList(GCLEF, (int)'B'));91list = "X\ud834\udd1eY".codePoints().boxed().collect(Collectors.toList());92assertEquals(list, Arrays.asList((int)'X', GCLEF, (int)'Y'));93}9495public void testUndefUnpaired() {96List<Integer> list = "W\udd1eX\ud834Y\ufffeZ".codePoints().boxed().collect(Collectors.toList());97assertEquals(list, Arrays.asList(98(int)'W', 0xdd1e, (int)'X', 0xd834, (int)'Y', 0xfffe, (int)'Z'));99}100}101102103