Skip to content

Commit 9de06a3

Browse files
committed
Polish "Avoid warnings when parsing AsciiDoc sub-content in Asciidoctor.load"
See gh-628
1 parent b66c8b4 commit 9de06a3

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/AbstractOperationBlockMacroTests.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.asciidoctor.Options;
3636
import org.asciidoctor.OptionsBuilder;
3737
import org.asciidoctor.SafeMode;
38+
import org.junit.After;
3839
import org.junit.Before;
3940
import org.junit.Rule;
4041
import org.junit.Test;
@@ -64,6 +65,12 @@ public void setUp() throws IOException {
6465
prepareOperationSnippets(getBuildOutputLocation());
6566
this.options = OptionsBuilder.options().safe(SafeMode.UNSAFE).baseDir(getSourceLocation()).get();
6667
this.options.setAttributes(getAttributes());
68+
CapturingLogHandler.clear();
69+
}
70+
71+
@After
72+
public void verifyLogging() {
73+
assertThat(CapturingLogHandler.getLogRecords()).isEmpty();
6774
}
6875

6976
public void prepareOperationSnippets(File buildOutputLocation) throws IOException {
@@ -110,7 +117,8 @@ public void tableSnippetIncludeWithPdfBackend() throws Exception {
110117

111118
@Test
112119
public void includeSnippetInSection() throws Exception {
113-
String result = this.asciidoctor.convert("== Section\n" + "operation::some-operation[snippets='curl-request']",
120+
String result = this.asciidoctor.convert(
121+
"= A\n\nAlpha\n\n== B\n\nBravo\n\n" + "operation::some-operation[snippets='curl-request']",
114122
this.options);
115123
assertThat(result).isEqualTo(getExpectedContentFromFile("snippet-in-section"));
116124
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.restdocs.asciidoctor;
18+
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
22+
import org.asciidoctor.log.LogHandler;
23+
import org.asciidoctor.log.LogRecord;
24+
25+
public class CapturingLogHandler implements LogHandler {
26+
27+
private static final List<LogRecord> logRecords = new ArrayList<LogRecord>();
28+
29+
@Override
30+
public void log(LogRecord logRecord) {
31+
logRecords.add(logRecord);
32+
}
33+
34+
static List<LogRecord> getLogRecords() {
35+
return logRecords;
36+
}
37+
38+
static void clear() {
39+
logRecords.clear();
40+
}
41+
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.springframework.restdocs.asciidoctor.CapturingLogHandler

spring-restdocs-asciidoctor/src/test/resources/operations/snippet-in-section.html

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1+
<div id="preamble">
2+
<div class="sectionbody">
3+
<div class="paragraph">
4+
<p>Alpha</p>
5+
</div>
6+
</div>
7+
</div>
18
<div class="sect1">
2-
<h2 id="_section">Section</h2>
9+
<h2 id="_b">B</h2>
310
<div class="sectionbody">
11+
<div class="paragraph">
12+
<p>Bravo</p>
13+
</div>
414
<div class="sect2">
5-
<h3 id="_section_curl_request">Curl request</h3>
15+
<h3 id="_b_curl_request">Curl request</h3>
616
<div class="listingblock">
717
<div class="content">
818
<pre class="highlight"><code class="language-bash" data-lang="bash">$ curl 'http://localhost:8080/' -i</code></pre>

0 commit comments

Comments
 (0)