asciidoctor 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +10 -0
  3. data/Guardfile +18 -0
  4. data/LICENSE +1 -1
  5. data/README.adoc +65 -21
  6. data/Rakefile +10 -0
  7. data/asciidoctor.gemspec +17 -35
  8. data/compat/asciidoc.conf +130 -13
  9. data/lib/asciidoctor.rb +107 -87
  10. data/lib/asciidoctor/abstract_block.rb +6 -2
  11. data/lib/asciidoctor/abstract_node.rb +21 -13
  12. data/lib/asciidoctor/attribute_list.rb +2 -5
  13. data/{stylesheets/asciidoctor.css → lib/asciidoctor/backends/_stylesheets.rb} +96 -46
  14. data/lib/asciidoctor/backends/base_template.rb +9 -4
  15. data/lib/asciidoctor/backends/docbook45.rb +246 -138
  16. data/lib/asciidoctor/backends/html5.rb +580 -381
  17. data/lib/asciidoctor/block.rb +2 -50
  18. data/lib/asciidoctor/cli/options.rb +9 -8
  19. data/lib/asciidoctor/document.rb +35 -45
  20. data/lib/asciidoctor/helpers.rb +10 -0
  21. data/lib/asciidoctor/lexer.rb +456 -148
  22. data/lib/asciidoctor/list_item.rb +0 -21
  23. data/lib/asciidoctor/path_resolver.rb +18 -12
  24. data/lib/asciidoctor/reader.rb +71 -26
  25. data/lib/asciidoctor/renderer.rb +2 -19
  26. data/lib/asciidoctor/section.rb +0 -1
  27. data/lib/asciidoctor/substituters.rb +150 -36
  28. data/lib/asciidoctor/table.rb +30 -24
  29. data/lib/asciidoctor/version.rb +1 -1
  30. data/man/asciidoctor.1 +22 -16
  31. data/man/asciidoctor.ad +24 -16
  32. data/test/attributes_test.rb +50 -0
  33. data/test/blocks_test.rb +660 -9
  34. data/test/document_test.rb +191 -14
  35. data/test/fixtures/encoding.asciidoc +8 -0
  36. data/test/invoker_test.rb +47 -0
  37. data/test/lexer_test.rb +172 -0
  38. data/test/links_test.rb +28 -0
  39. data/test/lists_test.rb +172 -13
  40. data/test/options_test.rb +29 -2
  41. data/test/paragraphs_test.rb +105 -47
  42. data/test/paths_test.rb +3 -3
  43. data/test/reader_test.rb +46 -0
  44. data/test/sections_test.rb +365 -12
  45. data/test/substitutions_test.rb +127 -11
  46. data/test/tables_test.rb +81 -14
  47. data/test/test_helper.rb +18 -7
  48. data/test/text_test.rb +17 -5
  49. metadata +9 -36
@@ -19,6 +19,30 @@ context 'Document' do
19
19
  assert_equal Asciidoctor::SafeMode::SECURE, doc.safe
20
20
  end
21
21
 
22
+ test 'safe mode level set using string' do
23
+ doc = Asciidoctor::Document.new [], :safe => 'server'
24
+ assert_equal Asciidoctor::SafeMode::SERVER, doc.safe
25
+
26
+ doc = Asciidoctor::Document.new [], :safe => 'foo'
27
+ assert_equal Asciidoctor::SafeMode::SECURE, doc.safe
28
+ end
29
+
30
+ test 'safe mode level set using symbol' do
31
+ doc = Asciidoctor::Document.new [], :safe => :server
32
+ assert_equal Asciidoctor::SafeMode::SERVER, doc.safe
33
+
34
+ doc = Asciidoctor::Document.new [], :safe => :foo
35
+ assert_equal Asciidoctor::SafeMode::SECURE, doc.safe
36
+ end
37
+
38
+ test 'safe mode level set using integer' do
39
+ doc = Asciidoctor::Document.new [], :safe => 10
40
+ assert_equal Asciidoctor::SafeMode::SERVER, doc.safe
41
+
42
+ doc = Asciidoctor::Document.new [], :safe => 100
43
+ assert_equal 100, doc.safe
44
+ end
45
+
22
46
  test 'safe mode attributes are set on document' do
23
47
  doc = Asciidoctor::Document.new
24
48
  assert_equal Asciidoctor::SafeMode::SECURE, doc.attr('safe-mode-level')
@@ -99,6 +123,65 @@ preamble
99
123
  assert !doc.attr?('docfile')
100
124
  assert_equal doc.base_dir, doc.attr('docdir')
101
125
  end
126
+
127
+ test 'should accept attributes as array' do
128
+ # NOTE there's a tab character before idseparator
129
+ doc = Asciidoctor.load('text', :attributes => %w(toc numbered source-highlighter=coderay idprefix idseparator=-))
130
+ assert doc.attributes.is_a?(Hash)
131
+ assert doc.attr?('toc')
132
+ assert_equal '', doc.attr('toc')
133
+ assert doc.attr?('numbered')
134
+ assert_equal '', doc.attr('numbered')
135
+ assert doc.attr?('source-highlighter')
136
+ assert_equal 'coderay', doc.attr('source-highlighter')
137
+ assert doc.attr?('idprefix')
138
+ assert_equal '', doc.attr('idprefix')
139
+ assert doc.attr?('idseparator')
140
+ assert_equal '-', doc.attr('idseparator')
141
+ end
142
+
143
+ test 'should accept attributes as empty array' do
144
+ doc = Asciidoctor.load('text', :attributes => [])
145
+ assert doc.attributes.is_a?(Hash)
146
+ end
147
+
148
+ test 'should accept attributes as string' do
149
+ # NOTE there's a tab character before idseparator
150
+ doc = Asciidoctor.load('text', :attributes => 'toc numbered source-highlighter=coderay idprefix idseparator=-')
151
+ assert doc.attributes.is_a?(Hash)
152
+ assert doc.attr?('toc')
153
+ assert_equal '', doc.attr('toc')
154
+ assert doc.attr?('numbered')
155
+ assert_equal '', doc.attr('numbered')
156
+ assert doc.attr?('source-highlighter')
157
+ assert_equal 'coderay', doc.attr('source-highlighter')
158
+ assert doc.attr?('idprefix')
159
+ assert_equal '', doc.attr('idprefix')
160
+ assert doc.attr?('idseparator')
161
+ assert_equal '-', doc.attr('idseparator')
162
+ end
163
+
164
+ test 'should accept values containing spaces in attributes string' do
165
+ # NOTE there's a tab character before self:
166
+ doc = Asciidoctor.load('text', :attributes => 'idprefix idseparator=- note-caption=Note\ to\ self: toc')
167
+ assert doc.attributes.is_a?(Hash)
168
+ assert doc.attr?('idprefix')
169
+ assert_equal '', doc.attr('idprefix')
170
+ assert doc.attr?('idseparator')
171
+ assert_equal '-', doc.attr('idseparator')
172
+ assert doc.attr?('note-caption')
173
+ assert_equal "Note to self:", doc.attr('note-caption')
174
+ end
175
+
176
+ test 'should accept attributes as empty string' do
177
+ doc = Asciidoctor.load('text', :attributes => '')
178
+ assert doc.attributes.is_a?(Hash)
179
+ end
180
+
181
+ test 'should accept attributes as nil' do
182
+ doc = Asciidoctor.load('text', :attributes => nil)
183
+ assert doc.attributes.is_a?(Hash)
184
+ end
102
185
  end
103
186
 
104
187
  context 'Render APIs' do
@@ -114,6 +197,18 @@ preamble
114
197
  assert_xpath '/html/body/*[@id="header"]/h1[text() = "Document Title"]', output, 1
115
198
  end
116
199
 
200
+ test 'should accept attributes as array' do
201
+ sample_input_path = fixture_path('sample.asciidoc')
202
+ output = Asciidoctor.render_file(sample_input_path, :attributes => %w(numbered idprefix idseparator=-))
203
+ assert_css '#section-a', output, 1
204
+ end
205
+
206
+ test 'should accept attributes as string' do
207
+ sample_input_path = fixture_path('sample.asciidoc')
208
+ output = Asciidoctor.render_file(sample_input_path, :attributes => 'numbered idprefix idseparator=-')
209
+ assert_css '#section-a', output, 1
210
+ end
211
+
117
212
  test 'should include docinfo files for html backend' do
118
213
  sample_input_path = fixture_path('basic.asciidoc')
119
214
 
@@ -309,6 +404,27 @@ text
309
404
  end
310
405
  end
311
406
 
407
+ test 'should render document to file when base dir is set' do
408
+ sample_input_path = fixture_path('sample.asciidoc')
409
+ sample_output_path = fixture_path('result.html')
410
+ fixture_dir = fixture_path('')
411
+ begin
412
+ Asciidoctor.render_file(sample_input_path, :to_file => 'result.html', :base_dir => fixture_dir)
413
+ assert File.exist?(sample_output_path)
414
+ output = File.read(sample_output_path)
415
+ assert !output.empty?
416
+ assert_xpath '/html', output, 1
417
+ assert_xpath '/html/head', output, 1
418
+ assert_xpath '/html/body', output, 1
419
+ assert_xpath '/html/head/title[text() = "Document Title"]', output, 1
420
+ assert_xpath '/html/body/*[@id="header"]/h1[text() = "Document Title"]', output, 1
421
+ rescue => e
422
+ flunk e.message
423
+ ensure
424
+ FileUtils::rm(sample_output_path, :force => true)
425
+ end
426
+ end
427
+
312
428
  test 'in_place option must not be used with to_file option' do
313
429
  sample_input_path = fixture_path('sample.asciidoc')
314
430
  sample_output_path = fixture_path('result.html')
@@ -347,7 +463,7 @@ text
347
463
  end
348
464
  end
349
465
 
350
- test 'missing directories should be created if specified' do
466
+ test 'missing directories should be created if mkdirs is enabled' do
351
467
  sample_input_path = fixture_path('sample.asciidoc')
352
468
  output_dir = File.join(File.join(File.dirname(sample_input_path), 'test_output'), 'subdir')
353
469
  sample_output_path = File.join(output_dir, 'sample.html')
@@ -389,7 +505,7 @@ text
389
505
  assert !renderer.nil?
390
506
  views = renderer.views
391
507
  assert !views.nil?
392
- assert_equal 33, views.size
508
+ assert_equal 36, views.size
393
509
  assert views.has_key? 'document'
394
510
  assert views['document'].is_a?(Asciidoctor::HTML5::DocumentTemplate)
395
511
  assert_equal 'ERB', views['document'].eruby.to_s
@@ -405,7 +521,7 @@ text
405
521
  assert !renderer.nil?
406
522
  views = renderer.views
407
523
  assert !views.nil?
408
- assert_equal 33, views.size
524
+ assert_equal 36, views.size
409
525
  assert views.has_key? 'document'
410
526
  assert views['document'].is_a?(Asciidoctor::DocBook45::DocumentTemplate)
411
527
  assert_equal 'ERB', views['document'].eruby.to_s
@@ -450,27 +566,49 @@ preamble
450
566
 
451
567
  test 'document with title attribute entry overrides doctitle' do
452
568
  input = <<-EOS
453
- = Title
454
- :title: Document Title
569
+ = Document Title
570
+ :title: Override
455
571
 
456
- preamble
572
+ {doctitle}
457
573
 
458
574
  == First Section
459
575
  EOS
460
576
  doc = document_from_string input
461
- assert_equal 'Document Title', doc.doctitle
462
- assert_equal 'Document Title', doc.title
577
+ assert_equal 'Override', doc.doctitle
578
+ assert_equal 'Override', doc.title
463
579
  assert doc.has_header?
464
- assert_equal 'Title', doc.header.title
465
- assert_equal 'Title', doc.first_section.title
580
+ assert_equal 'Document Title', doc.header.title
581
+ assert_equal 'Document Title', doc.first_section.title
582
+ assert_xpath '//*[@id="preamble"]//p[text()="Document Title"]', doc.render, 1
583
+ end
584
+
585
+ test 'document with title attribute entry overrides doctitle attribute entry' do
586
+ input = <<-EOS
587
+ = Document Title
588
+ :snapshot: {doctitle}
589
+ :doctitle: doctitle
590
+ :title: Override
591
+
592
+ {snapshot}, {doctitle}
593
+
594
+ == First Section
595
+ EOS
596
+ doc = document_from_string input
597
+ assert_equal 'Override', doc.doctitle
598
+ assert_equal 'Override', doc.title
599
+ assert doc.has_header?
600
+ assert_equal 'doctitle', doc.header.title
601
+ assert_equal 'doctitle', doc.first_section.title
602
+ assert_xpath '//*[@id="preamble"]//p[text()="Document Title, doctitle"]', doc.render, 1
466
603
  end
467
604
 
468
605
  test 'document with doctitle attribute entry overrides header title and doctitle' do
469
606
  input = <<-EOS
470
- = Title
607
+ = Document Title
608
+ :snapshot: {doctitle}
471
609
  :doctitle: Override
472
610
 
473
- preamble
611
+ {snapshot}, {doctitle}
474
612
 
475
613
  == First Section
476
614
  EOS
@@ -480,14 +618,15 @@ preamble
480
618
  assert doc.has_header?
481
619
  assert_equal 'Override', doc.header.title
482
620
  assert_equal 'Override', doc.first_section.title
621
+ assert_xpath '//*[@id="preamble"]//p[text()="Document Title, Override"]', doc.render, 1
483
622
  end
484
623
 
485
624
  test 'doctitle attribute entry above header overrides header title and doctitle' do
486
625
  input = <<-EOS
487
626
  :doctitle: Override
488
- = Title
627
+ = Document Title
489
628
 
490
- preamble
629
+ {doctitle}
491
630
 
492
631
  == First Section
493
632
  EOS
@@ -497,6 +636,7 @@ preamble
497
636
  assert doc.has_header?
498
637
  assert_equal 'Override', doc.header.title
499
638
  assert_equal 'Override', doc.first_section.title
639
+ assert_xpath '//*[@id="preamble"]//p[text()="Override"]', doc.render, 1
500
640
  end
501
641
 
502
642
  test 'should recognize document title when preceded by blank lines' do
@@ -575,6 +715,23 @@ more info...
575
715
  assert_xpath '/article/articleinfo/revhistory/revision/revremark[text() = "See changelog."]', output, 1
576
716
  end
577
717
 
718
+ test 'with author defined using attribute entry to DocBook' do
719
+ input = <<-EOS
720
+ = Document Title
721
+ :author: Doc Writer
722
+ :email: thedoctor@asciidoc.org
723
+
724
+ content
725
+ EOS
726
+
727
+ output = render_string input, :backend => 'docbook'
728
+ assert_xpath '//articleinfo/author', output, 1
729
+ assert_xpath '//articleinfo/author/firstname[text() = "Doc"]', output, 1
730
+ assert_xpath '//articleinfo/author/surname[text() = "Writer"]', output, 1
731
+ assert_xpath '//articleinfo/author/email[text() = "thedoctor@asciidoc.org"]', output, 1
732
+ assert_xpath '//articleinfo/authorinitials[text() = "DW"]', output, 1
733
+ end
734
+
578
735
  test 'should create authorgroup in DocBook when multiple authors' do
579
736
  input = <<-EOS
580
737
  = Document Title
@@ -591,6 +748,26 @@ content
591
748
  assert_xpath '//articleinfo/authorgroup/author[2]/firstname[text() = "Junior"]', output, 1
592
749
  end
593
750
 
751
+ test 'with authors defined using attribute entry to DocBook' do
752
+ input = <<-EOS
753
+ = Document Title
754
+ :authors: Doc Writer; Junior Writer
755
+ :email_1: thedoctor@asciidoc.org
756
+ :email_2: junior@asciidoc.org
757
+
758
+ content
759
+ EOS
760
+
761
+ output = render_string input, :backend => 'docbook'
762
+ assert_xpath '//articleinfo/author', output, 0
763
+ assert_xpath '//articleinfo/authorgroup', output, 1
764
+ assert_xpath '//articleinfo/authorgroup/author', output, 2
765
+ assert_xpath '(//articleinfo/authorgroup/author)[1]/firstname[text() = "Doc"]', output, 1
766
+ assert_xpath '(//articleinfo/authorgroup/author)[1]/email[text() = "thedoctor@asciidoc.org"]', output, 1
767
+ assert_xpath '(//articleinfo/authorgroup/author)[2]/firstname[text() = "Junior"]', output, 1
768
+ assert_xpath '(//articleinfo/authorgroup/author)[2]/email[text() = "junior@asciidoc.org"]', output, 1
769
+ end
770
+
594
771
  test 'with header footer' do
595
772
  doc = document_from_string "= Title\n\npreamble"
596
773
  assert !doc.attr?('embedded')
@@ -3,3 +3,11 @@ Gregory Romé has written an AsciiDoc plugin for the Redmine project management
3
3
  https://github.com/foo-users/foo
4
4
  へと `vicmd` キーマップを足してみている試み、
5
5
  アニメーションgifです。
6
+
7
+ tag::romé[]
8
+ Gregory Romé has written an AsciiDoc plugin for the Redmine project management application.
9
+ end::romé[]
10
+
11
+ == Überschrift
12
+
13
+ * Codierungen sind verrückt auf älteren Versionen von Ruby
data/test/invoker_test.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require 'test_helper'
2
3
  require 'asciidoctor/cli/options'
3
4
  require 'asciidoctor/cli/invoker'
@@ -234,6 +235,23 @@ context 'Invoker' do
234
235
  assert_xpath '//h2[@id="idsection_a"]', output, 1
235
236
  end
236
237
 
238
+ test 'should set attribute with value containing equal sign' do
239
+ invoker = invoke_cli_to_buffer %w(--trace -a toc -a toc-title=t=o=c -o -)
240
+ doc = invoker.document
241
+ assert_equal 't=o=c', doc.attr('toc-title')
242
+ output = invoker.read_output
243
+ assert_xpath '//*[@id="toctitle"][text() = "t=o=c"]', output, 1
244
+ end
245
+
246
+ test 'should set attribute with quoted value containing a space' do
247
+ # emulating commandline arguments: --trace -a toc -a note-caption="Note to self:" -o -
248
+ invoker = invoke_cli_to_buffer %w(--trace -a toc -a note-caption=Note\ to\ self: -o -)
249
+ doc = invoker.document
250
+ assert_equal 'Note to self:', doc.attr('note-caption')
251
+ output = invoker.read_output
252
+ assert_xpath %(//*[#{contains_class('admonitionblock')}]//*[@class='title'][text() = 'Note to self:']), output, 1
253
+ end
254
+
237
255
  test 'should not set attribute ending in @ if defined in document' do
238
256
  invoker = invoke_cli_to_buffer %w(--trace -a idprefix=id@ -s -o -)
239
257
  doc = invoker.document
@@ -291,4 +309,33 @@ context 'Invoker' do
291
309
  assert_equal 'erubis', doc.instance_variable_get('@options')[:eruby]
292
310
  end
293
311
 
312
+ test 'should force default external encoding to UTF-8' do
313
+ executable = File.expand_path(File.join(File.dirname(__FILE__), '..', 'bin', 'asciidoctor'))
314
+ input_path = fixture_path 'encoding.asciidoc'
315
+ old_lang = ENV['LANG']
316
+ ENV['LANG'] = 'US-ASCII'
317
+ begin
318
+ # using open3 to work around a bug in JRuby process_manager.rb,
319
+ # which tries to run a gsub on stdout prematurely breaking the test
320
+ require 'open3'
321
+ #cmd = "#{executable} -o - --trace #{input_path}"
322
+ cmd = "#{File.join RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']} #{executable} -o - --trace #{input_path}"
323
+ _, stdout, stderr = Open3.popen3 cmd
324
+ stderr_lines = stderr.readlines
325
+ puts stderr_lines.join unless stderr_lines.empty?
326
+ assert stderr_lines.empty?, 'Command failed. Expected to receive a rendered document.'
327
+ stdout_lines = stdout.readlines
328
+ assert !stdout_lines.empty?
329
+ if Asciidoctor::FORCE_ENCODING
330
+ stdout_lines.each do |l|
331
+ l.force_encoding Encoding::UTF_8
332
+ end
333
+ end
334
+ stdout_str = stdout_lines.join
335
+ assert stdout_str.include?('Codierungen sind verrückt auf älteren Versionen von Ruby')
336
+ ensure
337
+ ENV['LANG'] = old_lang
338
+ end
339
+ end
340
+
294
341
  end
data/test/lexer_test.rb CHANGED
@@ -71,6 +71,14 @@ context "Lexer" do
71
71
  assert_equal expected, attributes
72
72
  end
73
73
 
74
+ test "collect unnamed attribute in second position after empty attribute" do
75
+ attributes = {}
76
+ line = ', John Smith'
77
+ expected = {1 => nil, 2 => 'John Smith'}
78
+ Asciidoctor::AttributeList.new(line).parse_into(attributes)
79
+ assert_equal expected, attributes
80
+ end
81
+
74
82
  test "collect unnamed attributes" do
75
83
  attributes = {}
76
84
  line = "first, second one, third"
@@ -182,6 +190,79 @@ context "Lexer" do
182
190
  assert_equal expected, attributes
183
191
  end
184
192
 
193
+ test 'parse style attribute with id and role' do
194
+ attributes = {1 => 'style#id.role'}
195
+ style, original_style = Asciidoctor::Lexer.parse_style_attribute(attributes)
196
+ assert_equal 'style', style
197
+ assert_nil original_style
198
+ assert_equal 'style', attributes['style']
199
+ assert_equal 'id', attributes['id']
200
+ assert_equal 'role', attributes['role']
201
+ assert_equal 'style#id.role', attributes[1]
202
+ end
203
+
204
+ test 'parse style attribute with style, role and id' do
205
+ attributes = {1 => 'style.role#id'}
206
+ style, original_style = Asciidoctor::Lexer.parse_style_attribute(attributes)
207
+ assert_equal 'style', style
208
+ assert_nil original_style
209
+ assert_equal 'style', attributes['style']
210
+ assert_equal 'id', attributes['id']
211
+ assert_equal 'role', attributes['role']
212
+ assert_equal 'style.role#id', attributes[1]
213
+ end
214
+
215
+ test 'parse style attribute with style, id and multiple roles' do
216
+ attributes = {1 => 'style#id.role1.role2'}
217
+ style, original_style = Asciidoctor::Lexer.parse_style_attribute(attributes)
218
+ assert_equal 'style', style
219
+ assert_nil original_style
220
+ assert_equal 'style', attributes['style']
221
+ assert_equal 'id', attributes['id']
222
+ assert_equal 'role1 role2', attributes['role']
223
+ assert_equal 'style#id.role1.role2', attributes[1]
224
+ end
225
+
226
+ test 'parse style attribute with style, multiple roles and id' do
227
+ attributes = {1 => 'style.role1.role2#id'}
228
+ style, original_style = Asciidoctor::Lexer.parse_style_attribute(attributes)
229
+ assert_equal 'style', style
230
+ assert_nil original_style
231
+ assert_equal 'style', attributes['style']
232
+ assert_equal 'id', attributes['id']
233
+ assert_equal 'role1 role2', attributes['role']
234
+ assert_equal 'style.role1.role2#id', attributes[1]
235
+ end
236
+
237
+ test 'parse style attribute with positional and original style' do
238
+ attributes = {1 => 'new_style', 'style' => 'original_style'}
239
+ style, original_style = Asciidoctor::Lexer.parse_style_attribute(attributes)
240
+ assert_equal 'new_style', style
241
+ assert_equal 'original_style', original_style
242
+ assert_equal 'new_style', attributes['style']
243
+ assert_equal 'new_style', attributes[1]
244
+ end
245
+
246
+ test 'parse style attribute with id and role only' do
247
+ attributes = {1 => '#id.role'}
248
+ style, original_style = Asciidoctor::Lexer.parse_style_attribute(attributes)
249
+ assert_nil style
250
+ assert_nil original_style
251
+ assert_equal 'id', attributes['id']
252
+ assert_equal 'role', attributes['role']
253
+ assert_equal '#id.role', attributes[1]
254
+ end
255
+
256
+ test 'parse empty style attribute' do
257
+ attributes = {1 => nil}
258
+ style, original_style = Asciidoctor::Lexer.parse_style_attribute(attributes)
259
+ assert_nil style
260
+ assert_nil original_style
261
+ assert_nil attributes['id']
262
+ assert_nil attributes['role']
263
+ assert_nil attributes[1]
264
+ end
265
+
185
266
  test "parse author first" do
186
267
  metadata, = parse_header_metadata 'Stuart'
187
268
  assert_equal 5, metadata.size
@@ -406,4 +487,95 @@ context "Lexer" do
406
487
  assert_equal 'SJR', blankdoc.attributes['authorinitials']
407
488
  end
408
489
 
490
+ test 'reset block indent to 0' do
491
+ input = <<-EOS
492
+ def names
493
+
494
+ @name.split ' '
495
+
496
+ end
497
+ EOS
498
+
499
+ expected = <<-EOS
500
+ def names
501
+
502
+ @name.split ' '
503
+
504
+ end
505
+ EOS
506
+
507
+ lines = input.lines.entries
508
+ Asciidoctor::Lexer.reset_block_indent! lines
509
+ assert_equal expected, lines.join
510
+ end
511
+
512
+ test 'reset block indent mixed with tabs and spaces to 0' do
513
+ input = <<-EOS
514
+ def names
515
+
516
+ \t @name.split ' '
517
+
518
+ end
519
+ EOS
520
+
521
+ expected = <<-EOS
522
+ def names
523
+
524
+ @name.split ' '
525
+
526
+ end
527
+ EOS
528
+
529
+ lines = input.lines.entries
530
+ Asciidoctor::Lexer.reset_block_indent! lines
531
+ assert_equal expected, lines.join
532
+ end
533
+
534
+ test 'reset block indent to non-zero' do
535
+ input = <<-EOS
536
+ def names
537
+
538
+ @name.split ' '
539
+
540
+ end
541
+ EOS
542
+
543
+ expected = <<-EOS
544
+ def names
545
+
546
+ @name.split ' '
547
+
548
+ end
549
+ EOS
550
+
551
+ lines = input.lines.entries
552
+ Asciidoctor::Lexer.reset_block_indent! lines, 2
553
+ assert_equal expected, lines.join
554
+ end
555
+
556
+ test 'preserve block indent' do
557
+ input = <<-EOS
558
+ def names
559
+
560
+ @name.split ' '
561
+
562
+ end
563
+ EOS
564
+
565
+ expected = input
566
+
567
+ lines = input.lines.entries
568
+ Asciidoctor::Lexer.reset_block_indent! lines, nil
569
+ assert_equal expected, lines.join
570
+ end
571
+
572
+ test 'reset block indent hands empty lines gracefully' do
573
+ input = []
574
+ expected = input
575
+
576
+ lines = input.dup
577
+ Asciidoctor::Lexer.reset_block_indent! lines
578
+ assert_equal expected, lines
579
+ end
580
+
409
581
  end