require 'test_helper' require 'review/textutils' class TextUtilsTest < Test::Unit::TestCase include ReVIEW::TextUtils def setup @tu_nil = Object.new @tu_nil.extend(ReVIEW::TextUtils) @tu_nil.instance_eval { @book = Book::Base.new('.') } def @tu_nil.config @book.config end def @tu_nil.pre_paragraph nil end def @tu_nil.post_paragraph nil end @tu_p = Object.new @tu_p.extend(ReVIEW::TextUtils) @tu_p.instance_eval { @book = Book::Base.new('.') } def @tu_p.config @book.config end def @tu_p.pre_paragraph '

' end def @tu_p.post_paragraph '

' end end def test_detab detabed = detab("\t\tabc") assert_equal ' abc', detabed detabed = detab("\tabc\tbcd") assert_equal ' abc bcd', detabed end def test_detab_with_arg detabed = detab("\t\tabcd\tef", 2) assert_equal ' abcd ef', detabed detabed = detab("\tabc\tdef", 4) assert_equal ' abc def', detabed end def test_split_paragraph_empty_nil ret = @tu_nil.split_paragraph([]) assert_equal ret, [''] end def test_split_paragraph_empty_p ret = @tu_p.split_paragraph([]) assert_equal ret, ['

'] end def test_split_paragraph_p ret = @tu_p.split_paragraph(['abc']) assert_equal ['

abc

'], ret ret = @tu_p.split_paragraph(['abc', 'def']) assert_equal ['

abcdef

'], ret ret = @tu_p.split_paragraph(['abc', '', 'def']) assert_equal ['

abc

', '

def

'], ret ret = @tu_p.split_paragraph(['abc', '', '', 'def']) assert_equal ['

abc

', '

def

'], ret ret = @tu_p.split_paragraph(['abc', '', '', 'def', 'ghi']) assert_equal ['

abc

', '

defghi

'], ret ret = @tu_p.split_paragraph(['abc', '', '', 'def', 'ghi', '', '']) assert_equal ['

abc

', '

defghi

'], ret @tu_p.config['join_lines_by_lang'] = true ret = @tu_p.split_paragraph(['abc']) assert_equal ['

abc

'], ret ret = @tu_p.split_paragraph(['abc', 'def']) assert_equal ['

abc def

'], ret ret = @tu_p.split_paragraph(['abc', '', 'def']) assert_equal ['

abc

', '

def

'], ret ret = @tu_p.split_paragraph(['abc', '', '', 'def']) assert_equal ['

abc

', '

def

'], ret ret = @tu_p.split_paragraph(['abc', '', '', 'def', 'ghi']) assert_equal ['

abc

', '

def ghi

'], ret ret = @tu_p.split_paragraph(['abc', '', '', 'def', 'ghi', '', '']) assert_equal ['

abc

', '

def ghi

'], ret end def test_split_paragraph_nil ret = @tu_nil.split_paragraph(['abc']) assert_equal ['abc'], ret ret = @tu_nil.split_paragraph(['abc', 'def']) assert_equal ['abcdef'], ret ret = @tu_nil.split_paragraph(['abc', '', 'def']) assert_equal ['abc', 'def'], ret ret = @tu_nil.split_paragraph(['abc', '', '', 'def']) assert_equal ['abc', 'def'], ret ret = @tu_nil.split_paragraph(['abc', '', '', 'def', 'ghi']) assert_equal ['abc', 'defghi'], ret @tu_nil.config['join_lines_by_lang'] = true ret = @tu_nil.split_paragraph(['abc']) assert_equal ['abc'], ret ret = @tu_nil.split_paragraph(['abc', 'def']) assert_equal ['abc def'], ret ret = @tu_nil.split_paragraph(['abc', '', 'def']) assert_equal ['abc', 'def'], ret ret = @tu_nil.split_paragraph(['abc', '', '', 'def']) assert_equal ['abc', 'def'], ret ret = @tu_nil.split_paragraph(['abc', '', '', 'def', 'ghi']) assert_equal ['abc', 'def ghi'], ret end def test_split_paragraph_p_lang ret = @tu_p.split_paragraph(['I', 'have.']) assert_equal ['

Ihave.

'], ret ret = @tu_p.split_paragraph(['I', 'have', '.']) assert_equal ['

Ihave.

'], ret ret = @tu_p.split_paragraph(['01', '23', 'a', '4']) assert_equal ['

0123a4

'], ret ret = @tu_p.split_paragraph(['こんにちは', '漢字', 'α', 'アルファ?', '!']) assert_equal ['

こんにちは漢字αアルファ?!

'], ret ret = @tu_p.split_paragraph(['こんにちは', '0814', '日']) assert_equal ['

こんにちは0814日

'], ret ret = @tu_p.split_paragraph(['あ', 'a', 'い', '?', 'a']) assert_equal ['

あaい?a

'], ret ret = @tu_p.split_paragraph(['안녕하세요', 'こんにちは']) assert_equal ['

안녕하세요こんにちは

'], ret ret = @tu_p.split_paragraph(['Hello', '안녕하세요', '처음뵙겠습니다']) assert_equal ['

Hello안녕하세요처음뵙겠습니다

'], ret ret = @tu_p.split_paragraph(['']) assert_equal ['

'], ret # LaTeX ret = @tu_p.split_paragraph(['\tag{a}', 'A', '\tag{b}', 'B']) assert_equal ['

\tag{a}A\tag{b}B

'], ret ret = @tu_p.split_paragraph(['\tag{あ}', 'い', '\tag{う}', 'A', '\tag{え}', '\tag{b}', '\tag{お}', '\tag{か}']) assert_equal ['

\tag{あ}い\tag{う}A\tag{え}\tag{b}\tag{お}\tag{か}

'], ret # HTML/IDGXML ret = @tu_p.split_paragraph(['a', 'A', 'b', 'B']) assert_equal ['

aAbB

'], ret ret = @tu_p.split_paragraph(['', 'い', '', 'A', '', 'b', '', '']) assert_equal ['

Ab

'], ret # Text ret = @tu_p.split_paragraph(['★a☆', 'A', '★b☆', 'B']) assert_equal ['

★a☆A★b☆B

'], ret ret = @tu_p.split_paragraph(['★あ☆', 'い', '★う☆', 'A', '★え☆', '★b☆', '★お☆', '★か☆']) assert_equal ['

★あ☆い★う☆A★え☆★b☆★お☆★か☆

'], ret @tu_p.config['join_lines_by_lang'] = true ret = @tu_p.split_paragraph(['I', 'have.']) assert_equal ['

I have.

'], ret ret = @tu_p.split_paragraph(['I', 'have', '.']) assert_equal ['

I have .

'], ret # ...OK? (I have. ?) ret = @tu_p.split_paragraph(['01', '23', 'a', '4']) assert_equal ['

01 23 a 4

'], ret ret = @tu_p.split_paragraph(['こんにちは', '漢字', 'α', 'アルファ?', '!']) assert_equal ['

こんにちは漢字αアルファ?!

'], ret ret = @tu_p.split_paragraph(['こんにちは', '0814', '日']) assert_equal ['

こんにちは0814日

'], ret ret = @tu_p.split_paragraph(['あ', 'a', 'い', '?', 'a']) assert_equal ['

あaい? a

'], ret ret = @tu_p.split_paragraph(['안녕하세요', 'こんにちは']) assert_equal ['

안녕하세요こんにちは

'], ret ret = @tu_p.split_paragraph(['Hello', '안녕하세요', '처음뵙겠습니다']) assert_equal ['

Hello 안녕하세요 처음뵙겠습니다

'], ret ret = @tu_p.split_paragraph(['']) assert_equal ['

'], ret # LaTeX ret = @tu_p.split_paragraph(['\tag{a}', 'A', '\tag{b}', 'B']) assert_equal ['

\tag{a} A \tag{b} B

'], ret ret = @tu_p.split_paragraph(['\tag{あ}', 'い', '\tag{う}', 'A', '\tag{え}', '\tag{b}', '\tag{お}', '\tag{か}']) assert_equal ['

\tag{あ}い\tag{う} A \tag{え} \tag{b} \tag{お} \tag{か}

'], ret # ...OK? (\tag{お}\tag{か}?) # HTML/IDGXML ret = @tu_p.split_paragraph(['a', 'A', 'b', 'B']) assert_equal ['

a A b B

'], ret ret = @tu_p.split_paragraph(['', 'い', '', 'A', '', 'b', '', '']) assert_equal ['

A b

'], ret # ...OK? (?) # Text ret = @tu_p.split_paragraph(['★a☆', 'A', '★b☆', 'B']) assert_equal ['

★a☆ A ★b☆ B

'], ret ret = @tu_p.split_paragraph(['★あ☆', 'い', '★う☆', 'A', '★え☆', '★b☆', '★お☆', '★か☆']) assert_equal ['

★あ☆い★う☆ A ★え☆ ★b☆ ★お☆ ★か☆

'], ret # ...OK? (★お☆★か☆?) end end