-
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 methods setSource to Block, Cell and ListItem (#523)
- Loading branch information
1 parent
9956d1c
commit f7fcb42
Showing
8 changed files
with
237 additions
and
94 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
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
94 changes: 0 additions & 94 deletions
94
asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenTheRawTextShouldBeRetrieved.groovy
This file was deleted.
Oops, something went wrong.
188 changes: 188 additions & 0 deletions
188
asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenTheSourceShouldBeAccessed.groovy
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,188 @@ | ||
package org.asciidoctor | ||
|
||
import org.asciidoctor.ast.Block | ||
import org.asciidoctor.ast.Cell | ||
import org.asciidoctor.ast.Document | ||
import org.asciidoctor.ast.List | ||
import org.asciidoctor.ast.ListItem | ||
import org.asciidoctor.ast.Table | ||
import org.asciidoctor.extension.Treeprocessor | ||
import org.jboss.arquillian.spock.ArquillianSputnik | ||
import org.jboss.arquillian.test.api.ArquillianResource | ||
import org.jsoup.Jsoup | ||
import org.junit.runner.RunWith | ||
import spock.lang.Specification | ||
|
||
/** | ||
* Tests that the unsubstituted text can be retrieved from nodes | ||
*/ | ||
@RunWith(ArquillianSputnik) | ||
class WhenTheSourceShouldBeAccessed extends Specification { | ||
|
||
public static final String SOURCE = 'This paragraph should show {foo}' | ||
public static final String CONVERTED = 'This paragraph should show bar' | ||
public static final String P = 'p' | ||
public static final String TD = 'td' | ||
@ArquillianResource | ||
private Asciidoctor asciidoctor | ||
|
||
def 'it should be possible to get the raw text from a paragraph'() { | ||
|
||
given: | ||
String document = ''' | ||
= Test | ||
:foo: bar | ||
== Section | ||
This paragraph should show {foo} | ||
''' | ||
when: | ||
Document doc = asciidoctor.load(document, OptionsBuilder.options().asMap()) | ||
Block block = doc.blocks[0].blocks[0] | ||
|
||
then: | ||
block.source == SOURCE | ||
block.content == CONVERTED | ||
} | ||
|
||
def 'it should be possible to get the raw text from a list item'() { | ||
|
||
given: | ||
String document = ''' | ||
= Test | ||
:foo: bar | ||
== Section | ||
* This list item should show {foo} | ||
and should continue here | ||
* This does not interest at all | ||
''' | ||
when: | ||
Document doc = asciidoctor.load(document, OptionsBuilder.options().asMap()) | ||
List list = doc.blocks[0].blocks[0] | ||
ListItem listItem = list.items[0] | ||
|
||
then: | ||
listItem.source == '''This list item should show {foo} | ||
and should continue here''' | ||
listItem.text == '''This list item should show bar | ||
and should continue here''' | ||
} | ||
|
||
def 'it should be possible to get the raw text from a table cell'() { | ||
|
||
given: | ||
String document = ''' | ||
= Test | ||
:foo: bar | ||
== Section | ||
|=== | ||
| Hello {foo} | ||
|=== | ||
''' | ||
when: | ||
Document doc = asciidoctor.load(document, OptionsBuilder.options().asMap()) | ||
Table table = doc.blocks[0].blocks[0] | ||
Cell cell = table.body[0].cells[0] | ||
|
||
then: | ||
cell.source == 'Hello {foo}' | ||
cell.text == 'Hello bar' | ||
} | ||
|
||
|
||
def 'it should be possible to set the raw text of a paragraph'() { | ||
|
||
given: | ||
String document = ''' | ||
= Test | ||
:foo: bar | ||
== Section | ||
xxx | ||
''' | ||
when: | ||
asciidoctor.javaExtensionRegistry().treeprocessor(new Treeprocessor() { | ||
@Override | ||
Document process(Document doc) { | ||
doc.blocks[0].blocks[0].source = SOURCE | ||
doc | ||
} | ||
}) | ||
String html = asciidoctor.convert(document, OptionsBuilder.options().headerFooter(false).asMap()) | ||
org.jsoup.nodes.Document doc = Jsoup.parse(html) | ||
|
||
then: | ||
doc.select(P).text() == CONVERTED | ||
} | ||
|
||
def 'it should be possible to set the source of a list item'() { | ||
|
||
given: | ||
String document = ''' | ||
= Test | ||
:foo: bar | ||
== Section | ||
* xxx | ||
* This does not interest at all | ||
''' | ||
when: | ||
asciidoctor.javaExtensionRegistry().treeprocessor(new Treeprocessor() { | ||
@Override | ||
Document process(Document doc) { | ||
doc.blocks[0].blocks[0].items[0].source = SOURCE | ||
doc | ||
} | ||
}) | ||
String html = asciidoctor.convert(document, OptionsBuilder.options().headerFooter(false).asMap()) | ||
org.jsoup.nodes.Document doc = Jsoup.parse(html) | ||
|
||
then: | ||
doc.select(P).get(0).text() == CONVERTED | ||
doc.select(P).get(1).text() == 'This does not interest at all' | ||
} | ||
|
||
def 'it should be possible to set the raw text of a table cell'() { | ||
|
||
given: | ||
String document = ''' | ||
= Test | ||
:foo: bar | ||
== Section | ||
|=== | ||
| xxx | ||
|=== | ||
''' | ||
when: | ||
asciidoctor.javaExtensionRegistry().treeprocessor(new Treeprocessor() { | ||
@Override | ||
Document process(Document doc) { | ||
Table table = doc.blocks[0].blocks[0] | ||
Cell cell = table.body[0].cells[0] | ||
cell.source = SOURCE | ||
doc | ||
} | ||
}) | ||
String html = asciidoctor.convert(document, OptionsBuilder.options().headerFooter(false).asMap()) | ||
org.jsoup.nodes.Document doc = Jsoup.parse(html) | ||
|
||
then: | ||
doc.select(TD).text() == CONVERTED | ||
} | ||
|
||
} |