test/test_latexbuilder.rb in review-5.0.0 vs test/test_latexbuilder.rb in review-5.1.0

- old
+ new

@@ -195,10 +195,20 @@ def test_inline_u actual = compile_inline('abc@<u>{def}ghi') assert_equal 'abc\\reviewunderline{def}ghi', actual end + def test_inline_ins + actual = compile_inline('abc@<ins>{def}ghi') + assert_equal 'abc\\reviewinsert{def}ghi', actual + end + + def test_inline_del + actual = compile_inline('abc@<del>{def}ghi') + assert_equal 'abc\\reviewstrike{def}ghi', actual + end + def test_inline_bou actual = compile_inline('傍点の@<bou>{テスト}です。') assert_equal '傍点の\\reviewbou{テスト}です。', actual end @@ -294,19 +304,71 @@ rescue LoadError $stderr.puts 'skip test_inline_idx_yomi (cannot find MeCab)' return true end tmpdir = Dir.mktmpdir - File.write(File.join(tmpdir, 'sample.dic'), "強運\tはーどらっく\n") + File.write(File.join(tmpdir, 'sample.dic'), "強運\tはーどらっく\nmain(ブロック)\tmain{|}\n") @book.config['pdfmaker']['makeindex'] = true @book.config['pdfmaker']['makeindex_dic'] = "#{tmpdir}/sample.dic" @builder.setup_index actual = compile_inline('@<hidx>{漢字}@<hidx>{強運}@<hidx>{項目@1<<>>項目@2}') - FileUtils.remove_entry_secure(tmpdir) assert_equal %Q(\\index{かんじ@漢字}\\index{はーどらっく@強運}\\index{こうもく"@1@項目"@1!こうもく"@2@項目"@2}), actual + actual = compile_inline('@<hidx>{main(ブロック)}@<hidx>{あいうえお{\}}') + FileUtils.remove_entry_secure(tmpdir) + assert_equal %Q(\\index{main{|}@main(ブロック)}\\index{あいうえお{}@あいうえお\\reviewleftcurlybrace{}\\reviewrightcurlybrace{}}), actual end + def test_inline_idx_escape + # as is + %w[a あ ' ( ) = ` + ; * : , . ? /].each do |c| + actual = @builder.index(c) + assert_equal %Q(\\index{#{c}}), actual + end + actual = @builder.index('[') + assert_equal %Q(\\index{[}), actual + actual = @builder.index(']') + assert_equal %Q(\\index{]}), actual + + # escape display string by " + %w[! " @].each do |c| + actual = @builder.index(c) + assert_equal %Q(\\index{"#{c}@"#{c}}), actual + end + + # escape display string by \ + %w[# % &].each do |c| + actual = @builder.index(c) + assert_equal %Q(\\index{#{c}@\\#{c}}), actual + end + + # escape display string by macro + actual = @builder.index('$') + assert_equal %Q(\\index{$@\\textdollar{}}), actual + actual = @builder.index('-') + assert_equal %Q(\\index{-@{-}}), actual + actual = @builder.index('~') + assert_equal %Q(\\index{~@\\textasciitilde{}}), actual + actual = @builder.index('^') + assert_equal %Q(\\index{^@\\textasciicircum{}}), actual + actual = @builder.index('\\') + assert_equal %Q(\\index{\\@\\reviewbackslash{}}), actual + actual = @builder.index('<') + assert_equal %Q(\\index{<@\\textless{}}), actual + actual = @builder.index('>') + assert_equal %Q(\\index{>@\\textgreater{}}), actual + actual = @builder.index('_') + assert_equal %Q(\\index{_@\\textunderscore{}}), actual + + # escape both sort key and display string + actual = @builder.index('{') + assert_equal %Q(\\index{{@\\reviewleftcurlybrace{}}), actual + actual = @builder.index('|') + assert_equal %Q(\\index{|@\\textbar{}}), actual + actual = @builder.index('}') + assert_equal %Q(\\index{}@\\reviewrightcurlybrace{}}), actual + end + def test_jis_x_0201_kana # uplatex can handle half-width kana natively actual = compile_inline('foo・カンジ、テスト') assert_equal 'foo・カンジ、テスト', actual # assert_equal %Q(foo\\aj半角{・}\\aj半角{カ}\\aj半角{ン}\\aj半角{シ}\\aj半角{゛}\\aj半角{、}テスト), actual @@ -1037,10 +1099,23 @@ \\label{image:chap1:sampleimg} \\reviewincludegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png} \\end{reviewimage} EOS assert_equal expected, actual + + actual = compile_block("//image[sampleimg][]{\n//}\n") + expected = <<-EOS +\\begin{reviewimage}%%sampleimg +\\reviewimagecaption{} +\\label{image:chap1:sampleimg} +\\reviewincludegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png} +\\end{reviewimage} +EOS + assert_equal expected, actual + + actual = compile_block("//image[sampleimg][][]{\n//}\n") + assert_equal expected, actual end def test_image_with_metric def @chapter.image(_id) item = Book::Index::Item.new('sampleimg', 1) @@ -1185,10 +1260,16 @@ \\begin{reviewimage}%%sampleimg \\reviewincludegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png} \\end{reviewimage} 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) @@ -1284,11 +1365,11 @@ end item end io = StringIO.new - @builder.instance_eval{ @logger = ReVIEW::Logger.new(io) } + @builder.instance_eval { @logger = ReVIEW::Logger.new(io) } actual = compile_block("//indepimage[sample_img_nofile_][sample photo]\n") expected = <<-EOS \\begin{reviewdummyimage} --[[path = sample\\textunderscore{}img\\textunderscore{}nofile\\textunderscore{} (not exist)]]-- @@ -1322,10 +1403,20 @@ \\end{reviewtable} \\end{table} EOS assert_equal expected, actual + actual = compile_block("//table[foo][]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n") + expected = <<-EOS +\\begin{reviewtable}{|l|l|} +\\hline +\\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline +ccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline +\\end{reviewtable} +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 \\begin{table}%%foo \\begin{reviewtable}{|l|l|} @@ -1489,10 +1580,22 @@ \\end{reviewimage} \\end{table} EOS assert_equal expected, actual + actual = compile_block("//imgtable[sampleimg][]{\n//}\n") + expected = <<-EOS +\\label{table:chap1:sampleimg} +\\begin{reviewimage}%%sampleimg +\\reviewincludegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png} +\\end{reviewimage} +EOS + assert_equal expected, actual + + actual = compile_block("//imgtable[sampleimg][][]{\n//}\n") + assert_equal expected, actual + @book.config['pdfmaker']['use_original_image_size'] = true actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n") expected = <<-EOS \\begin{table}[h]%%sampleimg @@ -2310,10 +2413,10 @@ EOB end @book.config['words_file'] = File.join(dir, 'words.csv') io = StringIO.new - @builder.instance_eval{ @logger = ReVIEW::Logger.new(io) } + @builder.instance_eval { @logger = ReVIEW::Logger.new(io) } actual = compile_block('@<w>{F} @<w>{B} @<wb>{B} @<w>{N}') expected = <<-EOS foo bar"\\reviewbackslash{}\\textless{}\\textgreater{}\\textunderscore{}@\\textless{}b\\textgreater{}\\{BAZ\\} \\reviewbold{bar"\\reviewbackslash{}\\textless{}\\textgreater{}\\textunderscore{}@\\textless{}b\\textgreater{}\\{BAZ\\}} [missing word: N] EOS