neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

test_cjk_linebreak.vim (2816B)


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