File: TestAutoHeaderId.java

package info (click to toggle)
openjdk-24 24.0.2%2B12-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 831,900 kB
  • sloc: java: 5,677,020; cpp: 1,323,154; xml: 1,320,524; ansic: 486,889; asm: 405,131; objc: 21,025; sh: 15,221; javascript: 11,049; python: 8,222; makefile: 2,504; perl: 357; awk: 351; sed: 172; pascal: 103; exp: 54; jsp: 24; csh: 3
file content (236 lines) | stat: -rw-r--r-- 10,749 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
 * 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.
                         *
                         * <h2>1.0 First Header</h2>
                         *
                         * <h3 id="fixed-id-1">1.1 Header with ID</h3>
                         *
                         * <h4><a id="fixed-id-2">Embedded A-Tag with ID</a></h4>
                         *
                         * <h5>{@code Embedded Code Tag}</h5>
                         *
                         * <h6>{@linkplain C Embedded Link Tag}</h6>
                         *
                         * <h3>Duplicate Text</h3>
                         *
                         * <h4>Duplicate Text</h4>
                         *
                         * <h2>2.0 Extra (#*!. chars</h2>
                         *
                         * <h3 style="color: red;" class="some-class">Other attributes</h3>
                         *
                         * <h4></h4>
                         *
                         * <h2> 3.0 Multi-line
                         *       heading   with extra
                         *                 whitespace</h2>
                         *
                         * 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,
                """
                    <h2 id="1-0-first-header-heading">1.0 First Header</h2>
                    """,
                """
                    <h3 id="fixed-id-1">1.1 Header with ID</h3>
                    """,
                """
                    <h4><a id="fixed-id-2">Embedded A-Tag with ID</a></h4>
                    """,
                """
                    <h5 id="embedded-code-tag-heading"><code>Embedded Code Tag</code></h5>
                    """,
                """
                    <h6 id="embedded-link-tag-heading"><a href="C.html" title="class in p">Embedded Link Tag</a></h6>
                    """,
                """
                    <h3 id="duplicate-text-heading">Duplicate Text</h3>
                    """,
                """
                    <h4 id="duplicate-text-heading1">Duplicate Text</h4>
                    """,
                """
                    <h2 id="2-0-extra-chars-heading">2.0 Extra (#*!. chars</h2>
                    """,
                """
                    <h3 id="other-attributes-heading" style="color: red;" class="some-class">Other attributes</h3>
                    """,
                """
                    <h4 id="-heading"></h4>
                    """,
                """
                    <h2 id="3-0-multi-line-heading-with-extra-whitespace-heading"> 3.0 Multi-line
                           heading   with extra
                                     whitespace</h2>""");
    }

    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,
                """
                    <a href="#I:C">C</a>&nbsp;<a href="#I:D">D</a>&nbsp;<a href="#I:E">E</a>&nbsp;<a href="#I\
                    :F">F</a>&nbsp;<a href="#I:H">H</a>&nbsp;<a href="#I:M">M</a>&nbsp;<a href="#I:O">O</a>&n\
                    bsp;<a href="#I:P">P</a>&nbsp;<br><a href="allclasses-index.html">All&nbsp;Classes&nbsp;a\
                    nd&nbsp;Interfaces</a><span class="vertical-separator">|</span><a href="allpackages-index\
                    .html">All&nbsp;Packages</a>
                    <h2 class="title" id="I:C">C</h2>
                    <dl class="index">
                    <dt><a href="p/C.html" class="type-name-link" title="class in p">C</a> - Class in <a href\
                    ="p/package-summary.html">p</a></dt>
                    <dd>
                    <div class="block">First sentence.</div>
                    </dd>
                    </dl>
                    <h2 class="title" id="I:D">D</h2>
                    <dl class="index">
                    <dt><a href="p/C.html#duplicate-text-heading" class="search-tag-link">Duplicate Text</a> \
                    - Search tag in class p.C</dt>
                    <dd>Section</dd>
                    <dt><a href="p/C.html#duplicate-text-heading1" class="search-tag-link">Duplicate Text</a>\
                     - Search tag in class p.C</dt>
                    <dd>Section</dd>
                    </dl>
                    <h2 class="title" id="I:E">E</h2>
                    <dl class="index">
                    <dt><a href="p/C.html#2-0-extra-chars-heading" class="search-tag-link">2.0 Extra (#*!. ch\
                    ars</a> - Search tag in class p.C</dt>
                    <dd>Section</dd>
                    <dt><a href="p/C.html#fixed-id-2" class="search-tag-link">Embedded A-Tag with ID</a> - Se\
                    arch tag in class p.C</dt>
                    <dd>Section</dd>
                    <dt><a href="p/C.html#embedded-code-tag-heading" class="search-tag-link">Embedded Code Ta\
                    g</a> - Search tag in class p.C</dt>
                    <dd>Section</dd>
                    <dt><a href="p/C.html#embedded-link-tag-heading" class="search-tag-link">Embedded Link Ta\
                    g</a> - Search tag in class p.C</dt>
                    <dd>Section</dd>
                    </dl>
                    <h2 class="title" id="I:F">F</h2>
                    <dl class="index">
                    <dt><a href="p/C.html#1-0-first-header-heading" class="search-tag-link">1.0 First Header<\
                    /a> - Search tag in class p.C</dt>
                    <dd>Section</dd>
                    </dl>
                    <h2 class="title" id="I:H">H</h2>
                    <dl class="index">
                    <dt><a href="p/C.html#fixed-id-1" class="search-tag-link">1.1 Header with ID</a> - Search\
                     tag in class p.C</dt>
                    <dd>Section</dd>
                    </dl>
                    <h2 class="title" id="I:M">M</h2>
                    <dl class="index">
                    <dt><a href="p/C.html#3-0-multi-line-heading-with-extra-whitespace-heading" class="search\
                    -tag-link">3.0 Multi-line heading with extra whitespace</a> - Search tag in class p.C</dt>
                    <dd>Section</dd>
                    </dl>
                    <h2 class="title" id="I:O">O</h2>
                    <dl class="index">
                    <dt><a href="p/C.html#other-attributes-heading" class="search-tag-link">Other attributes<\
                    /a> - Search tag in class p.C</dt>
                    <dd>Section</dd>
                    </dl>
                    <h2 class="title" id="I:P">P</h2>
                    <dl class="index">
                    <dt><a href="p/package-summary.html">p</a> - package p</dt>
                    <dd>&nbsp;</dd>
                    </dl>""");
    }
}