Bram Moolenaar | e52702f | 2020-06-04 18:22:13 +0200 | [diff] [blame^] | 1 | scriptencoding utf-8 |
| 2 | |
| 3 | func Run_cjk_linebreak_after() |
| 4 | set textwidth=12 |
| 5 | for punct in [ |
| 6 | \ '!', '%', ')', ',', ':', ';', '>', '?', ']', '}', '’', '”', '†', '‡', |
| 7 | \ '…', '‰', '‱', '‼', '⁇', '⁈', '⁉', '℃', '℉', '、', '。', '〉', '》', |
| 8 | \ '」', '』', '】', '〕', '〗', '〙', '〛', '!', ')', ',', '.', ':', |
| 9 | \ ';', '?', ']', '}'] |
| 10 | call setline('.', '这是一个测试'.punct.'试试 CJK 行禁则补丁。') |
| 11 | normal gqq |
| 12 | call assert_equal('这是一个测试'.punct, getline(1)) |
| 13 | %d_ |
| 14 | endfor |
| 15 | endfunc |
| 16 | |
| 17 | func Test_cjk_linebreak_after() |
| 18 | set formatoptions=croqn2mB1j |
| 19 | call Run_cjk_linebreak_after() |
| 20 | endfunc |
| 21 | |
| 22 | " TODO: this test fails |
| 23 | "func Test_cjk_linebreak_after_rigorous() |
| 24 | " set formatoptions=croqn2mB1j] |
| 25 | " call Run_cjk_linebreak_after() |
| 26 | "endfunc |
| 27 | |
| 28 | func Run_cjk_linebreak_before() |
| 29 | set textwidth=12 |
| 30 | for punct in [ |
| 31 | \ '(', '<', '[', '`', '{', '‘', '“', '〈', '《', '「', '『', '【', '〔', |
| 32 | \ '〖', '〘', '〚', '(', '[', '{'] |
| 33 | call setline('.', '这是个测试'.punct.'试试 CJK 行禁则补丁。') |
| 34 | normal gqq |
| 35 | call assert_equal('这是个测试', getline(1)) |
| 36 | %d_ |
| 37 | endfor |
| 38 | endfunc |
| 39 | |
| 40 | func Test_cjk_linebreak_before() |
| 41 | set formatoptions=croqn2mB1j |
| 42 | call Run_cjk_linebreak_before() |
| 43 | endfunc |
| 44 | |
| 45 | func Test_cjk_linebreak_before_rigorous() |
| 46 | set formatoptions=croqn2mB1j] |
| 47 | call Run_cjk_linebreak_before() |
| 48 | endfunc |
| 49 | |
| 50 | func Run_cjk_linebreak_nobetween() |
| 51 | " …… must not start a line |
| 52 | call setline('.', '这是个测试……试试 CJK 行禁则补丁。') |
| 53 | set textwidth=12 ambiwidth=double |
| 54 | normal gqq |
| 55 | " TODO: this fails |
| 56 | " call assert_equal('这是个测试……', getline(1)) |
| 57 | %d_ |
| 58 | |
| 59 | call setline('.', '这是一个测试……试试 CJK 行禁则补丁。') |
| 60 | set textwidth=12 ambiwidth=double |
| 61 | normal gqq |
| 62 | call assert_equal('这是一个测', getline(1)) |
| 63 | %d_ |
| 64 | |
| 65 | " but —— can |
| 66 | call setline('.', '这是个测试——试试 CJK 行禁则补丁。') |
| 67 | set textwidth=12 ambiwidth=double |
| 68 | normal gqq |
| 69 | call assert_equal('这是个测试', getline(1)) |
| 70 | endfunc |
| 71 | |
| 72 | func Test_cjk_linebreak_nobetween() |
| 73 | set formatoptions=croqn2mB1j |
| 74 | call Run_cjk_linebreak_nobetween() |
| 75 | endfunc |
| 76 | |
| 77 | func Test_cjk_linebreak_nobetween_rigorous() |
| 78 | set formatoptions=croqn2mB1j] |
| 79 | call Run_cjk_linebreak_nobetween() |
| 80 | endfunc |
| 81 | |
| 82 | func Test_cjk_linebreak_join_punct() |
| 83 | for punct in ['——', '〗', ',', '。', '……'] |
| 84 | call setline(1, '文本文本'.punct) |
| 85 | call setline(2, 'English') |
| 86 | set formatoptions=croqn2mB1j |
| 87 | normal ggJ |
| 88 | call assert_equal('文本文本'.punct.'English', getline(1)) |
| 89 | %d_ |
| 90 | endfor |
| 91 | endfunc |