asciidoctor 0.0.9 → 0.1.0

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 (42) hide show
  1. data/README.asciidoc +163 -41
  2. data/Rakefile +3 -1
  3. data/asciidoctor.gemspec +13 -5
  4. data/bin/asciidoctor +6 -3
  5. data/bin/asciidoctor-safe +13 -0
  6. data/lib/asciidoctor.rb +237 -26
  7. data/lib/asciidoctor/abstract_node.rb +27 -17
  8. data/lib/asciidoctor/attribute_list.rb +6 -0
  9. data/lib/asciidoctor/backends/base_template.rb +3 -4
  10. data/lib/asciidoctor/backends/docbook45.rb +114 -55
  11. data/lib/asciidoctor/backends/html5.rb +173 -104
  12. data/lib/asciidoctor/cli/invoker.rb +105 -0
  13. data/lib/asciidoctor/cli/options.rb +146 -0
  14. data/lib/asciidoctor/document.rb +135 -35
  15. data/lib/asciidoctor/lexer.rb +86 -33
  16. data/lib/asciidoctor/list_item.rb +2 -2
  17. data/lib/asciidoctor/reader.rb +6 -7
  18. data/lib/asciidoctor/section.rb +17 -5
  19. data/lib/asciidoctor/substituters.rb +216 -97
  20. data/lib/asciidoctor/table.rb +9 -2
  21. data/lib/asciidoctor/version.rb +1 -1
  22. data/man/asciidoctor.1 +212 -0
  23. data/man/asciidoctor.ad +156 -0
  24. data/test/attributes_test.rb +108 -5
  25. data/test/blocks_test.rb +102 -15
  26. data/test/document_test.rb +214 -3
  27. data/test/fixtures/encoding.asciidoc +4 -0
  28. data/test/fixtures/sample.asciidoc +26 -0
  29. data/test/invoker_test.rb +254 -0
  30. data/test/lexer_test.rb +53 -0
  31. data/test/links_test.rb +30 -0
  32. data/test/lists_test.rb +648 -9
  33. data/test/options_test.rb +68 -0
  34. data/test/paragraphs_test.rb +65 -1
  35. data/test/reader_test.rb +18 -4
  36. data/test/{headers_test.rb → sections_test.rb} +237 -0
  37. data/test/substitutions_test.rb +247 -5
  38. data/test/tables_test.rb +22 -4
  39. data/test/test_helper.rb +47 -3
  40. data/test/text_test.rb +20 -4
  41. metadata +34 -6
  42. data/noof.rb +0 -16
@@ -331,6 +331,228 @@ context 'Substitutions' do
331
331
  para = block_from_string('image:tiger.png[Tiger, link="http://en.wikipedia.org/wiki/Tiger"]')
332
332
  assert_equal %{<span class="image">\n <a class="image" href="http://en.wikipedia.org/wiki/Tiger"><img src="tiger.png" alt="Tiger"></a>\n</span>}, para.sub_macros(para.buffer.join)
333
333
  end
334
+
335
+ test 'a single-line footnote macro should be registered and rendered as a footnote' do
336
+ para = block_from_string('Sentence text footnote:[An example footnote.].')
337
+ assert_equal %(Sentence text <span class="footnote">[<a id="_footnoteref_1" href="#_footnote_1" title="View footnote." class="footnote">1</a>]</span>.), para.sub_macros(para.buffer.join)
338
+ assert_equal 1, para.document.references[:footnotes].size
339
+ footnote = para.document.references[:footnotes].first
340
+ assert_equal 1, footnote.index
341
+ assert footnote.id.nil?
342
+ assert_equal 'An example footnote.', footnote.text
343
+ end
344
+
345
+ test 'a multi-line footnote macro should be registered and rendered as a footnote' do
346
+ para = block_from_string("Sentence text footnote:[An example footnote\nwith wrapped text.].")
347
+ assert_equal %(Sentence text <span class="footnote">[<a id="_footnoteref_1" href="#_footnote_1" title="View footnote." class="footnote">1</a>]</span>.), para.sub_macros(para.buffer.join)
348
+ assert_equal 1, para.document.references[:footnotes].size
349
+ footnote = para.document.references[:footnotes].first
350
+ assert_equal 1, footnote.index
351
+ assert footnote.id.nil?
352
+ assert_equal "An example footnote\nwith wrapped text.", footnote.text
353
+ end
354
+
355
+ test 'a footnote macro can be directly adjacent to preceding word' do
356
+ para = block_from_string('Sentence textfootnote:[An example footnote.].')
357
+ assert_equal %(Sentence text<span class="footnote">[<a id="_footnoteref_1" href="#_footnote_1" title="View footnote." class="footnote">1</a>]</span>.), para.sub_macros(para.buffer.join)
358
+ end
359
+
360
+ test 'a footnote macro may contain a macro' do
361
+ para = block_from_string('Share your code. footnote:[http://github.com[GitHub]]')
362
+ assert_equal %(Share your code. <span class="footnote">[<a id="_footnoteref_1" href="#_footnote_1" title="View footnote." class="footnote">1</a>]</span>), para.sub_macros(para.buffer.join)
363
+ assert_equal 1, para.document.references[:footnotes].size
364
+ footnote1 = para.document.references[:footnotes][0]
365
+ assert_equal '<a href="http://github.com">GitHub</a>', footnote1.text
366
+ end
367
+
368
+ test 'should increment index of subsequent footnote macros' do
369
+ para = block_from_string("Sentence text footnote:[An example footnote.]. Sentence text footnote:[Another footnote.].")
370
+ assert_equal %(Sentence text <span class="footnote">[<a id="_footnoteref_1" href="#_footnote_1" title="View footnote." class="footnote">1</a>]</span>. Sentence text <span class="footnote">[<a id="_footnoteref_2" href="#_footnote_2" title="View footnote." class="footnote">2</a>]</span>.), para.sub_macros(para.buffer.join)
371
+ assert_equal 2, para.document.references[:footnotes].size
372
+ footnote1 = para.document.references[:footnotes][0]
373
+ assert_equal 1, footnote1.index
374
+ assert footnote1.id.nil?
375
+ assert_equal "An example footnote.", footnote1.text
376
+ footnote2 = para.document.references[:footnotes][1]
377
+ assert_equal 2, footnote2.index
378
+ assert footnote2.id.nil?
379
+ assert_equal "Another footnote.", footnote2.text
380
+ end
381
+
382
+ test 'a footnoteref macro with id and single-line text should be registered and rendered as a footnote' do
383
+ para = block_from_string('Sentence text footnoteref:[ex1, An example footnote.].')
384
+ assert_equal %(Sentence text <span class="footnote" id="_footnote_ex1">[<a id="_footnoteref_1" href="#_footnote_1" title="View footnote." class="footnote">1</a>]</span>.), para.sub_macros(para.buffer.join)
385
+ assert_equal 1, para.document.references[:footnotes].size
386
+ footnote = para.document.references[:footnotes].first
387
+ assert_equal 1, footnote.index
388
+ assert_equal 'ex1', footnote.id
389
+ assert_equal 'An example footnote.', footnote.text
390
+ end
391
+
392
+ test 'a footnoteref macro with id and multi-line text should be registered and rendered as a footnote' do
393
+ para = block_from_string("Sentence text footnoteref:[ex1, An example footnote\nwith wrapped text.].")
394
+ assert_equal %(Sentence text <span class="footnote" id="_footnote_ex1">[<a id="_footnoteref_1" href="#_footnote_1" title="View footnote." class="footnote">1</a>]</span>.), para.sub_macros(para.buffer.join)
395
+ assert_equal 1, para.document.references[:footnotes].size
396
+ footnote = para.document.references[:footnotes].first
397
+ assert_equal 1, footnote.index
398
+ assert_equal 'ex1', footnote.id
399
+ assert_equal "An example footnote\nwith wrapped text.", footnote.text
400
+ end
401
+
402
+ test 'a footnoteref macro with id should refer to footnoteref with same id' do
403
+ para = block_from_string('Sentence text footnoteref:[ex1, An example footnote.]. Sentence text footnoteref:[ex1].')
404
+ assert_equal %(Sentence text <span class="footnote" id="_footnote_ex1">[<a id="_footnoteref_1" href="#_footnote_1" title="View footnote." class="footnote">1</a>]</span>. Sentence text <span class="footnoteref">[<a href="#_footnote_1" title="View footnote." class="footnote">1</a>]</span>.), para.sub_macros(para.buffer.join)
405
+ assert_equal 1, para.document.references[:footnotes].size
406
+ footnote = para.document.references[:footnotes].first
407
+ assert_equal 1, footnote.index
408
+ assert_equal 'ex1', footnote.id
409
+ assert_equal 'An example footnote.', footnote.text
410
+ end
411
+
412
+ test 'a single-line index term macro with a primary term should be registered as an index reference' do
413
+ sentence = "The tiger (Panthera tigris) is the largest cat species.\n"
414
+ macros = ['indexterm:[Tigers]', '(((Tigers)))']
415
+ macros.each do |macro|
416
+ para = block_from_string("#{sentence}#{macro}")
417
+ output = para.sub_macros(para.buffer.join)
418
+ assert_equal sentence, output
419
+ assert_equal 1, para.document.references[:indexterms].size
420
+ assert_equal ['Tigers'], para.document.references[:indexterms].first
421
+ end
422
+ end
423
+
424
+ test 'a single-line index term macro with primary and secondary terms should be registered as an index reference' do
425
+ sentence = "The tiger (Panthera tigris) is the largest cat species.\n"
426
+ macros = ['indexterm:[Big cats, Tigers]', '(((Big cats, Tigers)))']
427
+ macros.each do |macro|
428
+ para = block_from_string("#{sentence}#{macro}")
429
+ output = para.sub_macros(para.buffer.join)
430
+ assert_equal sentence, output
431
+ assert_equal 1, para.document.references[:indexterms].size
432
+ assert_equal ['Big cats', 'Tigers'], para.document.references[:indexterms].first
433
+ end
434
+ end
435
+
436
+ test 'a single-line index term macro with primary, secondary and tertiary terms should be registered as an index reference' do
437
+ sentence = "The tiger (Panthera tigris) is the largest cat species.\n"
438
+ macros = ['indexterm:[Big cats,Tigers , Panthera tigris]', '(((Big cats,Tigers , Panthera tigris)))']
439
+ macros.each do |macro|
440
+ para = block_from_string("#{sentence}#{macro}")
441
+ output = para.sub_macros(para.buffer.join)
442
+ assert_equal sentence, output
443
+ assert_equal 1, para.document.references[:indexterms].size
444
+ assert_equal ['Big cats', 'Tigers', 'Panthera tigris'], para.document.references[:indexterms].first
445
+ end
446
+ end
447
+
448
+ test 'a multi-line index term macro should be compacted and registered as an index reference' do
449
+ sentence = "The tiger (Panthera tigris) is the largest cat species.\n"
450
+ macros = ["indexterm:[Panthera\ntigris]", "(((Panthera\ntigris)))"]
451
+ macros.each do |macro|
452
+ para = block_from_string("#{sentence}#{macro}")
453
+ output = para.sub_macros(para.buffer.join)
454
+ assert_equal sentence, output
455
+ assert_equal 1, para.document.references[:indexterms].size
456
+ assert_equal ['Panthera tigris'], para.document.references[:indexterms].first
457
+ end
458
+ end
459
+
460
+ test 'normal substitutions are performed on an index term macro' do
461
+ sentence = "The tiger (Panthera tigris) is the largest cat species.\n"
462
+ macros = ['indexterm:[*Tigers*]', '(((*Tigers*)))']
463
+ macros.each do |macro|
464
+ para = block_from_string("#{sentence}#{macro}")
465
+ output = para.apply_normal_subs(para.buffer)
466
+ assert_equal sentence, output
467
+ assert_equal 1, para.document.references[:indexterms].size
468
+ assert_equal ['<strong>Tigers</strong>'], para.document.references[:indexterms].first
469
+ end
470
+ end
471
+
472
+ test 'registers multiple index term macros' do
473
+ sentence = "The tiger (Panthera tigris) is the largest cat species."
474
+ macros = "(((Tigers)))\n(((Animals,Cats)))"
475
+ para = block_from_string("#{sentence}\n#{macros}")
476
+ output = para.sub_macros(para.buffer.join)
477
+ assert_equal sentence, output.rstrip
478
+ assert_equal 2, para.document.references[:indexterms].size
479
+ assert_equal ['Tigers'], para.document.references[:indexterms][0]
480
+ assert_equal ['Animals', 'Cats'], para.document.references[:indexterms][1]
481
+ end
482
+
483
+ test 'an index term macro with round bracket syntax may contain round brackets in term' do
484
+ sentence = "The tiger (Panthera tigris) is the largest cat species.\n"
485
+ macro = '(((Tiger (Panthera tigris))))'
486
+ para = block_from_string("#{sentence}#{macro}")
487
+ output = para.sub_macros(para.buffer.join)
488
+ assert_equal sentence, output
489
+ assert_equal 1, para.document.references[:indexterms].size
490
+ assert_equal ['Tiger (Panthera tigris)'], para.document.references[:indexterms].first
491
+ end
492
+
493
+ test 'an index term macro with square bracket syntax may contain square brackets in term' do
494
+ sentence = "The tiger (Panthera tigris) is the largest cat species.\n"
495
+ macro = 'indexterm:[Tiger [Panthera tigris\\]]'
496
+ para = block_from_string("#{sentence}#{macro}")
497
+ output = para.sub_macros(para.buffer.join)
498
+ assert_equal sentence, output
499
+ assert_equal 1, para.document.references[:indexterms].size
500
+ assert_equal ['Tiger [Panthera tigris]'], para.document.references[:indexterms].first
501
+ end
502
+
503
+ test 'a single-line index term 2 macro should be registered as an index reference and retain term inline' do
504
+ sentence = 'The tiger (Panthera tigris) is the largest cat species.'
505
+ macros = ['The indexterm2:[tiger] (Panthera tigris) is the largest cat species.', 'The ((tiger)) (Panthera tigris) is the largest cat species.']
506
+ macros.each do |macro|
507
+ para = block_from_string(macro)
508
+ output = para.sub_macros(para.buffer.join)
509
+ assert_equal sentence, output
510
+ assert_equal 1, para.document.references[:indexterms].size
511
+ assert_equal ['tiger'], para.document.references[:indexterms].first
512
+ end
513
+ end
514
+
515
+ test 'a multi-line index term 2 macro should be compacted and registered as an index reference and retain term inline' do
516
+ sentence = 'The panthera tigris is the largest cat species.'
517
+ macros = ["The indexterm2:[ panthera\ntigris ] is the largest cat species.", "The (( panthera\ntigris )) is the largest cat species."]
518
+ macros.each do |macro|
519
+ para = block_from_string(macro)
520
+ output = para.sub_macros(para.buffer.join)
521
+ assert_equal sentence, output
522
+ assert_equal 1, para.document.references[:indexterms].size
523
+ assert_equal ['panthera tigris'], para.document.references[:indexterms].first
524
+ end
525
+ end
526
+
527
+ test 'registers multiple index term 2 macros' do
528
+ sentence = "The ((tiger)) (Panthera tigris) is the largest ((cat)) species."
529
+ para = block_from_string(sentence)
530
+ output = para.sub_macros(para.buffer.join)
531
+ assert_equal 'The tiger (Panthera tigris) is the largest cat species.', output
532
+ assert_equal 2, para.document.references[:indexterms].size
533
+ assert_equal ['tiger'], para.document.references[:indexterms][0]
534
+ assert_equal ['cat'], para.document.references[:indexterms][1]
535
+ end
536
+
537
+ test 'normal substitutions are performed on an index term 2 macro' do
538
+ sentence = 'The ((*tiger*)) (Panthera tigris) is the largest cat species.'
539
+ para = block_from_string sentence
540
+ output = para.apply_normal_subs(para.buffer)
541
+ assert_equal 'The <strong>tiger</strong> (Panthera tigris) is the largest cat species.', output
542
+ assert_equal 1, para.document.references[:indexterms].size
543
+ assert_equal ['<strong>tiger</strong>'], para.document.references[:indexterms].first
544
+ end
545
+
546
+ test 'index term 2 macro with round bracket syntex should not interfer with index term macro with round bracket syntax' do
547
+ sentence = "The ((panthera tigris)) is the largest cat species.\n(((Big cats,Tigers)))"
548
+ para = block_from_string sentence
549
+ output = para.sub_macros(para.buffer.join)
550
+ assert_equal "The panthera tigris is the largest cat species.\n", output
551
+ terms = para.document.references[:indexterms]
552
+ assert_equal 2, terms.size
553
+ assert_equal ['Big cats', 'Tigers'], terms[0]
554
+ assert_equal ['panthera tigris'], terms[1]
555
+ end
334
556
  end
335
557
 
336
558
  context 'Passthroughs' do
@@ -388,27 +610,47 @@ context 'Substitutions' do
388
610
  assert_equal [:specialcharacters, :quotes], para.passthroughs.first[:subs]
389
611
  end
390
612
 
613
+ # NOTE placeholder is surrounded by text to prevent reader from stripping trailing boundary char (unique to test scenario)
391
614
  test 'restore inline passthroughs without subs' do
392
- para = block_from_string("\x0" + '0' + "\x0")
615
+ para = block_from_string("some \x0" + '0' + "\x0 to study")
393
616
  para.passthroughs << {:text => '<code>inline code</code>', :subs => []}
394
617
  result = para.restore_passthroughs(para.buffer.join)
395
- assert_equal '<code>inline code</code>', result
618
+ assert_equal "some <code>inline code</code> to study", result
396
619
  end
397
620
 
621
+ # NOTE placeholder is surrounded by text to prevent reader from stripping trailing boundary char (unique to test scenario)
398
622
  # TODO add two entries to ensure index lookup is working correctly (0 indx could be ambiguous)
399
623
  test 'restore inline passthroughs with subs' do
400
- para = block_from_string("\x0" + '0' + "\x0")
624
+ para = block_from_string("some \x0" + '0' + "\x0 to study")
401
625
  para.passthroughs << {:text => '<code>{code}</code>', :subs => [:specialcharacters]}
402
626
  result = para.restore_passthroughs(para.buffer.join)
403
- assert_equal '&lt;code&gt;{code}&lt;/code&gt;', result
627
+ assert_equal 'some &lt;code&gt;{code}&lt;/code&gt; to study', result
404
628
  end
405
629
  end
406
630
 
407
631
  context 'Post replacements' do
408
- test 'line break' do
632
+ test 'line break inserted after line with line break character' do
409
633
  para = block_from_string("First line +\nSecond line")
410
634
  result = para.apply_subs(para.buffer, :post_replacements)
411
635
  assert_equal "First line<br>\n", result.first
412
636
  end
637
+
638
+ test 'line break inserted after line wrap with hardbreaks enabled' do
639
+ para = block_from_string("First line\nSecond line", :attributes => {'hardbreaks' => ''})
640
+ result = para.apply_subs(para.buffer, :post_replacements)
641
+ assert_equal "First line<br>\n", result.first
642
+ end
643
+
644
+ test 'line break character stripped from end of line with hardbreaks enabled' do
645
+ para = block_from_string("First line +\nSecond line", :attributes => {'hardbreaks' => ''})
646
+ result = para.apply_subs(para.buffer, :post_replacements)
647
+ assert_equal "First line<br>\n", result.first
648
+ end
649
+
650
+ test 'line break not inserted for single line with hardbreaks enabled' do
651
+ para = block_from_string("First line", :attributes => {'hardbreaks' => ''})
652
+ result = para.apply_subs(para.buffer, :post_replacements)
653
+ assert_equal "First line", result.first
654
+ end
413
655
  end
414
656
  end
@@ -39,7 +39,7 @@ context 'Tables' do
39
39
  |=======
40
40
  EOS
41
41
  output = render_embedded_string input
42
- assert_xpath '/table/caption[@class="title"][text()="Simple psv table"]', output, 1
42
+ assert_xpath '/table/caption[@class="title"][text()="Table 1. Simple psv table"]', output, 1
43
43
  assert_xpath '/table/caption/following-sibling::colgroup', output, 1
44
44
  end
45
45
 
@@ -58,6 +58,23 @@ context 'Tables' do
58
58
  assert_xpath '/table/tbody/tr/td[2]/p[text()="a | there"]', output, 1
59
59
  end
60
60
 
61
+ test 'should auto recover with warning if missing leading separator on first cell' do
62
+ input = <<-EOS
63
+ |===
64
+ A | here| a | there
65
+ |===
66
+ EOS
67
+ output = render_embedded_string input
68
+ assert_css 'table', output, 1
69
+ assert_css 'table > colgroup > col', output, 4
70
+ assert_css 'table > tbody > tr', output, 1
71
+ assert_css 'table > tbody > tr > td', output, 4
72
+ assert_xpath '/table/tbody/tr/td[1]/p[text()="A"]', output, 1
73
+ assert_xpath '/table/tbody/tr/td[2]/p[text()="here"]', output, 1
74
+ assert_xpath '/table/tbody/tr/td[3]/p[text()="a"]', output, 1
75
+ assert_xpath '/table/tbody/tr/td[4]/p[text()="there"]', output, 1
76
+ end
77
+
61
78
  test 'performs normal substitutions on cell content' do
62
79
  input = <<-EOS
63
80
  :show_title: Cool new show
@@ -217,7 +234,7 @@ I am getting in shape!
217
234
  output = render_embedded_string input
218
235
  assert_css 'table', output, 1
219
236
  assert_css 'table[style~="width: 80%;"]', output, 1
220
- assert_xpath '/table/caption[@class="title"][text()="Horizontal and vertical source data"]', output, 1
237
+ assert_xpath '/table/caption[@class="title"][text()="Table 1. Horizontal and vertical source data"]', output, 1
221
238
  assert_css 'table > colgroup > col', output, 4
222
239
  assert_css 'table > colgroup > col:nth-child(1)[@style~="width: 17%;"]', output, 1
223
240
  assert_css 'table > colgroup > col:nth-child(2)[@style~="width: 11%;"]', output, 1
@@ -242,7 +259,7 @@ I am getting in shape!
242
259
  |1 >s|2 |3 |4
243
260
  ^|5 2.2+^.^|6 .3+<.>m|7
244
261
  ^|8
245
- |9 2+>|10
262
+ d|9 2+>|10
246
263
  |===
247
264
  EOS
248
265
  output = render_embedded_string input
@@ -267,7 +284,8 @@ I am getting in shape!
267
284
 
268
285
  assert_css 'table tr:nth-child(3) > td:nth-child(1).halign-center.valign-top p em', output, 1
269
286
 
270
- assert_css 'table tr:nth-child(4) > td:nth-child(1).halign-left.valign-top p em', output, 1
287
+ assert_css 'table tr:nth-child(4) > td:nth-child(1).halign-left.valign-top p', output, 1
288
+ assert_css 'table tr:nth-child(4) > td:nth-child(1).halign-left.valign-top p em', output, 0
271
289
  assert_css 'table tr:nth-child(4) > td:nth-child(2).halign-right.valign-top[colspan="2"] p tt', output, 1
272
290
  end
273
291
 
@@ -1,4 +1,5 @@
1
1
  require 'fileutils'
2
+ require 'pathname'
2
3
  require 'test/unit'
3
4
 
4
5
  require "#{File.expand_path(File.dirname(__FILE__))}/../lib/asciidoctor.rb"
@@ -15,6 +16,14 @@ require 'pending'
15
16
  ENV['SUPPRESS_DEBUG'] ||= 'true'
16
17
 
17
18
  class Test::Unit::TestCase
19
+ def windows?
20
+ RbConfig::CONFIG['host_os'] =~ /win|ming/
21
+ end
22
+
23
+ def disk_root
24
+ "#{windows? ? File.expand_path(__FILE__).split('/').first : nil}/"
25
+ end
26
+
18
27
  def sample_doc_path(name)
19
28
  name = name.to_s
20
29
  unless name.include?('.')
@@ -29,11 +38,12 @@ class Test::Unit::TestCase
29
38
  end
30
39
 
31
40
  def fixture_path(name)
32
- File.join(File.dirname(__FILE__), "fixtures", name )
41
+ File.join(File.expand_path(File.dirname(__FILE__)), 'fixtures', name)
33
42
  end
34
43
 
35
- def example_document(name)
36
- Asciidoctor::Document.new(File.readlines(sample_doc_path(name)))
44
+ def example_document(name, opts = {})
45
+ opts[:header_footer] = true unless opts.has_key?(:header_footer)
46
+ Asciidoctor::Document.new(File.readlines(sample_doc_path(name)), opts)
37
47
  end
38
48
 
39
49
  def assert_difference(expression, difference = 1, message = nil, &block)
@@ -111,6 +121,7 @@ class Test::Unit::TestCase
111
121
  end
112
122
 
113
123
  def document_from_string(src, opts = {})
124
+ opts[:header_footer] = true unless opts.has_key?(:header_footer)
114
125
  Asciidoctor::Document.new(src.lines.entries, opts)
115
126
  end
116
127
 
@@ -133,6 +144,39 @@ class Test::Unit::TestCase
133
144
  reader = Asciidoctor::Reader.new source.lines.entries
134
145
  [Asciidoctor::Lexer.parse_header_metadata(reader), reader]
135
146
  end
147
+
148
+ def invoke_cli_to_buffer(argv = [], filename = 'sample.asciidoc', &block)
149
+ invoke_cli(argv, filename, [StringIO.new, StringIO.new], &block)
150
+ end
151
+
152
+ def invoke_cli(argv = [], filename = 'sample.asciidoc', buffers = nil, &block)
153
+ if filename.nil? || filename == '-' || ::Pathname.new(filename).absolute?
154
+ filepath = filename
155
+ else
156
+ filepath = File.join(File.dirname(__FILE__), 'fixtures', filename)
157
+ end
158
+ invoker = Asciidoctor::Cli::Invoker.new(argv + [filepath])
159
+ if buffers
160
+ invoker.redirect_streams(*buffers)
161
+ end
162
+ invoker.invoke!(&block)
163
+ invoker
164
+ end
165
+
166
+ def redirect_streams
167
+ old_stdout = $stdout
168
+ old_stderr = $stderr
169
+ stdout = StringIO.new
170
+ stderr = StringIO.new
171
+ $stdout = stdout
172
+ $stderr = stderr
173
+ begin
174
+ yield(stdout, stderr)
175
+ ensure
176
+ $stdout = old_stdout
177
+ $stderr = old_stderr
178
+ end
179
+ end
136
180
  end
137
181
 
138
182
  ###
@@ -1,12 +1,28 @@
1
1
  require 'test_helper'
2
2
 
3
3
  context "Text" do
4
- test "proper encoding to handle utf8 characters in document" do
5
- assert_xpath "//p", example_document(:encoding).render, 1
4
+ test "proper encoding to handle utf8 characters in document using html backend" do
5
+ output = example_document(:encoding).render
6
+ assert_xpath '//p', output, 2
7
+ assert_xpath '//a', output, 1
6
8
  end
7
9
 
8
- test "proper encoding to handle utf8 characters in embedded document" do
9
- assert_xpath "//p", example_document(:encoding).render(:header_footer => false), 1
10
+ test "proper encoding to handle utf8 characters in embedded document using html backend" do
11
+ output = example_document(:encoding, :header_footer => false).render
12
+ assert_xpath '//p', output, 2
13
+ assert_xpath '//a', output, 1
14
+ end
15
+
16
+ test "proper encoding to handle utf8 characters in document using docbook backend" do
17
+ output = example_document(:encoding, :attributes => {'backend' => 'docbook'}).render
18
+ assert_xpath '//simpara', output, 2
19
+ assert_xpath '//ulink', output, 1
20
+ end
21
+
22
+ test "proper encoding to handle utf8 characters in embedded document using docbook backend" do
23
+ output = example_document(:encoding, :header_footer => false, :attributes => {'backend' => 'docbook'}).render
24
+ assert_xpath '//simpara', output, 2
25
+ assert_xpath '//ulink', output, 1
10
26
  end
11
27
 
12
28
  # NOTE this test ensures we have the encoding line on block templates too