Path: blob/master/test/jdk/java/text/BreakIterator/Bug4740757.java
41152 views
/*1* Copyright (c) 2011, 2016, 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*/2223/*24* @test25* @bug 474075726* @summary Confirm line-breaking behavior of Hangul27*/2829import java.text.*;30import java.util.*;3132public class Bug4740757 {3334private static boolean err = false;3536public static void main(String[] args) {37Locale defaultLocale = Locale.getDefault();38if (defaultLocale.getLanguage().equals("th")) {39Locale.setDefault(Locale.KOREA);40test4740757();41Locale.setDefault(defaultLocale);42} else {43test4740757();44}4546if (err) {47throw new RuntimeException("Incorrect Line-breaking");48}49}5051private static void test4740757() {52String source = "\uc548\ub155\ud558\uc138\uc694? \uc88b\uc740 \uc544\uce68, \uc5ec\ubcf4\uc138\uc694! \uc548\ub155. End.";53String expected = "\uc548/\ub155/\ud558/\uc138/\uc694? /\uc88b/\uc740 /\uc544/\uce68, /\uc5ec/\ubcf4/\uc138/\uc694! /\uc548/\ub155. /End./";5455BreakIterator bi = BreakIterator.getLineInstance(Locale.KOREAN);56bi.setText(source);57int start = bi.first();58int end = bi.next();59StringBuilder sb = new StringBuilder();6061for (; end != BreakIterator.DONE; start = end, end = bi.next()) {62sb.append(source.substring(start,end));63sb.append('/');64}6566if (!expected.equals(sb.toString())) {67System.err.println("Failed: Hangul line-breaking failed." +68"\n\tExpected: " + expected +69"\n\tGot: " + sb +70"\nin " + Locale.getDefault() + " locale.");71err = true;72}73}7475}767778