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 "<a id=\"skip.navbar.top\">", 65 "<a href=\"#skip.navbar.top\" title=\"Skip navigation links\">", 66 "<a id=\"nested.class.summary\">", 67 "<a href=\"#nested.class.summary\">", 68 "<a id=\"method.summary\">", 69 "<a href=\"#method.summary\">", 70 "<a id=\"field.detail\">", 71 "<a href=\"#field.detail\">", 72 "<a id=\"constructor.detail\">", 73 "<a href=\"#constructor.detail\">"); 74 75 // Test some members and link to these members 76 checkOutput("pkg1/RegClass.html", true, 77 //The marker for this appears in the serialized-form.html which we will 78 //test below 79 "<a href=\"../serialized-form.html#pkg1.RegClass\">"); 80 81 // Test some fields 82 checkOutput("pkg1/RegClass.html", true, 83 "<a id=\"_\">", 84 "<a href=\"#_\">", 85 "<a id=\"_$\">", 86 "<a href=\"#_$\">", 87 "<a id=\"$_\">", 88 "<a href=\"#$_\">", 89 "<a id=\"$field\">", 90 "<a href=\"#$field\">", 91 "<a id=\"fieldInCla$$\">", 92 "<a href=\"#fieldInCla$$\">", 93 "<a id=\"S_$$$$$INT\">", 94 "<a href=\"#S_$$$$$INT\">", 95 "<a id=\"method$$\">", 96 "<a href=\"#method$$\">"); 97 98 checkOutput("pkg1/DeprMemClass.html", true, 99 "<a id=\"_field_In_Class\">", 100 "<a href=\"#_field_In_Class\">"); 101 102 // Test constructor 103 checkOutput("pkg1/RegClass.html", true, 104 "<a id=\"<init>(java.lang.String,int)\">", 105 "<a href=\"#%3Cinit%3E(java.lang.String,int)\">"); 106 107 // Test some methods 108 checkOutput("pkg1/RegClass.html", true, 109 "<a id=\"_methodInClass(java.lang.String)\">", 110 "<a href=\"#_methodInClass(java.lang.String)\">", 111 "<a id=\"method()\">", 112 "<a href=\"#method()\">", 113 "<a id=\"foo(java.util.Map)\">", 114 "<a href=\"#foo(java.util.Map)\">", 115 "<a id=\"methodInCla$s(java.lang.String[])\">", 116 "<a href=\"#methodInCla$s(java.lang.String%5B%5D)\">", 117 "<a id=\"_methodInClas$(java.lang.String,int)\">", 118 "<a href=\"#_methodInClas$(java.lang.String,int)\">", 119 "<a id=\"methodD(pkg1.RegClass.$A)\">", 120 "<a href=\"#methodD(pkg1.RegClass.$A)\">", 121 "<a id=\"methodD(pkg1.RegClass.D[])\">", 122 "<a href=\"#methodD(pkg1.RegClass.D%5B%5D)\">"); 123 124 checkOutput("pkg1/DeprMemClass.html", true, 125 "<a id=\"$method_In_Class()\">", 126 "<a href=\"#$method_In_Class()\">"); 127 128 // Test enum 129 checkOutput("pkg1/RegClass.Te$t_Enum.html", true, 130 "<a id=\"$FLD2\">", 131 "<a href=\"#$FLD2\">"); 132 133 // Test nested class 134 checkOutput("pkg1/RegClass._NestedClas$.html", true, 135 "<a id=\"<init>()\">", 136 "<a href=\"#%3Cinit%3E()\">"); 137 138 // Test class use page 139 checkOutput("pkg1/class-use/DeprMemClass.html", true, 140 "<a href=\"../RegClass.html#d____mc\">"); 141 142 // Test deprecated list page 143 checkOutput("deprecated-list.html", true, 144 "<a href=\"pkg1/DeprMemClass.html#_field_In_Class\">", 145 "<a href=\"pkg1/DeprMemClass.html#$method_In_Class()\">"); 146 147 // Test constant values page 148 checkOutput("constant-values.html", true, 149 "<a href=\"pkg1/RegClass.html#S_$$$$$INT\">"); 150 151 // Test serialized form page 152 checkOutput("serialized-form.html", true, 153 //This is the marker for the link that appears in the pkg1.RegClass.html page 154 "<a id=\"pkg1.RegClass\">"); 155 156 // Test member name index page 157 checkOutput("index-all.html", true, 158 "<a id=\"I:$\">", 159 "<a href=\"#I:$\">$", 160 "<a href=\"#I:_\">_"); 161 } 162 163 /** 164 * The following test is somewhat simplistic, but it is useful 165 * in conjunction with the W3C Validation Service at https://validator.w3.org/nu/#file 166 * @param base A working directory for this method, in which some UTF-8 source files 167 * will be generated 168 * @throws IOException if there is a problem generating the source files 169 */ 170 @Test 171 public void testNonAscii(Path base) throws IOException { 172 Path src = base.resolve("src"); 173 tb.writeJavaFiles(src, 174 "package p; public class Def {\n" 175 + " public int \u00e0\u00e9;\n" // a`e' 176 + " public void \u00c0\u00c9() { }\n" // A`E' 177 + " public int \u03b1\u03b2\u03b3;\n" // alpha beta gamma 178 + " public void \u0391\u0392\u0393() { }\n" // ALPHA BETA GAMMA 179 + "}", 180 "package p; \n" 181 + "/**\n" 182 + " * {@link Def#\u00e0\u00e9 àé}<br>\n" 183 + " * {@link Def#\u00c0\u00c9() ÀÉ}<br>\n" 184 + " * {@link Def#\u03b1\u03b2\u03b3 αβγ}<br>\n" 185 + " * {@link Def#\u0391\u0392\u0393() ΑΒΓ}<br>\n" 186 + " */\n" 187 + "public class Ref { }"); 188 189 javadoc("-d", "out-nonAscii", 190 "-sourcepath", src.toString(), 191 "-html5", 192 "-encoding", "utf-8", 193 "p"); 194 checkExit(Exit.OK); 195 196 checkOutput("p/Def.html", true, 197 "<a id=\"\u00e0\u00e9\">", 198 "<a id=\"\u00c0\u00c9()\">", 199 "<a id=\"\u03b1\u03b2\u03b3\">", 200 "<a id=\"\u0391\u0392\u0393()\">"); 201 202 checkOutput("p/Ref.html", true, 203 "<a href=\"Def.html#%C3%A0%C3%A9\"><code>àé</code></a>", 204 "<a href=\"Def.html#%C3%80%C3%89()\"><code>ÀÉ</code></a>", 205 "<a href=\"Def.html#%CE%B1%CE%B2%CE%B3\"><code>αβγ</code></a>", 206 "<a href=\"Def.html#%CE%91%CE%92%CE%93()\"><code>ΑΒΓ</code></a>"); 207 208 } 209 } | 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 "<span class=\"skipNav\" id=\"skip.navbar.top\">", 65 "<a href=\"#skip.navbar.top\" title=\"Skip navigation links\">", 66 "<section class=\"nestedClassSummary\" id=\"nested.class.summary\">\n" 67 + "<h2>Nested Class Summary</h2>", 68 "<a href=\"#nested.class.summary\">", 69 "<section class=\"methodSummary\" id=\"method.summary\">\n" 70 + "<h2>Method Summary</h2>", 71 "<a href=\"#method.summary\">", 72 "<section class=\"fieldDetails\" id=\"field.detail\">\n" 73 + "<h2>Field Details</h2>", 74 "<a href=\"#field.detail\">", 75 "<section class=\"constructorDetails\" id=\"constructor.detail\">\n" 76 + "<h2>Constructor Details</h2>", 77 "<a href=\"#constructor.detail\">"); 78 79 // Test some members and link to these members 80 checkOutput("pkg1/RegClass.html", true, 81 //The marker for this appears in the serialized-form.html which we will 82 //test below 83 "<a href=\"../serialized-form.html#pkg1.RegClass\">"); 84 85 // Test some fields 86 checkOutput("pkg1/RegClass.html", true, 87 "<section class=\"detail\" id=\"_\">", 88 "<a href=\"#_\">", 89 "<section class=\"detail\" id=\"_$\">", 90 "<a href=\"#_$\">", 91 "<section class=\"detail\" id=\"$_\">", 92 "<a href=\"#$_\">", 93 "<section class=\"detail\" id=\"$field\">", 94 "<a href=\"#$field\">", 95 "<section class=\"detail\" id=\"fieldInCla$$\">", 96 "<a href=\"#fieldInCla$$\">", 97 "<section class=\"detail\" id=\"S_$$$$$INT\">", 98 "<a href=\"#S_$$$$$INT\">", 99 "<section class=\"detail\" id=\"method$$\">", 100 "<a href=\"#method$$\">"); 101 102 checkOutput("pkg1/DeprMemClass.html", true, 103 "<section class=\"detail\" id=\"_field_In_Class\">", 104 "<a href=\"#_field_In_Class\">"); 105 106 // Test constructor 107 checkOutput("pkg1/RegClass.html", true, 108 "<section class=\"detail\" id=\"<init>(java.lang.String,int)\">", 109 "<a href=\"#%3Cinit%3E(java.lang.String,int)\">"); 110 111 // Test some methods 112 checkOutput("pkg1/RegClass.html", true, 113 "<section class=\"detail\" id=\"_methodInClass(java.lang.String)\">", 114 "<a href=\"#_methodInClass(java.lang.String)\">", 115 "<section class=\"detail\" id=\"method()\">", 116 "<a href=\"#method()\">", 117 "<section class=\"detail\" id=\"foo(java.util.Map)\">", 118 "<a href=\"#foo(java.util.Map)\">", 119 "<section class=\"detail\" id=\"methodInCla$s(java.lang.String[])\">", 120 "<a href=\"#methodInCla$s(java.lang.String%5B%5D)\">", 121 "<section class=\"detail\" id=\"_methodInClas$(java.lang.String,int)\">", 122 "<a href=\"#_methodInClas$(java.lang.String,int)\">", 123 "<section class=\"detail\" id=\"methodD(pkg1.RegClass.$A)\">", 124 "<a href=\"#methodD(pkg1.RegClass.$A)\">", 125 "<section class=\"detail\" id=\"methodD(pkg1.RegClass.D[])\">", 126 "<a href=\"#methodD(pkg1.RegClass.D%5B%5D)\">"); 127 128 checkOutput("pkg1/DeprMemClass.html", true, 129 "<section class=\"detail\" id=\"$method_In_Class()\">", 130 "<a href=\"#$method_In_Class()\">"); 131 132 // Test enum 133 checkOutput("pkg1/RegClass.Te$t_Enum.html", true, 134 "<section class=\"detail\" id=\"$FLD2\">", 135 "<a href=\"#$FLD2\">"); 136 137 // Test nested class 138 checkOutput("pkg1/RegClass._NestedClas$.html", true, 139 "<section class=\"detail\" id=\"<init>()\">", 140 "<a href=\"#%3Cinit%3E()\">"); 141 142 // Test class use page 143 checkOutput("pkg1/class-use/DeprMemClass.html", true, 144 "<a href=\"../RegClass.html#d____mc\">"); 145 146 // Test deprecated list page 147 checkOutput("deprecated-list.html", true, 148 "<a href=\"pkg1/DeprMemClass.html#_field_In_Class\">", 149 "<a href=\"pkg1/DeprMemClass.html#$method_In_Class()\">"); 150 151 // Test constant values page 152 checkOutput("constant-values.html", true, 153 "<a href=\"pkg1/RegClass.html#S_$$$$$INT\">"); 154 155 // Test serialized form page 156 checkOutput("serialized-form.html", true, 157 //This is the marker for the link that appears in the pkg1.RegClass.html page 158 "<section class=\"serializedClassDetails\" id=\"pkg1.RegClass\">"); 159 160 // Test member name index page 161 checkOutput("index-all.html", true, 162 "<h2 class=\"title\" id=\"I:$\">$</h2>", 163 "<a href=\"#I:$\">$", 164 "<a href=\"#I:_\">_"); 165 } 166 167 /** 168 * The following test is somewhat simplistic, but it is useful 169 * in conjunction with the W3C Validation Service at https://validator.w3.org/nu/#file 170 * @param base A working directory for this method, in which some UTF-8 source files 171 * will be generated 172 * @throws IOException if there is a problem generating the source files 173 */ 174 @Test 175 public void testNonAscii(Path base) throws IOException { 176 Path src = base.resolve("src"); 177 tb.writeJavaFiles(src, 178 "package p; public class Def {\n" 179 + " public int \u00e0\u00e9;\n" // a`e' 180 + " public void \u00c0\u00c9() { }\n" // A`E' 181 + " public int \u03b1\u03b2\u03b3;\n" // alpha beta gamma 182 + " public void \u0391\u0392\u0393() { }\n" // ALPHA BETA GAMMA 183 + "}", 184 "package p; \n" 185 + "/**\n" 186 + " * {@link Def#\u00e0\u00e9 àé}<br>\n" 187 + " * {@link Def#\u00c0\u00c9() ÀÉ}<br>\n" 188 + " * {@link Def#\u03b1\u03b2\u03b3 αβγ}<br>\n" 189 + " * {@link Def#\u0391\u0392\u0393() ΑΒΓ}<br>\n" 190 + " */\n" 191 + "public class Ref { }"); 192 193 javadoc("-d", "out-nonAscii", 194 "-sourcepath", src.toString(), 195 "-html5", 196 "-encoding", "utf-8", 197 "p"); 198 checkExit(Exit.OK); 199 200 checkOutput("p/Def.html", true, 201 "<section class=\"detail\" id=\"\u00e0\u00e9\">", 202 "<section class=\"detail\" id=\"\u00c0\u00c9()\">", 203 "<section class=\"detail\" id=\"\u03b1\u03b2\u03b3\">", 204 "<section class=\"detail\" id=\"\u0391\u0392\u0393()\">"); 205 206 checkOutput("p/Ref.html", true, 207 "<a href=\"Def.html#%C3%A0%C3%A9\"><code>àé</code></a>", 208 "<a href=\"Def.html#%C3%80%C3%89()\"><code>ÀÉ</code></a>", 209 "<a href=\"Def.html#%CE%B1%CE%B2%CE%B3\"><code>αβγ</code></a>", 210 "<a href=\"Def.html#%CE%91%CE%92%CE%93()\"><code>ΑΒΓ</code></a>"); 211 212 } 213 } |