diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2018-04-15 19:48:22 -0600 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2018-04-18 22:49:20 -0600 |
| commit | 00acebbb4a2ff30516ae71a063d563d6c86ccf4f (patch) | |
| tree | 754d4fc46ceca7d1547f1f5e1b335c0911a766d2 /test | |
| parent | 26af4f9a848303686bf0306f540a73577e997ba3 (diff) | |
resolves #2433 warn if nested sections are used where not allowed
- only allow nested sections in appendix, preface, and abstract sections
- add tests to verify warning
- fix tests that use nested sections in sections that don't support them
Diffstat (limited to 'test')
| -rw-r--r-- | test/sections_test.rb | 179 |
1 files changed, 155 insertions, 24 deletions
diff --git a/test/sections_test.rb b/test/sections_test.rb index 05120d69..180188d3 100644 --- a/test/sections_test.rb +++ b/test/sections_test.rb @@ -578,6 +578,123 @@ content end end + context 'Nesting' do + test 'should log error if subsections are found in special sections in article that do not support subsections' do + input = <<-EOS += Document Title + +== Section + +=== Subsection of Section + +allowed + +[appendix] +== Appendix + +=== Subsection of Appendix + +allowed + +[glossary] +== Glossary + +=== Subsection of Glossary + +not allowed + +[bibliography] +== Bibliography + +=== Subsection of Bibliography + +not allowed + EOS + + using_memory_logger do |logger| + render_embedded_string input + assert_messages logger, [ + [:ERROR, '<stdin>: line 19: glossary sections do not support nested sections', Hash], + [:ERROR, '<stdin>: line 26: bibliography sections do not support nested sections', Hash], + ] + end + end + + test 'should log error if subsections are found in special sections in book that do not support subsections' do + input = <<-EOS += Document Title +:doctype: book + +[preface] += Preface + +=== Subsection of Preface + +allowed + +[colophon] += Colophon + +=== Subsection of Colophon + +not allowed + +[dedication] += Dedication + +=== Subsection of Dedication + +not allowed + += Part 1 + +[abstract] +== Abstract + +=== Subsection of Abstract + +allowed + +== Chapter 1 + +=== Subsection of Chapter + +allowed + +[appendix] += Appendix + +=== Subsection of Appendix + +allowed + +[glossary] += Glossary + +=== Subsection of Glossary + +not allowed + +[bibliography] += Bibliography + +=== Subsection of Bibliography + +not allowed + EOS + + using_memory_logger do |logger| + render_embedded_string input + assert_messages logger, [ + [:ERROR, '<stdin>: line 14: colophon sections do not support nested sections', Hash], + [:ERROR, '<stdin>: line 21: dedication sections do not support nested sections', Hash], + [:ERROR, '<stdin>: line 50: glossary sections do not support nested sections', Hash], + [:ERROR, '<stdin>: line 57: bibliography sections do not support nested sections', Hash] + ] + end + end + end + context 'Markdown-style headings' do test 'atx document title with leading marker' do input = <<-EOS @@ -1707,17 +1824,20 @@ Terms test 'should not number special sections or their subsections by default except for appendices' do input = <<-EOS +:doctype: book :sectnums: -[dedication] -== Dedication +[preface] +== Preface -=== Dedication Subsection +=== Preface Subsection content == Section One +content + [appendix] == Attribute Options @@ -1739,8 +1859,8 @@ Terms EOS output = render_embedded_string input - assert_xpath '(//h2)[1][text()="Dedication"]', output, 1 - assert_xpath '(//h3)[1][text()="Dedication Subsection"]', output, 1 + assert_xpath '(//h2)[1][text()="Preface"]', output, 1 + assert_xpath '(//h3)[1][text()="Preface Subsection"]', output, 1 assert_xpath '(//h2)[2][text()="1. Section One"]', output, 1 assert_xpath '(//h2)[3][text()="Appendix A: Attribute Options"]', output, 1 assert_xpath '(//h2)[4][text()="Appendix B: Migration"]', output, 1 @@ -1750,18 +1870,21 @@ Terms test 'should not number special sections or their subsections in toc by default except for appendices' do input = <<-EOS +:doctype: book :sectnums: :toc: -[dedication] -== Dedication +[preface] +== Preface -=== Dedication Subsection +=== Preface Subsection content == Section One +content + [appendix] == Attribute Options @@ -1783,8 +1906,8 @@ Terms EOS output = render_string input - assert_xpath '//*[@id="toc"]/ul//li/a[text()="Dedication"]', output, 1 - assert_xpath '//*[@id="toc"]/ul//li/a[text()="Dedication Subsection"]', output, 1 + assert_xpath '//*[@id="toc"]/ul//li/a[text()="Preface"]', output, 1 + assert_xpath '//*[@id="toc"]/ul//li/a[text()="Preface Subsection"]', output, 1 assert_xpath '//*[@id="toc"]/ul//li/a[text()="1. Section One"]', output, 1 assert_xpath '//*[@id="toc"]/ul//li/a[text()="Appendix A: Attribute Options"]', output, 1 assert_xpath '//*[@id="toc"]/ul//li/a[text()="Appendix B: Migration"]', output, 1 @@ -1794,17 +1917,20 @@ Terms test 'should number special sections and their subsections when sectnums is all' do input = <<-EOS +:doctype: book :sectnums: all -[dedication] -== Dedication +[preface] +== Preface -=== Dedication Subsection +=== Preface Subsection content == Section One +content + [appendix] == Attribute Options @@ -1826,29 +1952,33 @@ Terms EOS output = render_embedded_string input - assert_xpath '(//h2)[1][text()="1. Dedication"]', output, 1 - assert_xpath '(//h3)[1][text()="1.1. Dedication Subsection"]', output, 1 - assert_xpath '(//h2)[2][text()="2. Section One"]', output, 1 + # FIXME numbering is borked + assert_xpath '(//h2)[1][text()="1. Preface"]', output, 1 + assert_xpath '(//h3)[1][text()="1.1. Preface Subsection"]', output, 1 + assert_xpath '(//h2)[2][text()="1. Section One"]', output, 1 assert_xpath '(//h2)[3][text()="Appendix A: Attribute Options"]', output, 1 assert_xpath '(//h2)[4][text()="Appendix B: Migration"]', output, 1 assert_xpath '(//h3)[2][text()="B.1. Gotchas"]', output, 1 - assert_xpath '(//h2)[5][text()="3. Glossary"]', output, 1 + assert_xpath '(//h2)[5][text()="2. Glossary"]', output, 1 end test 'should number special sections and their subsections in toc when sectnums is all' do input = <<-EOS +:doctype: book :sectnums: all :toc: -[dedication] -== Dedication +[preface] +== Preface -=== Dedication Subsection +=== Preface Subsection content == Section One +contennt + [appendix] == Attribute Options @@ -1870,13 +2000,14 @@ Terms EOS output = render_string input - assert_xpath '//*[@id="toc"]/ul//li/a[text()="1. Dedication"]', output, 1 - assert_xpath '//*[@id="toc"]/ul//li/a[text()="1.1. Dedication Subsection"]', output, 1 - assert_xpath '//*[@id="toc"]/ul//li/a[text()="2. Section One"]', output, 1 + # FIXME numbering is borked + assert_xpath '//*[@id="toc"]/ul//li/a[text()="1. Preface"]', output, 1 + assert_xpath '//*[@id="toc"]/ul//li/a[text()="1.1. Preface Subsection"]', output, 1 + assert_xpath '//*[@id="toc"]/ul//li/a[text()="1. Section One"]', output, 1 assert_xpath '//*[@id="toc"]/ul//li/a[text()="Appendix A: Attribute Options"]', output, 1 assert_xpath '//*[@id="toc"]/ul//li/a[text()="Appendix B: Migration"]', output, 1 assert_xpath '//*[@id="toc"]/ul//li/a[text()="B.1. Gotchas"]', output, 1 - assert_xpath '//*[@id="toc"]/ul//li/a[text()="3. Glossary"]', output, 1 + assert_xpath '//*[@id="toc"]/ul//li/a[text()="2. Glossary"]', output, 1 end test 'level 0 special sections in multipart book should be rendered as level 1' do |
