第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_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_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_emtable
actual = compile_block("//emtable[foo]{\nA\n//}\n//emtable{\nA\n//}")
assert_equal %Q(
foo
A
A
), 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_paragraph
actual = compile_block("foo\nbar\n")
assert_equal '
foobar
', actual
end
def test_tabbed_paragraph
actual = compile_block("\tfoo\nbar\n")
assert_equal %Q(
foobar
), actual
end
def test_quote
actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n")
assert_equal '
foobar
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_term
actual = compile_block("//term{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
assert_equal '
test1test1.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
end
def test_point_without_caption
actual = compile_block("//point{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
assert_equal '
test1test1.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
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
end
def test_emlist_listinfo
@config['listinfo'] = true
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
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")
assert_equal %Q(
this is test<&>_
test1\n test1.5\n\n test2\n
), 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")
assert_equal %Q(
this is test<&>_
test1\n test1.5\n\n test2\n
), actual
end
def test_list
def @chapter.list(_id)
Book::ListIndex::Item.new('samplelist', 1)
end
actual = compile_block("//list[samplelist][this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
assert_equal %Q(
リスト1.1 this is test<&>_
test1\ntest1.5\n\ntest2\n
), actual
end
def test_listnum
def @chapter.list(_id)
Book::ListIndex::Item.new('samplelist', 1)
end
actual = compile_block("//listnum[samplelist][this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
assert_equal %Q(
リスト1.1 this is test<&>_
1: test1\n 2: test1.5\n 3: \n 4: test2\n
), actual
end
def test_listnum_linenum
def @chapter.list(_id)
Book::ListIndex::Item.new('samplelist', 1)
end
actual = compile_block("//firstlinenum[100]\n//listnum[samplelist][this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
assert_equal %Q(
リスト1.1 this is test<&>_
100: test1\n101: test1.5\n102: \n103: test2\n
), actual
end
def test_list_listinfo
def @chapter.list(_id)
Book::ListIndex::Item.new('samplelist', 1)
end
@config['listinfo'] = true
actual = compile_block("//list[samplelist][this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
assert_equal %Q(
リスト1.1 this is test<&>_
test1\ntest1.5\n\ntest2\n
), actual
end
def test_insn
@config['listinfo'] = true
actual = compile_block("//insn[this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
assert_equal %Q(this is test<&>_test1\ntest1.5\n\ntest2\n), actual
end
def test_box
@config['listinfo'] = true
actual = compile_block("//box[this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n")
assert_equal %Q(
this is test<&>_
test1\ntest1.5\n\ntest2\n), 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")
assert_equal %Q(
this is test<&>_
test1\ntest1.5\n\ntest2\n), actual
end
def test_flushright
actual = compile_block("//flushright{\nfoo\nbar\n\nbuz\n//}\n")
assert_equal %Q(
foobar
buz
), actual
end
def test_centering
actual = compile_block("//centering{\nfoo\nbar\n\nbuz\n//}\n")
assert_equal %Q(
foobar
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
end
def test_image
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]{\n//}\n")
assert_equal %Q(
図1.1 sample photo
), 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(
図1.1 sample photo
), 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, idgxml::ostyle=object]{\n//}\n")
assert_equal %Q(
図1.1 sample photo
), 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(
sample photo
), actual
end
def test_indepimage_without_caption
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]\n")
assert_equal %Q(), 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(
sample photo
), 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, 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::ImageIndex::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)
end
def test_column_in_aother_chapter_ref
def @chapter.column_index
items = [Book::ColumnIndex::Item.new('chap1|column', 1, 'column_cap')]
Book::ColumnIndex.new(items)
end
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
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
* BBB
** BB
EOS
expected = <<-EOS.chomp
AAA
AA
BBB
BB
EOS
actual = compile_block(src)
assert_equal expected, actual
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::ImageIndex::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::NumberlessImageIndex::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
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
end