test/test_latexbuilder.rb in review-2.4.0 vs test/test_latexbuilder.rb in review-2.5.0

- old
+ new

@@ -301,10 +301,15 @@ def test_emlist_caption actual = compile_block("//emlist[cap1]{\nfoo\nbar\n\nbuz\n//}\n") assert_equal %Q(\n\\reviewemlistcaption{cap1}\n\\begin{reviewemlist}\nfoo\nbar\n\nbuz\n\\end{reviewemlist}\n), actual end + def test_emlist_empty_caption + actual = compile_block("//emlist[]{\nfoo\nbar\n\nbuz\n//}\n") + assert_equal %Q(\n\\begin{reviewemlist}\nfoo\nbar\n\nbuz\n\\end{reviewemlist}\n), actual + end + def test_emlist_with_tab actual = compile_block("//emlist{\n\tfoo\n\t\tbar\n\n\tbuz\n//}\n") assert_equal %Q(\n\\begin{reviewemlist}\n foo\n bar\n\n buz\n\\end{reviewemlist}\n), actual end @@ -366,10 +371,15 @@ 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_empty_caption + actual = compile_block("//source[]{\nfoo\nbar\n\nbuz\n//}\n") + assert_equal %Q(\\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 @@ -393,10 +403,15 @@ def test_centering actual = compile_block("//centering{\nfoo\nbar\n\nbuz\n//}\n") assert_equal %Q(\n\\begin{center}\nfoobar\n\nbuz\n\\end{center}\n), actual end + def test_blankline + actual = compile_block("//blankline\nfoo\n") + assert_equal %Q(\\vspace*{\\baselineskip}\n\nfoo\n), actual + end + def test_noindent actual = compile_block("//noindent\nfoo\nbar\n\nfoo2\nbar2\n") assert_equal %Q(\\noindent\nfoo\nbar\n\nfoo2\nbar2\n), actual end @@ -406,22 +421,22 @@ item.instance_eval { @path = './images/chap1-sampleimg.png' } item end actual = compile_block("//image[sampleimg][sample photo]{\n//}\n") - 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), actual + assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual end def test_image_with_metric def @chapter.image(_id) item = Book::ImageIndex::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") - 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), actual + assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual end def test_image_with_metric_width def @chapter.image(_id) item = Book::ImageIndex::Item.new('sampleimg', 1) @@ -429,22 +444,22 @@ item end @config['image_scale2width'] = true actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n") - assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[width=1.2\\maxwidth]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual + assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[width=1.2\\maxwidth]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual end def test_image_with_metric2 def @chapter.image(_id) item = Book::ImageIndex::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") - assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[scale=1.2,ignore=params]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual + assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[scale=1.2,ignore=params]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual end def test_image_with_metric2_width def @chapter.image(_id) item = Book::ImageIndex::Item.new('sampleimg', 1) @@ -452,22 +467,22 @@ item end @config['image_scale2width'] = true actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n") - assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[width=1.2\\maxwidth,ignore=params]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual + assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[width=1.2\\maxwidth,ignore=params]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual end def test_indepimage def @chapter.image(_id) item = Book::ImageIndex::Item.new('sampleimg', 1) item.instance_eval { @path = './images/chap1-sampleimg.png' } item end actual = compile_block("//indepimage[sampleimg][sample photo]\n") - assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual + assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual end def test_indepimage_without_caption def @chapter.image(_id) item = Book::ImageIndex::Item.new('sampleimg', 1) @@ -475,22 +490,22 @@ item end # FIXME: indepimage's caption should not be with a counter. actual = compile_block("//indepimage[sampleimg]\n") - assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\end{reviewimage}\n), actual + assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\end{reviewimage}\n), actual end def test_indepimage_with_metric def @chapter.image(_id) item = Book::ImageIndex::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") - assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual + assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual end def test_indepimage_with_metric_width def @chapter.image(_id) item = Book::ImageIndex::Item.new('sampleimg', 1) @@ -498,22 +513,22 @@ item end @config['image_scale2width'] = true actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n") - assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[width=1.2\\maxwidth]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual + assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[width=1.2\\maxwidth]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual end def test_indepimage_with_metric2 def @chapter.image(_id) item = Book::ImageIndex::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)) - assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[scale=1.2,ignore=params]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual + assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[scale=1.2,ignore=params]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual end def test_indepimage_without_caption_but_with_metric def @chapter.image(_id) item = Book::ImageIndex::Item.new('sampleimg', 1) @@ -521,11 +536,11 @@ item end # FIXME: indepimage's caption should not be with a counter. actual = compile_block("//indepimage[sampleimg][][scale=1.2]\n") - assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\end{reviewimage}\n), actual + assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\end{reviewimage}\n), actual end def test_table 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", @@ -549,11 +564,11 @@ assert_equal %Q(\\begin{reviewtable}{|p{5mm}|cr|}\n\\hline\n\\reviewth{A} & B & C \\\\ \\hline\n\\end{reviewtable}\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") - assert_equal "\\begin{table}[h]\n\\reviewtablecaption*{foo}\n\\begin{reviewtable}{|l|l|}\n\\hline\n\\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline\nccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline\n\\end{reviewtable}\n\\end{table}\n\n\\begin{reviewtable}{|l|l|}\n\\hline\n\\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline\nccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline\n\\end{reviewtable}\n", + assert_equal "\\begin{table}[h]%%\n\\reviewtablecaption*{foo}\n\\begin{reviewtable}{|l|l|}\n\\hline\n\\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline\nccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline\n\\end{reviewtable}\n\\end{table}\n\n\\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_imgtable def @chapter.image(_id) @@ -563,14 +578,14 @@ end actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n") expected = <<-EOS -\\begin{table}[h] +\\begin{table}[h]%%sampleimg \\reviewimgtablecaption{test for imgtable} \\label{table:chap1:sampleimg} -\\begin{reviewimage} +\\begin{reviewimage}%%sampleimg \\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png} \\end{reviewimage} \\end{table} EOS assert_equal expected, actual @@ -956,10 +971,27 @@ def test_inline_fence actual = compile_inline('test @<code>|@<code>{$サンプル$}|') assert_equal 'test \\texttt{@\\textless{}code\\textgreater{}\\{\\textdollar{}サンプル\\textdollar{}\\}}', actual end + def test_inline_unknown + e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<img>{n}\n" } + assert_equal ':1: error: unknown image: n', e.message + e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<fn>{n}\n" } + assert_equal ':1: error: unknown footnote: n', e.message + e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<hd>{n}\n" } + assert_equal ':1: error: unknown headline: n', e.message + %w[list table column].each do |name| + e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<#{name}>{n}\n" } + assert_equal ":1: error: unknown #{name}: n", e.message + end + %w[chap chapref title].each do |name| + e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<#{name}>{n}\n" } + assert_equal ':1: error: key not found: "n"', e.message + end + end + def test_appendix_list @chapter.instance_eval do def on_appendix? true end @@ -995,11 +1027,11 @@ EOS expected = <<-EOS \\reviewtableref{A.1}{table:chap1:foo} -\\begin{table}[h] +\\begin{table}[h]%%foo \\reviewtablecaption{FOO} \\label{table:chap1:foo} \\begin{reviewtable}{|l|l|} \\hline \\reviewth{A} & B \\\\ \\hline @@ -1030,10 +1062,10 @@ EOS expected = <<-EOS \\reviewimageref{A.1}{image:chap1:sampleimg} -\\begin{reviewimage} +\\begin{reviewimage}%%sampleimg \\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png} \\caption{FOO} \\label{image:chap1:sampleimg} \\end{reviewimage} EOS