test/test_latexbuilder.rb in review-2.0.0.beta1 vs test/test_latexbuilder.rb in review-2.0.0
- old
+ new
@@ -1,24 +1,24 @@
# -*- coding: utf-8 -*-
require 'test_helper'
-require 'review/book'
require 'review/compiler'
+require 'review/book'
require 'review/latexbuilder'
require 'review/i18n'
class LATEXBuidlerTest < Test::Unit::TestCase
include ReVIEW
def setup
@builder = LATEXBuilder.new()
@config = ReVIEW::Configure.values
@config.merge!( {
- "secnolevel" => 2, # for IDGXMLBuilder, EPUBBuilder
+ "secnolevel" => 2, # for IDGXMLBuilder, EPUBBuilder
"toclevel" => 2,
- "inencoding" => "UTF-8",
- "outencoding" => "UTF-8",
- "stylesheet" => nil, # for EPUBBuilder
+ "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)
@@ -154,11 +154,11 @@
assert_equal %Q|abc\\reviewstrong{def}|, actual
end
def test_inline_u
actual = compile_inline("abc@<u>{def}ghi")
- assert_equal %Q|abc\\Underline{def}ghi|, actual
+ assert_equal %Q|abc\\reviewunderline{def}ghi|, actual
end
def test_inline_m
actual = compile_inline("abc@<m>{\\alpha^n = \inf < 2}ghi")
assert_equal "abc $\\alpha^n = inf < 2$ ghi", actual
@@ -209,12 +209,14 @@
actual = compile_inline("@<idx>{__TEST%$}, @<hidx>{__TEST%$}")
assert_equal %Q|\\textunderscore{}\\textunderscore{}TEST\\%\\textdollar{}\\index{__TEST%$}, \\index{__TEST%$}|, actual
end
def test_jis_x_0201_kana
+ # uplatex can handle half-width kana natively
actual = compile_inline("foo・カンジ、テスト")
- assert_equal %Q|foo\\aj半角{・}\\aj半角{カ}\\aj半角{ン}\\aj半角{シ}\\aj半角{゛}\\aj半角{、}テスト|, actual
+ assert_equal %Q|foo・カンジ、テスト|, actual
+ # assert_equal %Q|foo\\aj半角{・}\\aj半角{カ}\\aj半角{ン}\\aj半角{シ}\\aj半角{゛}\\aj半角{、}テスト|, actual
end
def test_dlist
actual = compile_block(": foo\n foo.\n bar.\n")
assert_equal %Q|\n\\begin{description}\n\\item[foo] \\mbox{} \\\\\nfoo.bar.\n\\end{description}\n|, actual
@@ -277,13 +279,38 @@
@config["tabwidth"] = 4
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
+ def test_emlistnum_caption
+ actual = compile_block("//emlistnum[cap1]{\nfoo\nbar\n\nbuz\n//}\n")
+ assert_equal %Q|\n\\reviewemlistcaption{cap1}\n\\begin{reviewemlist}\n 1: foo\n 2: bar\n 3: \n 4: buz\n\\end{reviewemlist}\n|, actual
+ end
+
+ def test_list
+ actual = compile_block("//list[id1][cap1]{\nfoo\nbar\n\nbuz\n//}\n")
+ assert_equal %Q|\\reviewlistcaption{リスト1.1: cap1}\n\\begin{reviewlist}\nfoo\nbar\n\nbuz\n\\end{reviewlist}\n|, actual
+ end
+
+ def test_list_lst
+ @book.config["highlight"] = {}
+ @book.config["highlight"]["latex"] = "listings"
+ actual = compile_block("//list[id1][cap1][sql]{\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n//}\n")
+ assert_equal %Q|\\begin{reviewlistlst}[caption={cap1},language={sql}]\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n\\end{reviewlistlst}\n|, actual
+ end
+
+ def test_list_lst_with_lang
+ @book.config["highlight"] = {}
+ @book.config["highlight"]["latex"] = "listings"
+ @book.config["highlight"]["lang"] = "sql"
+ actual = compile_block("//list[id1][cap1]{\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n//}\n")
+ assert_equal %Q|\\begin{reviewlistlst}[caption={cap1},language={sql}]\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n\\end{reviewlistlst}\n|, actual
+ end
+
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\\reviewlistcaption{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
+ 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_lst
@book.config["highlight"] = {}
@book.config["highlight"]["latex"] = "listings"
@@ -311,11 +338,11 @@
assert_equal %Q|\n\\begin{center}\nfoobar\n\nbuz\n\\end{center}\n|, actual
end
def test_noindent
actual = compile_block("//noindent\nfoo\nbar\n\nfoo2\nbar2\n")
- assert_equal %Q|\\noindent\nfoobar\n\nfoo2bar2\n|, actual
+ assert_equal %Q|\\noindent\nfoo\nbar\n\nfoo2\nbar2\n|, actual
end
def test_image
def @chapter.image(id)
item = Book::ImageIndex::Item.new("sampleimg",1)
@@ -336,10 +363,22 @@
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
end
+ def test_image_with_metric_width
+ def @chapter.image(id)
+ item = Book::ImageIndex::Item.new("sampleimg",1)
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
+ 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
+ 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
@@ -347,29 +386,30 @@
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
end
- def test_indepimage
+ def test_image_with_metric2_width
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
+ @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
end
- def test_indepimage_esc
+ 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[sean_2_10][sample photo][]\n")
+ 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
end
def test_indepimage_without_caption
def @chapter.image(id)
@@ -392,10 +432,22 @@
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
end
+ def test_indepimage_with_metric_width
+ def @chapter.image(id)
+ item = Book::ImageIndex::Item.new("sampleimg",1)
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
+ 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
+ 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
@@ -415,10 +467,35 @@
# 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
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",
+ 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
+ end
+
+ actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n")
+
+ assert_equal "\\begin{table}[h]\n"+
+ "\\reviewimgtablecaption{test for imgtable}\n"+
+ "\\label{table:chap1:sampleimg}\n"+
+ "\\begin{reviewimage}\n"+
+ "\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n"+
+ "\\end{reviewimage}\n"+
+ "\\end{table}\n",
+ actual
+ end
+
def test_bib
def @chapter.bibpaper(id)
Book::BibpaperIndex::Item.new("samplebib",1,"sample bib")
end
@@ -465,18 +542,20 @@
\\hypertarget{column:chap1:1}{}
\\reviewcolumnhead{}{prev column}
\\addcontentsline{toc}{subsection}{prev column}
inside prev column
+
\\end{reviewcolumn}
\\begin{reviewcolumn}
\\hypertarget{column:chap1:2}{}
\\reviewcolumnhead{}{test}
\\addcontentsline{toc}{subsection}{test}
inside column
+
\\end{reviewcolumn}
EOS
@config["toclevel"] = 3
assert_equal expected, column_helper(review)
end
@@ -494,11 +573,13 @@
\\begin{reviewcolumn}
\\hypertarget{column:chap1:1}{}
\\reviewcolumnhead{}{test}
inside column
+
\\end{reviewcolumn}
+
\\subsection*{next level}
\\label{sec:1-0-1}
EOS
@config["toclevel"] = 1
@@ -580,10 +661,11 @@
\\item AAA
\\begin{itemize}
\\item AA
\\end{itemize}
+
\\end{itemize}
EOS
actual = compile_block(src)
assert_equal expected, actual
end
@@ -602,15 +684,17 @@
\\item AAA
\\begin{itemize}
\\item AA
\\end{itemize}
+
\\item BBB
\\begin{itemize}
\\item BB
\\end{itemize}
+
\\end{itemize}
EOS
actual = compile_block(src)
assert_equal expected, actual
end
@@ -643,9 +727,43 @@
\\item AAA
\\item \\lbrack{}]BBB
\\end{enumerate}
EOS
actual = compile_block(src)
+ assert_equal expected, actual
+ end
+
+ def test_major_blocks
+ actual = compile_block("//note{\nA\n\nB\n//}\n//note[caption]{\nA\n//}")
+ expected = %Q(\\begin{reviewminicolumn}\nA\n\nB\n\\end{reviewminicolumn}\n\\begin{reviewminicolumn}\n\\reviewminicolumntitle{caption}\nA\n\\end{reviewminicolumn}\n)
+ assert_equal expected, actual
+
+ actual = compile_block("//memo{\nA\n\nB\n//}\n//memo[caption]{\nA\n//}")
+ expected = %Q(\\begin{reviewminicolumn}\nA\n\nB\n\\end{reviewminicolumn}\n\\begin{reviewminicolumn}\n\\reviewminicolumntitle{caption}\nA\n\\end{reviewminicolumn}\n)
+ assert_equal expected, actual
+
+ actual = compile_block("//info{\nA\n\nB\n//}\n//info[caption]{\nA\n//}")
+ expected = %Q(\\begin{reviewminicolumn}\nA\n\nB\n\\end{reviewminicolumn}\n\\begin{reviewminicolumn}\n\\reviewminicolumntitle{caption}\nA\n\\end{reviewminicolumn}\n)
+ assert_equal expected, actual
+
+ actual = compile_block("//important{\nA\n\nB\n//}\n//important[caption]{\nA\n//}")
+ expected = %Q(\\begin{reviewminicolumn}\nA\n\nB\n\\end{reviewminicolumn}\n\\begin{reviewminicolumn}\n\\reviewminicolumntitle{caption}\nA\n\\end{reviewminicolumn}\n)
+ assert_equal expected, actual
+
+ actual = compile_block("//caution{\nA\n\nB\n//}\n//caution[caption]{\nA\n//}")
+ expected = %Q(\\begin{reviewminicolumn}\nA\n\nB\n\\end{reviewminicolumn}\n\\begin{reviewminicolumn}\n\\reviewminicolumntitle{caption}\nA\n\\end{reviewminicolumn}\n)
+ assert_equal expected, actual
+
+ actual = compile_block("//notice{\nA\n\nB\n//}\n//notice[caption]{\nA\n//}")
+ expected = %Q(\\begin{reviewminicolumn}\nA\n\nB\n\\end{reviewminicolumn}\n\\begin{reviewminicolumn}\n\\reviewminicolumntitle{caption}\nA\n\\end{reviewminicolumn}\n)
+ assert_equal expected, actual
+
+ actual = compile_block("//warning{\nA\n\nB\n//}\n//warning[caption]{\nA\n//}")
+ expected = %Q(\\begin{reviewminicolumn}\nA\n\nB\n\\end{reviewminicolumn}\n\\begin{reviewminicolumn}\n\\reviewminicolumntitle{caption}\nA\n\\end{reviewminicolumn}\n)
+ assert_equal expected, actual
+
+ actual = compile_block("//tip{\nA\n\nB\n//}\n//tip[caption]{\nA\n//}")
+ expected = %Q(\\begin{reviewminicolumn}\nA\n\nB\n\\end{reviewminicolumn}\n\\begin{reviewminicolumn}\n\\reviewminicolumntitle{caption}\nA\n\\end{reviewminicolumn}\n)
assert_equal expected, actual
end
def test_inline_raw0
assert_equal "normal", compile_inline("@<raw>{normal}")