-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit test for changing the context: ContextChangeTest.java (#1250) Reformatting the setContext function. Added entry to CHANGELOG.adoc (cherry picked from commit 4315499)
- Loading branch information
Showing
4 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
asciidoctorj-core/src/test/java/org/asciidoctor/jruby/ast/impl/ContextChangeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
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.Test; | ||
import static org.hamcrest.CoreMatchers.*; | ||
import static org.hamcrest.MatcherAssert.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, notNullValue()); | ||
assertThat(document.getBlocks().size(), equalTo(1)); | ||
|
||
StructuralNode orderedList = document.getBlocks().get(0).getBlocks().get(0); | ||
assertThat(orderedList, notNullValue()); | ||
|
||
// Odd – I expected this to send back :'olist' | ||
assertThat(orderedList.getContext(), equalTo("olist")); | ||
|
||
// But can you change it? | ||
|
||
orderedList.setContext("colist"); | ||
|
||
assertThat(orderedList.getContext(), equalTo("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); | ||
} | ||
} |