-
Notifications
You must be signed in to change notification settings - Fork 15
/
test_plantuml.rb
284 lines (216 loc) · 6.22 KB
/
test_plantuml.rb
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# frozen_string_literal: true
require 'test/unit'
require 'asciidoctor'
require 'stringio'
require 'nokogiri'
require 'asciidoctor-plantuml'
DOC_BASIC = <<~ENDOFSTRING
= Hello PlantUML!
[plantuml, format="png"]
.Title Of this
----
User -> (Start)
User --> (Use the application) : Label
----
ENDOFSTRING
DOC_BASIC2 = <<~ENDOFSTRING
= Hello PlantUML!
[plantuml, format="png"]
.Title Of this
[[fig-xref]]
----
@startuml
User -> (Start)
User --> (Use the application) : Label
@enduml
----
ENDOFSTRING
DOC_BASIC3 = <<~ENDOFSTRING
= Hello Compound PlantUML!
[plantuml, format="png"]
----
[COMP1]
[COMP2]
[COMP1] -> [COMP2]
[COMP2] --> [COMP3]
----
ENDOFSTRING
DOC_ID = <<~ENDOFSTRING
= Hello PlantUML!
[plantuml, format="png", id="myId"]
----
User -> (Start)
User --> (Use the application) : Label
----
ENDOFSTRING
DOC_DIM = <<~ENDOFSTRING
= Hello PlantUML!
[plantuml, format="png", width="100px", height="50px"]
----
User -> (Start)
User --> (Use the application) : Label
----
ENDOFSTRING
DOC_ALT = <<~ENDOFSTRING
= Hello PlantUML!
[plantuml, format="png", alt="alt"]
----
User -> (Start)
User --> (Use the application) : Label
----
ENDOFSTRING
DOC_BAD_FORMAT = <<~ENDOFSTRING
= Hello PlantUML!
[plantuml, format="jpg"]
----
User -> (Start)
User --> (Use the application) : Label
----
ENDOFSTRING
DOC_MULTI = <<~ENDOFSTRING
= Hello PlantUML!
[plantuml, format="png"]
----
User -> (Start)
User --> (Use the application) : Label
----
[plantuml, format="png"]
----
User -> (Start)
User --> (Use the application) : Label
----
[plantuml, format="txt"]
----
User -> (Start)
User --> (Use the application) : Label
----
ENDOFSTRING
DOC_TXT = <<~ENDOFSTRING
= Hello PlantUML!
[plantuml, format="txt"]
----
User -> (Start)
User --> (Use the application) : Label
----
ENDOFSTRING
class PlantUmlTest < Test::Unit::TestCase
GENURL = 'http://localhost:8080/plantuml/png/U9npA2v9B2efpStX2YrEBLBGjLFG20Q9Q4Bv804WIw4a8rKXiQ0W9pCviIGpFqzJmKh19p4fDOVB8JKl1QWT05kd5wq0'
GENURL2 = 'http://localhost:8080/plantuml/png/U9npA2v9B2efpStXYdRszmqmZ8NGHh4mleAkdGAAa15G22Pc7Clba9gN0jGE00W75Cm0'
def setup
Asciidoctor::PlantUml.configure do |c|
c.url = 'http://localhost:8080/plantuml'
c.txt_enable = true
end
end
def test_plantuml_block_processor
html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC), backend: 'html5')
page = Nokogiri::HTML(html)
elements = page.css('img.plantuml')
assert_equal elements.size, 1
element = elements.first
assert_equal GENURL, element['src']
end
def test_plantuml_block_processor2
html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC2), backend: 'html5')
page = Nokogiri::HTML(html)
elements = page.css('img.plantuml')
assert_equal elements.size, 1
element = elements.first
assert_equal GENURL, element['src']
end
def test_plantuml_block_processor3
html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC3), backend: 'html5')
page = Nokogiri::HTML(html)
elements = page.css('img.plantuml')
assert_equal elements.size, 1
element = elements.first
assert_equal GENURL2, element['src']
end
def test_plantuml_id_attribute
html = ::Asciidoctor.convert(StringIO.new(DOC_ID), backend: 'html5')
page = Nokogiri::HTML(html)
elements = page.css('img.plantuml')
assert_equal elements.size, 1
element = elements.first
assert_equal 'myId', element['id']
end
def test_plantuml_dimension_attribute
html = ::Asciidoctor.convert(StringIO.new(DOC_DIM), backend: 'html5')
page = Nokogiri::HTML(html)
elements = page.css('img.plantuml')
assert_equal elements.size, 1
element = elements.first
assert_equal '100px', element['width']
assert_equal '50px', element['height']
end
def test_plantuml_alt_attribute
html = ::Asciidoctor.convert(StringIO.new(DOC_ALT), backend: 'html5')
page = Nokogiri::HTML(html)
elements = page.css('img.plantuml')
assert_equal elements.size, 1
element = elements.first
assert_equal 'alt', element['alt']
end
def test_should_show_bad_format
html = ::Asciidoctor.convert(StringIO.new(DOC_BAD_FORMAT), backend: 'html5')
page = Nokogiri::HTML(html)
elements = page.css('pre.plantuml-error')
assert_equal elements.size, 1
end
def test_plantuml_multiple
html = ::Asciidoctor.convert(StringIO.new(DOC_MULTI), backend: 'html5')
page = Nokogiri::HTML(html)
elements = page.css('img.plantuml')
assert elements.size >= 2
elements = page.css('.plantuml-error')
assert_equal elements.size, 0
end
def test_plantuml_bad_server
Asciidoctor::PlantUml.configure do |c|
c.url = 'http://nonexistent.com/plantuml'
end
html = ::Asciidoctor.convert(StringIO.new(DOC_MULTI), backend: 'html5')
page = Nokogiri::HTML(html)
elements = page.css('img.plantuml')
assert_equal 3, elements.size
elements = page.css('.plantuml-error')
assert_equal 0, elements.size
end
def test_plantuml_invalid_uri
Asciidoctor::PlantUml.configure do |c|
c.url = 'ftp://test.com'
end
html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC), backend: 'html5')
page = Nokogiri::HTML(html)
elements = page.css('pre.plantuml-error')
assert_equal elements.size, 1
end
def test_plantuml_nil_uri
Asciidoctor::PlantUml.configure do |c|
c.url = nil
end
html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC), backend: 'html5')
page = Nokogiri::HTML(html)
elements = page.css('pre.plantuml-error')
assert_equal elements.size, 1
end
def test_plantuml_empty_uri
Asciidoctor::PlantUml.configure do |c|
c.url = ''
end
html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC), backend: 'html5')
page = Nokogiri::HTML(html)
elements = page.css('pre.plantuml-error')
assert_equal elements.size, 1
end
def test_disable_txt
Asciidoctor::PlantUml.configure do |c|
c.url = 'http://localhost:8080/plantuml'
c.txt_enable = false
end
html = ::Asciidoctor.convert(StringIO.new(DOC_TXT), backend: 'html5')
page = Nokogiri::HTML(html)
elements = page.css('pre.plantuml-error')
assert_equal elements.size, 1
end
end