require 'test_helper' require 'book_test_helper' require 'review' class HTMLBuidlerTest < Test::Unit::TestCase include ReVIEW include BookTestHelper def setup ReVIEW::I18n.setup @config = ReVIEW::Configure.values @config['secnolevel'] = 2 @config['stylesheet'] = nil @config['htmlext'] = 'html' @config['epubmaker'] = {} @book = Book::Base.new('.') @book.config = @config img_math = ReVIEW::ImgMath.new(@config) @log_io = StringIO.new ReVIEW.logger = ReVIEW::Logger.new(@log_io) @builder = HTMLBuilder.new(img_math: img_math) @compiler = ReVIEW::Compiler.new(@builder) @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new) location = Location.new(nil, nil) @builder.bind(@compiler, @chapter, location) I18n.setup('ja') @skip_pygments = true # temporary suppress pygments test end def test_xmlns_ops_prefix_epub3 assert_equal 'epub', @builder.xmlns_ops_prefix end def test_xmlns_ops_prefix_epub2 @book.config['epubversion'] = 2 assert_equal 'ops', @builder.xmlns_ops_prefix end def test_headline_level1 actual = compile_block("={test} this is test.\n") assert_equal %Q(

第1章 this is test.

\n), actual end def test_headline_level1_postdef @chapter.instance_eval do def on_appendix? true end end actual = compile_block("={test} this is test.\n") assert_equal %Q(

付録A this is test.

\n), actual end def test_headline_level2_postdef @chapter.instance_eval do def on_appendix? true end end actual = compile_block("=={test} this is test.\n") assert_equal %Q(\n

A.1 this is test.

\n), actual end def test_headline_postdef_roman Dir.mktmpdir do |dir| Dir.chdir(dir) do file = File.join(dir, 'locale.yml') File.write(file, "locale: ja\nappendix: 付録%pR") I18n.setup('ja') @chapter.instance_eval do def on_appendix? true end end actual = compile_block("={test} this is test.\n") assert_equal %Q(

付録I this is test.

\n), actual actual = compile_block("=={test} this is test.\n") assert_equal %Q(\n

I.1 this is test.

\n), actual end end end def test_headline_postdef_alpha Dir.mktmpdir do |dir| Dir.chdir(dir) do file = File.join(dir, 'locale.yml') File.write(file, "locale: ja\nappendix: 付録%pA") I18n.setup('ja') @chapter.instance_eval do def on_appendix? true end end actual = compile_block("={test} this is test.\n") assert_equal %Q(

付録A this is test.

\n), actual actual = compile_block("=={test} this is test.\n") assert_equal %Q(\n

A.1 this is test.

\n), actual end end end def test_headline_level1_without_secno @book.config['secnolevel'] = 0 actual = compile_block("={test} this is test.\n") assert_equal %Q(

this is test.

\n), actual end def test_headline_level1_with_tricky_id actual = compile_block("={123あ_} this is test.\n") assert_equal %Q(

第1章 this is test.

\n), actual end def test_headline_level1_with_inlinetag actual = compile_block(%Q(={test} this @{is} test.<&">\n)) assert_equal %Q(

第1章 this is test.<&">

\n), actual end def test_headline_level2 actual = compile_block("=={test} this is test.\n") assert_equal %Q(\n

1.1 this is test.

\n), actual end def test_headline_level3 actual = compile_block("==={test} this is test.\n") assert_equal %Q(\n

this is test.

\n), actual end def test_headline_level3_with_secno @book.config['secnolevel'] = 3 actual = compile_block("==={test} this is test.\n") assert_equal %Q(\n

1.0.1 this is test.

\n), actual end def test_headline_sections @book.config['epubmaker']['use_section'] = true actual = compile_block("= H1\n== H2\n== H2-2\n") expected = <<-EOS

第1章 H1

1.1 H2

1.2 H2-2

EOS assert_equal expected, actual actual = compile_block("= H1\n== H2\n==== H4\n== H2-2\n") expected = <<-EOS

第1章 H1

1.1 H2

H4

1.2 H2-2

EOS assert_equal expected, actual actual = compile_block("===== H5\n= H1\n") expected = <<-EOS
H5

第1章 H1

EOS assert_equal expected, actual end def test_label actual = compile_block("//label[label_test]\n") assert_equal %Q(\n), actual end def test_label_with_tricky_id actual = compile_block("//label[123あ_]\n") assert_equal %Q(\n), actual end def test_href actual = compile_inline('@{http://github.com,GitHub}') assert_equal %Q(GitHub), actual end def test_href_without_label actual = compile_inline('@{http://github.com}') assert_equal %Q(http://github.com), actual end def test_inline_href actual = compile_inline('@{http://github.com,Git\\,Hub}') assert_equal %Q(Git,Hub), actual @book.config['epubmaker'] ||= {} @book.config['epubmaker']['externallink'] = false actual = compile_inline('@{http://github.com&q=1,Git\\,Hub}') assert_equal %Q(Git,Hub), actual actual = compile_inline('@{http://github.com&q=1}') assert_equal %Q(http://github.com&q=1), actual end def test_inline_href_epubmaker @book.config.maker = 'epubmaker' actual = compile_inline('@{http://github.com,Git\\,Hub}') assert_equal %Q(Git,Hub), actual @book.config['epubmaker'] ||= {} @book.config['epubmaker']['externallink'] = false actual = compile_inline('@{http://github.com&q=1,Git\\,Hub}') assert_equal 'Git,Hub(http://github.com&q=1)', actual actual = compile_inline('@{http://github.com&q=1}') assert_equal 'http://github.com&q=1', actual @book.config['epubmaker']['externallink'] = true actual = compile_inline('@{http://github.com&q=1,Git\\,Hub}') assert_equal %Q(Git,Hub), actual actual = compile_inline('@{http://github.com&q=1}') assert_equal %Q(http://github.com&q=1), actual end def test_inline_raw actual = compile_inline('@{@{inline\\}}') assert_equal '@{inline}', actual end def test_inline_in_table actual = compile_block("//table{\n@{1}\t@{2}\n------------\n@{3}\t@{4}<>&\n//}\n") expected = <<-EOS
12
34<>&
EOS assert_equal expected, actual end def test_inline_br actual = compile_inline('@
{}') assert_equal '
', actual end def test_inline_i actual = compile_inline('test @{inline test} test2') assert_equal 'test inline test test2', actual end def test_inline_i_and_escape actual = compile_inline('test @{inline<&;\\ test} test2') assert_equal 'test inline<&;\\ test test2', actual end def test_inline_b actual = compile_inline('test @{inline test} test2') assert_equal 'test inline test test2', actual end def test_inline_b_and_escape actual = compile_inline('test @{inline<&;\\ test} test2') assert_equal 'test inline<&;\\ test test2', actual end def test_inline_tt actual = compile_inline('test @{inline test} test2') assert_equal %Q(test inline test test2), actual end def test_inline_tti actual = compile_inline('test @{inline test} test2') assert_equal %Q(test inline test test2), actual end def test_inline_ttb actual = compile_inline('test @{inline test} test2') assert_equal %Q(test inline test test2), actual end def test_inline_hd_chap def @chapter.headline_index item = Book::Index::Item.new('chap1|test', [1, 1], 'te_st') idx = Book::HeadlineIndex.new(self) idx.add_item(item) idx end @config['secnolevel'] = 2 actual = compile_inline('test @{chap1|test} test2') assert_equal 'test 「te_st」 test2', actual @config['secnolevel'] = 3 actual = compile_inline('test @{chap1|test} test2') assert_equal 'test 「1.1.1 te_st」 test2', actual @config['chapterlink'] = nil @config['secnolevel'] = 2 actual = compile_inline('test @{chap1|test} test2') assert_equal 'test 「te_st」 test2', actual @config['secnolevel'] = 3 actual = compile_inline('test @{chap1|test} test2') assert_equal 'test 「1.1.1 te_st」 test2', actual end def test_inline_hd_chap_postdef_roman Dir.mktmpdir do |dir| Dir.chdir(dir) do file = File.join(dir, 'locale.yml') File.write(file, "locale: ja\nappendix: 付録%pR") I18n.setup('ja') @chapter.instance_eval do def on_appendix? true end end def @chapter.headline_index item = Book::Index::Item.new('test', [1], 'te_st') idx = Book::HeadlineIndex.new(self) idx.add_item(item) idx end actual = compile_inline('test @{test} test2') assert_equal 'test 「I.1 te_st」 test2', actual @config['chapterlink'] = nil actual = compile_inline('test @{test} test2') assert_equal 'test 「I.1 te_st」 test2', actual end end end def test_inline_hd_chap_postdef_alpha Dir.mktmpdir do |dir| Dir.chdir(dir) do file = File.join(dir, 'locale.yml') File.write(file, "locale: ja\nappendix: 付録%pA") I18n.setup('ja') @chapter.instance_eval do def on_appendix? true end end def @chapter.headline_index item = Book::Index::Item.new('test', [1], 'te_st') idx = Book::HeadlineIndex.new(self) idx.add_item(item) idx end actual = compile_inline('test @{test} test2') assert_equal 'test 「A.1 te_st」 test2', actual @config['chapterlink'] = nil actual = compile_inline('test @{test} test2') assert_equal 'test 「A.1 te_st」 test2', actual end end end def test_inline_sec def @chapter.headline_index item = Book::Index::Item.new('chap1|test', [1, 1], 'te_st<>') idx = Book::HeadlineIndex.new(self) idx.add_item(item) idx end @config['secnolevel'] = 3 actual = compile_inline('test @{test}') assert_equal 'test 「1.1.1 te_st<>」', actual actual = compile_inline('test @{test}') assert_equal 'test te_st<>', actual actual = compile_inline('test @{test}') assert_equal 'test 1.1.1', actual @config['secnolevel'] = 2 actual = compile_inline('test @{test}') assert_equal 'test 「te_st<>」', actual actual = compile_inline('test @{test}') assert_equal 'test te_st<>', actual assert_raises(ReVIEW::ApplicationError) { compile_block('test @{test}') } assert_match(/the target headline doesn't have a number/, @log_io.string) @config['chapterlink'] = nil @config['secnolevel'] = 3 actual = compile_inline('test @{test}') assert_equal 'test 「1.1.1 te_st<>」', actual actual = compile_inline('test @{test}') assert_equal 'test te_st<>', actual actual = compile_inline('test @{test}') assert_equal 'test 1.1.1', actual end def test_inline_uchar actual = compile_inline('test @{2460} test2') assert_equal 'test ① test2', actual end def test_inline_balloon actual = compile_inline('test @{①}') assert_equal %Q(test ), actual end def test_inline_ruby actual = compile_inline('@{粗雑,クルード}と思われているなら@{繊細,テクニカル}にやり、繊細と思われているなら粗雑にやる。') assert_equal '粗雑クルードと思われているなら繊細テクニカルにやり、繊細と思われているなら粗雑にやる。', actual end def test_inline_ruby_comma actual = compile_inline('@{foo\\, bar\\, buz,フー・バー・バズ}') assert_equal 'foo, bar, buzフー・バー・バズ', actual end def test_inline_ref actual = compile_inline('@{外部参照<>&}') assert_equal %Q(「●● 外部参照<>&」), actual end def test_inline_mathml begin require 'math_ml' require 'math_ml/symbol/character_reference' rescue LoadError return true end @config['math_format'] = 'mathml' actual = compile_inline('@{\\frac{-b \\pm \\sqrt{b^2 - 4ac\\}\\}{2a\\}}') assert_equal %Q(-b±b2-4ac2a), actual end def test_inline_mathjax @config['math_format'] = 'mathjax' actual = compile_inline('@{\\frac{-b \\pm \\sqrt{b^2 - 4ac\\}\\}{2a\\}}') assert_equal %Q(\\( \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a} \\)), actual content = <<-EOF //texequation{ \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a} //} EOF actual = compile_block(content) expected = %Q(
\n$$\\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}$$\n
\n) assert_equal expected, actual end def test_inline_img def @chapter.image(_id) item = Book::Index::Item.new('sampleimg', 1, 'sample photo') item.instance_eval { @path = './images/chap1-sampleimg.png' } item end actual = compile_block("@{sampleimg}\n") expected = %Q(

図1.1

\n) assert_equal expected, actual @config['chapterlink'] = nil actual = compile_block("@{sampleimg}\n") expected = %Q(

図1.1

\n) assert_equal expected, actual end def test_inline_imgref def @chapter.image(_id) item = Book::Index::Item.new('sampleimg', 1, 'sample photo') item.instance_eval { @path = './images/chap1-sampleimg.png' } item end actual = compile_block("@{sampleimg}\n") expected = %Q(

図1.1「sample photo」

\n) assert_equal expected, actual @config['chapterlink'] = nil actual = compile_block("@{sampleimg}\n") expected = %Q(

図1.1「sample photo」

\n) assert_equal expected, actual end def test_inline_imgref2 def @chapter.image(_id) item = Book::Index::Item.new('sampleimg', 1) item.instance_eval { @path = './images/chap1-sampleimg.png' } item end actual = compile_block("@{sampleimg}\n") expected = %Q(

図1.1

\n) assert_equal expected, actual @config['chapterlink'] = nil actual = compile_block("@{sampleimg}\n") expected = %Q(

図1.1

\n) assert_equal expected, actual end def test_inline_imgref3 Dir.mktmpdir do |dir| Dir.chdir(dir) do file1 = File.join(dir, 'images', 'img1.png') filet1 = File.join(dir, 'images', 'tbl1.png') file2 = File.join(dir, 'images', 'img2.png') file3 = File.join(dir, 'images', 'icon3.png') re1 = File.join(dir, 'sample1.re') cat = File.join(dir, 'catalog.yml') FileUtils.mkdir_p(File.join(dir, 'images')) File.write(file1, '') File.write(filet1, '') File.write(file2, '') File.write(file3, '') File.write(cat, "CHAPS:\n - sample1.re\n") File.write(re1, <<-EOF) = test tbl1 is @{tbl1}. img2 is @{img2}. icon3 is @{icon3}. //image[img1][image 1]{ //} //imgtable[tbl1][table 1]{ //} //image[img2][image 2]{ //} EOF content = File.read(re1) actual = compile_block(content) expected = <<-EOS

第1章 test

tbl1 is 表1.1.

img2 is 図1.2.

icon3 is [icon3].

image 1

図1.1: image 1

表1.1: table 1

table 1
image 2

図1.2: image 2

EOS assert_equal expected, actual @config['chapterlink'] = nil actual = compile_block(content) expected = <<-EOS

第1章 test

tbl1 is 表1.1.

img2 is 図1.2.

icon3 is [icon3].

image 1

図1.1: image 1

表1.1: table 1

table 1
image 2

図1.2: image 2

EOS assert_equal expected, actual end end end def test_quote actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n") expected = <<-EOS

foobar

buz

EOS assert_equal expected, actual @book.config['join_lines_by_lang'] = true actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n") expected = <<-EOS

foo bar

buz

EOS assert_equal expected, actual end def test_memo actual = compile_block("//memo[this is @{test}<&>_]{\ntest1\n\ntest@{2}\n//}\n") expected = <<-EOS

this is test<&>_

test1

test2

EOS assert_equal expected, actual end def test_blankline actual = compile_block("//blankline\nfoo\n") expected = <<-EOS


foo

EOS assert_equal expected, actual end def test_noindent actual = compile_block("//noindent\nfoo\nbar\n\nfoo2\nbar2\n") expected = <<-EOS

foobar

foo2bar2

EOS assert_equal expected, actual @book.config['join_lines_by_lang'] = true actual = compile_block("//noindent\nfoo\nbar\n\nfoo2\nbar2\n") expected = <<-EOS

foo bar

foo2 bar2

EOS assert_equal expected, actual end def test_flushright actual = compile_block("//flushright{\nfoo\nbar\n\nbuz\n//}\n") expected = <<-EOS

foobar

buz

EOS assert_equal expected, actual @book.config['join_lines_by_lang'] = true actual = compile_block("//flushright{\nfoo\nbar\n\nbuz\n//}\n") expected = <<-EOS

foo bar

buz

EOS assert_equal expected, actual end def test_centering actual = compile_block("//centering{\nfoo\nbar\n\nbuz\n//}\n") expected = <<-EOS

foobar

buz

EOS assert_equal expected, actual @book.config['join_lines_by_lang'] = true actual = compile_block("//centering{\nfoo\nbar\n\nbuz\n//}\n") expected = <<-EOS

foo bar

buz

EOS assert_equal expected, actual end def test_image def @chapter.image(_id) item = Book::Index::Item.new('sampleimg', 1) item.instance_eval { @path = './images/chap1-sampleimg.png' } item end actual = compile_block("//image[sampleimg][sample photo]{\n//}\n") expected = <<-EOS
sample photo

図1.1: sample photo

EOS assert_equal expected, actual actual = compile_block("//image[sampleimg][]{\n//}\n") expected = <<-EOS

図1.1:

EOS assert_equal expected, actual actual = compile_block("//image[sampleimg][][]{\n//}\n") assert_equal expected, actual @config['caption_position']['image'] = 'top' actual = compile_block("//image[sampleimg][sample photo]{\n//}\n") expected = <<-EOS

図1.1: sample photo

sample photo
EOS assert_equal expected, actual end def test_image_with_metric def @chapter.image(_id) item = Book::Index::Item.new('sampleimg', 1) item.instance_eval { @path = './images/chap1-sampleimg.png' } item end actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n") expected = <<-EOS
sample photo

図1.1: sample photo

EOS assert_equal expected, actual end def test_image_with_metric2 def @chapter.image(_id) item = Book::Index::Item.new('sampleimg', 1) item.instance_eval { @path = './images/chap1-sampleimg.png' } item end actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n") expected = <<-EOS
sample photo

図1.1: sample photo

EOS assert_equal expected, actual end def test_image_with_tricky_id_kana def @chapter.image(_id) item = Book::Index::Item.new('123あいう', 1) item.instance_eval { @path = './images/123あいう.png' } item end @chapter.instance_eval { @name = 'ch01' } actual = compile_block("//image[123あいう][sample photo]{\n//}\nimg: @{123あいう}\n") expected = <<-EOS
sample photo

図1.1: sample photo

img: 図1.1

EOS assert_equal expected, actual end def test_indepimage def @chapter.image(_id) item = Book::Index::Item.new('sampleimg', 1) item.instance_eval { @path = './images/chap1-sampleimg.png' } item end actual = compile_block("//indepimage[sampleimg][sample photo]\n") expected = <<-EOS
sample photo

図: sample photo

EOS assert_equal expected, actual @config['caption_position']['image'] = 'top' actual = compile_block("//indepimage[sampleimg][sample photo]\n") expected = <<-EOS

図: sample photo

sample photo
EOS assert_equal expected, actual end def test_indepimage_without_caption def @chapter.image(_id) item = Book::Index::Item.new('sampleimg', 1) item.instance_eval { @path = './images/chap1-sampleimg.png' } item end actual = compile_block("//indepimage[sampleimg]\n") expected = <<-EOS
EOS assert_equal expected, actual actual = compile_block("//indepimage[sampleimg][]\n") assert_equal expected, actual actual = compile_block("//indepimage[sampleimg][][]\n") assert_equal expected, actual end def test_indepimage_with_metric def @chapter.image(_id) item = Book::Index::Item.new('sampleimg', 1) item.instance_eval { @path = './images/chap1-sampleimg.png' } item end actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n") expected = <<-EOS
sample photo

図: sample photo

EOS assert_equal expected, actual end def test_indepimage_with_metric2 def @chapter.image(_id) item = Book::Index::Item.new('sampleimg', 1) item.instance_eval { @path = './images/chap1-sampleimg.png' } item end actual = compile_block(%Q(//indepimage[sampleimg][sample photo][scale=1.2, html::class="sample",latex::ignore=params]\n)) expected = <<-EOS
sample photo

図: sample photo

EOS assert_equal expected, actual end def test_indepimage_without_caption_but_with_metric def @chapter.image(_id) item = Book::Index::Item.new('sampleimg', 1) item.instance_eval { @path = './images/chap1-sampleimg.png' } item end actual = compile_block("//indepimage[sampleimg][][scale=1.2]\n") expected = <<-EOS
EOS assert_equal expected, actual end def test_dlist actual = compile_block(" : foo\n foo.\n bar.\n") expected = <<-EOS
foo
foo.bar.
EOS assert_equal expected, actual @book.config['join_lines_by_lang'] = true actual = compile_block(" : foo\n foo.\n bar.\n") expected = <<-EOS
foo
foo. bar.
EOS assert_equal expected, actual end def test_dlist_with_bracket actual = compile_block(" : foo[bar]\n foo.\n bar.\n") expected = <<-EOS
foo[bar]
foo.bar.
EOS assert_equal expected, actual @book.config['join_lines_by_lang'] = true actual = compile_block(" : foo[bar]\n foo.\n bar.\n") expected = <<-EOS
foo[bar]
foo. bar.
EOS assert_equal expected, actual end def test_dlist_with_comment source = " : title\n body\n\#@ comment\n\#@ comment\n : title2\n body2\n" actual = compile_block(source) expected = <<-EOS
title
body
title2
body2
EOS assert_equal expected, actual end def test_dlist_beforeulol actual = compile_block(" : foo\n foo.\n\npara\n\n : foo\n foo.\n\n 1. bar\n\n : foo\n foo.\n\n * bar\n") expected = <<-EOS
foo
foo.

para

foo
foo.
  1. bar
foo
foo.
  • bar
EOS assert_equal expected, actual end def test_dt_inline actual = compile_block("//footnote[bar][bar]\n\n : foo@{bar}[]<>&@$\\alpha[]$\n") expected = <<-EOS

[*1] bar

foo*1[]<>&\\alpha[]
EOS assert_equal expected, actual end def test_list def @chapter.list(_id) Book::Index::Item.new('samplelist', 1) end actual = compile_block("//list[samplelist][this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n") expected = <<-EOS

リスト1.1: this is test<&>_

test1
test1.5

test2
EOS assert_equal expected, actual @config['caption_position']['list'] = 'bottom' actual = compile_block("//list[samplelist][this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n") expected = <<-EOS
test1
test1.5

test2

リスト1.1: this is test<&>_

EOS assert_equal expected, actual end def test_inline_list def @chapter.list(_id) Book::Index::Item.new('samplelist', 1) end actual = compile_block("@{samplelist}\n") assert_equal %Q(

リスト1.1

\n), actual @config['chapterlink'] = nil actual = compile_block("@{samplelist}\n") assert_equal %Q(

リスト1.1

\n), actual end def test_inline_list_href book = ReVIEW::Book::Base.new book.config['chapterlink'] = true book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re ch2.re]) io1 = StringIO.new("//list[sampletest][a]{\nfoo\n//}\n") io2 = StringIO.new("= BAR\n") chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1) chap2 = ReVIEW::Book::Chapter.new(book, 2, 'ch2', 'ch2.re', io2) book.parts = [ReVIEW::Book::Part.new(book, nil, [chap1, chap2])] builder = ReVIEW::HTMLBuilder.new comp = ReVIEW::Compiler.new(builder) builder.bind(comp, chap2, nil) chap1.generate_indexes actual = builder.inline_list('ch1|sampletest') assert_equal %Q(リスト1.1), actual end def test_list_pygments return true if @skip_pygments def @chapter.list(_id) Book::Index::Item.new('samplelist', 1) end begin require 'pygments' rescue LoadError $stderr.puts 'skip test_list_pygments_lang (cannot find pygments.rb)' return true end @book.config['highlight'] = {} @book.config['highlight']['html'] = 'pygments' actual = compile_block("//list[samplelist][this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n") expected = <<-EOS

リスト1.1: this is test<&>_

test1
test1.5

test<i>2</i>
EOS assert_equal expected, actual end def test_list_pygments_lang return true if @skip_pygments def @chapter.list(_id) Book::Index::Item.new('samplelist', 1) end begin require 'pygments' rescue LoadError $stderr.puts 'skip test_list_pygments_lang (cannot find pygments.rb)' return true end @book.config['highlight'] = {} @book.config['highlight']['html'] = 'pygments' actual = compile_block("//list[samplelist][this is @{test}<&>_][ruby]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n") expected = <<-EOS

リスト1.1: this is test<&>_

def foo(a1, a2=:test)
  (1..3).times{\|i| a.include?(:foo)}
  return true
end
EOS assert_equal expected, actual end def test_list_pygments_nulllang return true if @skip_pygments def @chapter.list(_id) Book::Index::Item.new('samplelist', 1) end begin require 'pygments' rescue LoadError $stderr.puts 'skip test_list_pygments_nulllang (cannot find pygments.rb)' return true end @book.config['highlight'] = {} @book.config['highlight']['html'] = 'pygments' actual = compile_block("//list[samplelist][this is @{test}<&>_][]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n") expected = <<-EOS

リスト1.1: this is test<&>_

def foo(a1, a2=:test)
  (1..3).times{|i| a.include?(:foo)}
  return true
end
EOS assert_equal expected, actual end def test_list_rouge begin require 'rouge' rescue LoadError $stderr.puts 'skip test_list_rouge (cannot find Rouge)' return true end def @chapter.list(_id) Book::Index::Item.new('samplelist', 1) end @book.config['highlight'] = {} @book.config['highlight']['html'] = 'rouge' actual = compile_block("//list[samplelist][this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n") expected = <<-EOS

リスト1.1: this is test<&>_

test1
test1.5

test<i>2</i>
EOS assert_equal expected, actual end def test_list_rouge_lang begin require 'rouge' rescue LoadError $stderr.puts 'skip test_list_rouge_lang (cannot find Rouge)' return true end def @chapter.list(_id) Book::Index::Item.new('samplelist', 1) end @book.config['highlight'] = {} @book.config['highlight']['html'] = 'rouge' actual = compile_block("//list[samplelist][this is @{test}<&>_][ruby]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n") expected = <<-EOS

リスト1.1: this is test<&>_

def foo(a1, a2=:test)
  (1..3).times{|i| a.include?(:foo)}
  return true
end

EOS assert_equal expected, actual end def test_list_rouge_nulllang begin require 'rouge' rescue LoadError $stderr.puts 'skip test_list_rouge_nulllang (cannot find Rouge)' return true end def @chapter.list(_id) Book::Index::Item.new('samplelist', 1) end @book.config['highlight'] = {} @book.config['highlight']['html'] = 'rouge' actual = compile_block("//list[samplelist][this is @{test}<&>_][]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n") expected = <<-EOS

リスト1.1: this is test<&>_

def foo(a1, a2=:test)
  (1..3).times{|i| a.include?(:foo)}
  return true
end

EOS assert_equal expected, actual end def test_listnum def @chapter.list(_id) Book::Index::Item.new('samplelist', 1) end @book.config['highlight'] = false actual = compile_block(<<-EOS) //listnum[samplelist][this is @{test}<&>_][ruby]{ def foo(a1, a2=:test) (1..3).times{|i| a.include?(:foo)} return true end //} EOS expected = <<-EOS

リスト1.1: this is test<&>_

 1: def foo(a1, a2=:test)
 2:   (1..3).times{|i| a.include?(:foo)}
 3:   return true
 4: end
EOS assert_equal expected, actual @config['caption_position']['list'] = 'bottom' actual = compile_block(<<-EOS) //listnum[samplelist][this is @{test}<&>_][ruby]{ def foo(a1, a2=:test) (1..3).times{|i| a.include?(:foo)} return true end //} EOS expected = <<-EOS
 1: def foo(a1, a2=:test)
 2:   (1..3).times{|i| a.include?(:foo)}
 3:   return true
 4: end

リスト1.1: this is test<&>_

EOS assert_equal expected, actual end def test_listnum_linenum def @chapter.list(_id) Book::Index::Item.new('samplelist', 1) end @book.config['highlight'] = false actual = compile_block(<<-EOS) //firstlinenum[100] //listnum[samplelist][this is @{test}<&>_][ruby]{ def foo(a1, a2=:test) (1..3).times{|i| a.include?(:foo)} return true end //} EOS expected = <<-EOS

リスト1.1: this is test<&>_

100: def foo(a1, a2=:test)
101:   (1..3).times{|i| a.include?(:foo)}
102:   return true
103: end
EOS assert_equal expected, actual end def test_listnum_pygments_lang return true if @skip_pygments def @chapter.list(_id) Book::Index::Item.new('samplelist', 1) end begin require 'pygments' rescue LoadError $stderr.puts 'skip test_listnum_pygments_lang (cannot find pygments.rb)' return true end @book.config['highlight'] = {} @book.config['highlight']['html'] = 'pygments' actual = compile_block("//listnum[samplelist][this is @{test}<&>_][ruby]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n") expected = <<-EOS

リスト1.1: this is test<&>_

1 def foo(a1, a2=:test)
2   (1..3).times{|i| a.include?(:foo)}
3   return true
4 end
EOS assert_equal expected, actual end def test_listnum_pygments_lang_linenum return true if @skip_pygments def @chapter.list(_id) Book::Index::Item.new('samplelist', 1) end begin require 'pygments' rescue LoadError $stderr.puts 'skip test_listnum_pygments_lang (cannot find pygments.rb)' return true end @book.config['highlight'] = {} @book.config['highlight']['html'] = 'pygments' actual = compile_block("//firstlinenum[100]\n//listnum[samplelist][this is @{test}<&>_][ruby]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n") expected = <<-EOS

リスト1.1: this is test<&>_

100 def foo(a1, a2=:test)
101   (1..3).times{|i| a.include?(:foo)}
102   return true
103 end
EOS assert_equal expected, actual end def test_listnum_pygments_lang_without_lang return true if @skip_pygments def @chapter.list(_id) Book::Index::Item.new('samplelist', 1) end begin require 'pygments' rescue LoadError $stderr.puts 'skip test_listnum_pygments_lang (cannot find pygments.rb)' return true end @book.config['highlight'] = {} @book.config['highlight']['html'] = 'pygments' @book.config['highlight']['lang'] = 'ruby' actual = compile_block("//listnum[samplelist][this is @{test}<&>_]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n") expected = <<-EOS

リスト1.1: this is test<&>_

1 def foo(a1, a2=:test)
2   (1..3).times{|i| a.include?(:foo)}
3   return true
4 end
EOS assert_equal expected, actual end def test_listnum_rouge_lang begin require 'rouge' rescue LoadError $stderr.puts 'skip test_listnum_rouge_lang (cannot find Rouge)' return true end def @chapter.list(_id) Book::Index::Item.new('samplelist', 1) end @book.config['highlight'] = {} @book.config['highlight']['html'] = 'rouge' actual = compile_block("//listnum[samplelist][this is @{test}<&>_][ruby]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n") expected = <<-EOS

リスト1.1: this is test<&>_

1
2
3
4
5
def foo(a1, a2=:test)
  (1..3).times{|i| a.include?(:foo)}
  return true
end

EOS assert_equal expected, actual end def test_listnum_rouge_lang_linenum begin require 'rouge' rescue LoadError $stderr.puts 'skip test_listnum_rouge_lang_linenum (cannot find Rouge)' return true end def @chapter.list(_id) Book::Index::Item.new('samplelist', 1) end @book.config['highlight'] = {} @book.config['highlight']['html'] = 'rouge' actual = compile_block("//firstlinenum[100]\n//listnum[samplelist][this is @{test}<&>_][ruby]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n") expected = <<-EOB

リスト1.1: this is test<&>_

100
101
102
103
104
def foo(a1, a2=:test)
  (1..3).times{|i| a.include?(:foo)}
  return true
end

EOB assert_equal expected, actual end def test_source actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n") expected = <<-EOS

foo/bar/test.rb

foo
bar

buz
EOS assert_equal expected, actual @config['caption_position']['list'] = 'bottom' actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n") expected = <<-EOS
foo
bar

buz

foo/bar/test.rb

EOS assert_equal expected, actual end def test_source_empty_caption actual = compile_block("//source[]{\nfoo\nbar\n\nbuz\n//}\n") expected = <<-EOS
foo
bar

buz
EOS assert_equal expected, actual end def test_box actual = compile_block("//box{\nfoo\nbar\n//}\n") expected = <<-EOS
foo
bar
EOS assert_equal expected, actual actual = compile_block("//box[FOO]{\nfoo\nbar\n//}\n") expected = <<-EOS

FOO

foo
bar
EOS assert_equal expected, actual @config['caption_position']['list'] = 'bottom' actual = compile_block("//box[FOO]{\nfoo\nbar\n//}\n") expected = <<-EOS
foo
bar

FOO

EOS assert_equal expected, actual end def test_emlist actual = compile_block("//emlist{\nlineA\nlineB\n//}\n") expected = <<-EOS
lineA
lineB
EOS assert_equal expected, actual end def test_emlist_pygments_lang return true if @skip_pygments begin require 'pygments' rescue LoadError $stderr.puts 'skip test_emlist_pygments_lang (cannot find pygments.rb)' return true end @book.config['highlight'] = {} @book.config['highlight']['html'] = 'pygments' actual = compile_block("//emlist[][sql]{\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n//}\n") expected = <<-EOS
SELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'
EOS assert_equal expected, actual end def test_emlist_caption actual = compile_block("//emlist[cap1]{\nlineA\nlineB\n//}\n") expected = <<-EOS

cap1

lineA
lineB
EOS assert_equal expected, actual @config['caption_position']['list'] = 'bottom' actual = compile_block("//emlist[cap1]{\nlineA\nlineB\n//}\n") expected = <<-EOS
lineA
lineB

cap1

EOS assert_equal expected, actual end def test_emlist_with_tab actual = compile_block("//emlist{\n\tlineA\n\t\tlineB\n\tlineC\n//}\n") expected = <<-EOS
        lineA
                lineB
        lineC
EOS assert_equal expected, actual end def test_emlistnum @book.config['highlight'] = false actual = compile_block("//emlistnum{\nlineA\nlineB\n//}\n") expected = <<-EOS
 1: lineA
 2: lineB
EOS assert_equal expected, actual end def test_emlistnum_lang @book.config['highlight'] = false actual = compile_block("//emlistnum[cap][text]{\nlineA\nlineB\n//}\n") expected = <<-EOS

cap

 1: lineA
 2: lineB
EOS assert_equal expected, actual @config['caption_position']['list'] = 'bottom' actual = compile_block("//emlistnum[cap][text]{\nlineA\nlineB\n//}\n") expected = <<-EOS
 1: lineA
 2: lineB

cap

EOS assert_equal expected, actual end def test_emlistnum_lang_linenum @book.config['highlight'] = false actual = compile_block("//firstlinenum[1000]\n//emlistnum[cap][text]{\nlineA\nlineB\n//}\n") expected = <<-EOS

cap

1000: lineA
1001: lineB
EOS assert_equal expected, actual end def test_emlist_with_4tab @config['tabwidth'] = 4 actual = compile_block("//emlist{\n\tlineA\n\t\tlineB\n\tlineC\n//}\n") expected = <<-EOS
    lineA
        lineB
    lineC
EOS assert_equal expected, actual end def test_cmd actual = compile_block("//cmd{\nlineA\nlineB\n//}\n") expected = <<-EOS
lineA
lineB
EOS assert_equal expected, actual end def test_cmd_pygments return true if @skip_pygments begin require 'pygments' rescue LoadError return true end @book.config['highlight'] = {} @book.config['highlight']['html'] = 'pygments' actual = compile_block("//cmd{\nlineA\nlineB\n//}\n") expected = <<-EOS
lineA
lineB
EOS assert_equal expected, actual end def test_cmd_caption actual = compile_block("//cmd[cap1]{\nlineA\nlineB\n//}\n") expected = <<-EOS

cap1

lineA
lineB
EOS assert_equal expected, actual @config['caption_position']['list'] = 'bottom' actual = compile_block("//cmd[cap1]{\nlineA\nlineB\n//}\n") expected = <<-EOS
lineA
lineB

cap1

EOS assert_equal expected, actual end def test_texequation return true if /mswin|mingw|cygwin/.match?(RUBY_PLATFORM) return true unless system('latex -version 1>/dev/null 2>/dev/null') mktmpbookdir('catalog.yml' => "CHAPS:\n - ch01.re\n", 'ch01.re' => "= test\n\n//texequation{\np \\land \\bm{P} q\n//}\n") do |dir, book, _files| @book = book @book.config = @config @config['math_format'] = 'imgmath' @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new) location = Location.new(nil, nil) img_math = ReVIEW::ImgMath.new(@config) @builder = HTMLBuilder.new(img_math: img_math) @builder.bind(@compiler, @chapter, location) FileUtils.mkdir_p(File.join(dir, 'images')) expected = <<-EOB
p \\land \\bm{P} q
EOB tmpio = $stderr $stderr = StringIO.new begin result = compile_block("//texequation{\np \\land \\bm{P} q\n//}\n") ensure $stderr = tmpio end actual = result.gsub(/_gen_[0-9a-f]+\.png/, '_gen_XXX.png') assert_equal expected, actual end end def test_texequation_fail # Re:VIEW 3 never fail on defer mode. This test is only for Re:VIEW 2. return true if /mswin|mingw|cygwin/.match?(RUBY_PLATFORM) return true unless system('latex -version 1>/dev/null 2>/dev/null') mktmpbookdir('catalog.yml' => "CHAPS:\n - ch01.re\n", 'ch01.re' => "= test\n\n//texequation{\np \\land \\bm{P}} q\n//}\n") do |dir, book, _files| @book = book @book.config = @config @config['review_version'] = 2 @config['math_format'] = 'imgmath' @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new) location = Location.new(nil, nil) img_math = ReVIEW::ImgMath.new(@config) @builder = HTMLBuilder.new(img_math: img_math) @builder.bind(@compiler, @chapter, location) FileUtils.mkdir_p(File.join(dir, 'images')) tmpio = $stderr $stderr = StringIO.new begin assert_raise(ReVIEW::ApplicationError) do _result = compile_block("//texequation{\np \\land \\bm{P}} q\n//}\n") end ensure $stderr = tmpio end end end def test_bib def @chapter.bibpaper(_id) Book::Index::Item.new('samplebib', 1, 'sample bib') end assert_equal %Q([1]), compile_inline('@{samplebib}') end def test_bib_noramlized def @chapter.bibpaper(_id) Book::Index::Item.new('sampleb=ib', 1, 'sample bib') end assert_equal %Q([1]), compile_inline('@{sample=bib}') end def test_bib_htmlext def @chapter.bibpaper(_id) Book::Index::Item.new('samplebib', 1, 'sample bib') end @config['htmlext'] = 'xhtml' assert_equal %Q([1]), compile_inline('@{samplebib}') end def test_bibpaper def @chapter.bibpaper(_id) Book::Index::Item.new('samplebib', 1, 'sample bib') end actual = compile_block("//bibpaper[samplebib][sample bib @{bold}]{\na\nb\n//}\n") expected = <<-EOS
[1] sample bib bold

ab

EOS assert_equal expected, actual @book.config['join_lines_by_lang'] = true actual = compile_block("//bibpaper[samplebib][sample bib @{bold}]{\na\nb\n//}\n") expected = <<-EOS
[1] sample bib bold

a b

EOS assert_equal expected, actual end def test_bibpaper_normalized def @chapter.bibpaper(_id) Book::Index::Item.new('sample=bib', 1, 'sample bib') end actual = compile_block("//bibpaper[sample=bib][sample bib @{bold}]{\na\nb\n//}\n") expected = <<-EOS
[1] sample bib bold

ab

EOS assert_equal expected, actual @book.config['join_lines_by_lang'] = true actual = compile_block("//bibpaper[sample=bib][sample bib @{bold}]{\na\nb\n//}\n") expected = <<-EOS
[1] sample bib bold

a b

EOS assert_equal expected, actual end def test_bibpaper_with_anchor def @chapter.bibpaper(_id) Book::Index::Item.new('samplebib', 1, 'sample bib') end actual = compile_block("//bibpaper[samplebib][sample bib @{http://example.jp}]{\na\nb\n//}\n") expected = <<-EOS
[1] sample bib http://example.jp

ab

EOS assert_equal expected, actual @book.config['join_lines_by_lang'] = true actual = compile_block("//bibpaper[samplebib][sample bib @{http://example.jp}]{\na\nb\n//}\n") expected = <<-EOS
[1] sample bib http://example.jp

a b

EOS assert_equal expected, actual end def column_helper(review) compile_block(review) end def test_column_1 review = <<-EOS ===[column] prev column inside prev column ===[column] test inside column ===[/column] EOS expected = <<-EOS

prev column

inside prev column

test

inside column

EOS assert_equal expected, column_helper(review) end def test_column_2 review = <<-EOS ===[column] test inside column === next level EOS expected = <<-EOS

test

inside column

next level

EOS assert_equal expected, column_helper(review) end def test_column_3 review = <<-EOS ===[column] test inside column ===[/column_dummy] EOS assert_raise(ReVIEW::ApplicationError) do column_helper(review) end end def test_column_ref review = <<-EOS ===[column]{foo} test inside column === next level this is @{foo}. EOS expected = <<-EOS

test

inside column

next level

this is コラム「test」.

EOS assert_equal expected, column_helper(review) @config['chapterlink'] = nil expected = <<-EOS

test

inside column

next level

this is コラム「test」.

EOS assert_equal expected, column_helper(review) end def test_column_in_aother_chapter_ref def @chapter.column_index item = Book::Index::Item.new('chap1|column', 1, 'column_cap') idx = Book::ColumnIndex.new idx.add_item(item) idx end actual = compile_inline('test @{chap1|column} test2') expected = 'test コラム「column_cap」 test2' assert_equal expected, actual @config['chapterlink'] = nil actual = compile_inline('test @{chap1|column} test2') expected = 'test コラム「column_cap」 test2' assert_equal expected, actual end def test_ul src = <<-EOS * AAA * BBB EOS expected = <<-EOS
  • AAA
  • BBB
EOS actual = compile_block(src) assert_equal expected, actual end def test_ul_cont src = <<-EOS * AAA -AA * BBB -BB EOS expected = <<-EOS
  • AAA-AA
  • BBB-BB
EOS actual = compile_block(src) assert_equal expected, actual @book.config['join_lines_by_lang'] = true expected = <<-EOS
  • AAA -AA
  • BBB -BB
EOS actual = compile_block(src) assert_equal expected, actual end def test_ul_nest1 src = <<-EOS * AAA ** AA EOS expected = <<-EOS
  • AAA
    • AA
EOS actual = compile_block(src) assert_equal expected, actual end def test_ul_nest2 src = <<-EOS * AAA ** AA * BBB ** BB EOS expected = <<-EOS
  • AAA
    • AA
  • BBB
    • BB
EOS actual = compile_block(src) assert_equal expected, actual end def test_ul_nest3 src = <<-EOS ** AAA * AA EOS assert_raises(ReVIEW::ApplicationError) { compile_block(src) } assert_match(/too many \*\./, @log_io.string) end def test_ul_nest4 src = <<-EOS * A ** AA *** AAA * B ** BB EOS expected = <<-EOS
  • A
    • AA
      • AAA
  • B
    • BB
EOS actual = compile_block(src) assert_equal expected, actual end def test_ol src = <<-EOS 3. AAA 3. BBB EOS expected = <<-EOS
  1. AAA
  2. BBB
EOS actual = compile_block(src) assert_equal expected, actual end def test_inline_raw0 assert_equal 'normal', compile_inline('@{normal}') end def test_inline_raw1 assert_equal 'body', compile_inline('@{|html|body}') end def test_inline_raw2 assert_equal 'body', compile_inline('@{|html, latex|body}') end def test_inline_raw3 assert_equal '', compile_inline('@{|idgxml, latex|body}') end def test_inline_raw4 assert_equal '|html body', compile_inline('@{|html body}') end def test_inline_raw5 assert_equal "nor\nmal", compile_inline('@{|html|nor\\nmal}') end def test_inline_embed0 assert_equal 'normal', compile_inline('@{normal}') end def test_inline_embed1 assert_equal 'body', compile_inline('@{|html|body}') end def test_inline_embed3 assert_equal '', compile_inline('@{|idgxml, latex|body}') end def test_inline_embed5 assert_equal 'nor\\nmal', compile_inline('@{|html|nor\\nmal}') end def test_inline_embed_math1 assert_equal '\[ \frac{\partial f}{\partial x} =x^2+xy \]', compile_inline('@{\[ \frac{\partial f\}{\partial x\} =x^2+xy \]}') end def test_inline_embed_math1a assert_equal '\[ \frac{\partial f}{\partial x} =x^2+xy \]', compile_inline('@{\\[ \\frac{\\partial f\}{\\partial x\} =x^2+xy \\]}') end def test_inline_embed_math1b assert_equal '\[ \frac{\partial f}{\partial x} =x^2+xy \]', compile_inline('@{\\\\[ \\\\frac{\\\\partial f\}{\\\\partial x\} =x^2+xy \\\\]}') end def test_inline_embed_math1c assert_equal '\\[ \\frac{}{} \\]', compile_inline('@{\[ \\frac{\}{\} \\]}') end def test_inline_embed_n1 assert_equal '\\n', compile_inline('@{\\n}') end def test_inline_embed_n2 assert_equal '\\n', compile_inline('@{\\\\n}') end def test_inline_embed_brace_right0 assert_equal '}', compile_inline('@{\\}}') end def test_inline_embed_brace_right1 assert_equal '\\}', compile_inline('@{\\\\}}') end def test_inline_embed_brace_right2 assert_equal '\\}', compile_inline('@{\\\\\\}}') end def test_inline_embed_brace_right3 assert_equal '\\\\}', compile_inline('@{\\\\\\\\}}') end def test_block_raw0 actual = compile_block(%Q(//raw[<>!"\\n& ]\n)) expected = %Q(<>!"\n& ) assert_equal expected, actual end def test_block_raw1 actual = compile_block(%Q(//raw[|html|<>!"\\n& ]\n)) expected = %Q(<>!"\n& ) assert_equal expected, actual end def test_block_raw2 actual = compile_block(%Q(//raw[|html, latex|<>!"\\n& ]\n)) expected = %Q(<>!"\n& ) assert_equal expected, actual end def test_block_raw3 actual = compile_block(%Q(//raw[|latex, idgxml|<>!"\\n& ]\n)) expected = '' assert_equal expected, actual end def test_block_raw4 actual = compile_block(%Q(//raw[|html <>!"\\n& ]\n)) expected = %Q(|html <>!"\n& ) assert_equal expected, actual end def test_embed0 lines = '//embed{' + "\n" + %Q( <>!"\\\\n& ) + "\n" + '//}' + "\n" actual = compile_block(lines) expected = %Q( <>!"\\\\n& ) + "\n" assert_equal expected, actual end def test_embed1 actual = compile_block("//embed[|html|]{\n" + %Q(<>!"\\\\n& \n) + "//}\n") expected = %Q(<>!"\\\\n& \n) assert_equal expected, actual end def test_embed2 actual = compile_block("//embed[html, latex]{\n" + %Q(<>!"\\\\n& \n) + "//}\n") expected = %Q(<>!"\\\\n& \n) assert_equal expected, actual end def test_embed2a actual = compile_block("//embed[|html, latex|]{\n" + %Q(<>!"\\\\n& \n) + "//}\n") expected = %Q(<>!"\\\\n& \n) assert_equal expected, actual end def test_embed2b actual = compile_block("//embed[html, latex]{\n" + '#@# comments are not ignored in //embed block' + "\n" + %Q(<>!"\\\\n& \n) + "//}\n") expected = '#@# comments are not ignored in //embed block' + "\n" + %Q(<>!"\\\\n& \n) assert_equal expected, actual end def test_footnote actual = compile_block("//footnote[foo][bar\\a\\$buz]\n") expected = <<-'EOS'

[*1] bar\a\$buz

EOS assert_equal expected, actual @book.config['epubmaker'] ||= {} @book.config['epubmaker']['back_footnote'] = true actual = compile_block("//footnote[foo][bar\\a\\$buz]\n") expected = <<-'EOS'

[*1] bar\a\$buz

EOS assert_equal expected, actual I18n.set('html_footnote_textmark', '+%s:') I18n.set('html_footnote_backmark', '←') actual = compile_block("//footnote[foo][bar\\a\\$buz]\n") expected = <<-'EOS'

+1:bar\a\$buz

EOS assert_equal expected, actual end def test_footnote_with_tricky_id actual = compile_block("//footnote[123あ_;][bar\\a\\$buz]\n") expected = <<-'EOS'

[*1] bar\a\$buz

EOS assert_equal expected, actual end def test_inline_fn fn = compile_block("//footnote[foo][bar]\n\n@{foo}\n") expected = <<-EOS

[*1] bar

*1

EOS assert_equal expected, fn I18n.set('html_footnote_refmark', '+%s') fn = compile_block("//footnote[foo][bar]\n\n@{foo}\n") expected = <<-EOS

[*1] bar

+1

EOS assert_equal expected, fn end def test_endnote e = assert_raises(ReVIEW::ApplicationError) { compile_block("//endnote[foo][bar]\n\n@{foo}\n") } assert_equal ':4: //endnote is found but //printendnotes is not found.', e.message actual = compile_block("@{foo}\n//endnote[foo][bar]\n//printendnotes\n") expected = <<-'EOS'

(1)

(1) bar

EOS assert_equal expected, actual @book.config['epubmaker'] ||= {} @book.config['epubmaker']['back_footnote'] = true actual = compile_block("@{foo}\n//endnote[foo][bar]\n//printendnotes\n") expected = <<-'EOS'

(1)

(1) bar

EOS assert_equal expected, actual I18n.set('html_endnote_textmark', '+%s:') I18n.set('html_endnote_refmark', '+%s:') I18n.set('html_footnote_backmark', '←') actual = compile_block("@{foo}\n//endnote[foo][bar]\n//printendnotes\n") expected = <<-'EOS'

+1:

+1:bar

EOS assert_equal expected, actual end def test_inline_hd book = ReVIEW::Book::Base.new book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re ch2.re]) io1 = StringIO.new("= test1\n\nfoo\n\n== test1-1\n\nbar\n\n== test1-2\n\nbar\n\n") io2 = StringIO.new("= test2\n\nfoo\n\n== test2-1\n\nbar\n\n== test2-2\n\nbar\n\n") chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1) chap2 = ReVIEW::Book::Chapter.new(book, 2, 'ch2', 'ch2.re', io2) book.parts = [ReVIEW::Book::Part.new(book, nil, [chap1, chap2])] builder = ReVIEW::HTMLBuilder.new comp = ReVIEW::Compiler.new(builder) builder.bind(comp, chap2, nil) chap1.generate_indexes chap2.generate_indexes hd = builder.inline_hd('ch1|test1-1') assert_equal '「1.1 test1-1」', hd builder.instance_eval { @book.config['chapterlink'] = nil } hd = builder.inline_hd('ch1|test1-1') assert_equal '「1.1 test1-1」', hd end def test_inline_hd_for_part book = ReVIEW::Book::Base.new book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re ch2.re]) io1 = StringIO.new("= test1\n\nfoo\n\n== test1-1\n\nbar\n\n== test1-2\n\nbar\n\n") io2 = StringIO.new("= test2\n\nfoo\n\n== test2-1\n\nbar\n\n== test2-2\n\nbar\n\n") io_p1 = StringIO.new("= part1\n\nfoo\n\n== part1-1\n\nbar\n\n== part1-2\n\nbar\n\n") chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1) chap2 = ReVIEW::Book::Chapter.new(book, 2, 'ch2', 'ch2.re', io2) book.parts = [ReVIEW::Book::Part.new(book, 1, [chap1, chap2], 'part1.re', io_p1)] builder = ReVIEW::HTMLBuilder.new comp = ReVIEW::Compiler.new(builder) builder.bind(comp, chap2, nil) book.generate_indexes hd = builder.inline_hd('part1|part1-1') assert_equal '「1.1 part1-1」', hd builder.instance_eval { @book.config['chapterlink'] = nil } hd = builder.inline_hd('part1|part1-1') assert_equal '「1.1 part1-1」', hd end def test_inline_hd_with_block io1 = StringIO.new("= test1\n=={foo} foo\n//emlist{\n======\nbar\n======\n}\n//}\n=={bar} bar") chap1 = Book::Chapter.new(@book, 1, '-', nil, io1) location = Location.new(nil, nil) @builder.bind(@compiler, chap1, location) hd = @builder.inline_hd('foo') assert_equal '「1.1 foo」', hd @config['chapterlink'] = nil hd = @builder.inline_hd('foo') assert_equal '「1.1 foo」', hd hd = @builder.inline_hd('bar') assert_equal '「1.2 bar」', hd end def test_table actual = compile_block("//table{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n") expected = <<-EOS
aaabbb
cccddd<>&
EOS assert_equal expected, actual actual = compile_block("//table[foo][FOO]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n") expected = <<-EOS

表1.1: FOO

aaabbb
cccddd<>&
EOS assert_equal expected, actual @config['caption_position']['table'] = 'bottom' actual = compile_block("//table[foo][FOO]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n") expected = <<-EOS
aaabbb
cccddd<>&

表1.1: FOO

EOS assert_equal expected, actual end def test_empty_table e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n//}\n") } assert_equal 'no rows in the table', e.message e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n------------\n//}\n") } assert_equal 'no rows in the table', e.message end def test_inline_table def @chapter.table(_id) Book::Index::Item.new('sampletable', 1) end actual = compile_block("@{sampletest}\n") assert_equal %Q(

表1.1

\n), actual @config['chapterlink'] = nil actual = compile_block("@
{sampletest}\n") assert_equal %Q(

表1.1

\n), actual end def test_emtable actual = compile_block("//emtable[foo]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n//emtable{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n") expected = <<-EOS

foo

aaabbb
cccddd<>&
aaabbb
cccddd<>&
EOS assert_equal expected, actual @config['caption_position']['table'] = 'bottom' actual = compile_block("//emtable[foo]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n//emtable{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n") expected = <<-EOS
aaabbb
cccddd<>&

foo

aaabbb
cccddd<>&
EOS assert_equal expected, actual end def test_imgtable def @chapter.image(_id) item = Book::Index::Item.new('sampleimg', 1, 'sample img') item.instance_eval { @path = './images/chap1-sampleimg.png' } item end actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n") expected = <<-EOS

表1.1: test for imgtable

test for imgtable
EOS assert_equal expected, actual @config['caption_position']['table'] = 'bottom' actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n") expected = <<-EOS
test for imgtable

表1.1: test for imgtable

EOS assert_equal expected, actual end def test_table_row_separator src = "//table{\n1\t2\t\t3 4| 5\n------------\na b\tc d |e\n//}\n" expected = <<-EOS
123 4| 5
a bc d |e
EOS actual = compile_block(src) assert_equal expected, actual @config['table_row_separator'] = 'singletab' actual = compile_block(src) expected = <<-EOS
123 4| 5
a bc d |e
EOS assert_equal expected, actual @config['table_row_separator'] = 'spaces' actual = compile_block(src) expected = <<-EOS
1234|5
abcd|e
EOS assert_equal expected, actual @config['table_row_separator'] = 'verticalbar' actual = compile_block(src) expected = <<-EOS
1 2 3 45
a b c de
EOS assert_equal expected, actual end def test_major_blocks actual = compile_block("//note{\nA\n\nB\n//}\n//note[caption]{\nA\n//}") expected = <<-EOS

A

B

caption

A

EOS assert_equal expected, actual actual = compile_block("//memo{\nA\n\nB\n//}\n//memo[caption]{\nA\n//}") expected = <<-EOS

A

B

caption

A

EOS assert_equal expected, actual actual = compile_block("//info{\nA\n\nB\n//}\n//info[caption]{\nA\n//}") expected = <<-EOS

A

B

caption

A

EOS assert_equal expected, actual actual = compile_block("//important{\nA\n\nB\n//}\n//important[caption]{\nA\n//}") expected = <<-EOS

A

B

caption

A

EOS assert_equal expected, actual actual = compile_block("//caution{\nA\n\nB\n//}\n//caution[caption]{\nA\n//}") expected = <<-EOS

A

B

caption

A

EOS assert_equal expected, actual actual = compile_block("//notice{\nA\n\nB\n//}\n//notice[caption]{\nA\n//}") expected = <<-EOS

A

B

caption

A

EOS assert_equal expected, actual actual = compile_block("//warning{\nA\n\nB\n//}\n//warning[caption]{\nA\n//}") expected = <<-EOS

A

B

caption

A

EOS assert_equal expected, actual actual = compile_block("//tip{\nA\n\nB\n//}\n//tip[caption]{\nA\n//}") expected = <<-EOS

A

B

caption

A

EOS assert_equal expected, actual end def test_minicolumn_blocks %w[note memo tip info warning important caution notice].each do |type| src = <<-EOS //#{type}[#{type}1]{ //} //#{type}[#{type}2]{ //} EOS expected = <<-EOS

#{type}1

#{type}2

EOS assert_equal expected, compile_block(src) src = <<-EOS //#{type}[#{type}2]{ //} //#{type}[#{type}3]{ //} //#{type}[#{type}4]{ //} //#{type}[#{type}5]{ //} //#{type}[#{type}6]{ //} EOS expected = <<-EOS

#{type}2

#{type}3

#{type}4

#{type}5

#{type}6

EOS assert_equal expected, compile_block(src) src = <<-EOS //#{type}{ * A 1. B //} //#{type}[OMITEND1]{ //emlist{ LIST //} //} //#{type}[OMITEND2]{ //} EOS expected = <<-EOS
  • A
  1. B

OMITEND1

LIST

OMITEND2

EOS assert_equal expected, compile_block(src) end end def test_minicolumn_blocks_nest_error1 %w[note memo tip info warning important caution notice].each do |type| @builder.doc_status.clear src = <<-EOS //#{type}{ //#{type}{ //} //} EOS assert_raises(ReVIEW::ApplicationError) { compile_block(src) } assert_match(/minicolumn cannot be nested:/, @log_io.string) end end def test_minicolumn_blocks_nest_error2 %w[note memo tip info warning important caution notice].each do |type| @builder.doc_status.clear src = <<-EOS //#{type}{ //#{type}{ //} //} EOS assert_raises(ReVIEW::ApplicationError) { compile_block(src) } assert_match(/minicolumn cannot be nested:/, @log_io.string) end end def test_minicolumn_blocks_nest_error3 %w[memo tip info warning important caution notice].each do |type| @builder.doc_status.clear src = <<-EOS //#{type}{ //note{ //} //} EOS assert_raises(ReVIEW::ApplicationError) { compile_block(src) } assert_match(/minicolumn cannot be nested:/, @log_io.string) end end def test_comment actual = compile_block('//comment[コメント]') assert_equal '', actual end def test_comment_for_draft @config['draft'] = true actual = compile_block('//comment[コメント<]') assert_equal %Q(
コメント<
\n), actual actual = compile_block("//comment{\nA<>\nB&\n//}") assert_equal %Q(
A<>
B&
\n), actual end def test_inline_comment actual = compile_inline('test @{コメント} test2') assert_equal 'test test2', actual end def test_inline_comment_for_draft @config['draft'] = true actual = compile_inline('test @{コメント} test2') assert_equal %Q(test コメント test2), actual end def test_inline_fence actual = compile_inline('test @|@{$サンプル$}|') assert_equal 'test @<code>{$サンプル$}', actual end def test_inline_w Dir.mktmpdir do |dir| File.write(File.join(dir, 'words.csv'), <_@{BAZ}" EOB ) @book.config['words_file'] = File.join(dir, 'words.csv') actual = compile_block('@{F} @{B} @{B} @{N}') assert_equal %Q(

foo bar"\\<>_@<b>{BAZ} bar"\\<>_@<b>{BAZ} [missing word: N]

\n), actual assert_match(/WARN --: :1: word not bound: N/, @log_io.string) end end def test_inline_unknown assert_raises(ReVIEW::ApplicationError) { compile_block("@{n}\n") } assert_match(/unknown image: n/, @log_io.string) assert_raises(ReVIEW::ApplicationError) { compile_block("@{n}\n") } assert_match(/unknown footnote: n/, @log_io.string) assert_raises(ReVIEW::ApplicationError) { compile_block("@{n}\n") } assert_match(/unknown endnote: n/, @log_io.string) assert_raises(ReVIEW::ApplicationError) { compile_block("@{n}\n") } assert_match(/unknown headline: n/, @log_io.string) %w[list table column].each do |name| assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") } assert_match(/unknown #{name}: n/, @log_io.string) end %w[chap chapref title].each do |name| assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") } assert_match(/key not found: "n"/, @log_io.string) end end def test_texequation_plain src = <<-EOS //texequation{ e=mc^2 //} EOS expected = <<-EOS
e=mc^2
EOS actual = compile_block(src) assert_equal expected, actual end def test_texequation_with_caption src = <<-EOS @{emc2} //texequation[emc2][The Equivalence of Mass @{and} Energy]{ e=mc^2 //} EOS expected = <<-EOS

式1.1

式1.1: The Equivalence of Mass and Energy

e=mc^2
EOS actual = compile_block(src) assert_equal expected, actual @config['chapterlink'] = nil expected = <<-EOS

式1.1

式1.1: The Equivalence of Mass and Energy

e=mc^2
EOS actual = compile_block(src) assert_equal expected, actual @config['caption_position']['equation'] = 'bottom' expected = <<-EOS

式1.1

e=mc^2

式1.1: The Equivalence of Mass and Energy

EOS actual = compile_block(src) assert_equal expected, actual end def test_nest_error_close1 src = <<-EOS //beginchild EOS e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) } assert_equal ":1: //beginchild is shown, but previous element isn't ul, ol, or dl", e.message end def test_nest_error_close2 src = <<-EOS * foo //beginchild 1. foo //beginchild : foo //beginchild EOS e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) } assert_equal ':12: //beginchild of dl,ol,ul misses //endchild', e.message end def test_nest_error_close3 src = <<-EOS * foo //beginchild 1. foo //beginchild : foo //beginchild //endchild EOS e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) } assert_equal ':14: //beginchild of ol,ul misses //endchild', e.message end def test_nest_ul src = <<-EOS * UL1 //beginchild 1. UL1-OL1 2. UL1-OL2 * UL1-UL1 * UL1-UL2 : UL1-DL1 UL1-DD1 : UL1-DL2 UL1-DD2 //endchild * UL2 //beginchild UL2-PARA //endchild EOS expected = <<-EOS
  • UL1
    1. UL1-OL1
    2. UL1-OL2
    • UL1-UL1
    • UL1-UL2
    UL1-DL1
    UL1-DD1
    UL1-DL2
    UL1-DD2
  • UL2

    UL2-PARA

EOS actual = compile_block(src) assert_equal expected, actual end def test_nest_ol src = <<-EOS 1. OL1 //beginchild 1. OL1-OL1 2. OL1-OL2 * OL1-UL1 * OL1-UL2 : OL1-DL1 OL1-DD1 : OL1-DL2 OL1-DD2 //endchild 2. OL2 //beginchild OL2-PARA //endchild EOS expected = <<-EOS
  1. OL1
    1. OL1-OL1
    2. OL1-OL2
    • OL1-UL1
    • OL1-UL2
    OL1-DL1
    OL1-DD1
    OL1-DL2
    OL1-DD2
  2. OL2

    OL2-PARA

EOS actual = compile_block(src) assert_equal expected, actual end def test_nest_dl src = <<-EOS : DL1 //beginchild 1. DL1-OL1 2. DL1-OL2 * DL1-UL1 * DL1-UL2 : DL1-DL1 DL1-DD1 : DL1-DL2 DL1-DD2 //endchild : DL2 DD2 //beginchild * DD2-UL1 * DD2-UL2 DD2-PARA //endchild EOS expected = <<-EOS
DL1
  1. DL1-OL1
  2. DL1-OL2
  • DL1-UL1
  • DL1-UL2
DL1-DL1
DL1-DD1
DL1-DL2
DL1-DD2
DL2
DD2
  • DD2-UL1
  • DD2-UL2

DD2-PARA

EOS actual = compile_block(src) assert_equal expected, actual end def test_nest_multi src = <<-EOS 1. OL1 //beginchild 1. OL1-OL1 //beginchild * OL1-OL1-UL1 OL1-OL1-PARA //endchild 2. OL1-OL2 * OL1-UL1 //beginchild : OL1-UL1-DL1 OL1-UL1-DD1 OL1-UL1-PARA //endchild * OL1-UL2 //endchild EOS expected = <<-EOS
  1. OL1
    1. OL1-OL1
      • OL1-OL1-UL1

      OL1-OL1-PARA

    2. OL1-OL2
    • OL1-UL1
      OL1-UL1-DL1
      OL1-UL1-DD1

      OL1-UL1-PARA

    • OL1-UL2
EOS actual = compile_block(src) assert_equal expected, actual end end