|
| 1 | +/* |
| 2 | + * Copyright (c) 2022, 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 | +/* |
| 25 | + * @test |
| 26 | + * @bug 8289332 |
| 27 | + * @summary Auto-generate ids for user-defined headings |
| 28 | + * @library /tools/lib ../../lib |
| 29 | + * @modules jdk.javadoc/jdk.javadoc.internal.tool |
| 30 | + * @build javadoc.tester.* toolbox.ToolBox |
| 31 | + * @run main TestAutoHeaderId |
| 32 | + */ |
| 33 | + |
| 34 | +import java.nio.file.Path; |
| 35 | + |
| 36 | +import toolbox.ToolBox; |
| 37 | + |
| 38 | +import javadoc.tester.JavadocTester; |
| 39 | + |
| 40 | +public class TestAutoHeaderId extends JavadocTester { |
| 41 | + |
| 42 | + public static void main(String... args) throws Exception { |
| 43 | + TestAutoHeaderId tester = new TestAutoHeaderId(); |
| 44 | + tester.runTests(); |
| 45 | + } |
| 46 | + |
| 47 | + private final ToolBox tb; |
| 48 | + |
| 49 | + TestAutoHeaderId() { |
| 50 | + tb = new ToolBox(); |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + public void testAutoHeaderId(Path base) throws Exception { |
| 55 | + Path src = base.resolve("src"); |
| 56 | + tb.writeJavaFiles(src, |
| 57 | + """ |
| 58 | + package p; |
| 59 | + /** |
| 60 | + * First sentence. |
| 61 | + * |
| 62 | + * <h2>First Header</h2> |
| 63 | + * |
| 64 | + * <h3 id="fixed-id-1">Header with ID</h3> |
| 65 | + * |
| 66 | + * <h4><a id="fixed-id-2">Embedded A-Tag with ID</a></h4> |
| 67 | + * |
| 68 | + * <h5>{@code Embedded Code Tag}</h5> |
| 69 | + * |
| 70 | + * <h6>{@linkplain C Embedded Link Tag}</h6> |
| 71 | + * |
| 72 | + * <h3>Duplicate Text</h3> |
| 73 | + * |
| 74 | + * <h4>Duplicate Text</h4> |
| 75 | + * |
| 76 | + * <h2>Extra (#*!. chars</h2> |
| 77 | + * |
| 78 | + * <h3 style="color: red;" class="some-class">Other attributes</h3> |
| 79 | + * |
| 80 | + * <h4></h4> |
| 81 | + * |
| 82 | + * Last sentence. |
| 83 | + */ |
| 84 | + public class C { |
| 85 | + /** Comment. */ |
| 86 | + C() { } |
| 87 | + } |
| 88 | + """); |
| 89 | + |
| 90 | + javadoc("-d", base.resolve("api").toString(), |
| 91 | + "-sourcepath", src.toString(), |
| 92 | + "--no-platform-links", "p"); |
| 93 | + |
| 94 | + checkOutput("p/C.html", true, |
| 95 | + """ |
| 96 | + <h2 id="first-header-heading">First Header</h2> |
| 97 | + """, |
| 98 | + """ |
| 99 | + <h3 id="fixed-id-1">Header with ID</h3> |
| 100 | + """, |
| 101 | + """ |
| 102 | + <h4><a id="fixed-id-2">Embedded A-Tag with ID</a></h4> |
| 103 | + """, |
| 104 | + """ |
| 105 | + <h5 id="embedded-code-tag-heading"><code>Embedded Code Tag</code></h5> |
| 106 | + """, |
| 107 | + """ |
| 108 | + <h6 id="embedded-link-tag-heading"><a href="C.html" title="class in p">Embedded Link Tag</a></h6> |
| 109 | + """, |
| 110 | + """ |
| 111 | + <h3 id="duplicate-text-heading">Duplicate Text</h3> |
| 112 | + """, |
| 113 | + """ |
| 114 | + <h4 id="duplicate-text-heading1">Duplicate Text</h4> |
| 115 | + """, |
| 116 | + """ |
| 117 | + <h2 id="extra-chars-heading">Extra (#*!. chars</h2> |
| 118 | + """, |
| 119 | + """ |
| 120 | + <h3 id="other-attributes-heading" style="color: red;" class="some-class">Other attributes</h3> |
| 121 | + """, |
| 122 | + """ |
| 123 | + <h4 id="-heading"></h4> |
| 124 | + """); |
| 125 | + } |
| 126 | +} |
0 commit comments