第1章 this is test.), actual
end
def test_headline_level1_without_secno
@config['secnolevel'] = 0
actual = compile_block("={test} this is test.\n")
assert_equal %Q(this is test.), actual
end
def test_headline_level2
actual = compile_block("=={test} this is test.\n")
assert_equal %Q(1.1 this is test.), actual
end
def test_headline_level3
actual = compile_block("==={test} this is test.\n")
assert_equal %Q(this is test.), actual
end
def test_headline_level3_with_secno
@config['secnolevel'] = 3
actual = compile_block("==={test} this is test.\n")
assert_equal %Q(1.0.1 this is test.), actual
end
def test_headline_secttags
@config['structuredxml'] = true
actual = compile_block("= HEAD1\n== HEAD1-1\n\n=== HEAD1-1-1\n\n== HEAD1-2\n\n==== HEAD1-2-0-1\n\n===== HEAD1-2-0-1-1\n\n== HEAD1-3\n")
expected = '第1章 HEAD1' +
'1.1 HEAD1-1' +
'HEAD1-1-1' +
'1.2 HEAD1-2' +
'HEAD1-2-0-1' +
'HEAD1-2-0-1-1' +
'1.3 HEAD1-3'
assert_equal expected, actual
end
def test_label
actual = compile_block("//label[label_test]\n")
assert_equal %Q(), actual
end
def test_inline_ref
actual = compile_inline('@{外部参照<>&}')
assert_equal %Q(「●● 外部参照<>&」), actual
end
def test_href
actual = compile_inline('@{http://github.com,GitHub}')
assert_equal %Q(GitHub), actual
end
def test_href_without_label
actual = compile_inline('@{http://github.com}')
assert_equal %Q(http://github.com), actual
end
def test_inline_href
actual = compile_inline('@{http://github.com, Git\\,Hub}')
assert_equal %Q(Git,Hub), actual
end
def test_inline_raw
actual = compile_inline('@{@{inline\\}}')
assert_equal %Q(@{inline}), actual
end
def test_inline_in_table
actual = compile_block("//table{\n@{1}\t@{2}\n------------\n@{3}\t@{4}<>&\n//}\n")
assert_equal %Q(
1
2
3
4<>&
), actual
end
def test_inline_in_table_without_header
actual = compile_block("//table{\n@{1}\t@{2}\n@{3}\t@{4}<>&\n//}\n")
assert_equal %Q(
1
2
3
4<>&
), actual
end
def test_inline_in_table_without_cellwidth
@config['tableopt'] = nil
actual = compile_block("//table{\n@{1}\t@{2}\n------------\n@{3}\t@{4}<>&\n//}\n")
assert_equal %Q(
1\t2
3\t4<>&
), actual
end
def test_inline_in_table_without_header_and_cellwidth
@config['tableopt'] = nil
actual = compile_block("//table{\n@{1}\t@{2}\n@{3}\t@{4}<>&\n//}\n")
assert_equal %Q(
1\t2
3\t4<>&
), actual
end
def test_table
actual = compile_block("//table{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
expected = <<-EOS.chomp
aaa
bbb
ccc
ddd<>&
EOS
assert_equal expected, actual
actual = compile_block("//table[foo][FOO]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
expected = <<-EOS.chomp
表1.1 FOO
aaa
bbb
ccc
ddd<>&
EOS
assert_equal expected, actual
@config['caption_position']['table'] = 'bottom'
actual = compile_block("//table[foo][FOO]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
expected = <<-EOS.chomp
aaa
bbb
ccc
ddd<>&
表1.1 FOO
EOS
assert_equal expected, actual
end
def test_customize_cellwidth
actual = compile_block("//tsize[2,3,5]\n//table{\nA\tB\tC\n//}\n")
assert_equal %Q(
A
B
C
), actual
actual = compile_block("//tsize[2,3]\n//table{\nA\tB\tC\n//}\n")
assert_equal %Q(
A
B
C
), actual
actual = compile_block("//tsize[2]\n//table{\nA\tB\tC\n//}\n")
assert_equal %Q(
A
B
C
), actual
actual = compile_block("//tsize[|idgxml|2]\n//table{\nA\tB\tC\n//}\n")
assert_equal %Q(
A
B
C
), actual
actual = compile_block("//tsize[|idgxml,html|2]\n//table{\nA\tB\tC\n//}\n")
assert_equal %Q(
A
B
C
), actual
actual = compile_block("//tsize[|html|2]\n//table{\nA\tB\tC\n//}\n")
assert_equal %Q(
A
B
C
), actual
end
def test_customize_mmtopt
actual = compile_block("//table{\nA\n//}\n")
assert_equal %Q(
A
), actual
@config['pt_to_mm_unit'] = 0.3514
actual = compile_block("//table{\nA\n//}\n")
assert_equal %Q(
A
), actual
@config['pt_to_mm_unit'] = '0.3514'
actual = compile_block("//table{\nA\n//}\n")
assert_equal %Q(
A
), actual
end
def test_empty_table
e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n//}\n") }
assert_equal ':2: error: no rows in the table', e.message
e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n------------\n//}\n") }
assert_equal ':3: error: no rows in the table', e.message
end
def test_emtable
actual = compile_block("//emtable[foo]{\nA\n//}\n//emtable{\nA\n//}")
assert_equal %Q(
foo
A
A
), actual
@config['caption_position']['table'] = 'bottom'
actual = compile_block("//emtable[foo]{\nA\n//}\n//emtable{\nA\n//}")
assert_equal %Q(
A
foo
A
), 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.chomp
1
2
3 4| 5
a b
c d |e
EOS
actual = compile_block(src)
assert_equal expected, actual
@config['table_row_separator'] = 'singletab'
actual = compile_block(src)
expected = <<-EOS.chomp
1
2
3 4| 5
a b
c d |e
EOS
assert_equal expected, actual
@config['table_row_separator'] = 'spaces'
actual = compile_block(src)
expected = <<-EOS.chomp
1
2
3
4|
5
a
b
c
d
|e
EOS
assert_equal expected, actual
@config['table_row_separator'] = 'verticalbar'
actual = compile_block(src)
expected = <<-EOS.chomp
1 2 3 4
5
a b c d
e
EOS
assert_equal expected, actual
end
def test_inline_br
actual = compile_inline('@ {}')
assert_equal "\n", actual
end
def test_inline_uchar
actual = compile_inline('test @{2460} test2')
assert_equal 'test ① test2', actual
end
def test_inline_ruby
actual = compile_inline('@{coffin, bed}')
assert_equal %Q(coffinbed), actual
end
def test_inline_kw
actual = compile_inline('@{ISO, International Organization for Standardization } @{Ruby<>}')
assert_equal %Q(ISO(International Organization for Standardization)Ruby<>), actual
end
def test_inline_maru
actual = compile_inline('@{1}@{20}@{A}@{z}')
assert_equal '①⑳Ⓐⓩ', actual
end
def test_inline_ttb
actual = compile_inline(%Q(@{test * <>"}))
assert_equal %Q(test * <>"), actual
end
def test_inline_ttbold
actual = compile_inline(%Q(@{test * <>"}))
assert_equal %Q(test * <>"), actual
end
def test_inline_balloon
actual = compile_inline('@{@maru[1]test}')
assert_equal '①test', actual
end
def test_inline_m
actual = compile_inline('@{\\sin} @{\\frac{1\\}{2\\}}')
assert_equal %Q(
\\sin
\\frac{1}{2}
), actual
end
def test_dlist_beforeulol
actual = compile_block(" : foo\n foo.\n\npara\n\n : foo\n foo.\n\n 1. bar\n\n : foo\n foo.\n\n * bar\n")
assert_equal %Q(
foo
foo.
para
foo
foo.
bar
foo
foo.
bar
), actual
end
def test_dt_inline
actual = compile_block("//footnote[bar][bar]\n\n : foo@{bar}[]<>&@$\\alpha[]$\n")
expected = <<-EOS.chomp
foobar[]<>&
\\alpha[]
EOS
assert_equal expected, actual
end
def test_paragraph
actual = compile_block("foo\nbar\n")
assert_equal '
foobar
', actual
@book.config['join_lines_by_lang'] = true
actual = compile_block("foo\nbar\n")
assert_equal '
foo bar
', actual
end
def test_tabbed_paragraph
actual = compile_block("\tfoo\nbar\n")
assert_equal %Q(
foobar
), actual
@book.config['join_lines_by_lang'] = true
actual = compile_block("\tfoo\nbar\n")
assert_equal %Q(
foo bar
), actual
end
def test_quote
actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n")
assert_equal '
foobar
buz
', actual
@book.config['join_lines_by_lang'] = true
actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n")
assert_equal '
foo bar
buz
', actual
end
def test_major_blocks
actual = compile_block("//note{\nA\n\nB\n//}\n//note[caption]{\nA\n//}")
expected = %Q(
A
B
caption
A
)
assert_equal expected, actual
actual = compile_block("//memo{\nA\n\nB\n//}\n//memo[caption]{\nA\n//}")
expected = %Q(
A
B
caption
A
)
assert_equal expected, actual
actual = compile_block("//info{\nA\n\nB\n//}\n//info[caption]{\nA\n//}")
expected = %Q(
A
B
caption
A
)
assert_equal expected, actual
actual = compile_block("//important{\nA\n\nB\n//}\n//important[caption]{\nA\n//}")
expected = %Q(
A
B
caption
A
)
assert_equal expected, actual
actual = compile_block("//caution{\nA\n\nB\n//}\n//caution[caption]{\nA\n//}")
expected = %Q(
A
B
caption
A
)
assert_equal expected, actual
# notice uses special tag notice-t if it includes caption
actual = compile_block("//notice{\nA\n\nB\n//}\n//notice[caption]{\nA\n//}")
expected = %Q(
A
B
caption
A
)
assert_equal expected, actual
actual = compile_block("//warning{\nA\n\nB\n//}\n//warning[caption]{\nA\n//}")
expected = %Q(
A
B
caption
A
)
assert_equal expected, actual
actual = compile_block("//tip{\nA\n\nB\n//}\n//tip[caption]{\nA\n//}")
expected = %Q(
A
B
caption
A
)
assert_equal expected, actual
end
def test_minicolumn_blocks
%w[note memo tip info warning important caution notice].each do |type|
src = <<-EOS
//#{type}[#{type}1]{
//}
//#{type}[#{type}2]{
//}
EOS
if type == 'notice' # exception pattern
expected = <<-EOS.chomp
<#{type}-t>#{type}1#{type}-t><#{type}-t>#{type}2#{type}-t>
EOS
else
expected = <<-EOS.chomp
<#{type}>#{type}1#{type}><#{type}>#{type}2#{type}>
EOS
end
assert_equal expected, compile_block(src)
src = <<-EOS
//#{type}[#{type}2]{
//}
//#{type}[#{type}3]{
//}
//#{type}[#{type}4]{
//}
//#{type}[#{type}5]{
//}
//#{type}[#{type}6]{
//}
EOS
if type == 'notice' # exception pattern
expected = <<-EOS.chomp
<#{type}-t>#{type}2#{type}-t><#{type}-t>#{type}3#{type}-t><#{type}-t>#{type}4#{type}-t><#{type}-t>#{type}5#{type}-t><#{type}-t>#{type}6#{type}-t>
EOS
else
expected = <<-EOS.chomp
<#{type}>#{type}2#{type}><#{type}>#{type}3#{type}><#{type}>#{type}4#{type}><#{type}>#{type}5#{type}><#{type}>#{type}6#{type}>
EOS
end
assert_equal expected, compile_block(src)
src = <<-EOS
//#{type}{
* A
1. B
//}
//#{type}[OMITEND1]{
//emlist{
LIST
//}
//}
//#{type}[OMITEND2]{
//}
EOS
if type == 'notice' # exception pattern
expected = <<-EOS.chomp
<#{type}>
A
B
#{type}><#{type}-t>OMITEND1
LIST
#{type}-t><#{type}-t>OMITEND2#{type}-t>
EOS
else
expected = <<-EOS.chomp
<#{type}>
A
B
#{type}><#{type}>OMITEND1
LIST
#{type}><#{type}>OMITEND2#{type}>
EOS
end
assert_equal expected, compile_block(src)
end
end
def test_minicolumn_blocks_nest_error1
%w[note memo tip info warning important caution notice].each do |type|
@builder.doc_status.clear
src = <<-EOS
//#{type}{
//#{type}{
//}
//}
EOS
e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
assert_match(/minicolumn cannot be nested:/, e.message)
end
end
def test_minicolumn_blocks_nest_error2
%w[note memo tip info warning important caution notice].each do |type|
@builder.doc_status.clear
src = <<-EOS
//#{type}{
//#{type}{
//}
//}
EOS
e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
assert_match(/minicolumn cannot be nested:/, e.message)
end
end
def test_minicolumn_blocks_nest_error3
%w[memo tip info warning important caution notice].each do |type|
@builder.doc_status.clear
src = <<-EOS
//#{type}{
//note{
//}
//}
EOS
e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
assert_match(/minicolumn cannot be nested:/, e.message)
end
end
def test_term
actual = compile_block("//term{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
assert_equal '
test1test1.5
test2
', actual
@book.config['join_lines_by_lang'] = true
actual = compile_block("//term{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
assert_equal '
test1 test1.5
test2
', actual
end
def test_point
actual = compile_block("//point[this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
assert_equal %Q(this is test<&>_
test1test1.5
test2
), actual
@book.config['join_lines_by_lang'] = true
actual = compile_block("//point[this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
assert_equal %Q(this is test<&>_
test1 test1.5
test2
), actual
end
def test_point_without_caption
actual = compile_block("//point{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
assert_equal '
test1test1.5
test2
', actual
@book.config['join_lines_by_lang'] = true
actual = compile_block("//point{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
assert_equal '
test1 test1.5
test2
', actual
end
def test_emlist
actual = compile_block("//emlist[this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
assert_equal %Q(
this is test<&>_
test1\ntest1.5\n\ntest2\n
), actual
@config['caption_position']['list'] = 'bottom'
actual = compile_block("//emlist[this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
assert_equal %Q(
test1\ntest1.5\n\ntest2\n
this is test<&>_
), actual
end
def test_emlistnum
actual = compile_block("//emlistnum[this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
assert_equal %Q(
this is test<&>_
1: test1\n 2: test1.5\n 3: \n 4: test2\n
), actual
@config['caption_position']['list'] = 'bottom'
actual = compile_block("//emlistnum[this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
assert_equal %Q(
1: test1\n 2: test1.5\n 3: \n 4: test2\n
this is test<&>_
), actual
end
def test_emlist_listinfo
@config['listinfo'] = true
actual = compile_block("//emlist[this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
expected = <<-EOS.chomp
this is test<&>_
test1
test1.5
test2
EOS
assert_equal expected, actual
end
def test_emlist_with_tab
actual = compile_block("//emlist[this is @{test}<&>_]{\n\ttest1\n\t\ttest1.5\n\n\ttest@{2}\n//}\n")
expected = <<-EOS.chomp
this is test<&>_
test1
test1.5
test2
EOS
assert_equal expected, actual
end
def test_emlist_with_4tab
@config['tabwidth'] = 4
actual = compile_block("//emlist[this is @{test}<&>_]{\n\ttest1\n\t\ttest1.5\n\n\ttest@{2}\n//}\n")
expected = <<-EOS.chomp
this is test<&>_
test1
test1.5
test2
EOS
assert_equal expected, actual
end
def test_list
def @chapter.list(_id)
Book::Index::Item.new('samplelist', 1)
end
actual = compile_block("//list[samplelist][this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
expected = <<-EOS.chomp
リスト1.1 this is test<&>_
test1
test1.5
test2
EOS
assert_equal expected, actual
@config['caption_position']['list'] = 'bottom'
actual = compile_block("//list[samplelist][this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
expected = <<-EOS.chomp
test1
test1.5
test2
リスト1.1 this is test<&>_
EOS
assert_equal expected, actual
end
def test_listnum
def @chapter.list(_id)
Book::Index::Item.new('samplelist', 1)
end
actual = compile_block("//listnum[samplelist][this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
expected = <<-EOS.chomp
リスト1.1 this is test<&>_
1: test1
2: test1.5
3: 4: test2
EOS
assert_equal expected, actual
@config['caption_position']['list'] = 'bottom'
actual = compile_block("//listnum[samplelist][this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
expected = <<-EOS.chomp
1: test1
2: test1.5
3: 4: test2
リスト1.1 this is test<&>_
EOS
assert_equal expected, actual
end
def test_listnum_linenum
def @chapter.list(_id)
Book::Index::Item.new('samplelist', 1)
end
actual = compile_block("//firstlinenum[100]\n//listnum[samplelist][this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
expected = <<-EOS.chomp
リスト1.1 this is test<&>_
100: test1
101: test1.5
102: 103: test2
EOS
assert_equal expected, actual
@config['caption_position']['list'] = 'bottom'
actual = compile_block("//firstlinenum[100]\n//listnum[samplelist][this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
expected = <<-EOS.chomp
100: test1
101: test1.5
102: 103: test2
リスト1.1 this is test<&>_
EOS
assert_equal expected, actual
end
def test_list_listinfo
def @chapter.list(_id)
Book::Index::Item.new('samplelist', 1)
end
@config['listinfo'] = true
actual = compile_block("//list[samplelist][this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
expected = <<-EOS.chomp
リスト1.1 this is test<&>_
test1
test1.5
test2
EOS
assert_equal expected, actual
@config['caption_position']['list'] = 'bottom'
actual = compile_block("//list[samplelist][this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
expected = <<-EOS.chomp
test1
test1.5
test2
リスト1.1 this is test<&>_
EOS
assert_equal expected, actual
end
def test_cmd
actual = compile_block("//cmd{\nlineA\nlineB\n//}\n")
expected = <<-EOS.chomp
lineA
lineB
EOS
assert_equal expected, actual
actual = compile_block("//cmd[cap1]{\nlineA\nlineB\n//}\n")
expected = <<-EOS.chomp
cap1
lineA
lineB
EOS
assert_equal expected, actual
@config['caption_position']['list'] = 'bottom'
actual = compile_block("//cmd[cap1]{\nlineA\nlineB\n//}\n")
expected = <<-EOS.chomp
lineA
lineB
cap1
EOS
assert_equal expected, actual
end
def test_source
actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n")
expected = <<-EOS.chomp
EOS
assert_equal expected, actual
@config['caption_position']['list'] = 'bottom'
actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n")
expected = <<-EOS.chomp
EOS
assert_equal expected, actual
end
def test_source_empty_caption
actual = compile_block("//source[]{\nfoo\nbar\n\nbuz\n//}\n")
expected = <<-EOS.chomp
EOS
assert_equal expected, actual
end
def test_source_nil_caption
actual = compile_block("//source{\nfoo\nbar\n\nbuz\n//}\n")
expected = <<-EOS.chomp
EOS
assert_equal expected, actual
end
def test_insn
@config['listinfo'] = true
actual = compile_block("//insn[this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
expected = <<-EOS.chomp
this is test<&>_test1
test1.5
test2
EOS
assert_equal expected, actual
@config['caption_position']['list'] = 'bottom'
actual = compile_block("//insn[this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
expected = <<-EOS.chomp
test1
test1.5
test2this is test<&>_
EOS
assert_equal expected, actual
end
def test_box
@config['listinfo'] = true
actual = compile_block("//box[this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
expected = <<-EOS.chomp
this is test<&>_
test1
test1.5
test2
EOS
assert_equal expected, actual
@config['caption_position']['list'] = 'bottom'
actual = compile_block("//box[this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
expected = <<-EOS.chomp
test1
test1.5
test2
this is test<&>_
EOS
assert_equal expected, actual
end
def test_box_non_listinfo
@config['listinfo'] = nil
actual = compile_block("//box[this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
expected = <<-EOS.chomp
this is test<&>_
test1
test1.5
test2
EOS
assert_equal expected, actual
@config['caption_position']['list'] = 'bottom'
actual = compile_block("//box[this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
expected = <<-EOS.chomp
test1
test1.5
test2
this is test<&>_
EOS
assert_equal expected, actual
end
def test_flushright
actual = compile_block("//flushright{\nfoo\nbar\n\nbuz\n//}\n")
assert_equal %Q(
foobar
buz
), actual
@book.config['join_lines_by_lang'] = true
actual = compile_block("//flushright{\nfoo\nbar\n\nbuz\n//}\n")
assert_equal %Q(
foo bar
buz
), actual
end
def test_centering
actual = compile_block("//centering{\nfoo\nbar\n\nbuz\n//}\n")
assert_equal %Q(
foobar
buz
), actual
@book.config['join_lines_by_lang'] = true
actual = compile_block("//centering{\nfoo\nbar\n\nbuz\n//}\n")
assert_equal %Q(
foo bar
buz
), actual
end
def test_blankline
actual = compile_block("//blankline\nfoo\n")
assert_equal %Q(
foo
), actual
end
def test_noindent
actual = compile_block("//noindent\nfoo\nbar\n\nfoo2\nbar2\n")
assert_equal %Q(
foobar
foo2bar2
), actual
@book.config['join_lines_by_lang'] = true
actual = compile_block("//noindent\nfoo\nbar\n\nfoo2\nbar2\n")
assert_equal %Q(
foo bar
foo2 bar2
), actual
end
def test_image
def @chapter.image(_id)
item = Book::Index::Item.new('sampleimg', 1)
item.instance_eval { @path = './images/chap1-sampleimg.png' }
item
end
actual = compile_block("//image[sampleimg][sample photo]{\n//}\n")
assert_equal %Q(
図1.1 sample photo
), actual
@config['caption_position']['image'] = 'top'
actual = compile_block("//image[sampleimg][sample photo]{\n//}\n")
assert_equal %Q(
図1.1 sample photo
), actual
end
def test_image_with_metric
def @chapter.image(_id)
item = Book::Index::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(
図1.1 sample photo
), actual
end
def test_image_with_metric2
def @chapter.image(_id)
item = Book::Index::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, idgxml::ostyle=object]{\n//}\n")
assert_equal %Q(
図1.1 sample photo
), actual
end
def test_indepimage
def @chapter.image(_id)
item = Book::Index::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(
sample photo
), actual
@config['caption_position']['image'] = 'top'
actual = compile_block("//indepimage[sampleimg][sample photo]\n")
assert_equal %Q(
sample photo
), actual
end
def test_indepimage_without_caption
def @chapter.image(_id)
item = Book::Index::Item.new('sampleimg', 1)
item.instance_eval { @path = './images/chap1-sampleimg.png' }
item
end
actual = compile_block("//indepimage[sampleimg]\n")
assert_equal %Q(), actual
end
def test_indepimage_with_metric
def @chapter.image(_id)
item = Book::Index::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(
sample photo
), actual
end
def test_indepimage_with_metric2
def @chapter.image(_id)
item = Book::Index::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, idgxml::ostyle="object"]\n))
assert_equal %Q(
sample photo
), actual
end
def test_indepimage_without_caption_but_with_metric
def @chapter.image(_id)
item = Book::Index::Item.new('sampleimg', 1)
item.instance_eval { @path = './images/chap1-sampleimg.png' }
item
end
actual = compile_block("//indepimage[sampleimg][][scale=1.2]\n")
assert_equal %Q(), actual
end
def column_helper(review)
compile_block(review)
end
def test_column_1
review = <<-EOS
===[column] prev column
inside prev column
===[column] test
inside column
===[/column]
EOS
expected = <<-EOS.chomp
prev column
inside prev column
test
inside column
EOS
assert_equal expected, column_helper(review)
end
def test_column_2
review = <<-EOS
===[column] test
inside column
=== next level
EOS
expected = <<-EOS.chomp
test
inside column
next level
EOS
assert_equal expected, column_helper(review)
end
def test_column_3
review = <<-EOS
===[column] test
inside column
===[/column_dummy]
EOS
assert_raise(ReVIEW::ApplicationError) do
column_helper(review)
end
end
def test_column_ref
review = <<-EOS
===[column]{foo} test
inside column
=== next level
this is @{foo}.
EOS
expected = <<-EOS.chomp
test
inside column
next level
this is コラム「test」.
EOS
assert_equal expected, column_helper(review)
@config['chapterlink'] = nil
expected = <<-EOS.chomp
test
inside column
next level
this is コラム「test」.
EOS
assert_equal expected, column_helper(review)
end
def test_column_in_aother_chapter_ref
def @chapter.column_index
item = Book::Index::Item.new('chap1|column', 1, 'column_cap')
idx = Book::ColumnIndex.new
idx.add_item(item)
idx
end
actual = compile_inline('test @{chap1|column} test2')
expected = 'test コラム「column_cap」 test2'
assert_equal expected, actual
@config['chapterlink'] = nil
actual = compile_inline('test @{chap1|column} test2')
expected = 'test コラム「column_cap」 test2'
assert_equal expected, actual
end
def test_ul
src = <<-EOS
* AAA
* BBB
EOS
expected = <<-EOS.chomp
AAA
BBB
EOS
actual = compile_block(src)
assert_equal expected, actual
end
def test_ul_cont
src = <<-EOS
* AAA
-AA
* BBB
-BB
EOS
expected = <<-EOS.chomp
AAA-AA
BBB-BB
EOS
actual = compile_block(src)
assert_equal expected, actual
@book.config['join_lines_by_lang'] = true
expected = <<-EOS.chomp
AAA -AA
BBB -BB
EOS
actual = compile_block(src)
assert_equal expected, actual
end
def test_ul_nest1
src = <<-EOS
* AAA
** AA
EOS
expected = <<-EOS.chomp
AAA
AA
EOS
actual = compile_block(src)
assert_equal expected, actual
end
def test_ul_nest2
src = <<-EOS
* AAA
** AA
* BBB
** BB
EOS
expected = <<-EOS.chomp
AAA
AA
BBB
BB
EOS
actual = compile_block(src)
assert_equal expected, actual
end
def test_ul_nest3
src = <<-EOS
** AAA
* AA
EOS
e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
assert_equal ':1: error: too many *.', e.message
end
def test_ul_nest4
src = <<-EOS
* A
** B
** C
*** D
** E
* F
** G
EOS
expected = <<-EOS.chomp
A
B
C
D
E
F
G
EOS
actual = compile_block(src)
assert_equal expected, actual
end
def test_ol
src = <<-EOS
3. AAA
3. BBB
EOS
expected = <<-EOS.chomp
AAA
BBB
EOS
actual = compile_block(src)
assert_equal expected, actual
end
def test_inline_unknown
e = assert_raises(ReVIEW::ApplicationError) { compile_block("@{n}\n") }
assert_equal ':1: error: unknown image: n', e.message
e = assert_raises(ReVIEW::ApplicationError) { compile_block("@{n}\n") }
assert_equal ':1: error: unknown footnote: n', e.message
e = assert_raises(ReVIEW::ApplicationError) { compile_block("@{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_inline_raw0
assert_equal 'normal', compile_inline('@{normal}')
end
def test_inline_raw1
assert_equal 'body', compile_inline('@{|idgxml|body}')
end
def test_inline_raw2
assert_equal 'body', compile_inline('@{|idgxml, latex|body}')
end
def test_inline_raw3
assert_equal '', compile_inline('@{|latex, html|body}')
end
def test_inline_raw4
assert_equal '|idgxml body', compile_inline('@{|idgxml body}')
end
def test_inline_raw5
assert_equal "nor\nmal", compile_inline('@{|idgxml|nor\\nmal}')
end
def test_inline_imgref
def @chapter.image(_id)
item = Book::Index::Item.new('sampleimg', 1, 'sample photo')
item.instance_eval { @path = './images/chap1-sampleimg.png' }
item
end
actual = compile_block("@{sampleimg}\n")
expected = %Q(
図1.1「sample photo」
)
assert_equal expected, actual
end
def test_inline_imgref2
def @chapter.image(_id)
item = Book::Index::Item.new('sampleimg', 1)
item.instance_eval { @path = './images/chap1-sampleimg.png' }
item
end
actual = compile_block("@{sampleimg}\n")
expected = %Q(
図1.1
)
assert_equal expected, actual
end
def test_block_raw0
actual = compile_block(%Q(//raw[<>!"\\n& ]\n))
expected = %Q(<>!"\n& )
assert_equal expected, actual
end
def test_block_raw1
actual = compile_block(%Q(//raw[|idgxml|<>!"\\n& ]\n))
expected = %Q(<>!"\n& )
assert_equal expected, actual
end
def test_block_raw2
actual = compile_block(%Q(//raw[|idgxml, latex|<>!"\\n& ]\n))
expected = %Q(<>!"\n& )
assert_equal expected, actual
end
def test_block_raw3
actual = compile_block(%Q(//raw[|latex, html|<>!"\\n& ]\n))
expected = ''
assert_equal expected, actual
end
def test_block_raw4
actual = compile_block(%Q(//raw[|idgxml <>!"\\n& ]\n))
expected = %Q(|idgxml <>!"\n& )
assert_equal expected.chomp, actual
end
def test_comment
actual = compile_block('//comment[コメント]')
assert_equal '', actual
end
def test_comment_for_draft
@config['draft'] = true
actual = compile_block('//comment[コメント<]')
assert_equal 'コメント<', actual
actual = compile_block("//comment{\nA<>\nB&\n//}")
assert_equal %Q(A<>\nB&), actual
end
def test_inline_comment
actual = compile_inline('test @{コメント} test2')
assert_equal 'test test2', actual
end
def test_inline_comment_for_draft
@config['draft'] = true
actual = compile_inline('test @{コメント} test2')
assert_equal 'test コメント test2', actual
end
def test_texequation
src = <<-EOS
//texequation{
e=mc^2
//}
EOS
expected = %Q(
e=mc^2
)
actual = compile_block(src)
assert_equal expected, actual
end
def test_texequation_with_caption
src = <<-EOS
@{emc2}
//texequation[emc2][The Equivalence of Mass @{and} Energy]{
e=mc^2
//}
EOS
expected = %Q(
式1.1
式1.1 The Equivalence of Mass and Energy
e=mc^2
)
actual = compile_block(src)
assert_equal expected, actual
@config['caption_position']['equation'] = 'bottom'
expected = %Q(
式1.1
e=mc^2
式1.1 The Equivalence of Mass and Energy
)
actual = compile_block(src)
assert_equal expected, actual
end
def test_nest_error_close1
src = <<-EOS
//beginchild
EOS
e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
assert_equal ":1: error: //beginchild is shown, but previous element isn't ul, ol, or dl", e.message
end
def test_nest_error_close2
src = <<-EOS
* foo
//beginchild
1. foo
//beginchild
: foo
//beginchild
EOS
e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
assert_equal ':12: error: //beginchild of dl,ol,ul misses //endchild', e.message
end
def test_nest_error_close3
src = <<-EOS
* foo
//beginchild
1. foo
//beginchild
: foo
//beginchild
//endchild
EOS
e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
assert_equal ':14: error: //beginchild of ol,ul misses //endchild', e.message
end
def test_nest_ul
src = <<-EOS
* UL1
//beginchild
1. UL1-OL1
2. UL1-OL2
* UL1-UL1
* UL1-UL2
: UL1-DL1
UL1-DD1
: UL1-DL2
UL1-DD2
//endchild
* UL2
//beginchild
UL2-PARA
//endchild
EOS
expected = <<-EOS.chomp
UL1
UL1-OL1
UL1-OL2
UL1-UL1
UL1-UL2
UL1-DL1
UL1-DD1
UL1-DL2
UL1-DD2
UL2
UL2-PARA
EOS
actual = compile_block(src)
assert_equal expected, actual
end
def test_nest_ol
src = <<-EOS
1. OL1
//beginchild
1. OL1-OL1
2. OL1-OL2
* OL1-UL1
* OL1-UL2
: OL1-DL1
OL1-DD1
: OL1-DL2
OL1-DD2
//endchild
2. OL2
//beginchild
OL2-PARA
//endchild
EOS
expected = <<-EOS.chomp
OL1
OL1-OL1
OL1-OL2
OL1-UL1
OL1-UL2
OL1-DL1
OL1-DD1
OL1-DL2
OL1-DD2
OL2
OL2-PARA
EOS
actual = compile_block(src)
assert_equal expected, actual
end
def test_nest_dl
src = <<-EOS
: DL1
//beginchild
1. DL1-OL1
2. DL1-OL2
* DL1-UL1
* DL1-UL2
: DL1-DL1
DL1-DD1
: DL1-DL2
DL1-DD2
//endchild
: DL2
DD2
//beginchild
* DD2-UL1
* DD2-UL2
DD2-PARA
//endchild
EOS
expected = <<-EOS.chomp
DL1
DL1-OL1
DL1-OL2
DL1-UL1
DL1-UL2
DL1-DL1
DL1-DD1
DL1-DL2
DL1-DD2
DL2
DD2
DD2-UL1
DD2-UL2
DD2-PARA
EOS
actual = compile_block(src)
assert_equal expected, actual
end
def test_nest_multi
src = <<-EOS
1. OL1
//beginchild
1. OL1-OL1
//beginchild
* OL1-OL1-UL1
OL1-OL1-PARA
//endchild
2. OL1-OL2
* OL1-UL1
//beginchild
: OL1-UL1-DL1
OL1-UL1-DD1
OL1-UL1-PARA
//endchild
* OL1-UL2
//endchild
EOS
expected = <<-EOS.chomp
OL1
OL1-OL1
OL1-OL1-UL1
OL1-OL1-PARA
OL1-OL2
OL1-UL1
OL1-UL1-DL1
OL1-UL1-DD1
OL1-UL1-PARA
OL1-UL2
EOS
actual = compile_block(src)
assert_equal expected, actual
end
end