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