Mercurial > vim
comparison src/testdir/test_cjk_linebreak.vim @ 20695:cea8ae407452 v8.2.0901
patch 8.2.0901: formatting CJK text isn't optimal
Commit: https://github.com/vim/vim/commit/e52702f00322c8a8861efd0bd6a3775e685e5685
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jun 4 18:22:13 2020 +0200
patch 8.2.0901: formatting CJK text isn't optimal
Problem: Formatting CJK text isn't optimal.
Solution: Properly break CJK lines. (closes https://github.com/vim/vim/issues/3875)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 04 Jun 2020 18:30:04 +0200 |
parents | |
children | ef2a4a650c67 |
comparison
equal
deleted
inserted
replaced
20694:3a049f4bdaa2 | 20695:cea8ae407452 |
---|---|
1 scriptencoding utf-8 | |
2 | |
3 func Run_cjk_linebreak_after() | |
4 set textwidth=12 | |
5 for punct in [ | |
6 \ '!', '%', ')', ',', ':', ';', '>', '?', ']', '}', '’', '”', '†', '‡', | |
7 \ '…', '‰', '‱', '‼', '⁇', '⁈', '⁉', '℃', '℉', '、', '。', '〉', '》', | |
8 \ '」', '』', '】', '〕', '〗', '〙', '〛', '!', ')', ',', '.', ':', | |
9 \ ';', '?', ']', '}'] | |
10 call setline('.', '这是一个测试'.punct.'试试 CJK 行禁则补丁。') | |
11 normal gqq | |
12 call assert_equal('这是一个测试'.punct, getline(1)) | |
13 %d_ | |
14 endfor | |
15 endfunc | |
16 | |
17 func Test_cjk_linebreak_after() | |
18 set formatoptions=croqn2mB1j | |
19 call Run_cjk_linebreak_after() | |
20 endfunc | |
21 | |
22 " TODO: this test fails | |
23 "func Test_cjk_linebreak_after_rigorous() | |
24 " set formatoptions=croqn2mB1j] | |
25 " call Run_cjk_linebreak_after() | |
26 "endfunc | |
27 | |
28 func Run_cjk_linebreak_before() | |
29 set textwidth=12 | |
30 for punct in [ | |
31 \ '(', '<', '[', '`', '{', '‘', '“', '〈', '《', '「', '『', '【', '〔', | |
32 \ '〖', '〘', '〚', '(', '[', '{'] | |
33 call setline('.', '这是个测试'.punct.'试试 CJK 行禁则补丁。') | |
34 normal gqq | |
35 call assert_equal('这是个测试', getline(1)) | |
36 %d_ | |
37 endfor | |
38 endfunc | |
39 | |
40 func Test_cjk_linebreak_before() | |
41 set formatoptions=croqn2mB1j | |
42 call Run_cjk_linebreak_before() | |
43 endfunc | |
44 | |
45 func Test_cjk_linebreak_before_rigorous() | |
46 set formatoptions=croqn2mB1j] | |
47 call Run_cjk_linebreak_before() | |
48 endfunc | |
49 | |
50 func Run_cjk_linebreak_nobetween() | |
51 " …… must not start a line | |
52 call setline('.', '这是个测试……试试 CJK 行禁则补丁。') | |
53 set textwidth=12 ambiwidth=double | |
54 normal gqq | |
55 " TODO: this fails | |
56 " call assert_equal('这是个测试……', getline(1)) | |
57 %d_ | |
58 | |
59 call setline('.', '这是一个测试……试试 CJK 行禁则补丁。') | |
60 set textwidth=12 ambiwidth=double | |
61 normal gqq | |
62 call assert_equal('这是一个测', getline(1)) | |
63 %d_ | |
64 | |
65 " but —— can | |
66 call setline('.', '这是个测试——试试 CJK 行禁则补丁。') | |
67 set textwidth=12 ambiwidth=double | |
68 normal gqq | |
69 call assert_equal('这是个测试', getline(1)) | |
70 endfunc | |
71 | |
72 func Test_cjk_linebreak_nobetween() | |
73 set formatoptions=croqn2mB1j | |
74 call Run_cjk_linebreak_nobetween() | |
75 endfunc | |
76 | |
77 func Test_cjk_linebreak_nobetween_rigorous() | |
78 set formatoptions=croqn2mB1j] | |
79 call Run_cjk_linebreak_nobetween() | |
80 endfunc | |
81 | |
82 func Test_cjk_linebreak_join_punct() | |
83 for punct in ['——', '〗', ',', '。', '……'] | |
84 call setline(1, '文本文本'.punct) | |
85 call setline(2, 'English') | |
86 set formatoptions=croqn2mB1j | |
87 normal ggJ | |
88 call assert_equal('文本文本'.punct.'English', getline(1)) | |
89 %d_ | |
90 endfor | |
91 endfunc |