/* * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 8289332 8286470 8309471 * @summary Auto-generate ids for user-defined headings * @library /tools/lib ../../lib * @modules jdk.javadoc/jdk.javadoc.internal.tool * @build javadoc.tester.* toolbox.ToolBox * @run main TestAutoHeaderId */ import java.nio.file.Path; import toolbox.ToolBox; import javadoc.tester.JavadocTester; public class TestAutoHeaderId extends JavadocTester { public static void main(String... args) throws Exception { var tester = new TestAutoHeaderId(); tester.runTests(); } private final ToolBox tb; TestAutoHeaderId() { tb = new ToolBox(); } @Test public void testAutoHeaderId(Path base) throws Exception { Path src = base.resolve("src"); tb.writeJavaFiles(src, """ package p; /** * First sentence. * *

1.0 First Header

* *

1.1 Header with ID

* *

Embedded A-Tag with ID

* *
{@code Embedded Code Tag}
* *
{@linkplain C Embedded Link Tag}
* *

Duplicate Text

* *

Duplicate Text

* *

2.0 Extra (#*!. chars

* *

Other attributes

* *

* *

3.0 Multi-line * heading with extra * whitespace

* * Last sentence. */ public class C { /** Comment. */ C() { } } """); javadoc("-d", base.resolve("api").toString(), "-sourcepath", src.toString(), "--no-platform-links", "p"); checkIds(); checkSearchIndex(); checkHtmlIndex(); } private void checkIds() { checkOutput("p/C.html", true, """

1.0 First Header

""", """

1.1 Header with ID

""", """

Embedded A-Tag with ID

""", """
Embedded Code Tag
""", """ """, """

Duplicate Text

""", """

Duplicate Text

""", """

2.0 Extra (#*!. chars

""", """

Other attributes

""", """

""", """

3.0 Multi-line heading with extra whitespace

"""); } private void checkSearchIndex() { checkOutput("tag-search-index.js", true, """ {"l":"Duplicate Text","h":"class p.C","d":"Section","u":"p/C.html#duplicate-text-heading"}""", """ {"l":"Duplicate Text","h":"class p.C","d":"Section","u":"p/C.html#duplicate-text-heading1"}""", """ {"l":"Embedded A-Tag with ID","h":"class p.C","d":"Section","u":"p/C.html#fixed-id-2"}""", """ {"l":"Embedded Code Tag","h":"class p.C","d":"Section","u":"p/C.html#embedded-code-tag-heading"}""", """ {"l":"Embedded Link Tag","h":"class p.C","d":"Section","u":"p/C.html#embedded-link-tag-heading"}""", """ {"l":"2.0 Extra (#*!. chars","h":"class p.C","d":"Section","u":"p/C.html#2-0-extra-chars-heading"}""", """ {"l":"1.0 First Header","h":"class p.C","d":"Section","u":"p/C.html#1-0-first-header-heading"}""", """ {"l":"1.1 Header with ID","h":"class p.C","d":"Section","u":"p/C.html#fixed-id-1"}""", """ {"l":"3.0 Multi-line heading with extra whitespace","h":"class p.C","d":"Section","u":"p/C.html\ #3-0-multi-line-heading-with-extra-whitespace-heading"}""", """ {"l":"Other attributes","h":"class p.C","d":"Section","u":"p/C.html#other-attributes-heading"}"""); } private void checkHtmlIndex() { // Make sure section links are not included in static index pages checkOutput("index-all.html", true, """ C D E F H M O&n\ bsp;P 
All Classes a\ nd Interfaces|All Packages

C

C - Class in p
First sentence.

D

Duplicate Text \ - Search tag in class p.C
Section
Duplicate Text\ - Search tag in class p.C
Section

E

2.0 Extra (#*!. ch\ ars - Search tag in class p.C
Section
Embedded A-Tag with ID - Se\ arch tag in class p.C
Section
Embedded Code Ta\ g - Search tag in class p.C
Section
Embedded Link Ta\ g - Search tag in class p.C
Section

F

1.0 First Header<\ /a> - Search tag in class p.C
Section

H

1.1 Header with ID - Search\ tag in class p.C
Section

M

3.0 Multi-line heading with extra whitespace - Search tag in class p.C
Section

O

Other attributes<\ /a> - Search tag in class p.C
Section

P

p - package p
 
"""); } }