1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
# frozen_string_literal: true
require_relative 'spec_helper'
describe 'Asciidoctor::PDF::Converter - Manpage' do
it 'should generate name section automatically' do
pdf = to_pdf <<~'EOS', doctype: :manpage, analyze: true
= cmd(1)
Author Name
v1.0.0
:manmanual: CMD
:mansource: CMD
== Name
cmd - does stuff
== Synopsis
*cmd* [_OPTION_]... _FILE_...
== Options
*-v*:: Prints the version.
EOS
expected_name_title = 'Name'
name_title_text = (pdf.find_text expected_name_title)[0]
(expect name_title_text).not_to be_nil
(expect name_title_text[:font_size]).to be 22
name_body_text = (pdf.find_text 'cmd - does stuff')[0]
(expect name_body_text).not_to be_nil
(expect name_body_text[:font_size]).to eql 10.5
(expect (pdf.find_text font_size: 22).map {|it| it[:string] }).to eql [expected_name_title, 'Synopsis', 'Options']
end
it 'should apply normal substitutions to manname section' do
pdf = to_pdf <<~'EOS', doctype: :manpage, analyze: true
= cmd(1)
== Name
cmd - does *lots* of stuff
== Synopsis
*cmd* [_OPTION_]... _FILE_...
EOS
lots_text = (pdf.find_text 'lots')[0]
(expect lots_text).not_to be_nil
(expect lots_text[:font_name]).to eql 'NotoSerif-Bold'
end
it 'should uppercase title of auto-generated name section if other sections are uppercase' do
pdf = to_pdf <<~'EOS', doctype: :manpage, analyze: true
= cmd(1)
Author Name
v1.0.0
:manmanual: CMD
:mansource: CMD
:manname: cmd
:manpurpose: does stuff
== SYNOPSIS
*cmd* [_OPTION_]... _FILE_...
== OPTIONS
*-v*:: Prints the version.
EOS
name_title_text = pdf.find_unique_text 'NAME'
(expect name_title_text).not_to be_nil
(expect name_title_text[:font_size]).to be 22
(expect pdf.lines).to include 'cmd - does stuff'
end
it 'should not uppercase title of auto-generated name section if no other sections are found' do
pdf = to_pdf <<~'EOS', doctype: :manpage, analyze: true
= cmd(1)
Author Name
v1.0.0
:manmanual: CMD
:mansource: CMD
:manname: cmd
:manpurpose: does stuff
EOS
name_title_text = pdf.find_unique_text 'Name'
(expect name_title_text).not_to be_nil
(expect name_title_text[:font_size]).to be 22
(expect pdf.lines).to include 'cmd - does stuff'
end
it 'should arrange body of manpage into columns if specified in theme' do
pdf = to_pdf <<~'EOS', doctype: :manpage, pdf_theme: { page_columns: 2 }, analyze: true
= cmd(1)
== Name
cmd - does stuff
== Synopsis
*cmd* [_OPTION_]... _FILE_...
[.column]
<<<
== Options
*-v*:: Prints the version.
EOS
midpoint = (get_page_size pdf)[0] * 0.5
name_text = pdf.find_unique_text 'Name'
options_text = pdf.find_unique_text 'Options'
(expect name_text[:x]).to eql 48.24
(expect options_text[:x]).to be > midpoint
(expect name_text[:y]).to eql options_text[:y]
end
end
|