blob: 17c59164a1a1d6ec4f5be5e5f2f77029828cb83a [file] [log] [blame]
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001" Test for CJK linebreak
2
Bram Moolenaare52702f2020-06-04 18:22:13 +02003scriptencoding utf-8
4
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +02005func Run_cjk_linebreak_after(rigorous)
Bram Moolenaare52702f2020-06-04 18:22:13 +02006 set textwidth=12
7 for punct in [
8 \ '!', '%', ')', ',', ':', ';', '>', '?', ']', '}', '’', '”', '†', '‡',
9 \ '…', '‰', '‱', '‼', '⁇', '⁈', '⁉', '℃', '℉', '、', '。', '〉', '》',
10 \ '」', '』', '】', '〕', '〗', '〙', '〛', '!', ')', ',', '.', ':',
11 \ ';', '?', ']', '}']
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +020012 call setline('.', '这是一个测试' .. punct.'试试 CJK 行禁则补丁。')
Bram Moolenaare52702f2020-06-04 18:22:13 +020013 normal gqq
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +020014 if a:rigorous
15 call assert_equal('这是一个测', getline(1))
16 else
17 call assert_equal('这是一个测试' .. punct, getline(1))
18 endif
Bram Moolenaare52702f2020-06-04 18:22:13 +020019 %d_
20 endfor
21endfunc
22
23func Test_cjk_linebreak_after()
24 set formatoptions=croqn2mB1j
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +020025 call Run_cjk_linebreak_after(0)
Bram Moolenaare52702f2020-06-04 18:22:13 +020026endfunc
27
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +020028func Test_cjk_linebreak_after_rigorous()
29 set formatoptions=croqn2mB1j]
30 call Run_cjk_linebreak_after(1)
31endfunc
Bram Moolenaare52702f2020-06-04 18:22:13 +020032
33func Run_cjk_linebreak_before()
34 set textwidth=12
35 for punct in [
36 \ '(', '<', '[', '`', '{', '‘', '“', '〈', '《', '「', '『', '【', '〔',
37 \ '〖', '〘', '〚', '(', '[', '{']
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +020038 call setline('.', '这是个测试' .. punct.'试试 CJK 行禁则补丁。')
Bram Moolenaare52702f2020-06-04 18:22:13 +020039 normal gqq
40 call assert_equal('这是个测试', getline(1))
41 %d_
42 endfor
43endfunc
44
45func Test_cjk_linebreak_before()
46 set formatoptions=croqn2mB1j
47 call Run_cjk_linebreak_before()
48endfunc
49
50func Test_cjk_linebreak_before_rigorous()
51 set formatoptions=croqn2mB1j]
52 call Run_cjk_linebreak_before()
53endfunc
54
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +020055func Run_cjk_linebreak_nobetween(rigorous)
Bram Moolenaare52702f2020-06-04 18:22:13 +020056 " …… must not start a line
57 call setline('.', '这是个测试……试试 CJK 行禁则补丁。')
58 set textwidth=12 ambiwidth=double
59 normal gqq
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +020060 if a:rigorous
61 call assert_equal('这是个测', getline(1))
62 else
63 call assert_equal('这是个测试……', getline(1))
64 endif
Bram Moolenaare52702f2020-06-04 18:22:13 +020065 %d_
66
67 call setline('.', '这是一个测试……试试 CJK 行禁则补丁。')
68 set textwidth=12 ambiwidth=double
69 normal gqq
70 call assert_equal('这是一个测', getline(1))
71 %d_
72
73 " but —— can
74 call setline('.', '这是个测试——试试 CJK 行禁则补丁。')
75 set textwidth=12 ambiwidth=double
76 normal gqq
77 call assert_equal('这是个测试', getline(1))
78endfunc
79
80func Test_cjk_linebreak_nobetween()
81 set formatoptions=croqn2mB1j
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +020082 call Run_cjk_linebreak_nobetween(0)
Bram Moolenaare52702f2020-06-04 18:22:13 +020083endfunc
84
85func Test_cjk_linebreak_nobetween_rigorous()
86 set formatoptions=croqn2mB1j]
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +020087 call Run_cjk_linebreak_nobetween(1)
Bram Moolenaare52702f2020-06-04 18:22:13 +020088endfunc
89
90func Test_cjk_linebreak_join_punct()
91 for punct in ['——', '〗', ',', '。', '……']
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +020092 call setline(1, '文本文本' .. punct)
Bram Moolenaare52702f2020-06-04 18:22:13 +020093 call setline(2, 'English')
94 set formatoptions=croqn2mB1j
95 normal ggJ
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +020096 call assert_equal('文本文本' .. punct.'English', getline(1))
Bram Moolenaare52702f2020-06-04 18:22:13 +020097 %d_
98 endfor
99endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200100
101" vim: shiftwidth=2 sts=2 expandtab