Skip to content

Commit 38fdb22

Browse files
authored
Fixing unit test (#1253)
Added unit test for changing the context: ContextChangeTest.java (#1250) Reformatting the setContext function. Added entry to CHANGELOG.adoc (cherry picked from commit 4315499)
1 parent c7aba4f commit 38fdb22

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

CHANGELOG.adoc

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ Documentation::
4949

5050
Improvement::
5151

52+
* Add `setContext` function to ContentNode.
53+
54+
* Add command line option --failure-level to force non-zero exit code from AsciidoctorJ CLI if specified logging level is reached. (#1114)
55+
* Upgrade to asciidoctorj 2.0.20 (#1208)
56+
* Upgrade to asciidoctorj-pdf 2.3.7 (#1182)
5257
* Add 'standalone' option, deprecates 'headerFooter' (#1160) (@abelsromero)
5358
* Upgrade to asciidoctorj-diagram 2.2.7
5459

asciidoctorj-api/src/main/java/org/asciidoctor/ast/ContentNode.java

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public interface ContentNode {
3232
@Deprecated
3333
String context();
3434
String getContext();
35+
36+
void setContext(String context);
37+
3538
/**
3639
* @deprecated Use {@linkplain #getDocument()} instead.
3740
*/

asciidoctorj-core/src/main/java/org/asciidoctor/jruby/ast/impl/ContentNodeImpl.java

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public String getContext() {
4646
return getString("context");
4747
}
4848

49+
@Override
50+
public void setContext(String context) {
51+
setString("context", context);
52+
53+
}
4954
@Override
5055
@Deprecated
5156
public ContentNode parent() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.asciidoctor.jruby.ast.impl;
2+
3+
import org.asciidoctor.Asciidoctor;
4+
import org.asciidoctor.Attributes;
5+
import org.asciidoctor.Options;
6+
import org.asciidoctor.ast.Document;
7+
import org.asciidoctor.ast.StructuralNode;
8+
9+
import org.junit.Test;
10+
import static org.hamcrest.CoreMatchers.*;
11+
import static org.hamcrest.MatcherAssert.assertThat;
12+
13+
14+
public class ContextChangeTest {
15+
16+
private final Asciidoctor asciiDoctor = Asciidoctor.Factory.create();
17+
18+
static String orderedListSample() {
19+
return "= Document Title\n\n" +
20+
"== Section A\n\n" +
21+
". This it item 1 in an ordered list\n\n" +
22+
". This is item 2 in an ordered list\n\n" +
23+
". This is item 3 in and ordered list\n\n";
24+
25+
}
26+
27+
@Test
28+
public void get_context_of_ordered_list(){
29+
30+
Document document = loadDocument(orderedListSample());
31+
32+
assertThat(document, notNullValue());
33+
assertThat(document.getBlocks().size(), equalTo(1));
34+
35+
StructuralNode orderedList = document.getBlocks().get(0).getBlocks().get(0);
36+
assertThat(orderedList, notNullValue());
37+
38+
// Odd – I expected this to send back :'olist'
39+
assertThat(orderedList.getContext(), equalTo("olist"));
40+
41+
// But can you change it?
42+
43+
orderedList.setContext("colist");
44+
45+
assertThat(orderedList.getContext(), equalTo("colist"));
46+
47+
}
48+
49+
private Document loadDocument(String source) {
50+
Attributes attributes = Attributes.builder().sectionNumbers(false).build();
51+
Options options = Options.builder().attributes(attributes).build();
52+
return asciiDoctor.load(source, options);
53+
}
54+
}

0 commit comments

Comments
 (0)