Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/jdk/javadoc/doclet/testAnchorNames/TestAnchorNames.java
40971 views
1
/*
2
* Copyright (c) 2013, 2021, 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 8025633 8025524 8081854 8187521 8182765 8261976
27
* @summary Test for valid name attribute in HTML anchors.
28
* @library /tools/lib ../../lib
29
* @modules jdk.javadoc/jdk.javadoc.internal.tool
30
* @build toolbox.ToolBox javadoc.tester.*
31
* @run main TestAnchorNames
32
*/
33
34
import java.io.IOException;
35
import java.nio.file.Path;
36
import java.nio.file.Paths;
37
38
import javadoc.tester.JavadocTester;
39
import toolbox.ToolBox;
40
41
public class TestAnchorNames extends JavadocTester {
42
43
public final ToolBox tb;
44
public static void main(String... args) throws Exception {
45
TestAnchorNames tester = new TestAnchorNames();
46
tester.runTests(m -> new Object[] { Paths.get(m.getName()) });
47
}
48
49
public TestAnchorNames() {
50
tb = new ToolBox();
51
}
52
53
@Test
54
public void testHtml5(Path ignore) {
55
javadoc("-d", "out-html5",
56
"-sourcepath", testSrc,
57
"-source", "8", //so that '_' can be used as an identifier
58
"-use",
59
"pkg1");
60
checkExit(Exit.OK);
61
62
// Test some section markers and links to these markers
63
checkOutput("pkg1/RegClass.html", true,
64
"""
65
<span class="skip-nav" id="skip-navbar-top">""",
66
"""
67
<a href="#skip-navbar-top" title="Skip navigation links">""",
68
"""
69
<section class="nested-class-summary" id="nested-class-summary">
70
<h2>Nested Class Summary</h2>""",
71
"<a href=\"#nested-class-summary\">",
72
"""
73
<section class="method-summary" id="method-summary">
74
<h2>Method Summary</h2>""",
75
"<a href=\"#method-summary\">",
76
"""
77
<section class="field-details" id="field-detail">
78
<h2>Field Details</h2>""",
79
"<a href=\"#field-detail\">",
80
"""
81
<section class="constructor-details" id="constructor-detail">
82
<h2>Constructor Details</h2>""",
83
"<a href=\"#constructor-detail\">");
84
85
// Test some members and link to these members
86
checkOutput("pkg1/RegClass.html", true,
87
//The marker for this appears in the serialized-form.html which we will
88
//test below
89
"""
90
<a href="../serialized-form.html#pkg1.RegClass">""");
91
92
// Test some fields
93
checkOutput("pkg1/RegClass.html", true,
94
"<section class=\"detail\" id=\"_\">",
95
"<a href=\"#_\" class=\"member-name-link\">",
96
"<section class=\"detail\" id=\"_$\">",
97
"<a href=\"#_$\" class=\"member-name-link\">",
98
"<section class=\"detail\" id=\"$_\">",
99
"<a href=\"#$_\" class=\"member-name-link\">",
100
"""
101
<section class="detail" id="$field">""",
102
"<a href=\"#$field\" class=\"member-name-link\">",
103
"""
104
<section class="detail" id="fieldInCla$$">""",
105
"<a href=\"#fieldInCla$$\" class=\"member-name-link\">",
106
"""
107
<section class="detail" id="S_$$$$$INT">""",
108
"<a href=\"#S_$$$$$INT\" class=\"member-name-link\">",
109
"""
110
<section class="detail" id="method$$">""",
111
"<a href=\"#method$$\" class=\"member-name-link\">");
112
113
checkOutput("pkg1/DeprMemClass.html", true,
114
"""
115
<section class="detail" id="_field_In_Class">""",
116
"<a href=\"#_field_In_Class\" class=\"member-name-link\">");
117
118
// Test constructor
119
checkOutput("pkg1/RegClass.html", true,
120
"""
121
<section class="detail" id="&lt;init&gt;(java.lang.String,int)">""",
122
"""
123
<a href="#%3Cinit%3E(java.lang.String,int)" class="member-name-link">""");
124
125
// Test some methods
126
checkOutput("pkg1/RegClass.html", true,
127
"""
128
<section class="detail" id="_methodInClass(java.lang.String)">""",
129
"""
130
<a href="#_methodInClass(java.lang.String)" class="member-name-link">""",
131
"""
132
<section class="detail" id="method()">""",
133
"<a href=\"#method()\" class=\"member-name-link\">",
134
"""
135
<section class="detail" id="foo(java.util.Map)">""",
136
"<a href=\"#foo(java.util.Map)\" class=\"member-name-link\">",
137
"""
138
<section class="detail" id="methodInCla$s(java.lang.String[])">""",
139
"""
140
<a href="#methodInCla$s(java.lang.String%5B%5D)" class="member-name-link">""",
141
"""
142
<section class="detail" id="_methodInClas$(java.lang.String,int)">""",
143
"""
144
<a href="#_methodInClas$(java.lang.String,int)" class="member-name-link">""",
145
"""
146
<section class="detail" id="methodD(pkg1.RegClass.$A)">""",
147
"""
148
<a href="#methodD(pkg1.RegClass.$A)" class="member-name-link">""",
149
"""
150
<section class="detail" id="methodD(pkg1.RegClass.D[])">""",
151
"""
152
<a href="#methodD(pkg1.RegClass.D%5B%5D)" class="member-name-link">""");
153
154
checkOutput("pkg1/DeprMemClass.html", true,
155
"""
156
<section class="detail" id="$method_In_Class()">""",
157
"<a href=\"#$method_In_Class()\" class=\"member-name-link\">");
158
159
// Test enum
160
checkOutput("pkg1/RegClass.Te$t_Enum.html", true,
161
"""
162
<section class="detail" id="$FLD2">""",
163
"<a href=\"#$FLD2\" class=\"member-name-link\">");
164
165
// Test nested class
166
checkOutput("pkg1/RegClass._NestedClas$.html", true,
167
"""
168
<section class="detail" id="&lt;init&gt;()">""",
169
"<a href=\"#%3Cinit%3E()\" class=\"member-name-link\">");
170
171
// Test class use page
172
checkOutput("pkg1/class-use/DeprMemClass.html", true,
173
"""
174
<a href="../RegClass.html#d____mc" class="member-name-link">""");
175
176
// Test deprecated list page
177
checkOutput("deprecated-list.html", true,
178
"""
179
<a href="pkg1/DeprMemClass.html#_field_In_Class">""",
180
"""
181
<a href="pkg1/DeprMemClass.html#$method_In_Class()">""");
182
183
// Test constant values page
184
checkOutput("constant-values.html", true,
185
"""
186
<a href="pkg1/RegClass.html#S_$$$$$INT">""");
187
188
// Test serialized form page
189
checkOutput("serialized-form.html", true,
190
//This is the marker for the link that appears in the pkg1.RegClass.html page
191
"""
192
<section class="serialized-class-details" id="pkg1.RegClass">""");
193
194
// Test member name index page
195
checkOutput("index-all.html", true,
196
"""
197
<h2 class="title" id="I:$">$</h2>""",
198
"<a href=\"#I:$\">$",
199
"<a href=\"#I:_\">_");
200
}
201
202
/**
203
* The following test is somewhat simplistic, but it is useful
204
* in conjunction with the W3C Validation Service at https://validator.w3.org/nu/#file
205
* @param base A working directory for this method, in which some UTF-8 source files
206
* will be generated
207
* @throws IOException if there is a problem generating the source files
208
*/
209
@Test
210
public void testNonAscii(Path base) throws IOException {
211
Path src = base.resolve("src");
212
tb.writeJavaFiles(src,
213
"package p; public class Def {\n"
214
+ " public int \u00e0\u00e9;\n" // a`e'
215
+ " public void \u00c0\u00c9() { }\n" // A`E'
216
+ " public int \u03b1\u03b2\u03b3;\n" // alpha beta gamma
217
+ " public void \u0391\u0392\u0393() { }\n" // ALPHA BETA GAMMA
218
+ "}",
219
"package p; \n"
220
+ "/**\n"
221
+ " * {@link Def#\u00e0\u00e9 &agrave;&eacute;}<br>\n"
222
+ " * {@link Def#\u00c0\u00c9() &Agrave;&Eacute;}<br>\n"
223
+ " * {@link Def#\u03b1\u03b2\u03b3 &alpha;&beta;&gamma;}<br>\n"
224
+ " * {@link Def#\u0391\u0392\u0393() &Alpha;&Beta;&Gamma;}<br>\n"
225
+ " */\n"
226
+ "public class Ref { }");
227
228
javadoc("-d", "out-nonAscii",
229
"-sourcepath", src.toString(),
230
"-html5",
231
"-encoding", "utf-8",
232
"p");
233
checkExit(Exit.OK);
234
235
checkOutput("p/Def.html", true,
236
"<section class=\"detail\" id=\"\u00e0\u00e9\">",
237
"<section class=\"detail\" id=\"\u00c0\u00c9()\">",
238
"<section class=\"detail\" id=\"\u03b1\u03b2\u03b3\">",
239
"<section class=\"detail\" id=\"\u0391\u0392\u0393()\">");
240
241
checkOutput("p/Ref.html", true,
242
"""
243
<a href="Def.html#%C3%A0%C3%A9"><code>&agrave;&eacute;</code></a>""",
244
"""
245
<a href="Def.html#%C3%80%C3%89()"><code>&Agrave;&Eacute;</code></a>""",
246
"""
247
<a href="Def.html#%CE%B1%CE%B2%CE%B3"><code>&alpha;&beta;&gamma;</code></a>""",
248
"""
249
<a href="Def.html#%CE%91%CE%92%CE%93()"><code>&Alpha;&Beta;&Gamma;</code></a>""");
250
251
}
252
}
253
254