test/test_latexbuilder.rb in review-2.1.0 vs test/test_latexbuilder.rb in review-2.2.0

- old
+ new

@@ -9,17 +9,17 @@ include ReVIEW def setup @builder = LATEXBuilder.new() @config = ReVIEW::Configure.values - @config.merge!( { - "secnolevel" => 2, # for IDGXMLBuilder, EPUBBuilder - "toclevel" => 2, - "stylesheet" => nil, # for EPUBBuilder - "image_scale2width" => false, - "texcommand" => "uplatex" - }) + @config.merge!({ + "secnolevel" => 2, # for IDGXMLBuilder, EPUBBuilder + "toclevel" => 2, + "stylesheet" => nil, # for EPUBBuilder + "image_scale2width" => false, + "texcommand" => "uplatex" + }) @book = Book::Base.new(nil) @book.config = @config @compiler = ReVIEW::Compiler.new(@builder) @chapter = Book::Chapter.new(@book, 1, 'chap1', nil, StringIO.new) location = Location.new(nil, nil) @@ -142,10 +142,11 @@ def test_inline_b_and_escape actual = compile_inline("test @<b>{inline<&;\\ test} test2") assert_equal %Q|test \\textbf{inline\\textless{}\\&;\\reviewbackslash{} test} test2|, actual end + def test_inline_em actual = compile_inline("abc@<em>{def}") assert_equal %Q|abc\\reviewem{def}|, actual end @@ -162,10 +163,17 @@ def test_inline_m actual = compile_inline("abc@<m>{\\alpha^n = \inf < 2}ghi") assert_equal "abc $\\alpha^n = inf < 2$ ghi", actual end + def test_inline_m2 + ## target text: @<m>{X = \{ {x_1\},{x_2\}, \cdots ,{x_n\} \\\}} + actual = compile_inline('@<m>{X = \\{ {x_1\\},{x_2\\}, \\cdots ,{x_n\\} \\\\\\}}') + ## expected text: $X = \{ {x_1},{x_2}, \cdots ,{x_n} \}$ + assert_equal ' $X = \\{ {x_1},{x_2}, \\cdots ,{x_n} \\}$ ', actual + end + def test_inline_tt actual = compile_inline("test @<tt>{inline test} test2") assert_equal %Q|test \\texttt{inline test} test2|, actual end @@ -205,13 +213,31 @@ assert_equal %Q|test \\UTF{2460} test2|, actual end def test_inline_idx actual = compile_inline("@<idx>{__TEST%$}, @<hidx>{__TEST%$}") - assert_equal %Q|\\textunderscore{}\\textunderscore{}TEST\\%\\textdollar{}\\index{__TEST%$}, \\index{__TEST%$}|, actual + assert_equal %Q|\\textunderscore{}\\textunderscore{}TEST\\%\\textdollar{}\\index{__TEST%$@\\textunderscore{}\\textunderscore{}TEST\\%\\textdollar{}}, \\index{__TEST%$@\\textunderscore{}\\textunderscore{}TEST\\%\\textdollar{}}|, actual end + def test_inline_idx_yomi + begin + require 'MeCab' + require 'nkf' + rescue LoadError + $stderr.puts "skip test_inline_idx_yomi (cannot find MeCab)" + return true + end + tmpdir = Dir.mktmpdir + File.write("#{tmpdir}/sample.dic", "強運\tはーどらっく\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 + end + def test_jis_x_0201_kana # uplatex can handle half-width kana natively actual = compile_inline("foo・カンジ、テスト") assert_equal %Q|foo・カンジ、テスト|, actual # assert_equal %Q|foo\\aj半角{・}\\aj半角{カ}\\aj半角{ン}\\aj半角{シ}\\aj半角{゛}\\aj半角{、}テスト|, actual @@ -309,17 +335,41 @@ def test_listnum actual = compile_block("//listnum[test1][ruby]{\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n//}\n") assert_equal %Q|\\reviewlistcaption{リスト1.1: ruby}\n\\begin{reviewlist}\n 1: class Foo\n 2: def foo\n 3: bar\n 4: \n 5: buz\n 6: end\n 7: end\n\\end{reviewlist}\n|, actual end + def test_listnum_linenum + actual = compile_block("//firstlinenum[100]\n//listnum[test1][ruby]{\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n//}\n") + assert_equal %Q|\\reviewlistcaption{リスト1.1: ruby}\n\\begin{reviewlist}\n100: class Foo\n101: def foo\n102: bar\n103: \n104: buz\n105: end\n106: end\n\\end{reviewlist}\n|, actual + end + def test_listnum_lst @book.config["highlight"] = {} @book.config["highlight"]["latex"] = "listings" actual = compile_block("//listnum[test1][ruby]{\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n//}\n") assert_equal %Q|\\begin{reviewlistnumlst}[caption={ruby},language={}]\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n\\end{reviewlistnumlst}\n|, actual end + def test_listnum_lst_linenum + @book.config["highlight"] = {} + @book.config["highlight"]["latex"] = "listings" + actual = compile_block("//firstlinenum[100]\n//listnum[test1][ruby]{\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n//}\n") + assert_equal %Q|\\begin{reviewlistnumlst}[caption={ruby},language={},firstnumber=100]\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n\\end{reviewlistnumlst}\n|, actual + end + + def test_source + actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n") + assert_equal %Q|\\reviewsourcecaption{foo/bar/test.rb}\n\\begin{reviewsource}\nfoo\nbar\n\nbuz\n\\end{reviewsource}\n|, actual + end + + def test_source_lst + @book.config["highlight"] = {} + @book.config["highlight"]["latex"] = "listings" + actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n") + assert_equal %Q|\\begin{reviewsourcelst}[title={foo/bar/test.rb},language={}]\nfoo\nbar\n\nbuz\n\\end{reviewsourcelst}\n|, actual + end + def test_quote actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n") assert_equal %Q|\n\\begin{quote}\nfoobar\n\nbuz\n\\end{quote}\n|, actual end @@ -473,10 +523,27 @@ actual = compile_block("//table{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n") assert_equal "\\begin{reviewtable}{|l|l|}\n\\hline\n\\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline\nccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline\n\\end{reviewtable}\n", actual end + def test_customize_cellwidth + actual = compile_block("//tsize[2,3,5]\n//table{\nA\tB\tC\n//}\n") + assert_equal %Q(\\begin{reviewtable}{|p{2mm}|p{3mm}|p{5mm}|}\n\\hline\n\\reviewth{A} & B & C \\\\ \\hline\n\\end{reviewtable}\n), actual + + actual = compile_block("//tsize[|latex,html|2,3,5]\n//table{\nA\tB\tC\n//}\n") + assert_equal %Q(\\begin{reviewtable}{|p{2mm}|p{3mm}|p{5mm}|}\n\\hline\n\\reviewth{A} & B & C \\\\ \\hline\n\\end{reviewtable}\n), actual + + actual = compile_block("//tsize[|html|2,3,5]\n//table{\nA\tB\tC\n//}\n") + assert_equal %Q(\\begin{reviewtable}{|l|l|l|}\n\\hline\n\\reviewth{A} & B & C \\\\ \\hline\n\\end{reviewtable}\n), actual + + actual = compile_block("//tsize[|latex|2,3,5]\n//table{\nA\tB\tC\n//}\n") + assert_equal %Q(\\begin{reviewtable}{|p{2mm}|p{3mm}|p{5mm}|}\n\\hline\n\\reviewth{A} & B & C \\\\ \\hline\n\\end{reviewtable}\n), actual + + actual = compile_block("//tsize[|latex||p{5mm}|cr|]\n//table{\nA\tB\tC\n//}\n") + assert_equal %Q(\\begin{reviewtable}{|p{5mm}|cr|}\n\\hline\n\\reviewth{A} & B & C \\\\ \\hline\n\\end{reviewtable}\n), actual + end + def test_imgtable def @chapter.image(id) item = Book::ImageIndex::Item.new("sampleimg",1, 'sample img') item.instance_eval{@path="./images/chap1-sampleimg.png"} item @@ -847,6 +914,27 @@ actual = compile_block("//raw[|latex <>!\"\\n& ]\n") expected = %Q(|latex <>!\"\n& ) assert_equal expected, actual end + def test_comment + actual = compile_block("//comment[コメント]") + assert_equal %Q||, actual + end + + def test_comment_for_draft + @config["draft"] = true + actual = compile_block("//comment[コメント]") + assert_equal %Q|\\pdfcomment{コメント}\n|, actual + end + + def test_inline_comment + actual = compile_inline("test @<comment>{コメント} test2") + assert_equal %Q|test test2|, actual + end + + def test_inline_comment_for_draft + @config["draft"] = true + actual = compile_inline("test @<comment>{コメント} test2") + assert_equal %Q|test \\pdfcomment{コメント} test2|, actual + end end