test/test_latexbuilder.rb in review-4.0.0 vs test/test_latexbuilder.rb in review-4.1.0
- old
+ new
@@ -12,14 +12,14 @@
@config = ReVIEW::Configure.values
@config.merge!(
'secnolevel' => 2, # for IDGXMLBuilder, EPUBBuilder
'toclevel' => 2,
'stylesheet' => nil, # for EPUBBuilder
- 'image_scale2width' => false,
'texcommand' => 'uplatex',
- 'review_version' => '3'
+ 'review_version' => '4'
)
+ @config['pdfmaker']['image_scale2width'] = nil
@book = Book::Base.new
@book.config = @config
@compiler = ReVIEW::Compiler.new(@builder)
@chapter = Book::Chapter.new(@book, 1, 'chap1', nil, StringIO.new)
location = Location.new(nil, nil)
@@ -245,12 +245,14 @@
assert_equal 'test \\reviewttb{inline test} test2', actual
end
def test_inline_hd_chap
def @chapter.headline_index
- items = [Book::Index::Item.new('chap1|test', [1, 1], 'te_st')]
- Book::HeadlineIndex.new(items, self)
+ item = Book::Index::Item.new('chap1|test', [1, 1], 'te_st')
+ idx = Book::HeadlineIndex.new(self)
+ idx.add_item(item)
+ idx
end
@config['secnolevel'] = 3
actual = compile_inline('test @<hd>{chap1|test} test2')
assert_equal 'test 「1.1.1 te\\textunderscore{}st」 test2', actual
@@ -280,13 +282,13 @@
actual = compile_inline('@<idx>{__TEST%$}, @<hidx>{__TEST%$}')
assert_equal '\\textunderscore{}\\textunderscore{}TEST\\%\\textdollar{}\\index{__TEST%$@\\textunderscore{}\\textunderscore{}TEST\\%\\textdollar{}}, \\index{__TEST%$@\\textunderscore{}\\textunderscore{}TEST\\%\\textdollar{}}', actual
end
def test_inline_idx_yomi
+ require 'nkf'
begin
require 'MeCab'
- require 'nkf'
rescue LoadError
$stderr.puts 'skip test_inline_idx_yomi (cannot find MeCab)'
return true
end
tmpdir = Dir.mktmpdir
@@ -384,10 +386,25 @@
\\end{itemize}
EOS
assert_equal expected, actual
end
+ def test_dt_inline
+ fn = Book::FootnoteIndex.parse(['//footnote[bar][bar]'])
+ @chapter.instance_eval { @footnote_index = fn }
+ actual = compile_block(" : foo@<fn>{bar}[]<>&@<m>$\\alpha[]$\n")
+
+ expected = <<-EOS
+
+\\begin{description}
+\\item[foo\\protect\\footnotemark{}\\lbrack{}\\rbrack{}\\textless{}\\textgreater{}\\&$\\alpha\\lbrack{}\\rbrack{}$] \\mbox{} \\\\
+
+\\end{description}
+EOS
+ assert_equal expected, actual
+ end
+
def test_cmd
actual = compile_block("//cmd{\nfoo\nbar\n\nbuz\n//}\n")
expected = <<-EOS
\\begin{reviewlistblock}
@@ -855,10 +872,24 @@
\\reviewimagecaption{sample photo}
\\label{image:chap1:sampleimg}
\\end{reviewimage}
EOS
assert_equal expected, actual
+
+ @book.config['pdfmaker']['use_original_image_size'] = true
+ actual = compile_block("//image[sampleimg][sample photo]{\n//}\n")
+ expected = <<-EOS
+\\begin{reviewimage}%%sampleimg
+\\reviewincludegraphics[ ]{./images/chap1-sampleimg.png}
+\\reviewimagecaption{sample photo}
+\\label{image:chap1:sampleimg}
+\\end{reviewimage}
+EOS
+ assert_equal expected, actual
+
+ actual = compile_block("//image[sampleimg][sample photo][]{\n//}\n")
+ assert_equal expected, actual
end
def test_image_with_metric
def @chapter.image(_id)
item = Book::Index::Item.new('sampleimg', 1)
@@ -873,29 +904,37 @@
\\reviewimagecaption{sample photo}
\\label{image:chap1:sampleimg}
\\end{reviewimage}
EOS
assert_equal expected, actual
+
+ @book.config['pdfmaker']['use_original_image_size'] = true
+ actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n")
+ assert_equal expected, actual
end
def test_image_with_metric_width
def @chapter.image(_id)
item = Book::Index::Item.new('sampleimg', 1)
item.instance_eval { @path = './images/chap1-sampleimg.png' }
item
end
- @config['image_scale2width'] = true
+ @config['pdfmaker']['image_scale2width'] = true
actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n")
expected = <<-EOS
\\begin{reviewimage}%%sampleimg
\\reviewincludegraphics[width=1.2\\maxwidth]{./images/chap1-sampleimg.png}
\\reviewimagecaption{sample photo}
\\label{image:chap1:sampleimg}
\\end{reviewimage}
EOS
assert_equal expected, actual
+
+ @book.config['pdfmaker']['use_original_image_size'] = true
+ actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n")
+ assert_equal expected, actual
end
def test_image_with_metric2
def @chapter.image(_id)
item = Book::Index::Item.new('sampleimg', 1)
@@ -910,29 +949,37 @@
\\reviewimagecaption{sample photo}
\\label{image:chap1:sampleimg}
\\end{reviewimage}
EOS
assert_equal expected, actual
+
+ @book.config['pdfmaker']['use_original_image_size'] = true
+ actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n")
+ assert_equal expected, actual
end
def test_image_with_metric2_width
def @chapter.image(_id)
item = Book::Index::Item.new('sampleimg', 1)
item.instance_eval { @path = './images/chap1-sampleimg.png' }
item
end
- @config['image_scale2width'] = true
+ @config['pdfmaker']['image_scale2width'] = true
actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n")
expected = <<-EOS
\\begin{reviewimage}%%sampleimg
\\reviewincludegraphics[width=1.2\\maxwidth,ignore=params]{./images/chap1-sampleimg.png}
\\reviewimagecaption{sample photo}
\\label{image:chap1:sampleimg}
\\end{reviewimage}
EOS
assert_equal expected, actual
+
+ @book.config['pdfmaker']['use_original_image_size'] = true
+ actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n")
+ assert_equal expected, actual
end
def test_indepimage
def @chapter.image(_id)
item = Book::Index::Item.new('sampleimg', 1)
@@ -946,10 +993,23 @@
\\reviewincludegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}
\\reviewindepimagecaption{図: sample photo}
\\end{reviewimage}
EOS
assert_equal expected, actual
+
+ @book.config['pdfmaker']['use_original_image_size'] = true
+ actual = compile_block("//indepimage[sampleimg][sample photo]\n")
+ expected = <<-EOS
+\\begin{reviewimage}%%sampleimg
+\\reviewincludegraphics[ ]{./images/chap1-sampleimg.png}
+\\reviewindepimagecaption{図: sample photo}
+\\end{reviewimage}
+EOS
+ assert_equal expected, actual
+
+ actual = compile_block("//indepimage[sampleimg][sample photo][]\n")
+ assert_equal expected, actual
end
def test_indepimage_without_caption
def @chapter.image(_id)
item = Book::Index::Item.new('sampleimg', 1)
@@ -980,28 +1040,36 @@
\\reviewincludegraphics[scale=1.2]{./images/chap1-sampleimg.png}
\\reviewindepimagecaption{図: sample photo}
\\end{reviewimage}
EOS
assert_equal expected, actual
+
+ @book.config['pdfmaker']['use_original_image_size'] = true
+ actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n")
+ assert_equal expected, actual
end
def test_indepimage_with_metric_width
def @chapter.image(_id)
item = Book::Index::Item.new('sampleimg', 1)
item.instance_eval { @path = './images/chap1-sampleimg.png' }
item
end
- @config['image_scale2width'] = true
+ @config['pdfmaker']['image_scale2width'] = true
actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n")
expected = <<-EOS
\\begin{reviewimage}%%sampleimg
\\reviewincludegraphics[width=1.2\\maxwidth]{./images/chap1-sampleimg.png}
\\reviewindepimagecaption{図: sample photo}
\\end{reviewimage}
EOS
assert_equal expected, actual
+
+ @book.config['pdfmaker']['use_original_image_size'] = true
+ actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n")
+ assert_equal expected, actual
end
def test_indepimage_with_metric2
def @chapter.image(_id)
item = Book::Index::Item.new('sampleimg', 1)
@@ -1015,10 +1083,14 @@
\\reviewincludegraphics[scale=1.2,ignore=params]{./images/chap1-sampleimg.png}
\\reviewindepimagecaption{図: sample photo}
\\end{reviewimage}
EOS
assert_equal expected, actual
+
+ @book.config['pdfmaker']['use_original_image_size'] = true
+ actual = compile_block(%Q(//indepimage[sampleimg][sample photo][scale=1.2, html::class="sample",latex::ignore=params]\n))
+ assert_equal expected, actual
end
def test_indepimage_without_caption_but_with_metric
def @chapter.image(_id)
item = Book::Index::Item.new('sampleimg', 1)
@@ -1032,10 +1104,14 @@
\\begin{reviewimage}%%sampleimg
\\reviewincludegraphics[scale=1.2]{./images/chap1-sampleimg.png}
\\end{reviewimage}
EOS
assert_equal expected, actual
+
+ @book.config['pdfmaker']['use_original_image_size'] = true
+ actual = compile_block("//indepimage[sampleimg][][scale=1.2]\n")
+ assert_equal expected, actual
end
def test_table
actual = compile_block("//table{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
expected = <<-EOS
@@ -1188,9 +1264,96 @@
\\label{table:chap1:sampleimg}
\\begin{reviewimage}%%sampleimg
\\reviewincludegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}
\\end{reviewimage}
\\end{table}
+EOS
+ assert_equal expected, actual
+
+ @book.config['pdfmaker']['use_original_image_size'] = true
+ actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n")
+
+ expected = <<-EOS
+\\begin{table}[h]%%sampleimg
+\\reviewimgtablecaption{test for imgtable}
+\\label{table:chap1:sampleimg}
+\\begin{reviewimage}%%sampleimg
+\\reviewincludegraphics[ ]{./images/chap1-sampleimg.png}
+\\end{reviewimage}
+\\end{table}
+EOS
+ assert_equal expected, actual
+
+ actual = compile_block("//imgtable[sampleimg][test for imgtable][]{\n//}\n")
+ assert_equal expected, actual
+ end
+
+ def test_imgtable_with_metrics
+ def @chapter.image(_id)
+ item = Book::Index::Item.new('sampleimg', 1, 'sample img')
+ item.instance_eval { @path = './images/chap1-sampleimg.png' }
+ item
+ end
+
+ actual = compile_block("//imgtable[sampleimg][test for imgtable][scale=1.2]{\n//}\n")
+ expected = <<-EOS
+\\begin{table}[h]%%sampleimg
+\\reviewimgtablecaption{test for imgtable}
+\\label{table:chap1:sampleimg}
+\\begin{reviewimage}%%sampleimg
+\\reviewincludegraphics[scale=1.2]{./images/chap1-sampleimg.png}
+\\end{reviewimage}
+\\end{table}
+EOS
+ assert_equal expected, actual
+
+ @book.config['pdfmaker']['use_original_image_size'] = true
+ actual = compile_block("//imgtable[sampleimg][test for imgtable][scale=1.2]{\n//}\n")
+ assert_equal expected, actual
+ end
+
+ def test_table_row_separator
+ src = "//table{\n1\t2\t\t3 4| 5\n------------\na b\tc d |e\n//}\n"
+ expected = <<-EOS
+\\begin{reviewtable}{|l|l|l|}
+\\hline
+\\reviewth{1} & \\reviewth{2} & \\reviewth{3 4\\textbar{} 5} \\\\ \\hline
+a b & c d \\textbar{}e & \\\\ \\hline
+\\end{reviewtable}
+EOS
+ actual = compile_block(src)
+ assert_equal expected, actual
+
+ @config['table_row_separator'] = 'singletab'
+ actual = compile_block(src)
+ expected = <<-EOS
+\\begin{reviewtable}{|l|l|l|l|}
+\\hline
+\\reviewth{1} & \\reviewth{2} & \\reviewth{} & \\reviewth{3 4\\textbar{} 5} \\\\ \\hline
+a b & c d \\textbar{}e & & \\\\ \\hline
+\\end{reviewtable}
+EOS
+ assert_equal expected, actual
+
+ @config['table_row_separator'] = 'spaces'
+ actual = compile_block(src)
+ expected = <<-EOS
+\\begin{reviewtable}{|l|l|l|l|l|}
+\\hline
+\\reviewth{1} & \\reviewth{2} & \\reviewth{3} & \\reviewth{4\\textbar{}} & \\reviewth{5} \\\\ \\hline
+a & b & c & d & \\textbar{}e \\\\ \\hline
+\\end{reviewtable}
+EOS
+ assert_equal expected, actual
+
+ @config['table_row_separator'] = 'verticalbar'
+ actual = compile_block(src)
+ expected = <<-EOS
+\\begin{reviewtable}{|l|l|}
+\\hline
+\\reviewth{1 2 3 4} & \\reviewth{5} \\\\ \\hline
+a b c d & e \\\\ \\hline
+\\end{reviewtable}
EOS
assert_equal expected, actual
end
def test_bib