-
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 method StructuralNode.setStyle() and added test to check that a…
…ttributes are copied. (#514)
- Loading branch information
1 parent
934dbfc
commit 4f10c14
Showing
3 changed files
with
73 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
66 changes: 66 additions & 0 deletions
66
...torj-core/src/test/groovy/org/asciidoctor/extension/WhenATreeProcessorCreatesNodes.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,66 @@ | ||
package org.asciidoctor.extension | ||
|
||
import org.asciidoctor.Asciidoctor | ||
import org.asciidoctor.OptionsBuilder | ||
import org.asciidoctor.ast.Document | ||
import org.asciidoctor.ast.StructuralNode | ||
import org.jboss.arquillian.spock.ArquillianSputnik | ||
import org.jboss.arquillian.test.api.ArquillianResource | ||
import org.jsoup.Jsoup | ||
import org.jsoup.select.Elements | ||
import org.junit.runner.RunWith | ||
import spock.lang.Issue | ||
import spock.lang.Specification | ||
|
||
@RunWith(ArquillianSputnik) | ||
class WhenATreeProcessorCreatesNodes extends Specification { | ||
|
||
public static final String NEW_CODE = 'puts "World"' | ||
|
||
public static final String OLD_CODE = 'puts "Hello"' | ||
|
||
public static final String ATTR_VALUE_LANGUAGE_RUBY = 'language-ruby' | ||
|
||
public static final String ELEM_CODE = 'code' | ||
|
||
@ArquillianResource | ||
private Asciidoctor asciidoctor | ||
|
||
@Issue('https://github.com/asciidoctor/asciidoctorj/issues/513') | ||
def 'it should be able to copy attributes from another node'() { | ||
|
||
given: 'A Asciidoctor document with one Ruby source block' | ||
String document = '''== Test doc | ||
[source,ruby] | ||
---- | ||
puts "Hello" | ||
---- | ||
''' | ||
|
||
and: 'a Treeprocessor that creates an additional source block passing the same attributes' | ||
Treeprocessor tp = new Treeprocessor() { | ||
@Override | ||
Document process(Document doc) { | ||
StructuralNode newSourceBlock = createBlock(doc.blocks[0], 'listing', NEW_CODE, doc.blocks[0].blocks[0].attributes) | ||
// The style 'source' is visible in the attributes, but for new blocks it has to be set individually as a object property. | ||
newSourceBlock.style = 'source' | ||
doc.blocks[0].append(newSourceBlock) | ||
} | ||
} | ||
asciidoctor.javaExtensionRegistry().treeprocessor(tp) | ||
|
||
when: 'The document is converted' | ||
String html = asciidoctor.convert(document, OptionsBuilder.options().headerFooter(true)) | ||
|
||
then: 'The second source block uses the same value of the language attribute and highlight as Ruby' | ||
org.jsoup.nodes.Document htmlDocument = Jsoup.parse(html) | ||
Elements elements = htmlDocument.getElementsByTag(ELEM_CODE) | ||
elements.size() == 2 | ||
elements.get(0).hasClass(ATTR_VALUE_LANGUAGE_RUBY) | ||
elements.get(0).text() == OLD_CODE | ||
elements.get(1).hasClass(ATTR_VALUE_LANGUAGE_RUBY) | ||
elements.get(1).text() == NEW_CODE | ||
} | ||
|
||
} |