Skip to content

Commit 4315499

Browse files
authored
Added unit test for changing the context: ContextChangeTest.java (#1250)
Reformatting the setContext function. Added entry to CHANGELOG.adoc
1 parent 978e7b2 commit 4315499

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

CHANGELOG.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Bug Fixes::
3636

3737
Improvement::
3838

39+
* Add `setContext` function to StructuralNode.
40+
3941
* Add command line option --failure-level to force non-zero exit code from AsciidoctorJ CLI if specified logging level is reached. (#1114)
4042
* Upgrade to asciidoctorj 2.0.20 (#1208)
4143
* Upgrade to asciidoctorj-pdf 2.3.7 (#1182)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public interface ContentNode {
1818

1919
String getContext();
2020

21+
void setContext(String context);
22+
2123
Document getDocument();
2224

2325
boolean isInline();

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public String getContext() {
3434
return getString("context");
3535
}
3636

37+
@Override
38+
public void setContext(String context) {
39+
setString("context", context);
40+
41+
}
3742

3843
@Override
3944
public ContentNode getParent() {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
import org.junit.jupiter.api.Test;
9+
10+
import static org.assertj.core.api.Assertions.assertThat;
11+
12+
13+
public class ContextChangeTest {
14+
15+
private final Asciidoctor asciiDoctor = Asciidoctor.Factory.create();
16+
17+
static String orderedListSample() {
18+
return "= Document Title\n\n" +
19+
"== Section A\n\n" +
20+
". This it item 1 in an ordered list\n\n" +
21+
". This is item 2 in an ordered list\n\n" +
22+
". This is item 3 in and ordered list\n\n";
23+
24+
}
25+
26+
@Test
27+
public void get_context_of_ordered_list(){
28+
29+
Document document = loadDocument(orderedListSample());
30+
31+
assertThat(document).isNotNull();
32+
assertThat(document.getBlocks().size()).isEqualTo(1);
33+
34+
StructuralNode orderedList = document.getBlocks().get(0).getBlocks().get(0);
35+
assertThat(orderedList).isNotNull();
36+
37+
// Odd – I expected this to send back :'olist'
38+
assertThat(orderedList.getContext()).isEqualTo("olist");
39+
40+
// But can you change it?
41+
42+
orderedList.setContext("colist");
43+
44+
assertThat(orderedList.getContext()).isEqualTo("colist");
45+
46+
}
47+
48+
private Document loadDocument(String source) {
49+
Attributes attributes = Attributes.builder().sectionNumbers(false).build();
50+
Options options = Options.builder().attributes(attributes).build();
51+
return asciiDoctor.load(source, options);
52+
}
53+
}

0 commit comments

Comments
 (0)