"Fossies" - the Fresh Open Source Software Archive

Member "asciidoctor-2.0.10/test/attribute_list_test.rb" (1 Jun 2019, 8504 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 'AttributeList' do
    5   test 'collect unnamed attribute' do
    6     attributes = {}
    7     line = 'quote'
    8     expected = { 1 => 'quote' }
    9     Asciidoctor::AttributeList.new(line).parse_into(attributes)
   10     assert_equal expected, attributes
   11   end
   12 
   13   test 'collect unnamed attribute double-quoted' do
   14     attributes = {}
   15     line = '"quote"'
   16     expected = { 1 => 'quote' }
   17     Asciidoctor::AttributeList.new(line).parse_into(attributes)
   18     assert_equal expected, attributes
   19   end
   20 
   21   test 'collect empty unnamed attribute double-quoted' do
   22     attributes = {}
   23     line = '""'
   24     expected = { 1 => '' }
   25     Asciidoctor::AttributeList.new(line).parse_into(attributes)
   26     assert_equal expected, attributes
   27   end
   28 
   29   test 'collect unnamed attribute double-quoted containing escaped quote' do
   30     attributes = {}
   31     line = '"ba\"zaar"'
   32     expected = { 1 => 'ba"zaar' }
   33     Asciidoctor::AttributeList.new(line).parse_into(attributes)
   34     assert_equal expected, attributes
   35   end
   36 
   37   test 'collect unnamed attribute single-quoted' do
   38     attributes = {}
   39     line = '\'quote\''
   40     expected = { 1 => 'quote' }
   41     Asciidoctor::AttributeList.new(line).parse_into(attributes)
   42     assert_equal expected, attributes
   43   end
   44 
   45   test 'collect empty unnamed attribute single-quoted' do
   46     attributes = {}
   47     line = '\'\''
   48     expected = { 1 => '' }
   49     Asciidoctor::AttributeList.new(line).parse_into(attributes)
   50     assert_equal expected, attributes
   51   end
   52 
   53   test 'collect isolated single quote positional attribute' do
   54     attributes = {}
   55     line = '\''
   56     expected = { 1 => '\'' }
   57     doc = empty_document
   58     def doc.apply_subs *args
   59       fail 'apply_subs should not be called'
   60     end
   61     Asciidoctor::AttributeList.new(line, doc).parse_into(attributes)
   62     assert_equal expected, attributes
   63   end
   64 
   65   test 'collect isolated single quote attribute value' do
   66     attributes = {}
   67     line = 'name=\''
   68     expected = { 'name' => '\'' }
   69     doc = empty_document
   70     def doc.apply_subs *args
   71       fail 'apply_subs should not be called'
   72     end
   73     Asciidoctor::AttributeList.new(line, doc).parse_into(attributes)
   74     assert_equal expected, attributes
   75   end
   76 
   77   test 'collect attribute value as is if it has only leading single quote' do
   78     attributes = {}
   79     line = 'name=\'{val}'
   80     expected = { 'name' => '\'{val}' }
   81     doc = empty_document attributes: { 'val' => 'val' }
   82     def doc.apply_subs *args
   83       fail 'apply_subs should not be called'
   84     end
   85     Asciidoctor::AttributeList.new(line, doc).parse_into(attributes)
   86     assert_equal expected, attributes
   87   end
   88 
   89   test 'collect unnamed attribute single-quoted containing escaped quote' do
   90     attributes = {}
   91     line = '\'ba\\\'zaar\''
   92     expected = { 1 => 'ba\'zaar' }
   93     Asciidoctor::AttributeList.new(line).parse_into(attributes)
   94     assert_equal expected, attributes
   95   end
   96 
   97   test 'collect unnamed attribute with dangling delimiter' do
   98     attributes = {}
   99     line = 'quote , '
  100     expected = { 1 => 'quote' }
  101     Asciidoctor::AttributeList.new(line).parse_into(attributes)
  102     assert_equal expected, attributes
  103   end
  104 
  105   test 'collect unnamed attribute in second position after empty attribute' do
  106     attributes = {}
  107     line = ', John Smith'
  108     expected = { 1 => nil, 2 => 'John Smith' }
  109     Asciidoctor::AttributeList.new(line).parse_into(attributes)
  110     assert_equal expected, attributes
  111   end
  112 
  113   test 'collect unnamed attributes' do
  114     attributes = {}
  115     line = 'first, second one, third'
  116     expected = { 1 => 'first', 2 => 'second one', 3 => 'third' }
  117     Asciidoctor::AttributeList.new(line).parse_into(attributes)
  118     assert_equal expected, attributes
  119   end
  120 
  121   test 'collect named attribute' do
  122     attributes = {}
  123     line = 'foo=bar'
  124     expected = { 'foo' => 'bar' }
  125     Asciidoctor::AttributeList.new(line).parse_into(attributes)
  126     assert_equal expected, attributes
  127   end
  128 
  129   test 'collect named attribute double-quoted' do
  130     attributes = {}
  131     line = 'foo="bar"'
  132     expected = { 'foo' => 'bar' }
  133     Asciidoctor::AttributeList.new(line).parse_into(attributes)
  134     assert_equal expected, attributes
  135   end
  136 
  137   test 'collect named attribute with double-quoted empty value' do
  138     attributes = {}
  139     line = 'height=100,caption="",link="images/octocat.png"'
  140     expected = { 'height' => '100', 'caption' => '', 'link' => 'images/octocat.png' }
  141     Asciidoctor::AttributeList.new(line).parse_into(attributes)
  142     assert_equal expected, attributes
  143   end
  144 
  145   test 'collect named attribute single-quoted' do
  146     attributes = {}
  147     line = 'foo=\'bar\''
  148     expected = { 'foo' => 'bar' }
  149     Asciidoctor::AttributeList.new(line).parse_into(attributes)
  150     assert_equal expected, attributes
  151   end
  152 
  153   test 'collect named attribute with single-quoted empty value' do
  154     attributes = {}
  155     line = %(height=100,caption='',link='images/octocat.png')
  156     expected = { 'height' => '100', 'caption' => '', 'link' => 'images/octocat.png' }
  157     Asciidoctor::AttributeList.new(line).parse_into(attributes)
  158     assert_equal expected, attributes
  159   end
  160 
  161   test 'collect single named attribute with empty value' do
  162     attributes = {}
  163     line = 'foo='
  164     expected = { 'foo' => '' }
  165     Asciidoctor::AttributeList.new(line).parse_into(attributes)
  166     assert_equal expected, attributes
  167   end
  168 
  169   test 'collect single named attribute with empty value when followed by other attributes' do
  170     attributes = {}
  171     line = 'foo=,bar=baz'
  172     expected = { 'foo' => '', 'bar' => 'baz' }
  173     Asciidoctor::AttributeList.new(line).parse_into(attributes)
  174     assert_equal expected, attributes
  175   end
  176 
  177   test 'collect named attributes unquoted' do
  178     attributes = {}
  179     line = 'first=value, second=two, third=3'
  180     expected = { 'first' => 'value', 'second' => 'two', 'third' => '3' }
  181     Asciidoctor::AttributeList.new(line).parse_into(attributes)
  182     assert_equal expected, attributes
  183   end
  184 
  185   test 'collect named attributes quoted' do
  186     attributes = {}
  187     line = %(first='value', second="value two", third=three)
  188     expected = { 'first' => 'value', 'second' => 'value two', 'third' => 'three' }
  189     Asciidoctor::AttributeList.new(line).parse_into(attributes)
  190     assert_equal expected, attributes
  191   end
  192 
  193   test 'collect named attributes quoted containing non-semantic spaces' do
  194     attributes = {}
  195     line = %(     first    =     'value', second     ="value two"     , third=       three      )
  196     expected = { 'first' => 'value', 'second' => 'value two', 'third' => 'three' }
  197     Asciidoctor::AttributeList.new(line).parse_into(attributes)
  198     assert_equal expected, attributes
  199   end
  200 
  201   test 'collect mixed named and unnamed attributes' do
  202     attributes = {}
  203     line = %(first, second="value two", third=three, Sherlock Holmes)
  204     expected = { 1 => 'first', 'second' => 'value two', 'third' => 'three', 4 => 'Sherlock Holmes' }
  205     Asciidoctor::AttributeList.new(line).parse_into(attributes)
  206     assert_equal expected, attributes
  207   end
  208 
  209   test 'collect options attribute' do
  210     attributes = {}
  211     line = %(quote, options='opt1,,opt2 , opt3')
  212     expected = { 1 => 'quote', 'opt1-option' => '', 'opt2-option' => '', 'opt3-option' => '' }
  213     Asciidoctor::AttributeList.new(line).parse_into(attributes)
  214     assert_equal expected, attributes
  215   end
  216 
  217   test 'collect opts attribute as options' do
  218     attributes = {}
  219     line = %(quote, opts='opt1,,opt2 , opt3')
  220     expected = { 1 => 'quote', 'opt1-option' => '', 'opt2-option' => '', 'opt3-option' => '' }
  221     Asciidoctor::AttributeList.new(line).parse_into(attributes)
  222     assert_equal expected, attributes
  223   end
  224 
  225   test 'should ignore options attribute if empty' do
  226     attributes = {}
  227     line = %(quote, opts=)
  228     expected = { 1 => 'quote' }
  229     Asciidoctor::AttributeList.new(line).parse_into(attributes)
  230     assert_equal expected, attributes
  231   end
  232 
  233   test 'collect and rekey unnamed attributes' do
  234     attributes = {}
  235     line = 'first, second one, third, fourth'
  236     expected = { 1 => 'first', 2 => 'second one', 3 => 'third', 4 => 'fourth', 'a' => 'first', 'b' => 'second one', 'c' => 'third' }
  237     Asciidoctor::AttributeList.new(line).parse_into(attributes, ['a', 'b', 'c'])
  238     assert_equal expected, attributes
  239   end
  240 
  241   test 'rekey positional attributes' do
  242     attributes = { 1 => 'source', 2 => 'java' }
  243     expected = { 1 => 'source', 2 => 'java', 'style' => 'source', 'language' => 'java' }
  244     Asciidoctor::AttributeList.rekey(attributes, ['style', 'language', 'linenums'])
  245     assert_equal expected, attributes
  246   end
  247 end