From 859eb428569c775a8b3b48837cc1280ad7889237 Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Thu, 1 May 2014 21:07:53 +0530 Subject: [PATCH] Added more tests for Realigning unicode content --- .../table/sample_for_header_unicode.txt | 9 ++++ .../sample_header_realign_unicode_after.txt | 8 +++ .../sample_header_realign_unicode_before.txt | 8 +++ .../table/sample_realign_unicode_after.txt | 4 ++ .../table/sample_realign_unicode_before.txt | 4 ++ t/table.vim | 52 +++++++++++++++++++ 6 files changed, 85 insertions(+) create mode 100644 t/fixtures/table/sample_for_header_unicode.txt create mode 100644 t/fixtures/table/sample_header_realign_unicode_after.txt create mode 100644 t/fixtures/table/sample_header_realign_unicode_before.txt create mode 100644 t/fixtures/table/sample_realign_unicode_after.txt create mode 100644 t/fixtures/table/sample_realign_unicode_before.txt diff --git a/t/fixtures/table/sample_for_header_unicode.txt b/t/fixtures/table/sample_for_header_unicode.txt new file mode 100644 index 0000000..7b4e02a --- /dev/null +++ b/t/fixtures/table/sample_for_header_unicode.txt @@ -0,0 +1,9 @@ + +| abc | 测试长度 | 长测试 | + +| 长 | 测试测试测试测试 | 测试测试 | + +| 测试测试 | 测试 | 测试测测试 | + +| 测试测试测试 | 测试测试 | 测试 | + diff --git a/t/fixtures/table/sample_header_realign_unicode_after.txt b/t/fixtures/table/sample_header_realign_unicode_after.txt new file mode 100644 index 0000000..285067b --- /dev/null +++ b/t/fixtures/table/sample_header_realign_unicode_after.txt @@ -0,0 +1,8 @@ +|--------------+------------------+------------| +| 测试测试 | 测试长度 | 长测试 | +|--------------+------------------+-----------:| +| abc | 测试长度 | 长测试 | +| 长 | 测试测试测试测试 | 测试测试 | +| 测试测试 | 测试 | 测试测测试 | +| 测试测试测试 | 测试测试 | 测试 | +|--------------+------------------+------------| diff --git a/t/fixtures/table/sample_header_realign_unicode_before.txt b/t/fixtures/table/sample_header_realign_unicode_before.txt new file mode 100644 index 0000000..70e4e49 --- /dev/null +++ b/t/fixtures/table/sample_header_realign_unicode_before.txt @@ -0,0 +1,8 @@ +|--------+--------+------| +|测试测试|测试长度|长测试| +|--------+--------+-----:| +|abc|测试长度|长测试| +|长|测试测试测试测试|测试测试| +|测试测试|测试|测试测测试| +|测试测试测试|测试测试|测试| +|------------+--------+----| diff --git a/t/fixtures/table/sample_realign_unicode_after.txt b/t/fixtures/table/sample_realign_unicode_after.txt new file mode 100644 index 0000000..b479b24 --- /dev/null +++ b/t/fixtures/table/sample_realign_unicode_after.txt @@ -0,0 +1,4 @@ +| abc | 测试长度 | 长测试 | +| 长 | 测试测试测试测试 | 测试测试 | +| 测试测试 | 测试 | 测试测测试 | +| 测试测试测试 | 测试测试 | 测试 | diff --git a/t/fixtures/table/sample_realign_unicode_before.txt b/t/fixtures/table/sample_realign_unicode_before.txt new file mode 100644 index 0000000..8c3124f --- /dev/null +++ b/t/fixtures/table/sample_realign_unicode_before.txt @@ -0,0 +1,4 @@ +|abc|测试长度|长测试| +|长|测试测试测试测试|测试测试| +|测试测试|测试|测试测测试| +|测试测试测试|测试测试|测试| diff --git a/t/table.vim b/t/table.vim index 8b84065..599e900 100644 --- a/t/table.vim +++ b/t/table.vim @@ -70,6 +70,32 @@ describe 'table' Expect tablemode#table#IsHeader(1) to_be_true Expect tablemode#table#IsBorder(2) to_be_true end + + describe 'for unicode' + before + new + read t/fixtures/table/sample_for_header_unicode.txt + end + + it 'should add border to line' + call tablemode#table#AddBorder(1) + call tablemode#table#AddBorder(3) + call tablemode#table#AddBorder(5) + call tablemode#table#AddBorder(7) + call tablemode#table#AddBorder(9) + + Expect tablemode#table#IsBorder(1) to_be_true + Expect tablemode#utils#StrDisplayWidth(getline(1)) == tablemode#utils#StrDisplayWidth(getline(2)) + Expect tablemode#table#IsBorder(3) to_be_true + Expect tablemode#utils#StrDisplayWidth(getline(3)) == tablemode#utils#StrDisplayWidth(getline(4)) + Expect tablemode#table#IsBorder(5) to_be_true + Expect tablemode#utils#StrDisplayWidth(getline(5)) == tablemode#utils#StrDisplayWidth(getline(6)) + Expect tablemode#table#IsBorder(7) to_be_true + Expect tablemode#utils#StrDisplayWidth(getline(7)) == tablemode#utils#StrDisplayWidth(getline(8)) + Expect tablemode#table#IsBorder(9) to_be_true + Expect tablemode#utils#StrDisplayWidth(getline(9)) == tablemode#utils#StrDisplayWidth(getline(8)) + end + end end describe 'Realign' @@ -83,6 +109,19 @@ describe 'table' call tablemode#table#Realign(1) Expect getline(1,'$') == readfile('t/fixtures/table/sample_realign_after.txt') end + + describe 'for unicode' + before + new + normal! ggdG + read t/fixtures/table/sample_realign_unicode_before.txt + end + + it 'should be aligned properly' + call tablemode#table#Realign(1) + Expect getline(1,'$') == readfile('t/fixtures/table/sample_realign_unicode_after.txt') + end + end end describe 'with header alignments' @@ -95,6 +134,19 @@ describe 'table' call tablemode#table#Realign(1) Expect getline(1,'$') == readfile('t/fixtures/table/sample_header_realign_after.txt') end + + describe 'for unicode' + before + new + normal! ggdG + read t/fixtures/table/sample_header_realign_unicode_before.txt + end + + it 'should be aligned properly' + call tablemode#table#Realign(1) + Expect getline(1,'$') == readfile('t/fixtures/table/sample_header_realign_unicode_after.txt') + end + end end end end