1" Test for CJK linebreak
2
3scriptencoding utf-8
4
5func Run_cjk_linebreak_after(rigorous)
6  set textwidth=12
7  for punct in [
8        \ '!', '%', ')', ',', ':', ';', '>', '?', ']', '}', '’', '”', '†', '‡',
9        \ '…', '‰', '‱', '‼', '⁇', '⁈', '⁉', '℃', '℉', '、', '。', '〉', '》',
10        \ '」', '』', '】', '〕', '〗', '〙', '〛', '!', ')', ',', '.', ':',
11        \ ';', '?', ']', '}']
12    call setline('.', '这是一个测试' .. punct.'试试 CJK 行禁则补丁。')
13    normal gqq
14    if a:rigorous
15      call assert_equal('这是一个测', getline(1))
16    else
17      call assert_equal('这是一个测试' .. punct, getline(1))
18    endif
19    %d_
20  endfor
21endfunc
22
23func Test_cjk_linebreak_after()
24  set formatoptions=croqn2mB1j
25  call Run_cjk_linebreak_after(0)
26endfunc
27
28func Test_cjk_linebreak_after_rigorous()
29 set formatoptions=croqn2mB1j]
30 call Run_cjk_linebreak_after(1)
31endfunc
32
33func Run_cjk_linebreak_before()
34  set textwidth=12
35  for punct in [
36        \ '(', '<', '[', '`', '{', '‘', '“', '〈', '《', '「', '『', '【', '〔',
37        \ '〖', '〘', '〚', '(', '[', '{']
38    call setline('.', '这是个测试' .. punct.'试试 CJK 行禁则补丁。')
39    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
55func Run_cjk_linebreak_nobetween(rigorous)
56  " …… must not start a line
57  call setline('.', '这是个测试……试试 CJK 行禁则补丁。')
58  set textwidth=12 ambiwidth=double
59  normal gqq
60  if a:rigorous
61    call assert_equal('这是个测', getline(1))
62  else
63    call assert_equal('这是个测试……', getline(1))
64  endif
65  %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
82  call Run_cjk_linebreak_nobetween(0)
83endfunc
84
85func Test_cjk_linebreak_nobetween_rigorous()
86  set formatoptions=croqn2mB1j]
87  call Run_cjk_linebreak_nobetween(1)
88endfunc
89
90func Test_cjk_linebreak_join_punct()
91  for punct in ['——', '〗', ',', '。', '……']
92    call setline(1, '文本文本' .. punct)
93    call setline(2, 'English')
94    set formatoptions=croqn2mB1j
95    normal ggJ
96    call assert_equal('文本文本' .. punct.'English', getline(1))
97    %d_
98  endfor
99endfunc
100
101" vim: shiftwidth=2 sts=2 expandtab
102