asciidoctor 1.5.5 → 1.5.6

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of asciidoctor might be problematic. Click here for more details.

Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +216 -1
  3. data/CONTRIBUTING.adoc +2 -2
  4. data/Gemfile +20 -1
  5. data/LICENSE.adoc +1 -1
  6. data/README-fr.adoc +4 -3
  7. data/README-jp.adoc +11 -10
  8. data/README-zh_CN.adoc +4 -3
  9. data/README.adoc +17 -202
  10. data/Rakefile +41 -25
  11. data/asciidoctor.gemspec +9 -10
  12. data/data/locale/attributes.adoc +216 -34
  13. data/data/stylesheets/asciidoctor-default.css +23 -16
  14. data/features/step_definitions.rb +15 -19
  15. data/features/xref.feature +584 -20
  16. data/lib/asciidoctor.rb +292 -278
  17. data/lib/asciidoctor/abstract_block.rb +155 -94
  18. data/lib/asciidoctor/abstract_node.rb +108 -94
  19. data/lib/asciidoctor/attribute_list.rb +30 -22
  20. data/lib/asciidoctor/block.rb +7 -7
  21. data/lib/asciidoctor/cli/invoker.rb +47 -34
  22. data/lib/asciidoctor/cli/options.rb +22 -11
  23. data/lib/asciidoctor/converter.rb +3 -3
  24. data/lib/asciidoctor/converter/base.rb +2 -2
  25. data/lib/asciidoctor/converter/composite.rb +1 -1
  26. data/lib/asciidoctor/converter/docbook45.rb +2 -2
  27. data/lib/asciidoctor/converter/docbook5.rb +132 -87
  28. data/lib/asciidoctor/converter/factory.rb +0 -1
  29. data/lib/asciidoctor/converter/html5.rb +116 -98
  30. data/lib/asciidoctor/converter/manpage.rb +51 -52
  31. data/lib/asciidoctor/converter/template.rb +47 -36
  32. data/lib/asciidoctor/core_ext.rb +8 -2
  33. data/lib/asciidoctor/core_ext/1.8.7/hash/key.rb +4 -0
  34. data/lib/asciidoctor/core_ext/1.8.7/io/binread.rb +6 -0
  35. data/lib/asciidoctor/core_ext/1.8.7/io/write.rb +5 -0
  36. data/lib/asciidoctor/core_ext/1.8.7/string/chr.rb +1 -1
  37. data/lib/asciidoctor/core_ext/1.8.7/string/{limit.rb → limit_bytesize.rb} +7 -6
  38. data/lib/asciidoctor/core_ext/1.8.7/symbol/empty.rb +6 -0
  39. data/lib/asciidoctor/core_ext/1.8.7/symbol/length.rb +1 -1
  40. data/lib/asciidoctor/core_ext/nil_or_empty.rb +5 -5
  41. data/lib/asciidoctor/core_ext/regexp/is_match.rb +3 -0
  42. data/lib/asciidoctor/core_ext/string/{limit.rb → limit_bytesize.rb} +2 -2
  43. data/lib/asciidoctor/document.rb +216 -213
  44. data/lib/asciidoctor/extensions.rb +318 -185
  45. data/lib/asciidoctor/helpers.rb +35 -35
  46. data/lib/asciidoctor/inline.rb +32 -1
  47. data/lib/asciidoctor/list.rb +22 -6
  48. data/lib/asciidoctor/parser.rb +1008 -1038
  49. data/lib/asciidoctor/path_resolver.rb +46 -50
  50. data/lib/asciidoctor/reader.rb +275 -251
  51. data/lib/asciidoctor/section.rb +86 -58
  52. data/lib/asciidoctor/stylesheets.rb +6 -6
  53. data/lib/asciidoctor/substitutors.rb +567 -649
  54. data/lib/asciidoctor/table.rb +163 -108
  55. data/lib/asciidoctor/version.rb +1 -1
  56. data/man/asciidoctor.1 +18 -16
  57. data/man/asciidoctor.adoc +15 -13
  58. data/test/attributes_test.rb +138 -22
  59. data/test/blocks_test.rb +377 -97
  60. data/test/converter_test.rb +13 -0
  61. data/test/document_test.rb +244 -34
  62. data/test/extensions_test.rb +409 -42
  63. data/test/fixtures/asciidoc_index.txt +521 -0
  64. data/test/fixtures/basic-docinfo-footer.html +6 -0
  65. data/test/fixtures/basic-docinfo-footer.xml +8 -0
  66. data/test/fixtures/basic-docinfo.html +1 -0
  67. data/test/fixtures/basic-docinfo.xml +4 -0
  68. data/test/fixtures/basic.asciidoc +5 -0
  69. data/test/fixtures/chapter-a.adoc +3 -0
  70. data/test/fixtures/child-include.adoc +5 -0
  71. data/test/fixtures/circle.svg +9 -0
  72. data/test/fixtures/custom-backends/erb/html5/block_paragraph.html.erb +6 -0
  73. data/test/fixtures/custom-backends/haml/docbook45/block_paragraph.xml.haml +6 -0
  74. data/test/fixtures/custom-backends/haml/html5-tweaks/block_paragraph.html.haml +1 -0
  75. data/test/fixtures/custom-backends/haml/html5/block_paragraph.html.haml +3 -0
  76. data/test/fixtures/custom-backends/haml/html5/block_sidebar.html.haml +5 -0
  77. data/test/fixtures/custom-backends/slim/docbook45/block_paragraph.xml.slim +6 -0
  78. data/test/fixtures/custom-backends/slim/html5/block_paragraph.html.slim +3 -0
  79. data/test/fixtures/custom-backends/slim/html5/block_sidebar.html.slim +5 -0
  80. data/test/fixtures/custom-docinfodir/basic-docinfo.html +1 -0
  81. data/test/fixtures/custom-docinfodir/docinfo.html +1 -0
  82. data/test/fixtures/docinfo-footer.html +1 -0
  83. data/test/fixtures/docinfo-footer.xml +9 -0
  84. data/test/fixtures/docinfo.html +1 -0
  85. data/test/fixtures/docinfo.xml +3 -0
  86. data/test/fixtures/dot.gif +0 -0
  87. data/test/fixtures/encoding.asciidoc +13 -0
  88. data/test/fixtures/grandchild-include.adoc +3 -0
  89. data/test/fixtures/hello-asciidoctor.pdf +69 -0
  90. data/test/fixtures/include-file.asciidoc +24 -0
  91. data/test/fixtures/include-file.ml +3 -0
  92. data/test/fixtures/include-file.xml +5 -0
  93. data/test/fixtures/master.adoc +5 -0
  94. data/test/fixtures/mismatched-end-tag.adoc +7 -0
  95. data/test/fixtures/parent-include-restricted.adoc +5 -0
  96. data/test/fixtures/parent-include.adoc +5 -0
  97. data/test/fixtures/sample.asciidoc +26 -0
  98. data/test/fixtures/stylesheets/custom.css +3 -0
  99. data/test/fixtures/subs-docinfo.html +2 -0
  100. data/test/fixtures/subs.adoc +7 -0
  101. data/test/fixtures/tagged-class-enclosed.rb +26 -0
  102. data/test/fixtures/tagged-class.rb +23 -0
  103. data/test/fixtures/tip.gif +0 -0
  104. data/test/invoker_test.rb +82 -4
  105. data/test/links_test.rb +312 -37
  106. data/test/lists_test.rb +204 -25
  107. data/test/manpage_test.rb +191 -4
  108. data/test/options_test.rb +18 -1
  109. data/test/paragraphs_test.rb +32 -7
  110. data/test/parser_test.rb +150 -30
  111. data/test/paths_test.rb +47 -13
  112. data/test/preamble_test.rb +1 -1
  113. data/test/reader_test.rb +366 -126
  114. data/test/sections_test.rb +203 -56
  115. data/test/substitutions_test.rb +339 -131
  116. data/test/tables_test.rb +315 -15
  117. data/test/test_helper.rb +400 -0
  118. data/test/text_test.rb +5 -5
  119. metadata +110 -22
@@ -147,7 +147,7 @@ The axe came swinging.
147
147
  assert_equal 'book', d.doctype
148
148
  output = d.render
149
149
  assert_xpath '//h1', output, 3
150
- assert_xpath %{//*[@id="preamble"]//p[text() = "Back then#{expand_entity 8230}#{expand_entity 8203}"]}, output, 1
150
+ assert_xpath %{//*[@id="preamble"]//p[text() = "Back then#{decode_char 8230}#{decode_char 8203}"]}, output, 1
151
151
  end
152
152
 
153
153
  test 'should render table of contents in preamble if toc-placement attribute value is preamble' do
@@ -7,7 +7,7 @@ end
7
7
  class ReaderTest < Minitest::Test
8
8
  DIRNAME = File.expand_path(File.dirname(__FILE__))
9
9
 
10
- SAMPLE_DATA = <<-EOS.chomp.split(::Asciidoctor::EOL)
10
+ SAMPLE_DATA = <<-EOS.chomp.split(::Asciidoctor::LF)
11
11
  first line
12
12
  second line
13
13
  third line
@@ -26,9 +26,9 @@ third line
26
26
  end
27
27
 
28
28
  test 'should remove UTF-8 BOM from first line of String data' do
29
- data = "\xef\xbb\xbf#{SAMPLE_DATA.join ::Asciidoctor::EOL}"
29
+ data = "\xef\xbb\xbf#{SAMPLE_DATA.join ::Asciidoctor::LF}"
30
30
  reader = Asciidoctor::Reader.new data, nil, :normalize => true
31
- assert_equal 'f', reader.lines.first[0..0]
31
+ assert_equal 'f', reader.lines.first.chr
32
32
  assert_equal SAMPLE_DATA, reader.lines
33
33
  end
34
34
 
@@ -36,36 +36,36 @@ third line
36
36
  data = SAMPLE_DATA.dup
37
37
  data[0] = "\xef\xbb\xbf#{data.first}"
38
38
  reader = Asciidoctor::Reader.new data, nil, :normalize => true
39
- assert_equal 'f', reader.lines.first[0..0]
39
+ assert_equal 'f', reader.lines.first.chr
40
40
  assert_equal SAMPLE_DATA, reader.lines
41
41
  end
42
42
 
43
43
  if Asciidoctor::COERCE_ENCODING
44
44
  test 'should encode UTF-16LE string to UTF-8 when BOM is found' do
45
- data = "\uFEFF#{SAMPLE_DATA.join ::Asciidoctor::EOL}".encode('UTF-16LE').force_encoding('UTF-8')
45
+ data = "\ufeff#{SAMPLE_DATA.join ::Asciidoctor::LF}".encode('UTF-16LE').force_encoding('UTF-8')
46
46
  reader = Asciidoctor::Reader.new data, nil, :normalize => true
47
- assert_equal 'f', reader.lines.first[0..0]
47
+ assert_equal 'f', reader.lines.first.chr
48
48
  assert_equal SAMPLE_DATA, reader.lines
49
49
  end
50
50
 
51
51
  test 'should encode UTF-16LE string array to UTF-8 when BOM is found' do
52
- data = "\uFEFF#{SAMPLE_DATA.join ::Asciidoctor::EOL}".encode('UTF-16LE').force_encoding('UTF-8').lines.to_a
52
+ data = "\ufeff#{SAMPLE_DATA.join ::Asciidoctor::LF}".encode('UTF-16LE').force_encoding('UTF-8').lines.to_a
53
53
  reader = Asciidoctor::Reader.new data, nil, :normalize => true
54
- assert_equal 'f', reader.lines.first[0..0]
54
+ assert_equal 'f', reader.lines.first.chr
55
55
  assert_equal SAMPLE_DATA, reader.lines
56
56
  end
57
57
 
58
58
  test 'should encode UTF-16BE string to UTF-8 when BOM is found' do
59
- data = "\uFEFF#{SAMPLE_DATA.join ::Asciidoctor::EOL}".encode('UTF-16BE').force_encoding('UTF-8')
59
+ data = "\ufeff#{SAMPLE_DATA.join ::Asciidoctor::LF}".encode('UTF-16BE').force_encoding('UTF-8')
60
60
  reader = Asciidoctor::Reader.new data, nil, :normalize => true
61
- assert_equal 'f', reader.lines.first[0..0]
61
+ assert_equal 'f', reader.lines.first.chr
62
62
  assert_equal SAMPLE_DATA, reader.lines
63
63
  end
64
64
 
65
65
  test 'should encode UTF-16BE string array to UTF-8 when BOM is found' do
66
- data = "\uFEFF#{SAMPLE_DATA.join ::Asciidoctor::EOL}".encode('UTF-16BE').force_encoding('UTF-8').lines.to_a
66
+ data = "\ufeff#{SAMPLE_DATA.join ::Asciidoctor::LF}".encode('UTF-16BE').force_encoding('UTF-8').lines.to_a
67
67
  reader = Asciidoctor::Reader.new data, nil, :normalize => true
68
- assert_equal 'f', reader.lines.first[0..0]
68
+ assert_equal 'f', reader.lines.first.chr
69
69
  assert_equal SAMPLE_DATA, reader.lines
70
70
  end
71
71
  end
@@ -150,6 +150,12 @@ third line
150
150
  assert_equal 1, reader.lineno
151
151
  end
152
152
 
153
+ test 'peek_lines should not increment line number if reader overruns buffer' do
154
+ reader = Asciidoctor::Reader.new SAMPLE_DATA
155
+ assert_equal SAMPLE_DATA, (reader.peek_lines SAMPLE_DATA.size * 2)
156
+ assert_equal 1, reader.lineno
157
+ end
158
+
153
159
  test 'peek_lines should not invert order of lines' do
154
160
  reader = Asciidoctor::Reader.new SAMPLE_DATA
155
161
  assert_equal SAMPLE_DATA, reader.lines
@@ -184,7 +190,7 @@ third line
184
190
 
185
191
  test 'read should return all lines joined as String' do
186
192
  reader = Asciidoctor::Reader.new SAMPLE_DATA
187
- assert_equal SAMPLE_DATA.join(::Asciidoctor::EOL), reader.read
193
+ assert_equal SAMPLE_DATA.join(::Asciidoctor::LF), reader.read
188
194
  end
189
195
 
190
196
  test 'has_more_lines? should return false after read_lines is invoked' do
@@ -229,7 +235,7 @@ third line
229
235
  test 'source should return original data Array joined as String' do
230
236
  reader = Asciidoctor::Reader.new SAMPLE_DATA
231
237
  reader.read_lines
232
- assert_equal SAMPLE_DATA.join(::Asciidoctor::EOL), reader.source
238
+ assert_equal SAMPLE_DATA.join(::Asciidoctor::LF), reader.source
233
239
  end
234
240
 
235
241
  end
@@ -286,7 +292,7 @@ This is another paragraph.
286
292
  end
287
293
 
288
294
  test 'Read lines until until blank line preserving last line' do
289
- lines = <<-EOS.chomp.split(::Asciidoctor::EOL)
295
+ lines = <<-EOS.chomp.split(::Asciidoctor::LF)
290
296
  This is one paragraph.
291
297
 
292
298
  This is another paragraph.
@@ -300,7 +306,7 @@ This is another paragraph.
300
306
  end
301
307
 
302
308
  test 'Read lines until until condition is true' do
303
- lines = <<-EOS.chomp.split(::Asciidoctor::EOL)
309
+ lines = <<-EOS.chomp.split(::Asciidoctor::LF)
304
310
  --
305
311
  This is one paragraph inside the block.
306
312
 
@@ -319,7 +325,7 @@ This is a paragraph outside the block.
319
325
  end
320
326
 
321
327
  test 'Read lines until until condition is true, taking last line' do
322
- lines = <<-EOS.chomp.split(::Asciidoctor::EOL)
328
+ lines = <<-EOS.chomp.split(::Asciidoctor::LF)
323
329
  --
324
330
  This is one paragraph inside the block.
325
331
 
@@ -338,7 +344,7 @@ This is a paragraph outside the block.
338
344
  end
339
345
 
340
346
  test 'Read lines until until condition is true, taking and preserving last line' do
341
- lines = <<-EOS.chomp.split(::Asciidoctor::EOL)
347
+ lines = <<-EOS.chomp.split(::Asciidoctor::LF)
342
348
  --
343
349
  This is one paragraph inside the block.
344
350
 
@@ -387,7 +393,7 @@ This is a paragraph outside the block.
387
393
  data = SAMPLE_DATA.map {|line| line.chomp}
388
394
  data.unshift ' '
389
395
  data.push ' '
390
- data_as_string = data * ::Asciidoctor::EOL
396
+ data_as_string = data * ::Asciidoctor::LF
391
397
  doc = Asciidoctor::Document.new data_as_string
392
398
  reader = doc.reader
393
399
  assert_equal SAMPLE_DATA, reader.lines
@@ -401,7 +407,7 @@ CRLF\r
401
407
  endlines\r
402
408
  EOS
403
409
 
404
- [input, input.lines.to_a, input.split(::Asciidoctor::EOL), input.split(::Asciidoctor::EOL).join(::Asciidoctor::EOL)].each do |lines|
410
+ [input, input.lines.to_a, input.split(::Asciidoctor::LF), input.split(::Asciidoctor::LF).join(::Asciidoctor::LF)].each do |lines|
405
411
  doc = Asciidoctor::Document.new lines
406
412
  reader = doc.reader
407
413
  reader.lines.each do |line|
@@ -551,7 +557,7 @@ include::fixtures/parent-include.adoc[]
551
557
  grandchild_include_docfile = File.join fixtures_dir, 'grandchild-include.adoc'
552
558
 
553
559
  doc = empty_safe_document :base_dir => DIRNAME
554
- reader = Asciidoctor::PreprocessorReader.new doc, input, pseudo_docfile
560
+ reader = Asciidoctor::PreprocessorReader.new doc, input, pseudo_docfile, :normalize => true
555
561
 
556
562
  assert_equal pseudo_docfile, reader.file
557
563
  assert_equal DIRNAME, reader.dir
@@ -608,10 +614,13 @@ trailing content
608
614
  EOS
609
615
 
610
616
  begin
611
- doc = document_from_string input, :safe => :safe, :base_dir => DIRNAME
617
+ doc, warnings = redirect_streams do |_, err|
618
+ [(document_from_string input, :safe => :safe, :base_dir => DIRNAME), err.string]
619
+ end
612
620
  assert_equal 2, doc.blocks.size
613
621
  assert_equal ['Unresolved directive in <stdin> - include::fixtures/no-such-file.adoc[]'], doc.blocks[0].lines
614
622
  assert_equal ['trailing content'], doc.blocks[1].lines
623
+ assert_includes warnings, 'include file not found'
615
624
  rescue
616
625
  flunk 'include directive should not raise exception on missing file'
617
626
  end
@@ -627,10 +636,13 @@ trailing content
627
636
  EOS
628
637
 
629
638
  begin
630
- doc = document_from_string input, :safe => :safe, :base_dir => DIRNAME
639
+ doc, warnings = redirect_streams do |_, err|
640
+ [(document_from_string input, :safe => :safe, :base_dir => DIRNAME), err.string]
641
+ end
631
642
  assert_equal 2, doc.blocks.size
632
643
  assert_equal ['Unresolved directive in <stdin> - include::fixtures/chapter-a.adoc[]'], doc.blocks[0].lines
633
644
  assert_equal ['trailing content'], doc.blocks[1].lines
645
+ assert_includes warnings, 'include file not readable'
634
646
  rescue
635
647
  flunk 'include directive should not raise exception on missing file'
636
648
  ensure
@@ -676,15 +688,20 @@ include::#{url}[]
676
688
  ....
677
689
  EOS
678
690
 
679
- output = begin
680
- using_test_webserver do
681
- render_embedded_string input, :safe => :safe, :attributes => {'allow-uri-read' => ''}
691
+ begin
692
+ output = warnings = nil
693
+ redirect_streams do |_, err|
694
+ output = using_test_webserver do
695
+ render_embedded_string input, :safe => :safe, :attributes => {'allow-uri-read' => ''}
696
+ end
697
+ warnings = err.string
682
698
  end
699
+ refute_nil output
700
+ assert_match(/Unresolved directive/, output)
701
+ assert_includes warnings, 'include uri not readable'
683
702
  rescue
684
703
  flunk 'include directive should not raise exception on inaccessible uri'
685
704
  end
686
- refute_nil output
687
- assert_match(/Unresolved directive/, output)
688
705
  end
689
706
 
690
707
  test 'include directive supports line selection' do
@@ -692,7 +709,7 @@ include::#{url}[]
692
709
  include::fixtures/include-file.asciidoc[lines=1;3..4;6..-1]
693
710
  EOS
694
711
 
695
- output = render_string input, :safe => :safe, :header_footer => false, :base_dir => DIRNAME
712
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
696
713
  assert_match(/first line/, output)
697
714
  refute_match(/second line/, output)
698
715
  assert_match(/third line/, output)
@@ -709,7 +726,7 @@ include::fixtures/include-file.asciidoc[lines=1;3..4;6..-1]
709
726
  include::fixtures/include-file.asciidoc[lines="1, 3..4 , 6 .. -1"]
710
727
  EOS
711
728
 
712
- output = render_string input, :safe => :safe, :header_footer => false, :base_dir => DIRNAME
729
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
713
730
  assert_match(/first line/, output)
714
731
  refute_match(/second line/, output)
715
732
  assert_match(/third line/, output)
@@ -721,12 +738,24 @@ include::fixtures/include-file.asciidoc[lines="1, 3..4 , 6 .. -1"]
721
738
  assert_match(/last line of included content/, output)
722
739
  end
723
740
 
741
+ test 'include directive ignores empty lines attribute' do
742
+ input = <<-EOS
743
+ ++++
744
+ include::fixtures/include-file.asciidoc[lines=]
745
+ ++++
746
+ EOS
747
+
748
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
749
+ assert_includes output, 'first line of included content'
750
+ assert_includes output, 'last line of included content'
751
+ end
752
+
724
753
  test 'include directive supports tagged selection' do
725
754
  input = <<-EOS
726
755
  include::fixtures/include-file.asciidoc[tag=snippetA]
727
756
  EOS
728
757
 
729
- output = render_string input, :safe => :safe, :header_footer => false, :base_dir => DIRNAME
758
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
730
759
  assert_match(/snippetA content/, output)
731
760
  refute_match(/snippetB content/, output)
732
761
  refute_match(/non-tagged content/, output)
@@ -738,27 +767,31 @@ include::fixtures/include-file.asciidoc[tag=snippetA]
738
767
  include::fixtures/include-file.asciidoc[tags=snippetA;snippetB]
739
768
  EOS
740
769
 
741
- output = render_string input, :safe => :safe, :header_footer => false, :base_dir => DIRNAME
770
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
742
771
  assert_match(/snippetA content/, output)
743
772
  assert_match(/snippetB content/, output)
744
773
  refute_match(/non-tagged content/, output)
745
774
  refute_match(/included content/, output)
746
775
  end
747
776
 
748
- test 'include directive supports tagged selection in XML file' do
749
- input = <<-EOS
777
+ test 'include directive supports tagged selection in language that uses circumfix comments' do
778
+ {
779
+ 'include-file.xml' => '<snippet>content</snippet>',
780
+ 'include-file.ml' => 'let s = SS.empty;;'
781
+ }.each do |filename, expect|
782
+ input = <<-EOS
750
783
  [source,xml,indent=0]
751
784
  ----
752
- include::fixtures/include-file.xml[tag=snippet]
785
+ include::fixtures/#{filename}[tag=snippet]
753
786
  ----
754
- EOS
787
+ EOS
755
788
 
756
- output = render_string input, :safe => :safe, :header_footer => false, :base_dir => DIRNAME
757
- assert_match('&lt;snippet&gt;content&lt;/snippet&gt;', output)
758
- refute_match('root', output)
789
+ doc = document_from_string input, :safe => :safe, :base_dir => DIRNAME
790
+ assert_equal expect, doc.blocks[0].source
791
+ end
759
792
  end
760
793
 
761
- test 'include directive does not select tagged lines inside tagged selection' do
794
+ test 'include directive does not select lines with tag directives inside tagged selection' do
762
795
  input = <<-EOS
763
796
  ++++
764
797
  include::fixtures/include-file.asciidoc[tags=snippet]
@@ -774,6 +807,137 @@ snippetB content)
774
807
  assert_equal expect, output
775
808
  end
776
809
 
810
+ test 'include directive skips lines marked with negated tags' do
811
+ input = <<-EOS
812
+ ----
813
+ include::fixtures/tagged-class-enclosed.rb[tags=all;!bark]
814
+ ----
815
+ EOS
816
+
817
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
818
+ expected = %(class Dog
819
+ def initialize breed
820
+ @breed = breed
821
+ end
822
+ end)
823
+ assert_includes output, expected
824
+ end
825
+
826
+ test 'include directive takes all lines without tag directives when value is double asterisk' do
827
+ input = <<-EOS
828
+ ----
829
+ include::fixtures/tagged-class.rb[tags=**]
830
+ ----
831
+ EOS
832
+
833
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
834
+ expected = %(class Dog
835
+ def initialize breed
836
+ @breed = breed
837
+ end
838
+
839
+ def bark
840
+ if @breed == 'beagle'
841
+ 'woof woof woof woof woof'
842
+ else
843
+ 'woof woof'
844
+ end
845
+ end
846
+ end)
847
+ assert_includes output, expected
848
+ end
849
+
850
+ test 'include directive takes all lines except negated tags when value contains double asterisk' do
851
+ input = <<-EOS
852
+ ----
853
+ include::fixtures/tagged-class.rb[tags=**;!bark]
854
+ ----
855
+ EOS
856
+
857
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
858
+ expected = %(class Dog
859
+ def initialize breed
860
+ @breed = breed
861
+ end
862
+ end)
863
+ assert_includes output, expected
864
+ end
865
+
866
+ test 'include directive selects lines for all tags when value of tags attribute is wildcard' do
867
+ input = <<-EOS
868
+ ----
869
+ include::fixtures/tagged-class-enclosed.rb[tags=*]
870
+ ----
871
+ EOS
872
+
873
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
874
+ expected = %(class Dog
875
+ def initialize breed
876
+ @breed = breed
877
+ end
878
+
879
+ def bark
880
+ if @breed == 'beagle'
881
+ 'woof woof woof woof woof'
882
+ else
883
+ 'woof woof'
884
+ end
885
+ end
886
+ end)
887
+ assert_includes output, expected
888
+ end
889
+
890
+ test 'include directive selects lines for all tags except exclusions when value of tags attribute is wildcard' do
891
+ input = <<-EOS
892
+ ----
893
+ include::fixtures/tagged-class-enclosed.rb[tags=*;!init]
894
+ ----
895
+ EOS
896
+
897
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
898
+ expected = %(class Dog
899
+
900
+ def bark
901
+ if @breed == 'beagle'
902
+ 'woof woof woof woof woof'
903
+ else
904
+ 'woof woof'
905
+ end
906
+ end
907
+ end)
908
+ assert_includes output, expected
909
+ end
910
+
911
+ test 'include directive skips lines all tagged lines when value of tags attribute is negated wildcard' do
912
+ input = <<-EOS
913
+ ----
914
+ include::fixtures/tagged-class.rb[tags=!*]
915
+ ----
916
+ EOS
917
+
918
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
919
+ expected = %(class Dog
920
+ end)
921
+ assert_includes output, expected
922
+ end
923
+
924
+ test 'include directive selects specified tagged lines and ignores the other tag directives' do
925
+ input = <<-EOS
926
+ [indent=0]
927
+ ----
928
+ include::fixtures/tagged-class.rb[tags=bark;!bark-other]
929
+ ----
930
+ EOS
931
+
932
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
933
+ expected = %(def bark
934
+ if @breed == 'beagle'
935
+ 'woof woof woof woof woof'
936
+ end
937
+ end)
938
+ assert_includes output, expected
939
+ end
940
+
777
941
  test 'should warn if tag is not found in include file' do
778
942
  input = <<-EOS
779
943
  include::fixtures/include-file.asciidoc[tag=snippetZ]
@@ -782,7 +946,7 @@ include::fixtures/include-file.asciidoc[tag=snippetZ]
782
946
  old_stderr = $stderr
783
947
  $stderr = StringIO.new
784
948
  begin
785
- render_string input, :safe => :safe, :header_footer => false, :base_dir => DIRNAME
949
+ render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
786
950
  warning = $stderr.tap(&:rewind).read
787
951
  refute_nil warning
788
952
  assert_match(/WARNING.*snippetZ/, warning)
@@ -791,12 +955,40 @@ include::fixtures/include-file.asciidoc[tag=snippetZ]
791
955
  end
792
956
  end
793
957
 
958
+ test 'should warn if end tag in included file is mismatched' do
959
+ input = <<-EOS
960
+ ++++
961
+ include::fixtures/mismatched-end-tag.adoc[tags=a;b]
962
+ ++++
963
+ EOS
964
+
965
+ result, warnings = redirect_streams do |out, err|
966
+ [(render_embedded_string input, :safe => :safe, :base_dir => DIRNAME), err.string]
967
+ end
968
+ assert_equal %(a\nb), result
969
+ refute_nil warnings
970
+ assert_match(/WARNING: .*end tag/, warnings)
971
+ end
972
+
973
+ test 'include directive ignores tags attribute when empty' do
974
+ ['tag', 'tags'].each do |attr_name|
975
+ input = <<-EOS
976
+ ++++
977
+ include::fixtures/include-file.xml[#{attr_name}=]
978
+ ++++
979
+ EOS
980
+
981
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
982
+ assert_match(/(?:tag|end)::/, output, 2)
983
+ end
984
+ end
985
+
794
986
  test 'lines attribute takes precedence over tags attribute in include directive' do
795
987
  input = <<-EOS
796
988
  include::fixtures/include-file.asciidoc[lines=1, tags=snippetA;snippetB]
797
989
  EOS
798
990
 
799
- output = render_string input, :safe => :safe, :header_footer => false, :base_dir => DIRNAME
991
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
800
992
  assert_match(/first line of included content/, output)
801
993
  refute_match(/snippetA content/, output)
802
994
  refute_match(/snippetB content/, output)
@@ -810,7 +1002,7 @@ include::fixtures/basic-docinfo.xml[lines=2..3, indent=0]
810
1002
  ----
811
1003
  EOS
812
1004
 
813
- output = render_string input, :safe => :safe, :header_footer => false, :base_dir => DIRNAME
1005
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
814
1006
  result = xmlnodes_at_xpath('//pre', output, 1).text
815
1007
  assert_equal "<year>2013</year>\n<holder>Acme™, Inc.</holder>", result
816
1008
  end
@@ -834,10 +1026,10 @@ include::fixtures/include-file.asciidoc[]
834
1026
  }
835
1027
 
836
1028
  document = empty_safe_document :base_dir => DIRNAME
837
- reader = Asciidoctor::PreprocessorReader.new document, input
1029
+ reader = Asciidoctor::PreprocessorReader.new document, input, nil, :normalize => true
838
1030
  reader.instance_variable_set '@include_processors', [include_processor.new(document)]
839
1031
  lines = reader.read_lines
840
- source = lines * ::Asciidoctor::EOL
1032
+ source = lines * ::Asciidoctor::LF
841
1033
  assert_match(/included content/, source)
842
1034
  end
843
1035
 
@@ -846,7 +1038,7 @@ include::fixtures/include-file.asciidoc[]
846
1038
  include::fixtures/master.adoc[]
847
1039
  EOS
848
1040
 
849
- expected = <<-EOS.chomp.split(::Asciidoctor::EOL)
1041
+ expected = <<-EOS.chomp.split(::Asciidoctor::LF)
850
1042
  = Master Document
851
1043
 
852
1044
  preamble
@@ -882,9 +1074,13 @@ include::{fixturesdir}/include-file.{ext}[]
882
1074
  include::{foodir}/include-file.asciidoc[]
883
1075
  EOS
884
1076
 
885
- doc = empty_safe_document :base_dir => DIRNAME
886
- reader = Asciidoctor::PreprocessorReader.new doc, input
887
- assert_equal 'Unresolved directive in <stdin> - include::{foodir}/include-file.asciidoc[]', reader.read_line
1077
+ line, warnings = redirect_streams do |_, err|
1078
+ doc = empty_safe_document :base_dir => DIRNAME
1079
+ reader = Asciidoctor::PreprocessorReader.new doc, input, nil, :normalize => true
1080
+ [reader.read_line, err.string]
1081
+ end
1082
+ assert_equal 'Unresolved directive in <stdin> - include::{foodir}/include-file.asciidoc[]', line
1083
+ assert_includes warnings, 'dropping line containing reference to missing attribute'
888
1084
  end
889
1085
 
890
1086
  test 'line is dropped if target of include directive resolves to empty and attribute-missing attribute is not skip' do
@@ -892,9 +1088,13 @@ include::{foodir}/include-file.asciidoc[]
892
1088
  include::{foodir}/include-file.asciidoc[]
893
1089
  EOS
894
1090
 
895
- doc = empty_safe_document :base_dir => DIRNAME, :attributes => {'attribute-missing' => 'drop'}
896
- reader = Asciidoctor::PreprocessorReader.new doc, input
897
- assert_nil reader.read_line
1091
+ line, warnings = redirect_streams do |_, err|
1092
+ doc = empty_safe_document :base_dir => DIRNAME, :attributes => {'attribute-missing' => 'drop'}
1093
+ reader = Asciidoctor::PreprocessorReader.new doc, input, nil, :normalize => true
1094
+ [reader.read_line, err.string]
1095
+ end
1096
+ assert_nil line
1097
+ assert_includes warnings, 'dropping line containing reference to missing attribute'
898
1098
  end
899
1099
 
900
1100
  test 'line following dropped include is not dropped' do
@@ -903,9 +1103,13 @@ include::{foodir}/include-file.asciidoc[]
903
1103
  yo
904
1104
  EOS
905
1105
 
906
- doc = empty_safe_document :base_dir => DIRNAME, :attributes => {'attribute-missing' => 'drop'}
907
- reader = Asciidoctor::PreprocessorReader.new doc, input
908
- assert_equal 'yo', reader.read_line
1106
+ line, warnings = redirect_streams do |_, err|
1107
+ doc = empty_safe_document :base_dir => DIRNAME, :attributes => {'attribute-missing' => 'drop'}
1108
+ reader = Asciidoctor::PreprocessorReader.new doc, input, nil, :normalize => true
1109
+ [reader.read_line, err.string]
1110
+ end
1111
+ assert_equal 'yo', line
1112
+ assert_includes warnings, 'dropping line containing reference to missing attribute'
909
1113
  end
910
1114
 
911
1115
  test 'escaped include directive is left unprocessed' do
@@ -914,7 +1118,7 @@ yo
914
1118
  \\escape preserved here
915
1119
  EOS
916
1120
  doc = empty_safe_document :base_dir => DIRNAME
917
- reader = Asciidoctor::PreprocessorReader.new doc, input
1121
+ reader = Asciidoctor::PreprocessorReader.new doc, input, nil, :normalize => true
918
1122
  # we should be able to peek it multiple times and still have the backslash preserved
919
1123
  # this is the test for @unescape_next_line
920
1124
  assert_equal 'include::fixtures/include-file.asciidoc[]', reader.peek_line
@@ -959,13 +1163,14 @@ include::include-file.asciidoc[]
959
1163
  include::fixtures/parent-include.adoc[depth=1]
960
1164
  EOS
961
1165
 
962
- pseudo_docfile = File.join DIRNAME, 'include-master.adoc'
963
-
964
- doc = empty_safe_document :base_dir => DIRNAME
965
- reader = Asciidoctor::PreprocessorReader.new doc, input, Asciidoctor::Reader::Cursor.new(pseudo_docfile)
966
-
967
- lines = reader.readlines
1166
+ lines, warnings = redirect_streams do |_, err|
1167
+ pseudo_docfile = File.join DIRNAME, 'include-master.adoc'
1168
+ doc = empty_safe_document :base_dir => DIRNAME
1169
+ reader = Asciidoctor::PreprocessorReader.new doc, input, Asciidoctor::Reader::Cursor.new(pseudo_docfile), :normalize => true
1170
+ [reader.readlines, err.string]
1171
+ end
968
1172
  assert lines.include?('include::child-include.adoc[]')
1173
+ assert_match(/maximum include depth .* exceeded/, warnings)
969
1174
  end
970
1175
 
971
1176
  test 'include directive should be disabled if max include depth set in nested context has been exceeded' do
@@ -973,14 +1178,15 @@ include::fixtures/parent-include.adoc[depth=1]
973
1178
  include::fixtures/parent-include-restricted.adoc[depth=3]
974
1179
  EOS
975
1180
 
976
- pseudo_docfile = File.join DIRNAME, 'include-master.adoc'
977
-
978
- doc = empty_safe_document :base_dir => DIRNAME
979
- reader = Asciidoctor::PreprocessorReader.new doc, input, Asciidoctor::Reader::Cursor.new(pseudo_docfile)
980
-
981
- lines = reader.readlines
1181
+ lines, warnings = redirect_streams do |_, err|
1182
+ pseudo_docfile = File.join DIRNAME, 'include-master.adoc'
1183
+ doc = empty_safe_document :base_dir => DIRNAME
1184
+ reader = Asciidoctor::PreprocessorReader.new doc, input, Asciidoctor::Reader::Cursor.new(pseudo_docfile), :normalize => true
1185
+ [reader.readlines, err.string]
1186
+ end
982
1187
  assert lines.include?('first line of child')
983
1188
  assert lines.include?('include::grandchild-include.adoc[]')
1189
+ assert_match(/maximum include depth .* exceeded/, warnings)
984
1190
  end
985
1191
 
986
1192
  test 'read_lines_until should not process lines if process option is false' do
@@ -991,7 +1197,7 @@ include::fixtures/no-such-file.adoc[]
991
1197
  EOS
992
1198
 
993
1199
  doc = empty_safe_document :base_dir => DIRNAME
994
- reader = Asciidoctor::PreprocessorReader.new doc, lines
1200
+ reader = Asciidoctor::PreprocessorReader.new doc, lines, nil, :normalize => true
995
1201
  reader.read_line
996
1202
  result = reader.read_lines_until(:terminator => '////', :skip_processing => true)
997
1203
  assert_equal lines.map {|l| l.chomp}[1..1], result
@@ -1005,7 +1211,7 @@ include::fixtures/no-such-file.adoc[]
1005
1211
  EOS
1006
1212
 
1007
1213
  doc = empty_safe_document :base_dir => DIRNAME
1008
- reader = Asciidoctor::PreprocessorReader.new doc, lines
1214
+ reader = Asciidoctor::PreprocessorReader.new doc, lines, nil, :normalize => true
1009
1215
  result = reader.skip_comment_lines
1010
1216
  assert_equal lines.map {|l| l.chomp}, result
1011
1217
  end
@@ -1093,7 +1299,7 @@ endif::holygrail[]
1093
1299
  while reader.has_more_lines?
1094
1300
  lines << reader.read_line
1095
1301
  end
1096
- assert_equal 'There is a holy grail!', (lines * ::Asciidoctor::EOL)
1302
+ assert_equal 'There is a holy grail!', (lines * ::Asciidoctor::LF)
1097
1303
  end
1098
1304
 
1099
1305
  test 'ifdef with defined attribute includes text in brackets' do
@@ -1109,7 +1315,21 @@ There was much rejoicing.
1109
1315
  while reader.has_more_lines?
1110
1316
  lines << reader.read_line
1111
1317
  end
1112
- assert_equal "On our quest we go...\nThere is a holy grail!\nThere was much rejoicing.", (lines * ::Asciidoctor::EOL)
1318
+ assert_equal "On our quest we go...\nThere is a holy grail!\nThere was much rejoicing.", (lines * ::Asciidoctor::LF)
1319
+ end
1320
+
1321
+ test 'ifdef with defined attribute processes include directive in brackets' do
1322
+ input = <<-EOS
1323
+ ifdef::asciidoctor-version[include::fixtures/include-file.asciidoc[tag=snippetA]]
1324
+ EOS
1325
+
1326
+ doc = Asciidoctor::Document.new input, :safe => :safe, :base_dir => DIRNAME
1327
+ reader = doc.reader
1328
+ lines = []
1329
+ while reader.has_more_lines?
1330
+ lines << reader.read_line
1331
+ end
1332
+ assert_equal 'snippetA content', lines[0]
1113
1333
  end
1114
1334
 
1115
1335
  test 'ifdef attribute name is not case sensitive' do
@@ -1137,7 +1357,7 @@ There was no rejoicing.
1137
1357
  while reader.has_more_lines?
1138
1358
  lines << reader.read_line
1139
1359
  end
1140
- assert_equal "On our quest we go...\nThere was no rejoicing.", (lines * ::Asciidoctor::EOL)
1360
+ assert_equal "On our quest we go...\nThere was no rejoicing.", (lines * ::Asciidoctor::LF)
1141
1361
  end
1142
1362
 
1143
1363
  test 'include with non-matching nested exclude' do
@@ -1157,7 +1377,7 @@ endif::grail[]
1157
1377
  while reader.has_more_lines?
1158
1378
  lines << reader.read_line
1159
1379
  end
1160
- assert_equal "holy\ngrail", (lines * ::Asciidoctor::EOL)
1380
+ assert_equal "holy\ngrail", (lines * ::Asciidoctor::LF)
1161
1381
  end
1162
1382
 
1163
1383
  test 'nested excludes with same condition' do
@@ -1175,7 +1395,7 @@ endif::grail[]
1175
1395
  while reader.has_more_lines?
1176
1396
  lines << reader.read_line
1177
1397
  end
1178
- assert_equal '', (lines * ::Asciidoctor::EOL)
1398
+ assert_equal '', (lines * ::Asciidoctor::LF)
1179
1399
  end
1180
1400
 
1181
1401
  test 'include with nested exclude of inverted condition' do
@@ -1195,7 +1415,7 @@ endif::grail[]
1195
1415
  while reader.has_more_lines?
1196
1416
  lines << reader.read_line
1197
1417
  end
1198
- assert_equal "holy\ngrail", (lines * ::Asciidoctor::EOL)
1418
+ assert_equal "holy\ngrail", (lines * ::Asciidoctor::LF)
1199
1419
  end
1200
1420
 
1201
1421
  test 'exclude with matching nested exclude' do
@@ -1217,7 +1437,7 @@ gone
1217
1437
  while reader.has_more_lines?
1218
1438
  lines << reader.read_line
1219
1439
  end
1220
- assert_equal "poof\ngone", (lines * ::Asciidoctor::EOL)
1440
+ assert_equal "poof\ngone", (lines * ::Asciidoctor::LF)
1221
1441
  end
1222
1442
 
1223
1443
  test 'exclude with nested include using shorthand end' do
@@ -1239,7 +1459,7 @@ gone
1239
1459
  while reader.has_more_lines?
1240
1460
  lines << reader.read_line
1241
1461
  end
1242
- assert_equal "poof\ngone", (lines * ::Asciidoctor::EOL)
1462
+ assert_equal "poof\ngone", (lines * ::Asciidoctor::LF)
1243
1463
  end
1244
1464
 
1245
1465
  test 'ifdef with one alternative attribute set includes content' do
@@ -1255,7 +1475,7 @@ endif::holygrail,swallow[]
1255
1475
  while reader.has_more_lines?
1256
1476
  lines << reader.read_line
1257
1477
  end
1258
- assert_equal 'Our quest is complete!', (lines * ::Asciidoctor::EOL)
1478
+ assert_equal 'Our quest is complete!', (lines * ::Asciidoctor::LF)
1259
1479
  end
1260
1480
 
1261
1481
  test 'ifdef with no alternative attributes set does not include content' do
@@ -1271,7 +1491,7 @@ endif::holygrail,swallow[]
1271
1491
  while reader.has_more_lines?
1272
1492
  lines << reader.read_line
1273
1493
  end
1274
- assert_equal '', (lines * ::Asciidoctor::EOL)
1494
+ assert_equal '', (lines * ::Asciidoctor::LF)
1275
1495
  end
1276
1496
 
1277
1497
  test 'ifdef with all required attributes set includes content' do
@@ -1287,7 +1507,7 @@ endif::holygrail+swallow[]
1287
1507
  while reader.has_more_lines?
1288
1508
  lines << reader.read_line
1289
1509
  end
1290
- assert_equal 'Our quest is complete!', (lines * ::Asciidoctor::EOL)
1510
+ assert_equal 'Our quest is complete!', (lines * ::Asciidoctor::LF)
1291
1511
  end
1292
1512
 
1293
1513
  test 'ifdef with missing required attributes does not include content' do
@@ -1303,7 +1523,25 @@ endif::holygrail+swallow[]
1303
1523
  while reader.has_more_lines?
1304
1524
  lines << reader.read_line
1305
1525
  end
1306
- assert_equal '', (lines * ::Asciidoctor::EOL)
1526
+ assert_equal '', (lines * ::Asciidoctor::LF)
1527
+ end
1528
+
1529
+ test 'ifdef should permit leading, trailing, and repeat operators' do
1530
+ {
1531
+ 'asciidoctor,' => 'content',
1532
+ ',asciidoctor' => 'content',
1533
+ 'asciidoctor+' => '',
1534
+ '+asciidoctor' => '',
1535
+ 'asciidoctor,,asciidoctor-version' => 'content',
1536
+ 'asciidoctor++asciidoctor-version' => ''
1537
+ }.each do |condition, expected|
1538
+ input = <<-EOS
1539
+ ifdef::#{condition}[]
1540
+ content
1541
+ endif::[]
1542
+ EOS
1543
+ assert_equal expected, (document_from_string input, :parse => false).reader.read
1544
+ end
1307
1545
  end
1308
1546
 
1309
1547
  test 'ifndef with undefined attribute includes block' do
@@ -1319,23 +1557,29 @@ endif::holygrail[]
1319
1557
  while reader.has_more_lines?
1320
1558
  lines << reader.read_line
1321
1559
  end
1322
- assert_equal 'Our quest continues to find the holy grail!', (lines * ::Asciidoctor::EOL)
1560
+ assert_equal 'Our quest continues to find the holy grail!', (lines * ::Asciidoctor::LF)
1323
1561
  end
1324
1562
 
1325
- test 'ifndef with one alternative attribute set includes content' do
1563
+ test 'ifndef with one alternative attribute set does not include content' do
1326
1564
  input = <<-EOS
1327
1565
  ifndef::holygrail,swallow[]
1328
1566
  Our quest is complete!
1329
1567
  endif::holygrail,swallow[]
1330
1568
  EOS
1331
1569
 
1332
- doc = Asciidoctor::Document.new input, :attributes => { 'swallow' => '' }
1333
- reader = doc.reader
1334
- lines = []
1335
- while reader.has_more_lines?
1336
- lines << reader.read_line
1337
- end
1338
- assert_equal 'Our quest is complete!', (lines * ::Asciidoctor::EOL)
1570
+ result = (Asciidoctor::Document.new input, :attributes => { 'swallow' => '' }).reader.read
1571
+ assert_empty result
1572
+ end
1573
+
1574
+ test 'ifndef with both alternative attributes set does not include content' do
1575
+ input = <<-EOS
1576
+ ifndef::holygrail,swallow[]
1577
+ Our quest is complete!
1578
+ endif::holygrail,swallow[]
1579
+ EOS
1580
+
1581
+ result = (Asciidoctor::Document.new input, :attributes => { 'swallow' => '', 'holygrail' => '' }).reader.read
1582
+ assert_empty result
1339
1583
  end
1340
1584
 
1341
1585
  test 'ifndef with no alternative attributes set includes content' do
@@ -1345,45 +1589,41 @@ Our quest is complete!
1345
1589
  endif::holygrail,swallow[]
1346
1590
  EOS
1347
1591
 
1348
- doc = Asciidoctor::Document.new input
1349
- reader = doc.reader
1350
- lines = []
1351
- while reader.has_more_lines?
1352
- lines << reader.read_line
1353
- end
1354
- assert_equal 'Our quest is complete!', (lines * ::Asciidoctor::EOL)
1592
+ result = (Asciidoctor::Document.new input).reader.read
1593
+ assert_equal 'Our quest is complete!', result
1355
1594
  end
1356
1595
 
1357
- test 'ifndef with any required attributes set does not include content' do
1596
+ test 'ifndef with no required attributes set includes content' do
1358
1597
  input = <<-EOS
1359
1598
  ifndef::holygrail+swallow[]
1360
1599
  Our quest is complete!
1361
1600
  endif::holygrail+swallow[]
1362
1601
  EOS
1363
1602
 
1364
- doc = Asciidoctor::Document.new input, :attributes => { 'swallow' => '' }
1365
- reader = doc.reader
1366
- lines = []
1367
- while reader.has_more_lines?
1368
- lines << reader.read_line
1369
- end
1370
- assert_equal '', (lines * ::Asciidoctor::EOL)
1603
+ result = (Asciidoctor::Document.new input).reader.read
1604
+ assert_equal 'Our quest is complete!', result
1371
1605
  end
1372
1606
 
1373
- test 'ifndef with no required attributes set includes content' do
1607
+ test 'ifndef with all required attributes set does not include content' do
1374
1608
  input = <<-EOS
1375
1609
  ifndef::holygrail+swallow[]
1376
1610
  Our quest is complete!
1377
1611
  endif::holygrail+swallow[]
1378
1612
  EOS
1379
1613
 
1380
- doc = Asciidoctor::Document.new input
1381
- reader = doc.reader
1382
- lines = []
1383
- while reader.has_more_lines?
1384
- lines << reader.read_line
1385
- end
1386
- assert_equal 'Our quest is complete!', (lines * ::Asciidoctor::EOL)
1614
+ result = (Asciidoctor::Document.new input, :attributes => { 'swallow' => '', 'holygrail' => '' }).reader.read
1615
+ assert_empty result
1616
+ end
1617
+
1618
+ test 'ifndef with at least one required attributes set does not include content' do
1619
+ input = <<-EOS
1620
+ ifndef::holygrail+swallow[]
1621
+ Our quest is complete!
1622
+ endif::holygrail+swallow[]
1623
+ EOS
1624
+
1625
+ result = (Asciidoctor::Document.new input, :attributes => { 'swallow' => '' }).reader.read
1626
+ assert_equal 'Our quest is complete!', result
1387
1627
  end
1388
1628
 
1389
1629
  test 'escaped ifdef is unescaped and ignored' do
@@ -1399,7 +1639,7 @@ content
1399
1639
  while reader.has_more_lines?
1400
1640
  lines << reader.read_line
1401
1641
  end
1402
- assert_equal "ifdef::holygrail[]\ncontent\nendif::holygrail[]", (lines * ::Asciidoctor::EOL)
1642
+ assert_equal "ifdef::holygrail[]\ncontent\nendif::holygrail[]", (lines * ::Asciidoctor::LF)
1403
1643
  end
1404
1644
 
1405
1645
  test 'ifeval comparing missing attribute to nil includes content' do
@@ -1415,7 +1655,7 @@ endif::[]
1415
1655
  while reader.has_more_lines?
1416
1656
  lines << reader.read_line
1417
1657
  end
1418
- assert_equal 'No foo for you!', (lines * ::Asciidoctor::EOL)
1658
+ assert_equal 'No foo for you!', (lines * ::Asciidoctor::LF)
1419
1659
  end
1420
1660
 
1421
1661
  test 'ifeval comparing missing attribute to 0 drops content' do
@@ -1431,7 +1671,7 @@ endif::[]
1431
1671
  while reader.has_more_lines?
1432
1672
  lines << reader.read_line
1433
1673
  end
1434
- assert_equal '', (lines * ::Asciidoctor::EOL)
1674
+ assert_equal '', (lines * ::Asciidoctor::LF)
1435
1675
  end
1436
1676
 
1437
1677
  test 'ifeval comparing double-quoted attribute to matching string includes content' do
@@ -1447,7 +1687,7 @@ endif::[]
1447
1687
  while reader.has_more_lines?
1448
1688
  lines << reader.read_line
1449
1689
  end
1450
- assert_equal 'Asciidoctor it is!', (lines * ::Asciidoctor::EOL)
1690
+ assert_equal 'Asciidoctor it is!', (lines * ::Asciidoctor::LF)
1451
1691
  end
1452
1692
 
1453
1693
  test 'ifeval comparing single-quoted attribute to matching string includes content' do
@@ -1463,7 +1703,7 @@ endif::[]
1463
1703
  while reader.has_more_lines?
1464
1704
  lines << reader.read_line
1465
1705
  end
1466
- assert_equal 'Asciidoctor it is!', (lines * ::Asciidoctor::EOL)
1706
+ assert_equal 'Asciidoctor it is!', (lines * ::Asciidoctor::LF)
1467
1707
  end
1468
1708
 
1469
1709
  test 'ifeval comparing quoted attribute to non-matching string drops content' do
@@ -1479,7 +1719,7 @@ endif::[]
1479
1719
  while reader.has_more_lines?
1480
1720
  lines << reader.read_line
1481
1721
  end
1482
- assert_equal '', (lines * ::Asciidoctor::EOL)
1722
+ assert_equal '', (lines * ::Asciidoctor::LF)
1483
1723
  end
1484
1724
 
1485
1725
  test 'ifeval comparing attribute to lower version number includes content' do
@@ -1495,7 +1735,7 @@ endif::[]
1495
1735
  while reader.has_more_lines?
1496
1736
  lines << reader.read_line
1497
1737
  end
1498
- assert_equal 'That version will do!', (lines * ::Asciidoctor::EOL)
1738
+ assert_equal 'That version will do!', (lines * ::Asciidoctor::LF)
1499
1739
  end
1500
1740
 
1501
1741
  test 'ifeval comparing attribute to self includes content' do
@@ -1511,7 +1751,7 @@ endif::[]
1511
1751
  while reader.has_more_lines?
1512
1752
  lines << reader.read_line
1513
1753
  end
1514
- assert_equal 'Of course it\'s the same!', (lines * ::Asciidoctor::EOL)
1754
+ assert_equal 'Of course it\'s the same!', (lines * ::Asciidoctor::LF)
1515
1755
  end
1516
1756
 
1517
1757
  test 'ifeval arguments can be transposed' do
@@ -1527,7 +1767,7 @@ endif::[]
1527
1767
  while reader.has_more_lines?
1528
1768
  lines << reader.read_line
1529
1769
  end
1530
- assert_equal 'That version will do!', (lines * ::Asciidoctor::EOL)
1770
+ assert_equal 'That version will do!', (lines * ::Asciidoctor::LF)
1531
1771
  end
1532
1772
 
1533
1773
  test 'ifeval matching numeric equality includes content' do
@@ -1543,7 +1783,7 @@ endif::[]
1543
1783
  while reader.has_more_lines?
1544
1784
  lines << reader.read_line
1545
1785
  end
1546
- assert_equal 'One ring to rule them all!', (lines * ::Asciidoctor::EOL)
1786
+ assert_equal 'One ring to rule them all!', (lines * ::Asciidoctor::LF)
1547
1787
  end
1548
1788
 
1549
1789
  test 'ifeval matching numeric inequality includes content' do
@@ -1559,7 +1799,7 @@ endif::[]
1559
1799
  while reader.has_more_lines?
1560
1800
  lines << reader.read_line
1561
1801
  end
1562
- assert_equal 'One ring to rule them all!', (lines * ::Asciidoctor::EOL)
1802
+ assert_equal 'One ring to rule them all!', (lines * ::Asciidoctor::LF)
1563
1803
  end
1564
1804
 
1565
1805
  test 'ifdef with no target is ignored' do
@@ -1574,7 +1814,7 @@ content
1574
1814
  while reader.has_more_lines?
1575
1815
  lines << reader.read_line
1576
1816
  end
1577
- assert_equal "ifdef::[]\ncontent", (lines * ::Asciidoctor::EOL)
1817
+ assert_equal "ifdef::[]\ncontent", (lines * ::Asciidoctor::LF)
1578
1818
  end
1579
1819
  end
1580
1820
  end