test_cjk_linebreak.vim 2.8 KB

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