forked from asciidoctor/asciidoctor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blocks_test.rb
4096 lines (3408 loc) · 133 KB
/
blocks_test.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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# frozen_string_literal: true
require_relative 'test_helper'
context 'Blocks' do
default_logger = Asciidoctor::LoggerManager.logger
setup do
Asciidoctor::LoggerManager.logger = (@logger = Asciidoctor::MemoryLogger.new)
end
teardown do
Asciidoctor::LoggerManager.logger = default_logger
end
context 'Layout Breaks' do
test 'horizontal rule' do
%w(''' '''' '''''').each do |line|
output = convert_string_to_embedded line
assert_includes output, '<hr>'
end
end
test 'horizontal rule with markdown syntax disabled' do
old_markdown_syntax = Asciidoctor::Compliance.markdown_syntax
begin
Asciidoctor::Compliance.markdown_syntax = false
%w(''' '''' '''''').each do |line|
output = convert_string_to_embedded line
assert_includes output, '<hr>'
end
%w(--- *** ___).each do |line|
output = convert_string_to_embedded line
refute_includes output, '<hr>'
end
ensure
Asciidoctor::Compliance.markdown_syntax = old_markdown_syntax
end
end
test '< 3 chars does not make horizontal rule' do
%w(' '').each do |line|
output = convert_string_to_embedded line
refute_includes output, '<hr>'
assert_includes output, %(<p>#{line}</p>)
end
end
test 'mixed chars does not make horizontal rule' do
[%q(''<), %q('''<), %q(' ' ')].each do |line|
output = convert_string_to_embedded line
refute_includes output, '<hr>'
assert_includes output, %(<p>#{line.sub '<', '<'}</p>)
end
end
test 'horizontal rule between blocks' do
output = convert_string_to_embedded %(Block above\n\n'''\n\nBlock below)
assert_xpath '/hr', output, 1
assert_xpath '/hr/preceding-sibling::*', output, 1
assert_xpath '/hr/following-sibling::*', output, 1
end
test 'horizontal rule with role' do
input = <<~'EOS'
[.fancy]
'''
EOS
output = convert_string_to_embedded input
assert_css 'hr', output, 1
assert_css 'hr.fancy', output, 1
end
test 'page break' do
output = convert_string_to_embedded %(page 1\n\n<<<\n\npage 2)
assert_xpath '/*[@class="page-break"]', output, 1
assert_xpath '/*[@class="page-break"]/preceding-sibling::div/p[text()="page 1"]', output, 1
assert_xpath '/*[@class="page-break"]/following-sibling::div/p[text()="page 2"]', output, 1
end
end
context 'Comments' do
test 'line comment between paragraphs offset by blank lines' do
input = <<~'EOS'
first paragraph
// line comment
second paragraph
EOS
output = convert_string_to_embedded input
refute_match(/line comment/, output)
assert_xpath '//p', output, 2
end
test 'adjacent line comment between paragraphs' do
input = <<~'EOS'
first line
// line comment
second line
EOS
output = convert_string_to_embedded input
refute_match(/line comment/, output)
assert_xpath '//p', output, 1
assert_xpath %(//p[1][text()='first line\nsecond line']), output, 1
end
test 'comment block between paragraphs offset by blank lines' do
input = <<~'EOS'
first paragraph
////
block comment
////
second paragraph
EOS
output = convert_string_to_embedded input
refute_match(/block comment/, output)
assert_xpath '//p', output, 2
end
test 'comment block between paragraphs offset by blank lines inside delimited block' do
input = <<~'EOS'
====
first paragraph
////
block comment
////
second paragraph
====
EOS
output = convert_string_to_embedded input
refute_match(/block comment/, output)
assert_xpath '//p', output, 2
end
test 'adjacent comment block between paragraphs' do
input = <<~'EOS'
first paragraph
////
block comment
////
second paragraph
EOS
output = convert_string_to_embedded input
refute_match(/block comment/, output)
assert_xpath '//p', output, 2
end
test 'can convert with block comment at end of document with trailing newlines' do
input = <<~'EOS'
paragraph
////
block comment
////
EOS
output = convert_string_to_embedded input
refute_match(/block comment/, output)
end
test 'trailing newlines after block comment at end of document does not create paragraph' do
input = <<~'EOS'
paragraph
////
block comment
////
EOS
d = document_from_string input
assert_equal 1, d.blocks.size
assert_xpath '//p', d.convert, 1
end
test 'line starting with three slashes should not be line comment' do
input = '/// not a line comment'
output = convert_string_to_embedded input
refute_empty output.strip, "Line should be emitted => #{input.rstrip}"
end
test 'preprocessor directives should not be processed within comment block within block metadata' do
input = <<~'EOS'
.sample title
////
ifdef::asciidoctor[////]
////
line should be shown
EOS
output = convert_string_to_embedded input
assert_xpath '//p[text()="line should be shown"]', output, 1
end
test 'preprocessor directives should not be processed within comment block' do
input = <<~'EOS'
dummy line
////
ifdef::asciidoctor[////]
////
line should be shown
EOS
output = convert_string_to_embedded input
assert_xpath '//p[text()="line should be shown"]', output, 1
end
test 'should warn if unterminated comment block is detected in body' do
input = <<~'EOS'
before comment block
////
content that has been disabled
supposed to be after comment block, except it got swallowed by block comment
EOS
convert_string_to_embedded input
assert_message @logger, :WARN, '<stdin>: line 3: unterminated comment block', Hash
end
test 'should warn if unterminated comment block is detected inside another block' do
input = <<~'EOS'
before sidebar block
****
////
content that has been disabled
****
supposed to be after sidebar block, except it got swallowed by block comment
EOS
convert_string_to_embedded input
assert_message @logger, :WARN, '<stdin>: line 4: unterminated comment block', Hash
end
# WARNING if first line of content is a directive, it will get interpreted before we know it's a comment block
# it happens because we always look a line ahead...not sure what we can do about it
test 'preprocessor directives should not be processed within comment open block' do
input = <<~'EOS'
[comment]
--
first line of comment
ifdef::asciidoctor[--]
line should not be shown
--
EOS
output = convert_string_to_embedded input
assert_xpath '//p', output, 0
end
# WARNING this assertion fails if the directive is the first line of the paragraph instead of the second
# it happens because we always look a line ahead; not sure what we can do about it
test 'preprocessor directives should not be processed on subsequent lines of a comment paragraph' do
input = <<~'EOS'
[comment]
first line of content
ifdef::asciidoctor[////]
this line should be shown
EOS
output = convert_string_to_embedded input
assert_xpath '//p[text()="this line should be shown"]', output, 1
end
test 'comment style on open block should only skip block' do
input = <<~'EOS'
[comment]
--
skip
this block
--
not this text
EOS
result = convert_string_to_embedded input
assert_xpath '//p', result, 1
assert_xpath '//p[text()="not this text"]', result, 1
end
test 'comment style on paragraph should only skip paragraph' do
input = <<~'EOS'
[comment]
skip
this paragraph
not this text
EOS
result = convert_string_to_embedded input
assert_xpath '//p', result, 1
assert_xpath '//p[text()="not this text"]', result, 1
end
test 'comment style on paragraph should not cause adjacent block to be skipped' do
input = <<~'EOS'
[comment]
skip
this paragraph
[example]
not this text
EOS
result = convert_string_to_embedded input
assert_xpath '/*[@class="exampleblock"]', result, 1
assert_xpath '/*[@class="exampleblock"]//*[normalize-space(text())="not this text"]', result, 1
end
# NOTE this test verifies the nil return value of Parser#next_block
test 'should not drop content that follows skipped content inside a delimited block' do
input = <<~'EOS'
====
paragraph
[comment#idname]
skip
paragraph
====
EOS
result = convert_string_to_embedded input
assert_xpath '/*[@class="exampleblock"]', result, 1
assert_xpath '/*[@class="exampleblock"]//*[@class="paragraph"]', result, 2
assert_xpath '//*[@class="paragraph"][@id="idname"]', result, 0
end
end
context 'Sidebar Blocks' do
test 'should parse sidebar block' do
input = <<~'EOS'
== Section
.Sidebar
****
Content goes here
****
EOS
result = convert_string input
assert_xpath '//*[@class="sidebarblock"]//p', result, 1
end
end
context 'Quote and Verse Blocks' do
test 'quote block with no attribution' do
input = <<~'EOS'
____
A famous quote.
____
EOS
output = convert_string input
assert_css '.quoteblock', output, 1
assert_css '.quoteblock > blockquote', output, 1
assert_css '.quoteblock > blockquote > .paragraph > p', output, 1
assert_css '.quoteblock > .attribution', output, 0
assert_xpath '//*[@class="quoteblock"]//p[text()="A famous quote."]', output, 1
end
test 'quote block with attribution' do
input = <<~'EOS'
[quote, Famous Person, Famous Book (1999)]
____
A famous quote.
____
EOS
output = convert_string input
assert_css '.quoteblock', output, 1
assert_css '.quoteblock > blockquote', output, 1
assert_css '.quoteblock > blockquote > .paragraph > p', output, 1
assert_css '.quoteblock > .attribution', output, 1
assert_css '.quoteblock > .attribution > cite', output, 1
assert_css '.quoteblock > .attribution > br + cite', output, 1
assert_xpath '//*[@class="quoteblock"]/*[@class="attribution"]/cite[text()="Famous Book (1999)"]', output, 1
attribution = xmlnodes_at_xpath '//*[@class="quoteblock"]/*[@class="attribution"]', output, 1
author = attribution.children.first
assert_equal "#{decode_char 8212} Famous Person", author.text.strip
end
test 'quote block with attribute and id and role shorthand' do
input = <<~'EOS'
[quote#justice-to-all.solidarity, Martin Luther King, Jr.]
____
Injustice anywhere is a threat to justice everywhere.
____
EOS
output = convert_string_to_embedded input
assert_css '.quoteblock', output, 1
assert_css '#justice-to-all.quoteblock.solidarity', output, 1
assert_css '.quoteblock > .attribution', output, 1
end
test 'setting ID using style shorthand should not reset block style' do
input = <<~'EOS'
[quote]
[#justice-to-all.solidarity, Martin Luther King, Jr.]
____
Injustice anywhere is a threat to justice everywhere.
____
EOS
output = convert_string_to_embedded input
assert_css '.quoteblock', output, 1
assert_css '#justice-to-all.quoteblock.solidarity', output, 1
assert_css '.quoteblock > .attribution', output, 1
end
test 'quote block with complex content' do
input = <<~'EOS'
____
A famous quote.
NOTE: _That_ was inspiring.
____
EOS
output = convert_string input
assert_css '.quoteblock', output, 1
assert_css '.quoteblock > blockquote', output, 1
assert_css '.quoteblock > blockquote > .paragraph', output, 1
assert_css '.quoteblock > blockquote > .paragraph + .admonitionblock', output, 1
end
test 'quote block with attribution converted to DocBook' do
input = <<~'EOS'
[quote, Famous Person, Famous Book (1999)]
____
A famous quote.
____
EOS
output = convert_string input, backend: :docbook
assert_css 'blockquote', output, 1
assert_css 'blockquote > simpara', output, 1
assert_css 'blockquote > attribution', output, 1
assert_css 'blockquote > attribution > citetitle', output, 1
assert_xpath '//blockquote/attribution/citetitle[text()="Famous Book (1999)"]', output, 1
attribution = xmlnodes_at_xpath '//blockquote/attribution', output, 1
author = attribution.children.first
assert_equal 'Famous Person', author.text.strip
end
test 'epigraph quote block with attribution converted to DocBook' do
input = <<~'EOS'
[.epigraph, Famous Person, Famous Book (1999)]
____
A famous quote.
____
EOS
output = convert_string input, backend: :docbook
assert_css 'epigraph', output, 1
assert_css 'epigraph > simpara', output, 1
assert_css 'epigraph > attribution', output, 1
assert_css 'epigraph > attribution > citetitle', output, 1
assert_xpath '//epigraph/attribution/citetitle[text()="Famous Book (1999)"]', output, 1
attribution = xmlnodes_at_xpath '//epigraph/attribution', output, 1
author = attribution.children.first
assert_equal 'Famous Person', author.text.strip
end
test 'markdown-style quote block with single paragraph and no attribution' do
input = <<~'EOS'
> A famous quote.
> Some more inspiring words.
EOS
output = convert_string input
assert_css '.quoteblock', output, 1
assert_css '.quoteblock > blockquote', output, 1
assert_css '.quoteblock > blockquote > .paragraph > p', output, 1
assert_css '.quoteblock > .attribution', output, 0
assert_xpath %(//*[@class="quoteblock"]//p[text()="A famous quote.\nSome more inspiring words."]), output, 1
end
test 'lazy markdown-style quote block with single paragraph and no attribution' do
input = <<~'EOS'
> A famous quote.
Some more inspiring words.
EOS
output = convert_string input
assert_css '.quoteblock', output, 1
assert_css '.quoteblock > blockquote', output, 1
assert_css '.quoteblock > blockquote > .paragraph > p', output, 1
assert_css '.quoteblock > .attribution', output, 0
assert_xpath %(//*[@class="quoteblock"]//p[text()="A famous quote.\nSome more inspiring words."]), output, 1
end
test 'markdown-style quote block with multiple paragraphs and no attribution' do
input = <<~'EOS'
> A famous quote.
>
> Some more inspiring words.
EOS
output = convert_string input
assert_css '.quoteblock', output, 1
assert_css '.quoteblock > blockquote', output, 1
assert_css '.quoteblock > blockquote > .paragraph > p', output, 2
assert_css '.quoteblock > .attribution', output, 0
assert_xpath %((//*[@class="quoteblock"]//p)[1][text()="A famous quote."]), output, 1
assert_xpath %((//*[@class="quoteblock"]//p)[2][text()="Some more inspiring words."]), output, 1
end
test 'markdown-style quote block with multiple blocks and no attribution' do
input = <<~'EOS'
> A famous quote.
>
> NOTE: Some more inspiring words.
EOS
output = convert_string input
assert_css '.quoteblock', output, 1
assert_css '.quoteblock > blockquote', output, 1
assert_css '.quoteblock > blockquote > .paragraph > p', output, 1
assert_css '.quoteblock > blockquote > .admonitionblock', output, 1
assert_css '.quoteblock > .attribution', output, 0
assert_xpath %((//*[@class="quoteblock"]//p)[1][text()="A famous quote."]), output, 1
assert_xpath %((//*[@class="quoteblock"]//*[@class="admonitionblock note"]//*[@class="content"])[1][normalize-space(text())="Some more inspiring words."]), output, 1
end
test 'markdown-style quote block with single paragraph and attribution' do
input = <<~'EOS'
> A famous quote.
> Some more inspiring words.
> -- Famous Person, Famous Source, Volume 1 (1999)
EOS
output = convert_string input
assert_css '.quoteblock', output, 1
assert_css '.quoteblock > blockquote', output, 1
assert_css '.quoteblock > blockquote > .paragraph > p', output, 1
assert_xpath %(//*[@class="quoteblock"]//p[text()="A famous quote.\nSome more inspiring words."]), output, 1
assert_css '.quoteblock > .attribution', output, 1
assert_css '.quoteblock > .attribution > cite', output, 1
assert_css '.quoteblock > .attribution > br + cite', output, 1
assert_xpath '//*[@class="quoteblock"]/*[@class="attribution"]/cite[text()="Famous Source, Volume 1 (1999)"]', output, 1
attribution = xmlnodes_at_xpath '//*[@class="quoteblock"]/*[@class="attribution"]', output, 1
author = attribution.children.first
assert_equal "#{decode_char 8212} Famous Person", author.text.strip
end
test 'markdown-style quote block with only attribution' do
input = '> -- Anonymous'
output = convert_string input
assert_css '.quoteblock', output, 1
assert_css '.quoteblock > blockquote', output, 1
assert_css '.quoteblock > blockquote > *', output, 0
assert_css '.quoteblock > .attribution', output, 1
assert_xpath %(//*[@class="quoteblock"]//*[@class="attribution"][contains(text(),"Anonymous")]), output, 1
end
test 'should parse credit line in markdown-style quote block like positional block attributes' do
input = <<~'EOS'
> I hold it that a little rebellion now and then is a good thing,
> and as necessary in the political world as storms in the physical.
-- Thomas Jefferson, https://jeffersonpapers.princeton.edu/selected-documents/james-madison-1[The Papers of Thomas Jefferson, Volume 11]
EOS
output = convert_string_to_embedded input
assert_css '.quoteblock', output, 1
assert_css '.quoteblock cite a[href="https://jeffersonpapers.princeton.edu/selected-documents/james-madison-1"]', output, 1
end
test 'quoted paragraph-style quote block with attribution' do
input = <<~'EOS'
"A famous quote.
Some more inspiring words."
-- Famous Person, Famous Source, Volume 1 (1999)
EOS
output = convert_string input
assert_css '.quoteblock', output, 1
assert_css '.quoteblock > blockquote', output, 1
assert_xpath %(//*[@class="quoteblock"]/blockquote[normalize-space(text())="A famous quote. Some more inspiring words."]), output, 1
assert_css '.quoteblock > .attribution', output, 1
assert_css '.quoteblock > .attribution > cite', output, 1
assert_css '.quoteblock > .attribution > br + cite', output, 1
assert_xpath '//*[@class="quoteblock"]/*[@class="attribution"]/cite[text()="Famous Source, Volume 1 (1999)"]', output, 1
attribution = xmlnodes_at_xpath '//*[@class="quoteblock"]/*[@class="attribution"]', output, 1
author = attribution.children.first
assert_equal "#{decode_char 8212} Famous Person", author.text.strip
end
test 'should parse credit line in quoted paragraph-style quote block like positional block attributes' do
input = <<~'EOS'
"I hold it that a little rebellion now and then is a good thing,
and as necessary in the political world as storms in the physical."
-- Thomas Jefferson, https://jeffersonpapers.princeton.edu/selected-documents/james-madison-1[The Papers of Thomas Jefferson, Volume 11]
EOS
output = convert_string_to_embedded input
assert_css '.quoteblock', output, 1
assert_css '.quoteblock cite a[href="https://jeffersonpapers.princeton.edu/selected-documents/james-madison-1"]', output, 1
end
test 'single-line verse block without attribution' do
input = <<~'EOS'
[verse]
____
A famous verse.
____
EOS
output = convert_string input
assert_css '.verseblock', output, 1
assert_css '.verseblock > pre', output, 1
assert_css '.verseblock > .attribution', output, 0
assert_css '.verseblock p', output, 0
assert_xpath '//*[@class="verseblock"]/pre[normalize-space(text())="A famous verse."]', output, 1
end
test 'single-line verse block with attribution' do
input = <<~'EOS'
[verse, Famous Poet, Famous Poem]
____
A famous verse.
____
EOS
output = convert_string input
assert_css '.verseblock', output, 1
assert_css '.verseblock p', output, 0
assert_css '.verseblock > pre', output, 1
assert_css '.verseblock > .attribution', output, 1
assert_css '.verseblock > .attribution > cite', output, 1
assert_css '.verseblock > .attribution > br + cite', output, 1
assert_xpath '//*[@class="verseblock"]/*[@class="attribution"]/cite[text()="Famous Poem"]', output, 1
attribution = xmlnodes_at_xpath '//*[@class="verseblock"]/*[@class="attribution"]', output, 1
author = attribution.children.first
assert_equal "#{decode_char 8212} Famous Poet", author.text.strip
end
test 'single-line verse block with attribution converted to DocBook' do
input = <<~'EOS'
[verse, Famous Poet, Famous Poem]
____
A famous verse.
____
EOS
output = convert_string input, backend: :docbook
assert_css 'blockquote', output, 1
assert_css 'blockquote simpara', output, 0
assert_css 'blockquote > literallayout', output, 1
assert_css 'blockquote > attribution', output, 1
assert_css 'blockquote > attribution > citetitle', output, 1
assert_xpath '//blockquote/attribution/citetitle[text()="Famous Poem"]', output, 1
attribution = xmlnodes_at_xpath '//blockquote/attribution', output, 1
author = attribution.children.first
assert_equal 'Famous Poet', author.text.strip
end
test 'single-line epigraph verse block with attribution converted to DocBook' do
input = <<~'EOS'
[verse.epigraph, Famous Poet, Famous Poem]
____
A famous verse.
____
EOS
output = convert_string input, backend: :docbook
assert_css 'epigraph', output, 1
assert_css 'epigraph simpara', output, 0
assert_css 'epigraph > literallayout', output, 1
assert_css 'epigraph > attribution', output, 1
assert_css 'epigraph > attribution > citetitle', output, 1
assert_xpath '//epigraph/attribution/citetitle[text()="Famous Poem"]', output, 1
attribution = xmlnodes_at_xpath '//epigraph/attribution', output, 1
author = attribution.children.first
assert_equal 'Famous Poet', author.text.strip
end
test 'multi-stanza verse block' do
input = <<~'EOS'
[verse]
____
A famous verse.
Stanza two.
____
EOS
output = convert_string input
assert_xpath '//*[@class="verseblock"]', output, 1
assert_xpath '//*[@class="verseblock"]/pre', output, 1
assert_xpath '//*[@class="verseblock"]//p', output, 0
assert_xpath '//*[@class="verseblock"]/pre[contains(text(), "A famous verse.")]', output, 1
assert_xpath '//*[@class="verseblock"]/pre[contains(text(), "Stanza two.")]', output, 1
end
test 'verse block does not contain block elements' do
input = <<~'EOS'
[verse]
____
A famous verse.
....
not a literal
....
____
EOS
output = convert_string input
assert_css '.verseblock', output, 1
assert_css '.verseblock > pre', output, 1
assert_css '.verseblock p', output, 0
assert_css '.verseblock .literalblock', output, 0
end
test 'verse should have normal subs' do
input = <<~'EOS'
[verse]
____
A famous verse
____
EOS
verse = block_from_string input
assert_equal Asciidoctor::Substitutors::NORMAL_SUBS, verse.subs
end
test 'should not recognize callouts in a verse' do
input = <<~'EOS'
[verse]
____
La la la <1>
____
<1> Not pointing to a callout
EOS
output = convert_string_to_embedded input
assert_xpath '//pre[text()="La la la <1>"]', output, 1
assert_message @logger, :WARN, '<stdin>: line 5: no callout found for <1>', Hash
end
test 'should perform normal subs on a verse block' do
input = <<~'EOS'
[verse]
____
_GET /groups/link:#group-id[\{group-id\}]_
____
EOS
output = convert_string_to_embedded input
assert_includes output, '<pre class="content"><em>GET /groups/<a href="#group-id">{group-id}</a></em></pre>'
end
end
context 'Example Blocks' do
test 'can convert example block' do
input = <<~'EOS'
====
This is an example of an example block.
How crazy is that?
====
EOS
output = convert_string input
assert_xpath '//*[@class="exampleblock"]//p', output, 2
end
test 'assigns sequential numbered caption to example block with title' do
input = <<~'EOS'
.Writing Docs with AsciiDoc
====
Here's how you write AsciiDoc.
You just write.
====
.Writing Docs with DocBook
====
Here's how you write DocBook.
You futz with XML.
====
EOS
doc = document_from_string input
assert_equal 1, doc.blocks[0].numeral
assert_equal 1, doc.blocks[0].number
assert_equal 2, doc.blocks[1].numeral
assert_equal 2, doc.blocks[1].number
output = doc.convert
assert_xpath '(//*[@class="exampleblock"])[1]/*[@class="title"][text()="Example 1. Writing Docs with AsciiDoc"]', output, 1
assert_xpath '(//*[@class="exampleblock"])[2]/*[@class="title"][text()="Example 2. Writing Docs with DocBook"]', output, 1
assert_equal 2, doc.attributes['example-number']
end
test 'assigns sequential character caption to example block with title' do
input = <<~'EOS'
:example-number: @
.Writing Docs with AsciiDoc
====
Here's how you write AsciiDoc.
You just write.
====
.Writing Docs with DocBook
====
Here's how you write DocBook.
You futz with XML.
====
EOS
doc = document_from_string input
assert_equal 'A', doc.blocks[0].numeral
assert_equal 'A', doc.blocks[0].number
assert_equal 'B', doc.blocks[1].numeral
assert_equal 'B', doc.blocks[1].number
output = doc.convert
assert_xpath '(//*[@class="exampleblock"])[1]/*[@class="title"][text()="Example A. Writing Docs with AsciiDoc"]', output, 1
assert_xpath '(//*[@class="exampleblock"])[2]/*[@class="title"][text()="Example B. Writing Docs with DocBook"]', output, 1
assert_equal 'B', doc.attributes['example-number']
end
test 'should increment counter for example even when example-number is locked by the API' do
input = <<~'EOS'
.Writing Docs with AsciiDoc
====
Here's how you write AsciiDoc.
You just write.
====
.Writing Docs with DocBook
====
Here's how you write DocBook.
You futz with XML.
====
EOS
doc = document_from_string input, attributes: { 'example-number' => '`' }
output = doc.convert
assert_xpath '(//*[@class="exampleblock"])[1]/*[@class="title"][text()="Example a. Writing Docs with AsciiDoc"]', output, 1
assert_xpath '(//*[@class="exampleblock"])[2]/*[@class="title"][text()="Example b. Writing Docs with DocBook"]', output, 1
assert_equal 'b', doc.attributes['example-number']
end
test 'should use explicit caption if specified' do
input = <<~'EOS'
[caption="Look! "]
.Writing Docs with AsciiDoc
====
Here's how you write AsciiDoc.
You just write.
====
EOS
doc = document_from_string input
assert_nil doc.blocks[0].numeral
output = doc.convert
assert_xpath '(//*[@class="exampleblock"])[1]/*[@class="title"][text()="Look! Writing Docs with AsciiDoc"]', output, 1
refute doc.attributes.key? 'example-number'
end
test 'automatic caption can be turned off and on and modified' do
input = <<~'EOS'
.first example
====
an example
====
:caption:
.second example
====
another example
====
:caption!:
:example-caption: Exhibit
.third example
====
yet another example
====
EOS
output = convert_string_to_embedded input
assert_xpath '/*[@class="exampleblock"]', output, 3
assert_xpath '(/*[@class="exampleblock"])[1]/*[@class="title"][starts-with(text(), "Example ")]', output, 1
assert_xpath '(/*[@class="exampleblock"])[2]/*[@class="title"][text()="second example"]', output, 1
assert_xpath '(/*[@class="exampleblock"])[3]/*[@class="title"][starts-with(text(), "Exhibit ")]', output, 1
end
test 'should use explicit caption if specified even if block-specific global caption is disabled' do
input = <<~'EOS'
:!example-caption:
[caption="Look! "]
.Writing Docs with AsciiDoc
====
Here's how you write AsciiDoc.
You just write.
====
EOS
doc = document_from_string input
assert_nil doc.blocks[0].numeral
output = doc.convert
assert_xpath '(//*[@class="exampleblock"])[1]/*[@class="title"][text()="Look! Writing Docs with AsciiDoc"]', output, 1
refute doc.attributes.key? 'example-number'
end
test 'should use global caption if specified even if block-specific global caption is disabled' do
input = <<~'EOS'
:!example-caption:
:caption: Look!{sp}
.Writing Docs with AsciiDoc
====
Here's how you write AsciiDoc.
You just write.
====
EOS
doc = document_from_string input
assert_nil doc.blocks[0].numeral
output = doc.convert
assert_xpath '(//*[@class="exampleblock"])[1]/*[@class="title"][text()="Look! Writing Docs with AsciiDoc"]', output, 1
refute doc.attributes.key? 'example-number'
end
test 'should not process caption attribute on block that does not support a caption' do
input = <<~'EOS'
[caption="Look! "]
.No caption here
--
content
--
EOS
doc = document_from_string input
assert_nil doc.blocks[0].caption
assert_equal 'Look! ', (doc.blocks[0].attr 'caption')
output = doc.convert
assert_xpath '(//*[@class="openblock"])[1]/*[@class="title"][text()="No caption here"]', output, 1
end
test 'should create details/summary set if collapsible option is set' do
input = <<~'EOS'
.Toggle Me
[%collapsible]
====
This content is revealed when the user clicks the words "Toggle Me".
====
EOS
output = convert_string_to_embedded input
assert_css 'details', output, 1
assert_css 'details[open]', output, 0
assert_css 'details > summary.title', output, 1
assert_xpath '//details/summary[text()="Toggle Me"]', output, 1
assert_css 'details > summary.title + .content', output, 1
assert_css 'details > summary.title + .content p', output, 1
end
test 'should open details/summary set if collapsible and open options are set' do
input = <<~'EOS'
.Toggle Me
[%collapsible%open]
====
This content is revealed when the user clicks the words "Toggle Me".
====
EOS
output = convert_string_to_embedded input
assert_css 'details', output, 1
assert_css 'details[open]', output, 1
assert_css 'details > summary.title', output, 1
assert_xpath '//details/summary[text()="Toggle Me"]', output, 1
end
test 'should add default summary element if collapsible option is set and title is not specifed' do
input = <<~'EOS'
[%collapsible]
====
This content is revealed when the user clicks the words "Details".
====
EOS
output = convert_string_to_embedded input
assert_css 'details', output, 1
assert_css 'details > summary.title', output, 1
assert_xpath '//details/summary[text()="Details"]', output, 1
end
test 'should not allow collapsible block to increment example number' do
input = <<~'EOS'
.Before
====
before
====