Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/jdk/javadoc/doclet/DocRootSlash/DocRootSlash.java
40971 views
1
/*
2
* Copyright (c) 2002, 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 4524350 4662945 4633447 8196202 8261976
27
* @summary stddoclet: {@docRoot} inserts an extra trailing "/"
28
* @library ../../lib
29
* @modules jdk.javadoc/jdk.javadoc.internal.tool
30
* @build javadoc.tester.*
31
* @run main DocRootSlash
32
*/
33
34
import java.util.regex.*;
35
36
/**
37
* Runs javadoc and runs regression tests on the resulting HTML.
38
* It reads each file, complete with newlines, into a string to easily
39
* find strings that contain newlines.
40
*/
41
import javadoc.tester.JavadocTester;
42
43
public class DocRootSlash extends JavadocTester {
44
45
public static void main(String... args) throws Exception {
46
DocRootSlash tester = new DocRootSlash();
47
tester.runTests();
48
}
49
50
@Test
51
public void test() {
52
// Directory that contains source files that javadoc runs on
53
String srcdir = System.getProperty("test.src", ".");
54
55
56
javadoc("-d", "out",
57
"-Xdoclint:none",
58
"-overview", (srcdir + "/overview.html"),
59
"-header", """
60
<A HREF="{@docroot}/element-list">{&#064;docroot}</A> <A HREF="{@docRoot}/help-doc.html">{&#064;docRoot}</A>""",
61
"-sourcepath", srcdir,
62
"p1", "p2");
63
64
checkFiles(
65
"p1/C1.html",
66
"p1/package-summary.html",
67
"index.html");
68
}
69
70
void checkFiles(String... filenameArray) {
71
int count = 0;
72
73
for (String f : filenameArray) {
74
// Read contents of file into a string
75
String fileString = readFile(f);
76
System.out.println("\nSub-tests for file: " + f + " --------------");
77
// Loop over all tests in a single file
78
for ( int j = 0; j < 7; j++ ) {
79
80
// Compare actual to expected string for a single subtest
81
compareActualToExpected(++count, fileString);
82
}
83
}
84
}
85
86
/**
87
* Regular expression pattern matching code
88
*
89
* Prefix Pattern:
90
* flag (?i) (case insensitive, so "a href" == "A HREF" and all combinations)
91
* group1 (
92
* <a or <A
93
* \\s+ (one or more whitespace characters)
94
* href or HREF
95
* \" (double quote)
96
* )
97
* group2 ([^\"]*) (link reference -- characters that don't include a quote)
98
* group3 (\".*?>) (" target="frameName">)
99
* group4 (.*?) (label - zero or more characters)
100
* group5 (</a>) (end tag)
101
*/
102
private static final String prefix = "(?i)(<a\\s+href="; // <a href= (start group1)
103
private static final String ref1 = "\")([^\"]*)(\".*?>)"; // doublequotes (end group1, group2, group3)
104
105
/**
106
* Compares the actual string to the expected string in the specified string
107
* @param str String to search through
108
*/
109
void compareActualToExpected(int count, String str) {
110
checking("comparison for " + str);
111
112
// Pattern must be compiled each run because numTestsRun is incremented
113
Pattern actualLinkPattern1 =
114
Pattern.compile("Sub-test " + count + " Actual: " + prefix + ref1, Pattern.DOTALL);
115
Pattern expectLinkPattern1 =
116
Pattern.compile("Sub-test " + count + " Expect: " + prefix + ref1, Pattern.DOTALL);
117
// Pattern linkPattern2 = Pattern.compile(prefix + ref2 + label + end, Pattern.DOTALL);
118
119
Matcher actualLinkMatcher1 = actualLinkPattern1.matcher(str);
120
Matcher expectLinkMatcher1 = expectLinkPattern1.matcher(str);
121
if (expectLinkMatcher1.find() && actualLinkMatcher1.find()) {
122
String expectRef = expectLinkMatcher1.group(2);
123
String actualRef = actualLinkMatcher1.group(2);
124
if (actualRef.equals(expectRef)) {
125
passed(expectRef);
126
// System.out.println("pattern: " + actualLinkPattern1.pattern());
127
// System.out.println("actualRef: " + actualRef);
128
// System.out.println("group0: " + actualLinkMatcher1.group());
129
// System.out.println("group1: " + actualLinkMatcher1.group(1));
130
// System.out.println("group2: " + actualLinkMatcher1.group(2));
131
// System.out.println("group3: " + actualLinkMatcher1.group(3));
132
// System.exit(0);
133
} else {
134
failed("\n"
135
+ "Actual: \"" + actualRef + "\"\n"
136
+ "Expect: \"" + expectRef + "\"");
137
}
138
} else {
139
failed("Didn't find <A HREF> that fits the pattern: "
140
+ expectLinkPattern1.pattern());
141
}
142
}
143
}
144
145