summaryrefslogtreecommitdiff
path: root/spec/index_spec.rb
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2022-05-04 15:18:06 -0600
committerGitHub <noreply@github.com>2022-05-04 15:18:06 -0600
commit734fa9bfef5feee080f9b07d0684e3f1ede528f8 (patch)
treed71cc344ca6cd8e19b5541e2e93cead15a7aa720 /spec/index_spec.rb
parent8b409328bb522581e8a74bc1f9d237b23bef5127 (diff)
resolves #1656 introduce index-pagenum-sequence-style document attribute to control style of sequential page numbers in index (PR #2130)
Diffstat (limited to 'spec/index_spec.rb')
-rw-r--r--spec/index_spec.rb104
1 files changed, 104 insertions, 0 deletions
diff --git a/spec/index_spec.rb b/spec/index_spec.rb
index 0e32fdf2..e12a32bd 100644
--- a/spec/index_spec.rb
+++ b/spec/index_spec.rb
@@ -456,6 +456,36 @@ describe 'Asciidoctor::PDF::Converter - Index' do
(expect monkey_term.dests.map {|it| it[:page] }).to eql %w(x xi c 1)
end
+ it 'should not combine deduplicate page numbers if same index entry occurs on the same page when media is screen' do
+ input = <<~'EOS'
+ = Document Title
+
+ == First Chapter
+
+ ((coming soon))
+
+ == Second Chapter
+
+ ((coming soon))
+
+ ((coming soon)), no really
+
+ == Third Chapter
+
+ ((coming soon)) means ((coming soon))
+
+ [index]
+ == Index
+ EOS
+
+ pdf = to_pdf input, doctype: :book, analyze: true
+ (expect (pdf.lines pdf.find_text page_number: 5).join ?\n).to include 'coming soon, 1, 2, 2, 3, 3'
+ pdf = to_pdf input, doctype: :book
+ annots = get_annotations pdf, 5
+ (expect annots).to have_size 5
+ (expect annots.uniq {|it| it[:Dest] }).to have_size 5
+ end
+
it 'should not combine range if same index entry occurs on sequential pages when media is screen' do
pdf = to_pdf <<~'EOS', doctype: :book, analyze: true
= Document Title
@@ -479,6 +509,80 @@ describe 'Asciidoctor::PDF::Converter - Index' do
(expect (pdf.lines pdf.find_text page_number: 5).join ?\n).to include 'coming soon, 1, 2, 3'
end
+ it 'should remove duplicate sequential pages and link to first occurrence when index-pagenum-sequence-style is page' do
+ input = <<~'EOS'
+ = Document Title
+ :doctype: book
+ :index-pagenum-sequence-style: page
+
+ == First Chapter
+
+ ((coming soon)) ((almost here))
+
+ ((coming soon)), really
+
+ == Second Chapter
+
+ ((coming soon)) ((in draft))
+
+ I promise, ((coming soon))
+
+ == Third Chapter
+
+ ((coming soon)) ((almost here))
+
+ [index]
+ == Index
+ EOS
+
+ pdf = to_pdf input, analyze: true
+ index_lines = pdf.lines pdf.find_text page_number: 5
+ (expect index_lines).to include 'coming soon, 1, 2, 3'
+ (expect index_lines).to include 'in draft, 2'
+ (expect index_lines).to include 'almost here, 1, 3'
+ pdf = to_pdf input
+ annots = get_annotations pdf, 5
+ (expect annots).to have_size 6
+ [[2, 2], [3, 3], [4, 4]].each do |idx, expected_pagenum|
+ dest = get_dest pdf, annots[idx][:Dest]
+ (expect dest[:page_number]).to eql expected_pagenum
+ end
+ end
+
+ it 'should combine range if same index entry occurs on sequential pages when index-pagenum-sequence-style is range' do
+ input = <<~'EOS'
+ = Document Title
+ :doctype: book
+ :index-pagenum-sequence-style: range
+
+ == First Chapter
+
+ ((coming soon)) ((almost here))
+
+ == Second Chapter
+
+ ((coming soon)) ((in draft))
+
+ == Third Chapter
+
+ ((coming soon)) ((almost here))
+
+ [index]
+ == Index
+ EOS
+
+ pdf = to_pdf input, analyze: true
+ index_lines = pdf.lines pdf.find_text page_number: 5
+ (expect index_lines).to include 'coming soon, 1-3'
+ (expect index_lines).to include 'in draft, 2'
+ (expect index_lines).to include 'almost here, 1, 3'
+ pdf = to_pdf input
+ annots = get_annotations pdf, 5
+ (expect annots).to have_size 4
+ coming_soon_dest = get_dest pdf, annots[2][:Dest]
+ (expect coming_soon_dest[:page_number]).to eql 2
+ end
+
it 'should combine range if same index entry occurs on sequential pages when media is not screen' do
pdf = to_pdf <<~'EOS', doctype: :book, attribute_overrides: { 'media' => 'print' }, analyze: true
= Document Title