blob: dfaa8fa1af2c286aa2f356839ab41594b08b893d [file] [log] [blame]
Bram Moolenaare52702f2020-06-04 18:22:13 +02001scriptencoding utf-8
2
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +02003func Run_cjk_linebreak_after(rigorous)
Bram Moolenaare52702f2020-06-04 18:22:13 +02004 set textwidth=12
5 for punct in [
6 \ '!', '%', ')', ',', ':', ';', '>', '?', ']', '}', '’', '”', '†', '‡',
7 \ '…', '‰', '‱', '‼', '⁇', '⁈', '⁉', '℃', '℉', '、', '。', '〉', '》',
8 \ '」', '』', '】', '〕', '〗', '〙', '〛', '!', ')', ',', '.', ':',
9 \ ';', '?', ']', '}']
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +020010 call setline('.', '这是一个测试' .. punct.'试试 CJK 行禁则补丁。')
Bram Moolenaare52702f2020-06-04 18:22:13 +020011 normal gqq
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +020012 if a:rigorous
13 call assert_equal('这是一个测', getline(1))
14 else
15 call assert_equal('这是一个测试' .. punct, getline(1))
16 endif
Bram Moolenaare52702f2020-06-04 18:22:13 +020017 %d_
18 endfor
19endfunc
20
21func Test_cjk_linebreak_after()
22 set formatoptions=croqn2mB1j
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +020023 call Run_cjk_linebreak_after(0)
Bram Moolenaare52702f2020-06-04 18:22:13 +020024endfunc
25
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +020026func Test_cjk_linebreak_after_rigorous()
27 set formatoptions=croqn2mB1j]
28 call Run_cjk_linebreak_after(1)
29endfunc
Bram Moolenaare52702f2020-06-04 18:22:13 +020030
31func Run_cjk_linebreak_before()
32 set textwidth=12
33 for punct in [
34 \ '(', '<', '[', '`', '{', '‘', '“', '〈', '《', '「', '『', '【', '〔',
35 \ '〖', '〘', '〚', '(', '[', '{']
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +020036 call setline('.', '这是个测试' .. punct.'试试 CJK 行禁则补丁。')
Bram Moolenaare52702f2020-06-04 18:22:13 +020037 normal gqq
38 call assert_equal('这是个测试', getline(1))
39 %d_
40 endfor
41endfunc
42
43func Test_cjk_linebreak_before()
44 set formatoptions=croqn2mB1j
45 call Run_cjk_linebreak_before()
46endfunc
47
48func Test_cjk_linebreak_before_rigorous()
49 set formatoptions=croqn2mB1j]
50 call Run_cjk_linebreak_before()
51endfunc
52
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +020053func Run_cjk_linebreak_nobetween(rigorous)
Bram Moolenaare52702f2020-06-04 18:22:13 +020054 " …… must not start a line
55 call setline('.', '这是个测试……试试 CJK 行禁则补丁。')
56 set textwidth=12 ambiwidth=double
57 normal gqq
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +020058 if a:rigorous
59 call assert_equal('这是个测', getline(1))
60 else
61 call assert_equal('这是个测试……', getline(1))
62 endif
Bram Moolenaare52702f2020-06-04 18:22:13 +020063 %d_
64
65 call setline('.', '这是一个测试……试试 CJK 行禁则补丁。')
66 set textwidth=12 ambiwidth=double
67 normal gqq
68 call assert_equal('这是一个测', getline(1))
69 %d_
70
71 " but —— can
72 call setline('.', '这是个测试——试试 CJK 行禁则补丁。')
73 set textwidth=12 ambiwidth=double
74 normal gqq
75 call assert_equal('这是个测试', getline(1))
76endfunc
77
78func Test_cjk_linebreak_nobetween()
79 set formatoptions=croqn2mB1j
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +020080 call Run_cjk_linebreak_nobetween(0)
Bram Moolenaare52702f2020-06-04 18:22:13 +020081endfunc
82
83func Test_cjk_linebreak_nobetween_rigorous()
84 set formatoptions=croqn2mB1j]
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +020085 call Run_cjk_linebreak_nobetween(1)
Bram Moolenaare52702f2020-06-04 18:22:13 +020086endfunc
87
88func Test_cjk_linebreak_join_punct()
89 for punct in ['——', '〗', ',', '。', '……']
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +020090 call setline(1, '文本文本' .. punct)
Bram Moolenaare52702f2020-06-04 18:22:13 +020091 call setline(2, 'English')
92 set formatoptions=croqn2mB1j
93 normal ggJ
Bram Moolenaar11f1ffd2020-06-06 15:23:26 +020094 call assert_equal('文本文本' .. punct.'English', getline(1))
Bram Moolenaare52702f2020-06-04 18:22:13 +020095 %d_
96 endfor
97endfunc