"Fossies" - the Fresh Open Source Software Archive

Member "asciidoctor-2.0.10/test/parser_test.rb" (1 Jun 2019, 25893 Bytes) of package /linux/www/asciidoctor-2.0.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 # frozen_string_literal: true
    2 require_relative 'test_helper'
    3 
    4 context "Parser" do
    5   test "is_section_title?" do
    6     assert Asciidoctor::Parser.is_section_title?('AsciiDoc Home Page', '==================')
    7     assert Asciidoctor::Parser.is_section_title?('=== AsciiDoc Home Page')
    8   end
    9 
   10   test 'sanitize attribute name' do
   11     assert_equal 'foobar', Asciidoctor::Parser.sanitize_attribute_name("Foo Bar")
   12     assert_equal 'foo', Asciidoctor::Parser.sanitize_attribute_name("foo")
   13     assert_equal 'foo3-bar', Asciidoctor::Parser.sanitize_attribute_name("Foo 3^ # - Bar[")
   14   end
   15 
   16   test 'store attribute with value' do
   17     attr_name, attr_value = Asciidoctor::Parser.store_attribute 'foo', 'bar'
   18     assert_equal 'foo', attr_name
   19     assert_equal 'bar', attr_value
   20   end
   21 
   22   test 'store attribute with negated value' do
   23     { 'foo!' => nil, '!foo' => nil, 'foo' => nil }.each do |name, value|
   24       attr_name, attr_value = Asciidoctor::Parser.store_attribute name, value
   25       assert_equal name.sub('!', ''), attr_name
   26       assert_nil attr_value
   27     end
   28   end
   29 
   30   test 'store accessible attribute on document with value' do
   31     doc = empty_document
   32     doc.set_attribute 'foo', 'baz'
   33     attrs = {}
   34     attr_name, attr_value = Asciidoctor::Parser.store_attribute 'foo', 'bar', doc, attrs
   35     assert_equal 'foo', attr_name
   36     assert_equal 'bar', attr_value
   37     assert_equal 'bar', (doc.attr 'foo')
   38     assert attrs.key?(:attribute_entries)
   39     assert_equal 1, attrs[:attribute_entries].size
   40     assert_equal 'foo', attrs[:attribute_entries][0].name
   41     assert_equal 'bar', attrs[:attribute_entries][0].value
   42   end
   43 
   44   test 'store accessible attribute on document with value that contains attribute reference' do
   45     doc = empty_document
   46     doc.set_attribute 'foo', 'baz'
   47     doc.set_attribute 'release', 'ultramega'
   48     attrs = {}
   49     attr_name, attr_value = Asciidoctor::Parser.store_attribute 'foo', '{release}', doc, attrs
   50     assert_equal 'foo', attr_name
   51     assert_equal 'ultramega', attr_value
   52     assert_equal 'ultramega', (doc.attr 'foo')
   53     assert attrs.key?(:attribute_entries)
   54     assert_equal 1, attrs[:attribute_entries].size
   55     assert_equal 'foo', attrs[:attribute_entries][0].name
   56     assert_equal 'ultramega', attrs[:attribute_entries][0].value
   57   end
   58 
   59   test 'store inaccessible attribute on document with value' do
   60     doc = empty_document attributes: { 'foo' => 'baz' }
   61     attrs = {}
   62     attr_name, attr_value = Asciidoctor::Parser.store_attribute 'foo', 'bar', doc, attrs
   63     assert_equal 'foo', attr_name
   64     assert_equal 'bar', attr_value
   65     assert_equal 'baz', (doc.attr 'foo')
   66     refute attrs.key?(:attribute_entries)
   67   end
   68 
   69   test 'store accessible attribute on document with negated value' do
   70     { 'foo!' => nil, '!foo' => nil, 'foo' => nil }.each do |name, value|
   71       doc = empty_document
   72       doc.set_attribute 'foo', 'baz'
   73       attrs = {}
   74       attr_name, attr_value = Asciidoctor::Parser.store_attribute name, value, doc, attrs
   75       assert_equal name.sub('!', ''), attr_name
   76       assert_nil attr_value
   77       assert attrs.key?(:attribute_entries)
   78       assert_equal 1, attrs[:attribute_entries].size
   79       assert_equal 'foo', attrs[:attribute_entries][0].name
   80       assert_nil attrs[:attribute_entries][0].value
   81     end
   82   end
   83 
   84   test 'store inaccessible attribute on document with negated value' do
   85     { 'foo!' => nil, '!foo' => nil, 'foo' => nil }.each do |name, value|
   86       doc = empty_document attributes: { 'foo' => 'baz' }
   87       attrs = {}
   88       attr_name, attr_value = Asciidoctor::Parser.store_attribute name, value, doc, attrs
   89       assert_equal name.sub('!', ''), attr_name
   90       assert_nil attr_value
   91       refute attrs.key?(:attribute_entries)
   92     end
   93   end
   94 
   95   test 'parse style attribute with id and role' do
   96     attributes = { 1 => 'style#id.role' }
   97     style = Asciidoctor::Parser.parse_style_attribute(attributes)
   98     assert_equal 'style', style
   99     assert_equal 'style', attributes['style']
  100     assert_equal 'id', attributes['id']
  101     assert_equal 'role', attributes['role']
  102     assert_equal 'style#id.role', attributes[1]
  103   end
  104 
  105   test 'parse style attribute with style, role, id and option' do
  106     attributes = { 1 => 'style.role#id%fragment' }
  107     style = Asciidoctor::Parser.parse_style_attribute(attributes)
  108     assert_equal 'style', style
  109     assert_equal 'style', attributes['style']
  110     assert_equal 'id', attributes['id']
  111     assert_equal 'role', attributes['role']
  112     assert_equal '', attributes['fragment-option']
  113     assert_equal 'style.role#id%fragment', attributes[1]
  114     refute attributes.key? 'options'
  115   end
  116 
  117   test 'parse style attribute with style, id and multiple roles' do
  118     attributes = { 1 => 'style#id.role1.role2' }
  119     style = Asciidoctor::Parser.parse_style_attribute(attributes)
  120     assert_equal 'style', style
  121     assert_equal 'style', attributes['style']
  122     assert_equal 'id', attributes['id']
  123     assert_equal 'role1 role2', attributes['role']
  124     assert_equal 'style#id.role1.role2', attributes[1]
  125   end
  126 
  127   test 'parse style attribute with style, multiple roles and id' do
  128     attributes = { 1 => 'style.role1.role2#id' }
  129     style = Asciidoctor::Parser.parse_style_attribute(attributes)
  130     assert_equal 'style', style
  131     assert_equal 'style', attributes['style']
  132     assert_equal 'id', attributes['id']
  133     assert_equal 'role1 role2', attributes['role']
  134     assert_equal 'style.role1.role2#id', attributes[1]
  135   end
  136 
  137   test 'parse style attribute with positional and original style' do
  138     attributes = { 1 => 'new_style', 'style' => 'original_style' }
  139     style = Asciidoctor::Parser.parse_style_attribute(attributes)
  140     assert_equal 'new_style', style
  141     assert_equal 'new_style', attributes['style']
  142     assert_equal 'new_style', attributes[1]
  143   end
  144 
  145   test 'parse style attribute with id and role only' do
  146     attributes = { 1 => '#id.role' }
  147     style = Asciidoctor::Parser.parse_style_attribute(attributes)
  148     assert_nil style
  149     assert_equal 'id', attributes['id']
  150     assert_equal 'role', attributes['role']
  151     assert_equal '#id.role', attributes[1]
  152   end
  153 
  154   test 'parse empty style attribute' do
  155     attributes = { 1 => nil }
  156     style = Asciidoctor::Parser.parse_style_attribute(attributes)
  157     assert_nil style
  158     assert_nil attributes['id']
  159     assert_nil attributes['role']
  160     assert_nil attributes[1]
  161   end
  162 
  163   test 'parse style attribute with option should preserve existing options' do
  164     attributes = { 1 => '%header', 'footer-option' => '' }
  165     style = Asciidoctor::Parser.parse_style_attribute(attributes)
  166     assert_nil style
  167     assert_equal '', attributes['header-option']
  168     assert_equal '', attributes['footer-option']
  169   end
  170 
  171   test "parse author first" do
  172     metadata, _ = parse_header_metadata 'Stuart'
  173     assert_equal 5, metadata.size
  174     assert_equal 1, metadata['authorcount']
  175     assert_equal metadata['author'], metadata['authors']
  176     assert_equal 'Stuart', metadata['firstname']
  177     assert_equal 'S', metadata['authorinitials']
  178   end
  179 
  180   test "parse author first last" do
  181     metadata, _ = parse_header_metadata 'Yukihiro Matsumoto'
  182     assert_equal 6, metadata.size
  183     assert_equal 1, metadata['authorcount']
  184     assert_equal 'Yukihiro Matsumoto', metadata['author']
  185     assert_equal metadata['author'], metadata['authors']
  186     assert_equal 'Yukihiro', metadata['firstname']
  187     assert_equal 'Matsumoto', metadata['lastname']
  188     assert_equal 'YM', metadata['authorinitials']
  189   end
  190 
  191   test "parse author first middle last" do
  192     metadata, _ = parse_header_metadata 'David Heinemeier Hansson'
  193     assert_equal 7, metadata.size
  194     assert_equal 1, metadata['authorcount']
  195     assert_equal 'David Heinemeier Hansson', metadata['author']
  196     assert_equal metadata['author'], metadata['authors']
  197     assert_equal 'David', metadata['firstname']
  198     assert_equal 'Heinemeier', metadata['middlename']
  199     assert_equal 'Hansson', metadata['lastname']
  200     assert_equal 'DHH', metadata['authorinitials']
  201   end
  202 
  203   test "parse author first middle last email" do
  204     metadata, _ = parse_header_metadata 'David Heinemeier Hansson <rails@ruby-lang.org>'
  205     assert_equal 8, metadata.size
  206     assert_equal 1, metadata['authorcount']
  207     assert_equal 'David Heinemeier Hansson', metadata['author']
  208     assert_equal metadata['author'], metadata['authors']
  209     assert_equal 'David', metadata['firstname']
  210     assert_equal 'Heinemeier', metadata['middlename']
  211     assert_equal 'Hansson', metadata['lastname']
  212     assert_equal 'rails@ruby-lang.org', metadata['email']
  213     assert_equal 'DHH', metadata['authorinitials']
  214   end
  215 
  216   test "parse author first email" do
  217     metadata, _ = parse_header_metadata 'Stuart <founder@asciidoc.org>'
  218     assert_equal 6, metadata.size
  219     assert_equal 1, metadata['authorcount']
  220     assert_equal 'Stuart', metadata['author']
  221     assert_equal metadata['author'], metadata['authors']
  222     assert_equal 'Stuart', metadata['firstname']
  223     assert_equal 'founder@asciidoc.org', metadata['email']
  224     assert_equal 'S', metadata['authorinitials']
  225   end
  226 
  227   test "parse author first last email" do
  228     metadata, _ = parse_header_metadata 'Stuart Rackham <founder@asciidoc.org>'
  229     assert_equal 7, metadata.size
  230     assert_equal 1, metadata['authorcount']
  231     assert_equal 'Stuart Rackham', metadata['author']
  232     assert_equal metadata['author'], metadata['authors']
  233     assert_equal 'Stuart', metadata['firstname']
  234     assert_equal 'Rackham', metadata['lastname']
  235     assert_equal 'founder@asciidoc.org', metadata['email']
  236     assert_equal 'SR', metadata['authorinitials']
  237   end
  238 
  239   test "parse author with hyphen" do
  240     metadata, _ = parse_header_metadata 'Tim Berners-Lee <founder@www.org>'
  241     assert_equal 7, metadata.size
  242     assert_equal 1, metadata['authorcount']
  243     assert_equal 'Tim Berners-Lee', metadata['author']
  244     assert_equal metadata['author'], metadata['authors']
  245     assert_equal 'Tim', metadata['firstname']
  246     assert_equal 'Berners-Lee', metadata['lastname']
  247     assert_equal 'founder@www.org', metadata['email']
  248     assert_equal 'TB', metadata['authorinitials']
  249   end
  250 
  251   test "parse author with single quote" do
  252     metadata, _ = parse_header_metadata 'Stephen O\'Grady <founder@redmonk.com>'
  253     assert_equal 7, metadata.size
  254     assert_equal 1, metadata['authorcount']
  255     assert_equal 'Stephen O\'Grady', metadata['author']
  256     assert_equal metadata['author'], metadata['authors']
  257     assert_equal 'Stephen', metadata['firstname']
  258     assert_equal 'O\'Grady', metadata['lastname']
  259     assert_equal 'founder@redmonk.com', metadata['email']
  260     assert_equal 'SO', metadata['authorinitials']
  261   end
  262 
  263   test "parse author with dotted initial" do
  264     metadata, _ = parse_header_metadata 'Heiko W. Rupp <hwr@example.de>'
  265     assert_equal 8, metadata.size
  266     assert_equal 1, metadata['authorcount']
  267     assert_equal 'Heiko W. Rupp', metadata['author']
  268     assert_equal metadata['author'], metadata['authors']
  269     assert_equal 'Heiko', metadata['firstname']
  270     assert_equal 'W.', metadata['middlename']
  271     assert_equal 'Rupp', metadata['lastname']
  272     assert_equal 'hwr@example.de', metadata['email']
  273     assert_equal 'HWR', metadata['authorinitials']
  274   end
  275 
  276   test "parse author with underscore" do
  277     metadata, _ = parse_header_metadata 'Tim_E Fella'
  278     assert_equal 6, metadata.size
  279     assert_equal 1, metadata['authorcount']
  280     assert_equal 'Tim E Fella', metadata['author']
  281     assert_equal metadata['author'], metadata['authors']
  282     assert_equal 'Tim E', metadata['firstname']
  283     assert_equal 'Fella', metadata['lastname']
  284     assert_equal 'TF', metadata['authorinitials']
  285   end
  286 
  287   test 'parse author name with letters outside basic latin' do
  288     metadata, _ = parse_header_metadata 'Stéphane Brontë'
  289     assert_equal 6, metadata.size
  290     assert_equal 1, metadata['authorcount']
  291     assert_equal 'Stéphane Brontë', metadata['author']
  292     assert_equal metadata['author'], metadata['authors']
  293     assert_equal 'Stéphane', metadata['firstname']
  294     assert_equal 'Brontë', metadata['lastname']
  295     assert_equal 'SB', metadata['authorinitials']
  296   end
  297 
  298   test 'parse ideographic author names' do
  299     metadata, _ = parse_header_metadata '李 四 <si.li@example.com>'
  300     assert_equal 7, metadata.size
  301     assert_equal 1, metadata['authorcount']
  302     assert_equal '李 四', metadata['author']
  303     assert_equal metadata['author'], metadata['authors']
  304     assert_equal '李', metadata['firstname']
  305     assert_equal '四', metadata['lastname']
  306     assert_equal 'si.li@example.com', metadata['email']
  307     assert_equal '李四', metadata['authorinitials']
  308   end
  309 
  310   test "parse author condenses whitespace" do
  311     metadata, _ = parse_header_metadata 'Stuart       Rackham     <founder@asciidoc.org>'
  312     assert_equal 7, metadata.size
  313     assert_equal 1, metadata['authorcount']
  314     assert_equal 'Stuart Rackham', metadata['author']
  315     assert_equal metadata['author'], metadata['authors']
  316     assert_equal 'Stuart', metadata['firstname']
  317     assert_equal 'Rackham', metadata['lastname']
  318     assert_equal 'founder@asciidoc.org', metadata['email']
  319     assert_equal 'SR', metadata['authorinitials']
  320   end
  321 
  322   test "parse invalid author line becomes author" do
  323     metadata, _ = parse_header_metadata '   Stuart       Rackham, founder of AsciiDoc   <founder@asciidoc.org>'
  324     assert_equal 5, metadata.size
  325     assert_equal 1, metadata['authorcount']
  326     assert_equal 'Stuart Rackham, founder of AsciiDoc <founder@asciidoc.org>', metadata['author']
  327     assert_equal metadata['author'], metadata['authors']
  328     assert_equal 'Stuart Rackham, founder of AsciiDoc <founder@asciidoc.org>', metadata['firstname']
  329     assert_equal 'S', metadata['authorinitials']
  330   end
  331 
  332   test 'parse multiple authors' do
  333     metadata, _ = parse_header_metadata 'Doc Writer <doc.writer@asciidoc.org>; John Smith <john.smith@asciidoc.org>'
  334     assert_equal 2, metadata['authorcount']
  335     assert_equal 'Doc Writer, John Smith', metadata['authors']
  336     assert_equal 'Doc Writer', metadata['author']
  337     assert_equal 'Doc Writer', metadata['author_1']
  338     assert_equal 'John Smith', metadata['author_2']
  339   end
  340 
  341   test 'should not parse multiple authors if semi-colon is not followed by space' do
  342     metadata, _ = parse_header_metadata 'Joe Doe;Smith Johnson'
  343     assert_equal 1, metadata['authorcount']
  344   end
  345 
  346   test 'skips blank author entries in implicit author line' do
  347     metadata, _ = parse_header_metadata 'Doc Writer; ; John Smith <john.smith@asciidoc.org>;'
  348     assert_equal 2, metadata['authorcount']
  349     assert_equal 'Doc Writer', metadata['author_1']
  350     assert_equal 'John Smith', metadata['author_2']
  351   end
  352 
  353   test 'parse name with more than 3 parts in author attribute' do
  354     doc = empty_document
  355     parse_header_metadata ':author: Leroy  Harold  Scherer,  Jr.', doc
  356     assert_equal 'Leroy Harold Scherer, Jr.', doc.attributes['author']
  357     assert_equal 'Leroy', doc.attributes['firstname']
  358     assert_equal 'Harold', doc.attributes['middlename']
  359     assert_equal 'Scherer, Jr.', doc.attributes['lastname']
  360   end
  361 
  362   test 'use explicit authorinitials if set after implicit author line' do
  363     input = <<~'EOS'
  364     Jean-Claude Van Damme
  365     :authorinitials: JCVD
  366     EOS
  367     doc = empty_document
  368     parse_header_metadata input, doc
  369     assert_equal 'JCVD', doc.attributes['authorinitials']
  370   end
  371 
  372   test 'use explicit authorinitials if set after author attribute' do
  373     input = <<~'EOS'
  374     :author: Jean-Claude Van Damme
  375     :authorinitials: JCVD
  376     EOS
  377     doc = empty_document
  378     parse_header_metadata input, doc
  379     assert_equal 'JCVD', doc.attributes['authorinitials']
  380   end
  381 
  382   test 'sets authorcount to 0 if document has no authors' do
  383     input = ''
  384     doc = empty_document
  385     metadata, _ = parse_header_metadata input, doc
  386     assert_equal 0, doc.attributes['authorcount']
  387     assert_equal 0, metadata['authorcount']
  388   end
  389 
  390   test 'does not drop name joiner when using multiple authors' do
  391     input = 'Kismet Chameleon; Lazarus het_Draeke'
  392     doc = empty_document
  393     parse_header_metadata input, doc
  394     assert_equal 2, doc.attributes['authorcount']
  395     assert_equal 'Kismet Chameleon, Lazarus het Draeke', doc.attributes['authors']
  396     assert_equal 'Kismet Chameleon', doc.attributes['author_1']
  397     assert_equal 'Lazarus het Draeke', doc.attributes['author_2']
  398     assert_equal 'het Draeke', doc.attributes['lastname_2']
  399   end
  400 
  401   test 'allows authors to be overridden using explicit author attributes' do
  402     input = <<~'EOS'
  403     Kismet Chameleon; Johnny Bravo; Lazarus het_Draeke
  404     :author_2: Danger Mouse
  405     EOS
  406     doc = empty_document
  407     parse_header_metadata input, doc
  408     assert_equal 3, doc.attributes['authorcount']
  409     assert_equal 'Kismet Chameleon, Danger Mouse, Lazarus het Draeke', doc.attributes['authors']
  410     assert_equal 'Kismet Chameleon', doc.attributes['author_1']
  411     assert_equal 'Danger Mouse', doc.attributes['author_2']
  412     assert_equal 'Lazarus het Draeke', doc.attributes['author_3']
  413     assert_equal 'het Draeke', doc.attributes['lastname_3']
  414   end
  415 
  416   test 'removes formatting before partitioning author defined using author attribute' do
  417     input = ':author: pass:n[http://example.org/community/team.html[Ze_**Project** team]]'
  418 
  419     doc = empty_document
  420     parse_header_metadata input, doc
  421     assert_equal 1, doc.attributes['authorcount']
  422     assert_equal '<a href="http://example.org/community/team.html">Ze <strong>Project</strong> team</a>', doc.attributes['authors']
  423     assert_equal 'Ze Project', doc.attributes['firstname']
  424     assert_equal 'team', doc.attributes['lastname']
  425   end
  426 
  427   test "parse rev number date remark" do
  428     input = <<~'EOS'
  429     Ryan Waldron
  430     v0.0.7, 2013-12-18: The first release you can stand on
  431     EOS
  432     metadata, _ = parse_header_metadata input
  433     assert_equal 9, metadata.size
  434     assert_equal '0.0.7', metadata['revnumber']
  435     assert_equal '2013-12-18', metadata['revdate']
  436     assert_equal 'The first release you can stand on', metadata['revremark']
  437   end
  438 
  439   test 'parse rev number, data, and remark as attribute references' do
  440     input = <<~'EOS'
  441     Author Name
  442     v{project-version}, {release-date}: {release-summary}
  443     EOS
  444     metadata, _ = parse_header_metadata input
  445     assert_equal 9, metadata.size
  446     assert_equal '{project-version}', metadata['revnumber']
  447     assert_equal '{release-date}', metadata['revdate']
  448     assert_equal '{release-summary}', metadata['revremark']
  449   end
  450 
  451   test 'should resolve attribute references in rev number, data, and remark' do
  452     input = <<~'EOS'
  453     = Document Title
  454     Author Name
  455     {project-version}, {release-date}: {release-summary}
  456     EOS
  457     doc = document_from_string input, attributes: {
  458       'project-version' => '1.0.1',
  459       'release-date' => '2018-05-15',
  460       'release-summary' => 'The one you can count on!',
  461     }
  462     assert_equal '1.0.1', (doc.attr 'revnumber')
  463     assert_equal '2018-05-15', (doc.attr 'revdate')
  464     assert_equal 'The one you can count on!', (doc.attr 'revremark')
  465   end
  466 
  467   test "parse rev date" do
  468     input = <<~'EOS'
  469     Ryan Waldron
  470     2013-12-18
  471     EOS
  472     metadata, _ = parse_header_metadata input
  473     assert_equal 7, metadata.size
  474     assert_equal '2013-12-18', metadata['revdate']
  475   end
  476 
  477   test 'parse rev number with trailing comma' do
  478     input = <<~'EOS'
  479     Stuart Rackham
  480     v8.6.8,
  481     EOS
  482     metadata, _ = parse_header_metadata input
  483     assert_equal 7, metadata.size
  484     assert_equal '8.6.8', metadata['revnumber']
  485     refute metadata.has_key?('revdate')
  486   end
  487 
  488   # Asciidoctor recognizes a standalone revision without a trailing comma
  489   test 'parse rev number' do
  490     input = <<~'EOS'
  491     Stuart Rackham
  492     v8.6.8
  493     EOS
  494     metadata, _ = parse_header_metadata input
  495     assert_equal 7, metadata.size
  496     assert_equal '8.6.8', metadata['revnumber']
  497     refute metadata.has_key?('revdate')
  498   end
  499 
  500   # while compliant w/ AsciiDoc, this is just sloppy parsing
  501   test "treats arbitrary text on rev line as revdate" do
  502     input = <<~'EOS'
  503     Ryan Waldron
  504     foobar
  505     EOS
  506     metadata, _ = parse_header_metadata input
  507     assert_equal 7, metadata.size
  508     assert_equal 'foobar', metadata['revdate']
  509   end
  510 
  511   test "parse rev date remark" do
  512     input = <<~'EOS'
  513     Ryan Waldron
  514     2013-12-18:  The first release you can stand on
  515     EOS
  516     metadata, _ = parse_header_metadata input
  517     assert_equal 8, metadata.size
  518     assert_equal '2013-12-18', metadata['revdate']
  519     assert_equal 'The first release you can stand on', metadata['revremark']
  520   end
  521 
  522   test "should not mistake attribute entry as rev remark" do
  523     input = <<~'EOS'
  524     Joe Cool
  525     :page-layout: post
  526     EOS
  527     metadata, _ = parse_header_metadata input
  528     refute_equal 'page-layout: post', metadata['revremark']
  529     refute metadata.has_key?('revdate')
  530   end
  531 
  532   test "parse rev remark only" do
  533     # NOTE cannot use single-quoted heredoc because of https://github.com/jruby/jruby/issues/4260
  534     input = <<~EOS
  535     Joe Cool
  536      :Must start revremark-only line with space
  537     EOS
  538     metadata, _ = parse_header_metadata input
  539     assert_equal 'Must start revremark-only line with space', metadata['revremark']
  540     refute metadata.has_key?('revdate')
  541   end
  542 
  543   test "skip line comments before author" do
  544     input = <<~'EOS'
  545     // Asciidoctor
  546     // release artist
  547     Ryan Waldron
  548     EOS
  549     metadata, _ = parse_header_metadata input
  550     assert_equal 6, metadata.size
  551     assert_equal 1, metadata['authorcount']
  552     assert_equal 'Ryan Waldron', metadata['author']
  553     assert_equal 'Ryan', metadata['firstname']
  554     assert_equal 'Waldron', metadata['lastname']
  555     assert_equal 'RW', metadata['authorinitials']
  556   end
  557 
  558   test "skip block comment before author" do
  559     input = <<~'EOS'
  560     ////
  561     Asciidoctor
  562     release artist
  563     ////
  564     Ryan Waldron
  565     EOS
  566     metadata, _ = parse_header_metadata input
  567     assert_equal 6, metadata.size
  568     assert_equal 1, metadata['authorcount']
  569     assert_equal 'Ryan Waldron', metadata['author']
  570     assert_equal 'Ryan', metadata['firstname']
  571     assert_equal 'Waldron', metadata['lastname']
  572     assert_equal 'RW', metadata['authorinitials']
  573   end
  574 
  575   test "skip block comment before rev" do
  576     input = <<~'EOS'
  577     Ryan Waldron
  578     ////
  579     Asciidoctor
  580     release info
  581     ////
  582     v0.0.7, 2013-12-18
  583     EOS
  584     metadata, _ = parse_header_metadata input
  585     assert_equal 8, metadata.size
  586     assert_equal 1, metadata['authorcount']
  587     assert_equal 'Ryan Waldron', metadata['author']
  588     assert_equal '0.0.7', metadata['revnumber']
  589     assert_equal '2013-12-18', metadata['revdate']
  590   end
  591 
  592   test 'break header at line with three forward slashes' do
  593     input = <<~'EOS'
  594     Joe Cool
  595     v1.0
  596     ///
  597     stuff
  598     EOS
  599     metadata, _ = parse_header_metadata input
  600     assert_equal 7, metadata.size
  601     assert_equal 1, metadata['authorcount']
  602     assert_equal 'Joe Cool', metadata['author']
  603     assert_equal '1.0', metadata['revnumber']
  604   end
  605 
  606   test 'attribute entry overrides generated author initials' do
  607     doc = empty_document
  608     metadata, _ = parse_header_metadata %(Stuart Rackham <founder@asciidoc.org>\n:Author Initials: SJR), doc
  609     assert_equal 'SR', metadata['authorinitials']
  610     assert_equal 'SJR', doc.attributes['authorinitials']
  611   end
  612 
  613   test 'adjust indentation to 0' do
  614     input = <<~EOS
  615     \x20   def names
  616 
  617     \x20     @name.split
  618 
  619     \x20   end
  620     EOS
  621 
  622     # NOTE cannot use single-quoted heredoc because of https://github.com/jruby/jruby/issues/4260
  623     expected = <<~EOS.chop
  624     def names
  625 
  626       @name.split
  627 
  628     end
  629     EOS
  630 
  631     lines = input.split ?\n
  632     Asciidoctor::Parser.adjust_indentation! lines
  633     assert_equal expected, (lines * ?\n)
  634   end
  635 
  636   test 'adjust indentation mixed with tabs and spaces to 0' do
  637     input = <<~EOS
  638         def names
  639 
  640     \t  @name.split
  641 
  642         end
  643     EOS
  644 
  645     expected = <<~EOS.chop
  646     def names
  647 
  648       @name.split
  649 
  650     end
  651     EOS
  652 
  653     lines = input.split ?\n
  654     Asciidoctor::Parser.adjust_indentation! lines, 0, 4
  655     assert_equal expected, (lines * ?\n)
  656   end
  657 
  658   test 'expands tabs to spaces' do
  659     input = <<~'EOS'
  660     Filesystem              Size    Used    Avail   Use%    Mounted on
  661     Filesystem              Size    Used    Avail   Use%    Mounted on
  662     devtmpfs                3.9G       0     3.9G     0%    /dev
  663     /dev/mapper/fedora-root  48G     18G      29G    39%    /
  664     EOS
  665 
  666     expected = <<~'EOS'.chop
  667     Filesystem              Size    Used    Avail   Use%    Mounted on
  668     Filesystem              Size    Used    Avail   Use%    Mounted on
  669     devtmpfs                3.9G       0     3.9G     0%    /dev
  670     /dev/mapper/fedora-root  48G     18G      29G    39%    /
  671     EOS
  672 
  673     lines = input.split ?\n
  674     Asciidoctor::Parser.adjust_indentation! lines, 0, 4
  675     assert_equal expected, (lines * ?\n)
  676   end
  677 
  678   test 'adjust indentation to non-zero' do
  679     input = <<~EOS
  680     \x20   def names
  681 
  682     \x20     @name.split
  683 
  684     \x20   end
  685     EOS
  686 
  687     expected = <<~EOS.chop
  688     \x20 def names
  689 
  690     \x20   @name.split
  691 
  692     \x20 end
  693     EOS
  694 
  695     lines = input.split ?\n
  696     Asciidoctor::Parser.adjust_indentation! lines, 2
  697     assert_equal expected, (lines * ?\n)
  698   end
  699 
  700   test 'preserve block indent if indent is -1' do
  701     input = <<~EOS
  702     \x20   def names
  703 
  704     \x20     @name.split
  705 
  706     \x20   end
  707     EOS
  708 
  709     expected = input
  710 
  711     lines = input.lines
  712     Asciidoctor::Parser.adjust_indentation! lines, -1
  713     assert_equal expected, lines.join
  714   end
  715 
  716   test 'adjust indentation handles empty lines gracefully' do
  717     input = []
  718     expected = input
  719 
  720     lines = input.dup
  721     Asciidoctor::Parser.adjust_indentation! lines
  722     assert_equal expected, lines
  723   end
  724 
  725   test 'should warn if inline anchor is already in use' do
  726     input = <<~'EOS'
  727     [#in-use]
  728     A paragraph with an id.
  729 
  730     Another paragraph
  731     [[in-use]]that uses an id
  732     which is already in use.
  733     EOS
  734 
  735     using_memory_logger do |logger|
  736       document_from_string input
  737       assert_message logger, :WARN, '<stdin>: line 5: id assigned to anchor already in use: in-use', Hash
  738     end
  739   end
  740 end