Path: blob/master/test/langtools/jdk/javadoc/doclet/testCRLineSeparator/TestCRLineSeparator.java
40971 views
/*1* Copyright (c) 2004, 2019, 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 497948626* @summary Make sure tool parses CR line separators properly.27* @library ../../lib28* @modules jdk.javadoc/jdk.javadoc.internal.tool29* @build javadoc.tester.*30* @run main TestCRLineSeparator31*/3233import java.io.*;34import java.util.*;3536import javadoc.tester.JavadocTester;3738public class TestCRLineSeparator extends JavadocTester {3940public static void main(String... args) throws Exception {41TestCRLineSeparator tester = new TestCRLineSeparator();42tester.runTests();43}4445@Test46public void test() throws IOException {47initFiles(new File(testSrc), new File("src"), "pkg");48javadoc("-d", "out",49"-sourcepath", "src",50"pkg");51checkExit(Exit.OK);5253checkOutput("pkg/MyClass.html", true,54"Line 1\n"55+ " Line 2");56}5758// recursively copy files from fromDir to toDir, replacing newlines59// with \r60void initFiles(File fromDir, File toDir, String f) throws IOException {61File from_f = new File(fromDir, f);62File to_f = new File(toDir, f);63if (from_f.isDirectory()) {64to_f.mkdirs();65for (String child: from_f.list()) {66initFiles(from_f, to_f, child);67}68} else {69List<String> lines = new ArrayList<>();70try (BufferedReader in = new BufferedReader(new FileReader(from_f))) {71String line;72while ((line = in.readLine()) != null)73lines.add(line);74}75try (BufferedWriter out = new BufferedWriter(new FileWriter(to_f))) {76for (String line: lines) {77out.write(line);78out.write("\r");79}80}81}82}83}848586