|
| 1 | +/* |
| 2 | + * Copyright (c) 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 8266666 |
| 27 | + * @summary Implementation for snippets |
| 28 | + * @library /tools/lib ../../lib |
| 29 | + * @modules jdk.compiler/com.sun.tools.javac.api |
| 30 | + * jdk.compiler/com.sun.tools.javac.main |
| 31 | + * jdk.javadoc/jdk.javadoc.internal.tool |
| 32 | + * @build javadoc.tester.* toolbox.ToolBox toolbox.ModuleBuilder builder.ClassBuilder |
| 33 | + * @run main TestLangProperties |
| 34 | + */ |
| 35 | + |
| 36 | +import java.io.IOException; |
| 37 | +import java.nio.file.Files; |
| 38 | +import java.nio.file.Path; |
| 39 | +import java.nio.file.Paths; |
| 40 | +import java.util.ArrayList; |
| 41 | +import java.util.List; |
| 42 | +import java.util.Optional; |
| 43 | + |
| 44 | +public class TestLangProperties extends SnippetTester { |
| 45 | + |
| 46 | + public static void main(String... args) throws Exception { |
| 47 | + new TestLangProperties().runTests(m -> new Object[]{Paths.get(m.getName())}); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void testPositiveOuterMarkup(Path base) throws Exception { |
| 52 | + var testCases = new ArrayList<TestSnippetMarkup.TestCase>(); |
| 53 | + for (String whitespace1 : List.of("", " ", "\t")) |
| 54 | + for (String commentIndicator1 : List.of("#", "!")) |
| 55 | + for (String whitespace2 : List.of("", " ", "\t")) { |
| 56 | + String markup = whitespace1 + commentIndicator1 |
| 57 | + + whitespace2 + "@highlight :"; |
| 58 | + var t = new TestSnippetMarkup.TestCase( |
| 59 | + """ |
| 60 | + %s |
| 61 | + coffee=espresso |
| 62 | + tea=black |
| 63 | + """.formatted(markup), |
| 64 | + """ |
| 65 | +
|
| 66 | + <span class="bold">coffee=espresso |
| 67 | + </span>tea=black |
| 68 | + """); |
| 69 | + testCases.add(t); |
| 70 | + } |
| 71 | + testPositive(base, testCases); |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + public void testPositiveInnerMarkup(Path base) throws Exception { |
| 76 | + var testCases = new ArrayList<TestSnippetMarkup.TestCase>(); |
| 77 | + for (String whitespace1 : List.of("", " ", "\t")) |
| 78 | + for (String commentIndicator1 : List.of("#", "!")) |
| 79 | + for (String whitespace2 : List.of("", " ", "\t")) |
| 80 | + for (String unrelatedComment : List.of("a comment")) |
| 81 | + for (String whitespace3 : List.of("", " ")) |
| 82 | + for (String commentIndicator2 : List.of("#", "!")) { |
| 83 | + String payload = whitespace1 + commentIndicator1 + whitespace2 + unrelatedComment; |
| 84 | + String markup = payload + whitespace3 + commentIndicator2 + "@highlight :"; |
| 85 | + var t = new TestSnippetMarkup.TestCase( |
| 86 | + """ |
| 87 | + %s |
| 88 | + coffee=espresso |
| 89 | + tea=black |
| 90 | + """.formatted(markup), |
| 91 | + """ |
| 92 | + %s |
| 93 | + <span class="bold">coffee=espresso |
| 94 | + </span>tea=black |
| 95 | + """.formatted(payload)); |
| 96 | + testCases.add(t); |
| 97 | + } |
| 98 | + testPositive(base, testCases); |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + public void testPositiveIneffectiveOuterMarkup(Path base) throws Exception { |
| 103 | + var testCases = new ArrayList<TestSnippetMarkup.TestCase>(); |
| 104 | + for (String whitespace1 : List.of("", " ", "\t")) |
| 105 | + for (String commentIndicator1 : List.of("#", "!")) |
| 106 | + for (String whitespace2 : List.of("", " ", "\t")) { |
| 107 | + String ineffectiveMarkup = whitespace1 |
| 108 | + + commentIndicator1 + whitespace2 |
| 109 | + + "@highlight :"; |
| 110 | + var t = new TestSnippetMarkup.TestCase( |
| 111 | + """ |
| 112 | + coffee=espresso%s |
| 113 | + tea=black |
| 114 | + """.formatted(ineffectiveMarkup), |
| 115 | + """ |
| 116 | + coffee=espresso%s |
| 117 | + tea=black |
| 118 | + """.formatted(ineffectiveMarkup)); |
| 119 | + testCases.add(t); |
| 120 | + } |
| 121 | + testPositive(base, testCases); |
| 122 | + } |
| 123 | + |
| 124 | + @Test |
| 125 | + public void testPositiveIneffectiveInnerMarkup(Path base) throws Exception { |
| 126 | + var testCases = new ArrayList<TestSnippetMarkup.TestCase>(); |
| 127 | + for (String whitespace1 : List.of("", " ", "\t")) |
| 128 | + for (String commentIndicator1 : List.of("#", "!")) |
| 129 | + for (String whitespace2 : List.of("", " ", "\t")) |
| 130 | + for (String unrelatedComment : List.of("a comment")) |
| 131 | + for (String whitespace3 : List.of("", " ")) |
| 132 | + for (String commentIndicator2 : List.of("#", "!")) { |
| 133 | + String ineffectiveMarkup = whitespace1 |
| 134 | + + commentIndicator1 + whitespace2 |
| 135 | + + unrelatedComment + whitespace3 |
| 136 | + + commentIndicator2 + "@highlight :"; |
| 137 | + var t = new TestSnippetMarkup.TestCase( |
| 138 | + """ |
| 139 | + coffee=espresso%s |
| 140 | + tea=black |
| 141 | + """.formatted(ineffectiveMarkup), |
| 142 | + """ |
| 143 | + coffee=espresso%s |
| 144 | + tea=black |
| 145 | + """.formatted(ineffectiveMarkup)); |
| 146 | + testCases.add(t); |
| 147 | + } |
| 148 | + testPositive(base, testCases); |
| 149 | + } |
| 150 | + |
| 151 | + private void testPositive(Path base, List<TestSnippetMarkup.TestCase> testCases) |
| 152 | + throws IOException { |
| 153 | + StringBuilder methods = new StringBuilder(); |
| 154 | + forEachNumbered(testCases, (i, n) -> { |
| 155 | + String r = i.region().isBlank() ? "" : "region=" + i.region(); |
| 156 | + var methodDef = """ |
| 157 | +
|
| 158 | + /** |
| 159 | + {@snippet lang="properties" %s: |
| 160 | + %s}*/ |
| 161 | + public void case%s() {} |
| 162 | + """.formatted(r, i.input(), n); |
| 163 | + methods.append(methodDef); |
| 164 | + }); |
| 165 | + var classDef = """ |
| 166 | + public class A { |
| 167 | + %s |
| 168 | + } |
| 169 | + """.formatted(methods.toString()); |
| 170 | + Path src = Files.createDirectories(base.resolve("src")); |
| 171 | + tb.writeJavaFiles(src, classDef); |
| 172 | + javadoc("-d", base.resolve("out").toString(), |
| 173 | + "-sourcepath", src.toString(), |
| 174 | + src.resolve("A.java").toString()); |
| 175 | + checkExit(Exit.OK); |
| 176 | + checkNoCrashes(); |
| 177 | + forEachNumbered(testCases, (t, index) -> { |
| 178 | + String html = """ |
| 179 | + <span class="element-name">case%s</span>()</div> |
| 180 | + <div class="block"> |
| 181 | + %s |
| 182 | + </div>""".formatted(index, getSnippetHtmlRepresentation("A.html", |
| 183 | + t.expectedOutput(), Optional.of("properties"))); |
| 184 | + checkOutput("A.html", true, html); |
| 185 | + }); |
| 186 | + } |
| 187 | +} |
0 commit comments