Skip to content

Commit

Permalink
Added unit test for changing the context: ContextChangeTest.java
Browse files Browse the repository at this point in the history
Reformatting the setContext function.
Added entry to CHANGELOG.adoc
  • Loading branch information
RayOffiah committed Dec 16, 2023
1 parent e6298f0 commit 5636889
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co
=== Breaking changes

Improvement::

* Add `setContext` function to StructuralNode. Move `getContext`
* Fix Macro APIs to take StructuralNodes and return Phrase- or StructuralNodes. (#1084)
* Allow Preprocessor extensions to create new Readers and replace the original Reader. (#1081)
* Set Java 11 as the minimal version (#1151) (@abelsromero)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public interface ContentNode {

String getContext();

void setContext(String context);

Document getDocument();

boolean isInline();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public String getContext() {
return getString("context");
}

@Override
public void setContext(String context) {
setString("context", context);

}

@Override
public ContentNode getParent() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.asciidoctor.jruby.ast.impl;

import org.asciidoctor.Asciidoctor;
import org.asciidoctor.Attributes;
import org.asciidoctor.Options;
import org.asciidoctor.ast.Document;
import org.asciidoctor.ast.StructuralNode;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;


public class ContextChangeTest {

private final Asciidoctor asciiDoctor = Asciidoctor.Factory.create();

static String orderedListSample() {
return "= Document Title\n\n" +
"== Section A\n\n" +
". This it item 1 in an ordered list\n\n" +
". This is item 2 in an ordered list\n\n" +
". This is item 3 in and ordered list\n\n";

}

@Test
public void get_context_of_ordered_list(){

Document document = loadDocument(orderedListSample());

assertThat(document).isNotNull();
assertThat(document.getBlocks().size()).isEqualTo(1);

StructuralNode orderedList = document.getBlocks().get(0).getBlocks().get(0);
assertThat(orderedList).isNotNull();

// Odd – I expected this to send back :'olist'
assertThat(orderedList.getContext()).isEqualTo("olist");

// But can you change it?

orderedList.setContext("colist");

assertThat(orderedList.getContext()).isEqualTo("colist");

}

private Document loadDocument(String source) {
Attributes attributes = Attributes.builder().sectionNumbers(false).build();
Options options = Options.builder().attributes(attributes).build();
return asciiDoctor.load(source, options);
}
}

0 comments on commit 5636889

Please sign in to comment.