test/test_latexbuilder.rb in review-1.0.0 vs test/test_latexbuilder.rb in review-1.1.0

- old
+ new

@@ -1,5 +1,6 @@ +# -*- coding: utf-8 -*- require 'test_helper' require 'review/compiler' require 'review/book' require 'review/latexbuilder' @@ -8,18 +9,19 @@ def setup @builder = LATEXBuilder.new() @param = { "secnolevel" => 2, # for IDGXMLBuilder, EPUBBuilder + "toclevel" => 2, "inencoding" => "UTF-8", "outencoding" => "UTF-8", "subdirmode" => nil, "stylesheet" => nil, # for EPUBBuilder } ReVIEW.book.param = @param @compiler = ReVIEW::Compiler.new(@builder) - @chapter = Chapter.new(nil, 1, 'chap1', nil, StringIO.new) + @chapter = Book::Chapter.new(nil, 1, 'chap1', nil, StringIO.new) location = Location.new(nil, nil) @builder.bind(@compiler, @chapter, location) end def test_headline_level1 @@ -28,16 +30,16 @@ end def test_headline_level1_without_secno @param["secnolevel"] = 0 @builder.headline(1,"test","this is test.") - assert_equal %Q|\\chapter*{this is test.}\n\\label{chap:chap1}\n|, @builder.result + assert_equal %Q|\\chapter*{this is test.}\n\\addcontentsline{toc}{chapter}{this is test.}\n\\label{chap:chap1}\n|, @builder.result end def test_headline_level1_with_inlinetag @builder.headline(1,"test","this @<b>{is} test.<&\"_>") - assert_equal %Q|\\chapter{this \\textbf{is} test.\\textless{}\\&"\\textunderscore{}\\textgreater{}}\n\\label{chap:chap1}\n|, @builder.result + assert_equal %Q|\\chapter{this \\textbf{is} test.\\textless{}\\&\"\\textunderscore{}\\textgreater{}}\n\\label{chap:chap1}\n|, @builder.result end def test_headline_level2 @builder.headline(2,"test","this is test.") assert_equal %Q|\\section{this is test.}\n|, @builder.result @@ -78,10 +80,15 @@ def test_href_with_underscore ret = @builder.compile_inline('@<href>{http://example.com/aaa/bbb, AAA_BBB}') assert_equal %Q|\\href{http://example.com/aaa/bbb}{AAA\\textunderscore{}BBB}|, ret end + def test_href_mailto + ret = @builder.compile_inline('@<href>{mailto:takahashim@example.com, takahashim@example.com}') + assert_equal %Q|\\href{mailto:takahashim@example.com}{takahashim@example.com}|, ret + end + def test_inline_br ret = @builder.inline_br("") assert_equal %Q|\\\\\n|, ret end @@ -139,16 +146,16 @@ ret = @builder.compile_inline("test @<b>{inline<&;\\ test} test2") assert_equal %Q|test \\textbf{inline\\textless{}\\&;\\reviewbackslash{} test} test2|, ret end def test_inline_em ret = @builder.compile_inline("abc@<em>{def}") - assert_equal %Q|abc\\textbf{def}|, ret + assert_equal %Q|abc\\reviewem{def}|, ret end def test_inline_strong ret = @builder.compile_inline("abc@<strong>{def}") - assert_equal %Q|abc\\textbf{def}|, ret + assert_equal %Q|abc\\reviewstrong{def}|, ret end def test_inline_u ret = @builder.compile_inline("abc@<u>{def}ghi") assert_equal %Q|abc\\Underline{def}ghi|, ret @@ -164,11 +171,11 @@ assert_equal %Q|test \\texttt{inline test} test2|, ret end def test_inline_tt_endash ret = @builder.compile_inline("test @<tt>{in-line --test ---foo ----bar -----buz} --test2") - assert_equal %Q|test \\texttt{in-line {-}{-}test {-}{-}-foo {-}{-}{-}{-}bar {-}{-}{-}{-}-buz} --test2|, ret + assert_equal %Q|test \\texttt{in{-}line {-}{-}test {-}{-}{-}foo {-}{-}{-}{-}bar {-}{-}{-}{-}{-}buz} {-}{-}test2|, ret end def test_inline_tti ret = @builder.compile_inline("test @<tti>{inline test} test2") assert_equal %Q|test \\texttt{\\textit{inline test}} test2|, ret @@ -177,47 +184,83 @@ def test_inline_ttb ret = @builder.compile_inline("test @<ttb>{inline test} test2") assert_equal %Q|test \\texttt{\\textbf{inline test}} test2|, ret end + def test_inline_hd_chap + def @chapter.headline_index + items = [Book::HeadlineIndex::Item.new("chap1|test", [1, 1], "te_st")] + Book::HeadlineIndex.new(items, self) + end + + ret = @builder.compile_inline("test @<hd>{chap1|test} test2") + assert_equal %Q|test 「1.1.1 te\\textunderscore{}st」 test2|, ret + end + def test_inline_uchar ret = @builder.compile_inline("test @<uchar>{2460} test2") assert_equal %Q|test \\UTF{2460} test2|, ret end + def test_jis_x_0201_kana + ret = @builder.compile_inline("foo・カンジ、テスト") + assert_equal %Q|foo\\aj半角{・}\\aj半角{カ}\\aj半角{ン}\\aj半角{シ}\\aj半角{゛}\\aj半角{、}テスト|, ret + end + def test_dlist @builder.dl_begin @builder.dt "foo" @builder.dd ["foo.\n", "bar.\n"] @builder.dl_end assert_equal %Q|\n\\begin{description}\n\\item[foo] \\mbox{} \\\\\nfoo.\nbar.\n\\end{description}\n|, @builder.result end + def test_dlist_with_bracket + @builder.dl_begin + @builder.dt "foo[bar]" + @builder.dd ["foo.\n", "bar.\n"] + @builder.dl_end + assert_equal %Q|\n\\begin{description}\n\\item[foo\\lbrack{}bar\\rbrack{}] \\mbox{} \\\\\nfoo.\nbar.\n\\end{description}\n|, @builder.result + end + def test_cmd lines = ["foo", "bar", "","buz"] @builder.cmd(lines) - assert_equal %Q|\n\\begin{reviewcmd}\n\\begin{alltt}\nfoo\nbar\n\nbuz\n\\end{alltt}\n\\end{reviewcmd}\n|, @builder.result + assert_equal %Q|\n\\begin{reviewcmd}\nfoo\nbar\n\nbuz\n\\end{reviewcmd}\n|, @builder.result end def test_cmd_caption lines = ["foo", "bar", "","buz"] @builder.cmd(lines, "cap1") - assert_equal %Q|\n\\reviewcmdcaption{cap1}\n\\begin{reviewcmd}\n\\begin{alltt}\nfoo\nbar\n\nbuz\n\\end{alltt}\n\\end{reviewcmd}\n|, @builder.result + assert_equal %Q|\n\\reviewcmdcaption{cap1}\n\\begin{reviewcmd}\nfoo\nbar\n\nbuz\n\\end{reviewcmd}\n|, @builder.result end def test_emlist lines = ["foo", "bar", "","buz"] @builder.emlist(lines) - assert_equal %Q|\n\\begin{reviewemlist}\n\\begin{alltt}\nfoo\nbar\n\nbuz\n\\end{alltt}\n\\end{reviewemlist}\n|, @builder.result + assert_equal %Q|\n\\begin{reviewemlist}\nfoo\nbar\n\nbuz\n\\end{reviewemlist}\n|, @builder.result end def test_emlist_caption lines = ["foo", "bar", "","buz"] @builder.emlist(lines, "cap1") - assert_equal %Q|\n\\reviewemlistcaption{cap1}\n\\begin{reviewemlist}\n\\begin{alltt}\nfoo\nbar\n\nbuz\n\\end{alltt}\n\\end{reviewemlist}\n|, @builder.result + assert_equal %Q|\n\\reviewemlistcaption{cap1}\n\\begin{reviewemlist}\nfoo\nbar\n\nbuz\n\\end{reviewemlist}\n|, @builder.result end + def test_emlist_with_tab + lines = ["\tfoo", "\t\tbar", "","\tbuz"] + @builder.emlist(lines) + assert_equal %Q|\n\\begin{reviewemlist}\n foo\n bar\n\n buz\n\\end{reviewemlist}\n|, @builder.result + end + + def test_emlist_with_tab4 + lines = ["\tfoo", "\t\tbar", "","\tbuz"] + @builder.instance_eval{@tabwidth=4} + @builder.emlist(lines) + assert_equal %Q|\n\\begin{reviewemlist}\n foo\n bar\n\n buz\n\\end{reviewemlist}\n|, @builder.result + end + def test_quote lines = ["foo", "bar", "","buz"] @builder.quote(lines) assert_equal %Q|\n\\begin{quote}\nfoobar\n\nbuz\n\\end{quote}\n|, @builder.result end @@ -230,65 +273,69 @@ def test_flushright @builder.flushright(["foo", "bar", "","buz"]) assert_equal %Q|\n\\begin{flushright}\nfoobar\n\nbuz\n\\end{flushright}\n|, @builder.raw_result end + def test_centering + @builder.centering(["foo", "bar", "","buz"]) + assert_equal %Q|\n\\begin{center}\nfoobar\n\nbuz\n\\end{center}\n|, @builder.raw_result + end + def test_noindent @builder.noindent @builder.paragraph(["foo", "bar"]) @builder.paragraph(["foo2", "bar2"]) assert_equal %Q|\\noindent\nfoo\nbar\n\nfoo2\nbar2\n|, @builder.raw_result end def test_image def @chapter.image(id) - item = ImageIndex::Item.new("sampleimg",1) + item = Book::ImageIndex::Item.new("sampleimg",1) item.instance_eval{@pathes=["./images/chap1-sampleimg.png"]} item end @builder.image_image("sampleimg","sample photo",nil) - assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\label{image:chap1:sampleimg}\n\\caption{sample photo}\n\\end{reviewimage}\n|, @builder.raw_result + assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n|, @builder.raw_result end def test_image_with_metric def @chapter.image(id) - item = ImageIndex::Item.new("sampleimg",1) + item = Book::ImageIndex::Item.new("sampleimg",1) item.instance_eval{@pathes=["./images/chap1-sampleimg.png"]} item end @builder.image_image("sampleimg","sample photo","scale=1.2") - assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\label{image:chap1:sampleimg}\n\\caption{sample photo}\n\\end{reviewimage}\n|, @builder.raw_result + assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n|, @builder.raw_result end def test_image_with_metric2 def @chapter.image(id) - item = ImageIndex::Item.new("sampleimg",1) + item = Book::ImageIndex::Item.new("sampleimg",1) item.instance_eval{@pathes=["./images/chap1-sampleimg.png"]} item end @builder.image_image("sampleimg","sample photo","scale=1.2, html::class=\"sample\", latex::height=3cm") - assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[scale=1.2,height=3cm]{./images/chap1-sampleimg.png}\n\\label{image:chap1:sampleimg}\n\\caption{sample photo}\n\\end{reviewimage}\n|, @builder.raw_result + assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[scale=1.2,height=3cm]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n|, @builder.raw_result end def test_indepimage def @chapter.image(id) - item = ImageIndex::Item.new("sampleimg",1) + item = Book::ImageIndex::Item.new("sampleimg",1) item.instance_eval{@pathes=["./images/chap1-sampleimg.png"]} item end - # FIXME: indepimage's caption should not be with a counter. @builder.indepimage("sampleimg","sample photo",nil) - assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\end{reviewimage}\n|, @builder.raw_result + assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n|, @builder.raw_result end def test_indepimage_without_caption def @chapter.image(id) - item = ImageIndex::Item.new("sampleimg",1) + item = Book::ImageIndex::Item.new("sampleimg",1) item.instance_eval{@pathes=["./images/chap1-sampleimg.png"]} item end # FIXME: indepimage's caption should not be with a counter. @@ -296,35 +343,33 @@ assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\end{reviewimage}\n|, @builder.raw_result end def test_indepimage_with_metric def @chapter.image(id) - item = ImageIndex::Item.new("sampleimg",1) + item = Book::ImageIndex::Item.new("sampleimg",1) item.instance_eval{@pathes=["./images/chap1-sampleimg.png"]} item end - # FIXME: indepimage's caption should not be with a counter. @builder.indepimage("sampleimg","sample photo","scale=1.2") - assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\end{reviewimage}\n|, @builder.raw_result + assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n|, @builder.raw_result end def test_indepimage_with_metric2 def @chapter.image(id) - item = ImageIndex::Item.new("sampleimg",1) + item = Book::ImageIndex::Item.new("sampleimg",1) item.instance_eval{@pathes=["./images/chap1-sampleimg.png"]} item end - # FIXME: indepimage's caption should not be with a counter. @builder.indepimage("sampleimg","sample photo","scale=1.2, latex::height=3cm, html::class=\"sample\"") - assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[scale=1.2,height=3cm]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\end{reviewimage}\n|, @builder.raw_result + assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[scale=1.2,height=3cm]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n|, @builder.raw_result end def test_indepimage_without_caption_but_with_metric def @chapter.image(id) - item = ImageIndex::Item.new("sampleimg",1) + item = Book::ImageIndex::Item.new("sampleimg",1) item.instance_eval{@pathes=["./images/chap1-sampleimg.png"]} item end # FIXME: indepimage's caption should not be with a counter. @@ -332,32 +377,32 @@ assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\end{reviewimage}\n|, @builder.raw_result end def test_bib def @chapter.bibpaper(id) - BibpaperIndex::Item.new("samplebib",1,"sample bib") + Book::BibpaperIndex::Item.new("samplebib",1,"sample bib") end - assert_equal "[1]", @builder.inline_bib("samplebib") + assert_equal "\\reviewbibref{[1]}{bib:samplebib}", @builder.inline_bib("samplebib") end def test_bibpaper def @chapter.bibpaper(id) - BibpaperIndex::Item.new("samplebib",1,"sample bib") + Book::BibpaperIndex::Item.new("samplebib",1,"sample bib") end @builder.bibpaper(["a", "b"], "samplebib", "sample bib @<b>{bold}") - assert_equal %Q|[1] sample bib \\textbf{bold}\n\na\nb\n\n|, @builder.raw_result + assert_equal %Q|[1] sample bib \\textbf{bold}\n\\label{bib:samplebib}\n\nab\n|, @builder.raw_result end def test_bibpaper_without_body def @chapter.bibpaper(id) - BibpaperIndex::Item.new("samplebib",1,"sample bib") + Book::BibpaperIndex::Item.new("samplebib",1,"sample bib") end @builder.bibpaper([], "samplebib", "sample bib") - assert_equal %Q|[1] sample bib\n\n|, @builder.raw_result + assert_equal %Q|[1] sample bib\n\\label{bib:samplebib}\n\n|, @builder.raw_result end def column_helper(review) chap_singleton = class << @chapter; self; end chap_singleton.send(:define_method, :content) { review } @@ -444,22 +489,37 @@ \\end{itemize} EOS ul_helper(src, expect) end + def test_ul_with_bracket + src =<<-EOS + * AAA + * []BBB +EOS + expect =<<-EOS + +\\begin{itemize} +\\item AAA +\\item \\lbrack{}]BBB +\\end{itemize} +EOS + ul_helper(src, expect) + end + def test_cont src =<<-EOS * AAA -AA * BBB -BB EOS expect =<<-EOS \\begin{itemize} -\\item AAA-AA -\\item BBB-BB +\\item AAA{-}AA +\\item BBB{-}BB \\end{itemize} EOS ul_helper(src, expect) end @@ -509,10 +569,25 @@ \\end{itemize} EOS ul_helper(src, expect) end + def test_ol_with_bracket + src =<<-EOS + 1. AAA + 2. []BBB +EOS + expect =<<-EOS + +\\begin{enumerate} +\\item AAA +\\item \\lbrack{}]BBB +\\end{enumerate} +EOS + builder_helper(src, expect, :compile_olist) + end + def test_inline_raw0 assert_equal "normal", @builder.inline_raw("normal") end def test_inline_raw1 @@ -531,9 +606,14 @@ assert_equal "|latex body", @builder.inline_raw("|latex body") end def test_inline_raw5 assert_equal "nor\nmal", @builder.inline_raw("|latex|nor\\nmal") + end + + def test_inline_endash + ret = @builder.compile_inline("- -- --- ----") + assert_equal "{-} {-}{-} {-}{-}{-} {-}{-}{-}{-}", ret end def test_block_raw0 @builder.raw("<>!\"\\n& ") expect =<<-EOS