-
Notifications
You must be signed in to change notification settings - Fork 173
/
WhenTheSourceShouldBeAccessed.groovy
221 lines (174 loc) · 5.37 KB
/
WhenTheSourceShouldBeAccessed.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
package org.asciidoctor
import org.asciidoctor.ast.Block
import org.asciidoctor.ast.Cell
import org.asciidoctor.ast.DescriptionList
import org.asciidoctor.ast.DescriptionListEntry
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'''
list.blocks.size() == list.items.size()
list.items[0].source == list.blocks[0].source
}
def 'it should be possible to get the raw text from a description list item'() {
given:
String document = '''
= Test
:foo: bar
== Section
This::
list item should show {foo}
and should continue here
That::
does not interest at all
'''
when:
Document doc = asciidoctor.load(document, OptionsBuilder.options().asMap())
DescriptionList list = doc.blocks[0].blocks[0]
DescriptionListEntry listItem = list.items[0]
then:
listItem.description.source == '''list item should show {foo}
and should continue here'''
listItem.description.text == '''list item should show bar
and should continue here'''
list.blocks.size() == 0
}
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
}
}