require 'test_helper' require 'review/webtocprinter' require 'book_test_helper' class WEBTOCPrinterTest < Test::Unit::TestCase include ReVIEW include BookTestHelper def setup I18n.setup end def test_webtocprinter_null dummy_book = ReVIEW::Book::Base.new # chap = ReVIEW::Book::Chapter.new(dummy_book, 1, '-', nil, StringIO.new) str = WEBTOCPrinter.book_to_string(dummy_book) expect = <<-EOB
EOB assert_equal expect, str end def test_webtocprinter_with_chapters catalog_yml = <<-EOB CHAPS: - ch1.re - ch2.re EOB mktmpbookdir('catalog.yml' => catalog_yml, 'ch1.re' => "= ch. 1\n\n111\n", 'ch2.re' => "= ch. 2\n\n222\n") do |_dir, book, _files| str = WEBTOCPrinter.book_to_string(book) expect = <<-EOB EOB assert_equal expect, str end end def test_webtocprinter_with_parts catalog_yml = <<-EOB CHAPS: - part1: - ch1.re - part2: - ch2.re EOB mktmpbookdir('catalog.yml' => catalog_yml, 'ch1.re' => "= ch. 1\n\n111\n", 'ch2.re' => "= ch. 2\n\n222\n") do |_dir, book, _files| str = WEBTOCPrinter.book_to_string(book) expect = <<-EOB EOB assert_equal expect, str end end def test_webtocprinter_with_partfiles catalog_yml = <<-EOB CHAPS: - p1.re: - ch1.re - p2.re: - ch2.re EOB mktmpbookdir('catalog.yml' => catalog_yml, 'p1.re' => "= This is PART1\n\np111\n", 'p2.re' => "= This is PART2\n\np111\n", 'ch1.re' => "= ch. 1\n\n111\n", 'ch2.re' => "= ch. 2\n\n222\n") do |_dir, book, _files| str = WEBTOCPrinter.book_to_string(book) expect = <<-EOB EOB assert_equal expect, str end end def test_webtocprinter_full catalog_yml = <<-EOB PREDEF: - pre1.re - pre2.re CHAPS: - part1.re: - ch1.re - part2.re: - ch2.re APPENDIX: - app1.re - app2.re POSTDEF: - post1.re - post2.re EOB mktmpbookdir('catalog.yml' => catalog_yml, 'pre1.re' => "= PRE1\n\npre111\n", 'pre2.re' => "= PRE2\n\npre222\n", 'app1.re' => "= APP1\n\napp111\n", 'app2.re' => "= APP2\n\napp222\n", 'part1.re' => "= PART1\n\np111\n", 'part2.re' => "= PART2\n\np111\n", 'post1.re' => "= POST1\n\npo111\n", 'post2.re' => "= POST2\n\npo222\n", 'ch1.re' => "= ch. 1\n\n111\n", 'ch2.re' => "= ch. 2\n\n222\n") do |_dir, book, _files| str = WEBTOCPrinter.book_to_string(book) expect = <<-EOB EOB assert_equal expect, str end end def test_webtocprinter_nochapter catalog_yml = <<-EOB CHAPS: EOB mktmpbookdir('catalog.yml' => catalog_yml) do |_dir, book, _files| str = WEBTOCPrinter.book_to_string(book) expect = <<-EOB EOB assert_equal expect, str end end def test_webtocprinter_noheadline catalog_yml = <<-EOB CHAPS: - ch1.re - ch2.re - ch3.re - ch4.re EOB mktmpbookdir('catalog.yml' => catalog_yml, 'ch1.re' => "A\n", 'ch2.re' => "B\n\n= C\n== D\n", 'ch3.re' => "//emlist{\nLIST\n//}\n", 'ch4.re' => "==[column] E\n\n= F") do |_dir, book, _files| str = WEBTOCPrinter.book_to_string(book) expect = <<-EOB EOB assert_equal expect, str end end end