test/test_latexbuilder.rb in review-1.2.0 vs test/test_latexbuilder.rb in review-1.3.0
- old
+ new
@@ -8,31 +8,31 @@
class LATEXBuidlerTest < Test::Unit::TestCase
include ReVIEW
def setup
@builder = LATEXBuilder.new()
- @param = {
+ @config = {
"secnolevel" => 2, # for IDGXMLBuilder, EPUBBuilder
"toclevel" => 2,
"inencoding" => "UTF-8",
"outencoding" => "UTF-8",
"stylesheet" => nil, # for EPUBBuilder
}
- ReVIEW.book.param = @param
+ ReVIEW.book.config = @config
@compiler = ReVIEW::Compiler.new(@builder)
- @chapter = Book::Chapter.new(nil, 1, 'chap1', nil, StringIO.new)
+ @chapter = Book::Chapter.new(Book::Base.new(nil), 1, 'chap1', nil, StringIO.new)
location = Location.new(nil, nil)
@builder.bind(@compiler, @chapter, location)
end
def test_headline_level1
@builder.headline(1,"test","this is test.")
assert_equal %Q|\\chapter{this is test.}\n\\label{chap:chap1}\n|, @builder.result
end
def test_headline_level1_without_secno
- @param["secnolevel"] = 0
+ @config["secnolevel"] = 0
@builder.headline(1,"test","this is test.")
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
@@ -40,23 +40,23 @@
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
+ assert_equal %Q|\\section{this is test.}\n\\label{sec:1-1}\n|, @builder.result
end
def test_headline_level3
@builder.headline(3,"test","this is test.")
- assert_equal %Q|\\subsection*{this is test.}\n|, @builder.result
+ assert_equal %Q|\\subsection*{this is test.}\n\\label{sec:1-0-1}\n|, @builder.result
end
def test_headline_level3_with_secno
- @param["secnolevel"] = 3
+ @config["secnolevel"] = 3
@builder.headline(3,"test","this is test.")
- assert_equal %Q|\\subsection{this is test.}\n|, @builder.result
+ assert_equal %Q|\\subsection{this is test.}\n\\label{sec:1-0-1}\n|, @builder.result
end
def test_label
@builder.label("label_test")
assert_equal %Q|\\label{label_test}\n|, @builder.result
@@ -95,15 +95,10 @@
def test_inline_br_with_other_strings
ret = @builder.compile_inline("abc@<br>{}def")
assert_equal %Q|abc\\\\\ndef|, ret
end
- def test_inline_u
- ret = @builder.compile_inline("abc@<u>{def}ghi")
- assert_equal %Q|abc\\Underline{def}ghi|, ret
- end
-
def test_inline_i
ret = @builder.compile_inline("abc@<i>{def}ghi")
assert_equal %Q|abc\\textit{def}ghi|, ret
end
@@ -190,10 +185,11 @@
def @chapter.headline_index
items = [Book::HeadlineIndex::Item.new("chap1|test", [1, 1], "te_st")]
Book::HeadlineIndex.new(items, self)
end
+ @config["secnolevel"] = 3
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_ruby_comma
@@ -204,10 +200,15 @@
def test_inline_uchar
ret = @builder.compile_inline("test @<uchar>{2460} test2")
assert_equal %Q|test \\UTF{2460} test2|, ret
end
+ def test_inline_idx
+ ret = @builder.compile_inline("@<idx>{__TEST%$}, @<hidx>{__TEST%$}")
+ assert_equal %Q|\\textunderscore{}\\textunderscore{}TEST\\%\\textdollar{}\\index{__TEST%$}, \\index{__TEST%$}|, 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
@@ -293,55 +294,55 @@
end
def test_image
def @chapter.image(id)
item = Book::ImageIndex::Item.new("sampleimg",1)
- item.instance_eval{@pathes=["./images/chap1-sampleimg.png"]}
+ item.instance_eval{@path="./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\\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 = Book::ImageIndex::Item.new("sampleimg",1)
- item.instance_eval{@pathes=["./images/chap1-sampleimg.png"]}
+ item.instance_eval{@path="./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\\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 = Book::ImageIndex::Item.new("sampleimg",1)
- item.instance_eval{@pathes=["./images/chap1-sampleimg.png"]}
+ item.instance_eval{@path="./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\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n|, @builder.raw_result
end
def test_indepimage
def @chapter.image(id)
item = Book::ImageIndex::Item.new("sampleimg",1)
- item.instance_eval{@pathes=["./images/chap1-sampleimg.png"]}
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
item
end
@builder.indepimage("sampleimg","sample photo",nil)
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 = Book::ImageIndex::Item.new("sampleimg",1)
- item.instance_eval{@pathes=["./images/chap1-sampleimg.png"]}
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
item
end
# FIXME: indepimage's caption should not be with a counter.
@builder.indepimage("sampleimg",nil,nil)
@@ -349,33 +350,33 @@
end
def test_indepimage_with_metric
def @chapter.image(id)
item = Book::ImageIndex::Item.new("sampleimg",1)
- item.instance_eval{@pathes=["./images/chap1-sampleimg.png"]}
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
item
end
@builder.indepimage("sampleimg","sample photo","scale=1.2")
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 = Book::ImageIndex::Item.new("sampleimg",1)
- item.instance_eval{@pathes=["./images/chap1-sampleimg.png"]}
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
item
end
@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\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n|, @builder.raw_result
end
def test_indepimage_without_caption_but_with_metric
def @chapter.image(id)
item = Book::ImageIndex::Item.new("sampleimg",1)
- item.instance_eval{@pathes=["./images/chap1-sampleimg.png"]}
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
item
end
# FIXME: indepimage's caption should not be with a counter.
@builder.indepimage("sampleimg",nil,"scale=1.2")
@@ -427,23 +428,28 @@
===[/column]
EOS
expect =<<-EOS
\\begin{reviewcolumn}
+\\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 expect, column_helper(review)
end
def test_column_2
review =<<-EOS
@@ -454,19 +460,22 @@
=== next level
EOS
expect =<<-EOS
\\begin{reviewcolumn}
+\\hypertarget{column:chap1:1}{}
\\reviewcolumnhead{}{test}
inside column
\\end{reviewcolumn}
\\subsection*{next level}
+\\label{sec:1-0-1}
EOS
+ @config["toclevel"] = 1
assert_equal expect, column_helper(review)
end
def test_column_3
review =<<-EOS
@@ -636,47 +645,34 @@
assert_equal "{-} {-}{-} {-}{-}{-} {-}{-}{-}{-}", ret
end
def test_block_raw0
@builder.raw("<>!\"\\n& ")
- expect =<<-EOS
-<>!"
-&
-EOS
+ expect = %Q(<>!\"\n& )
assert_equal expect.chomp, @builder.raw_result
end
def test_block_raw1
@builder.raw("|latex|<>!\"\\n& ")
- expect =<<-EOS
-<>!"
-&
-EOS
+ expect = %Q(<>!\"\n& )
assert_equal expect.chomp, @builder.raw_result
end
def test_block_raw2
@builder.raw("|html, latex|<>!\"\\n& ")
- expect =<<-EOS
-<>!\"
-&
-EOS
+ expect = %Q(<>!\"\n& )
assert_equal expect.chomp, @builder.raw_result
end
def test_block_raw3
@builder.raw("|html, idgxml|<>!\"\\n& ")
- expect =<<-EOS
-EOS
+ expect = ''
assert_equal expect.chomp, @builder.raw_result
end
def test_block_raw4
@builder.raw("|latex <>!\"\\n& ")
- expect =<<-EOS
-|latex <>!\"
-&
-EOS
+ expect = %Q(|latex <>!\"\n& )
assert_equal expect.chomp, @builder.raw_result
end
end