"Fossies" - the Fresh Open Source Software Archive

Member "asciidoctor-2.0.10/test/preamble_test.rb" (1 Jun 2019, 4094 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 'Preamble' do
    5   test 'title and single paragraph preamble before section' do
    6     input = <<~'EOS'
    7     = Title
    8 
    9     Preamble paragraph 1.
   10 
   11     == First Section
   12 
   13     Section paragraph 1.
   14     EOS
   15     result = convert_string(input)
   16     assert_xpath '//p', result, 2
   17     assert_xpath '//*[@id="preamble"]', result, 1
   18     assert_xpath '//*[@id="preamble"]//p', result, 1
   19     assert_xpath '//*[@id="preamble"]/following-sibling::*//h2[@id="_first_section"]', result, 1
   20     assert_xpath '//*[@id="preamble"]/following-sibling::*//p', result, 1
   21   end
   22 
   23   test 'title of preface is blank by default in DocBook output' do
   24     input = <<~'EOS'
   25     = Document Title
   26     :doctype: book
   27 
   28     Preface content.
   29 
   30     == First Section
   31 
   32     Section content.
   33     EOS
   34     result = convert_string input, backend: :docbook
   35     assert_xpath '//preface/title', result, 1
   36     title_node = xmlnodes_at_xpath '//preface/title', result, 1
   37     assert_equal '', title_node.text
   38   end
   39 
   40   test 'preface-title attribute is assigned as title of preface in DocBook output' do
   41     input = <<~'EOS'
   42     = Document Title
   43     :doctype: book
   44     :preface-title: Preface
   45 
   46     Preface content.
   47 
   48     == First Section
   49 
   50     Section content.
   51     EOS
   52     result = convert_string input, backend: :docbook
   53     assert_xpath '//preface/title[text()="Preface"]', result, 1
   54   end
   55 
   56   test 'title and multi-paragraph preamble before section' do
   57     input = <<~'EOS'
   58     = Title
   59 
   60     Preamble paragraph 1.
   61 
   62     Preamble paragraph 2.
   63 
   64     == First Section
   65 
   66     Section paragraph 1.
   67     EOS
   68     result = convert_string(input)
   69     assert_xpath '//p', result, 3
   70     assert_xpath '//*[@id="preamble"]', result, 1
   71     assert_xpath '//*[@id="preamble"]//p', result, 2
   72     assert_xpath '//*[@id="preamble"]/following-sibling::*//h2[@id="_first_section"]', result, 1
   73     assert_xpath '//*[@id="preamble"]/following-sibling::*//p', result, 1
   74   end
   75 
   76   test 'should not wrap content in preamble if document has title but no sections' do
   77     input = <<~'EOS'
   78     = Title
   79 
   80     paragraph
   81     EOS
   82     result = convert_string(input)
   83     assert_xpath '//p', result, 1
   84     assert_xpath '//*[@id="content"]/*[@class="paragraph"]/p', result, 1
   85     assert_xpath '//*[@id="content"]/*[@class="paragraph"]/following-sibling::*', result, 0
   86   end
   87 
   88   test 'title and section without preamble' do
   89     input = <<~'EOS'
   90     = Title
   91 
   92     == First Section
   93 
   94     Section paragraph 1.
   95     EOS
   96     result = convert_string(input)
   97     assert_xpath '//p', result, 1
   98     assert_xpath '//*[@id="preamble"]', result, 0
   99     assert_xpath '//h2[@id="_first_section"]', result, 1
  100   end
  101 
  102   test 'no title with preamble and section' do
  103     input = <<~'EOS'
  104     Preamble paragraph 1.
  105 
  106     == First Section
  107 
  108     Section paragraph 1.
  109     EOS
  110     result = convert_string(input)
  111     assert_xpath '//p', result, 2
  112     assert_xpath '//*[@id="preamble"]', result, 0
  113     assert_xpath '//h2[@id="_first_section"]/preceding::p', result, 1
  114   end
  115 
  116   test 'preamble in book doctype' do
  117       input = <<~'EOS'
  118       = Book
  119       :doctype: book
  120 
  121       Back then...
  122 
  123       = Chapter One
  124 
  125       [partintro]
  126       It was a dark and stormy night...
  127 
  128       == Scene One
  129 
  130       Someone's gonna get axed.
  131 
  132       = Chapter Two
  133 
  134       [partintro]
  135       They couldn't believe their eyes when...
  136 
  137       == Scene One
  138 
  139       The axe came swinging.
  140       EOS
  141 
  142       d = document_from_string(input)
  143       assert_equal 'book', d.doctype
  144       output = d.convert
  145       assert_xpath '//h1', output, 3
  146       assert_xpath %{//*[@id="preamble"]//p[text() = "Back then#{decode_char 8230}#{decode_char 8203}"]}, output, 1
  147   end
  148 
  149   test 'should output table of contents in preamble if toc-placement attribute value is preamble' do
  150     input = <<~'EOS'
  151     = Article
  152     :toc:
  153     :toc-placement: preamble
  154 
  155     Once upon a time...
  156 
  157     == Section One
  158 
  159     It was a dark and stormy night...
  160 
  161     == Section Two
  162 
  163     They couldn't believe their eyes when...
  164     EOS
  165 
  166     output = convert_string input
  167     assert_xpath '//*[@id="preamble"]/*[@id="toc"]', output, 1
  168   end
  169 end