annotate src/testdir/test_utf8.vim @ 26022:30e60bfd5fb3 v8.2.3545

patch 8.2.3545: setcellwidths() may make 'listchars' or 'fillchars' invalid Commit: https://github.com/vim/vim/commit/94358a1e6e640ca5ebeb295efdddd4e92b700673 Author: zeertzjq <zeertzjq@outlook.com> Date: Wed Oct 20 11:01:15 2021 +0100 patch 8.2.3545: setcellwidths() may make 'listchars' or 'fillchars' invalid Problem: setcellwidths() may make 'listchars' or 'fillchars' invalid. Solution: Check the value and give an error. (closes https://github.com/vim/vim/issues/9024)
author Bram Moolenaar <Bram@vim.org>
date Wed, 20 Oct 2021 12:15:04 +0200
parents c3d1f65365c4
children 8d4b44cc324e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10720
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Tests for Unicode manipulations
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
16133
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
3 source view_util.vim
10720
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 " Visual block Insert adjusts for multi-byte char
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 func Test_visual_block_insert()
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 new
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 call setline(1, ["aaa", "あああ", "bbb"])
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 exe ":norm! gg0l\<C-V>jjIx\<Esc>"
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 call assert_equal(['axaa', 'xあああ', 'bxbb'], getline(1, '$'))
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 bwipeout!
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 endfunc
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13
24130
c3d1f65365c4 patch 8.2.2606: strchars() defaults to counting composing characters
Bram Moolenaar <Bram@vim.org>
parents: 23064
diff changeset
14 " Test for built-in functions strchars() and strcharlen()
10720
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 func Test_strchars()
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 let inp = ["a", "あいa", "A\u20dd", "A\u20dd\u20dd", "\u20dd"]
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 let exp = [[1, 1, 1], [3, 3, 3], [2, 2, 1], [3, 3, 1], [1, 1, 1]]
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 for i in range(len(inp))
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 call assert_equal(exp[i][0], strchars(inp[i]))
18017
988e5a868b60 patch 8.1.2004: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17994
diff changeset
20 call assert_equal(exp[i][1], inp[i]->strchars(0))
10720
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 call assert_equal(exp[i][2], strchars(inp[i], 1))
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 endfor
24130
c3d1f65365c4 patch 8.2.2606: strchars() defaults to counting composing characters
Bram Moolenaar <Bram@vim.org>
parents: 23064
diff changeset
23
c3d1f65365c4 patch 8.2.2606: strchars() defaults to counting composing characters
Bram Moolenaar <Bram@vim.org>
parents: 23064
diff changeset
24 let exp = [1, 3, 1, 1, 1]
c3d1f65365c4 patch 8.2.2606: strchars() defaults to counting composing characters
Bram Moolenaar <Bram@vim.org>
parents: 23064
diff changeset
25 for i in range(len(inp))
c3d1f65365c4 patch 8.2.2606: strchars() defaults to counting composing characters
Bram Moolenaar <Bram@vim.org>
parents: 23064
diff changeset
26 call assert_equal(exp[i], inp[i]->strcharlen())
c3d1f65365c4 patch 8.2.2606: strchars() defaults to counting composing characters
Bram Moolenaar <Bram@vim.org>
parents: 23064
diff changeset
27 call assert_equal(exp[i], strcharlen(inp[i]))
c3d1f65365c4 patch 8.2.2606: strchars() defaults to counting composing characters
Bram Moolenaar <Bram@vim.org>
parents: 23064
diff changeset
28 endfor
c3d1f65365c4 patch 8.2.2606: strchars() defaults to counting composing characters
Bram Moolenaar <Bram@vim.org>
parents: 23064
diff changeset
29
21265
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
30 call assert_fails("let v=strchars('abc', [])", 'E745:')
22153
7aa10e8e7aec patch 8.2.1626: test for strchars() fails with different error number
Bram Moolenaar <Bram@vim.org>
parents: 21975
diff changeset
31 call assert_fails("let v=strchars('abc', 2)", 'E1023:')
10720
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 endfunc
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 " Test for customlist completion
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 10720
diff changeset
35 func CustomComplete1(lead, line, pos)
10720
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 return ['あ', 'い']
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 10720
diff changeset
37 endfunc
10720
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 10720
diff changeset
39 func CustomComplete2(lead, line, pos)
10720
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 return ['あたし', 'あたま', 'あたりめ']
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 10720
diff changeset
41 endfunc
10720
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 10720
diff changeset
43 func CustomComplete3(lead, line, pos)
10720
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 return ['Nこ', 'Nん', 'Nぶ']
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 10720
diff changeset
45 endfunc
10720
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 func Test_customlist_completion()
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 command -nargs=1 -complete=customlist,CustomComplete1 Test1 echo
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 call feedkeys(":Test1 \<C-L>\<C-B>\"\<CR>", 'itx')
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 call assert_equal('"Test1 ', getreg(':'))
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 call feedkeys(":Test2 \<C-L>\<C-B>\"\<CR>", 'itx')
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 call assert_equal('"Test2 あた', getreg(':'))
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 command -nargs=1 -complete=customlist,CustomComplete3 Test3 echo
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 call feedkeys(":Test3 \<C-L>\<C-B>\"\<CR>", 'itx')
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 call assert_equal('"Test3 N', getreg(':'))
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 call garbagecollect(1)
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 endfunc
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 " Yank one 3 byte character and check the mark columns.
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 func Test_getvcol()
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 new
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 call setline(1, "x\u2500x")
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 normal 0lvy
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 call assert_equal(2, col("'["))
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 call assert_equal(4, col("']"))
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 call assert_equal(2, virtcol("'["))
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71 call assert_equal(2, virtcol("']"))
44a1661f4cfa patch 8.0.0250: virtcol() does not work well for multi-byte characters
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 endfunc
16133
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
73
16235
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
74 func Test_list2str_str2list_utf8()
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
75 " One Unicode codepoint
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
76 let s = "\u3042\u3044"
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
77 let l = [0x3042, 0x3044]
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
78 call assert_equal(l, str2list(s, 1))
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
79 call assert_equal(s, list2str(l, 1))
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
80 if &enc ==# 'utf-8'
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
81 call assert_equal(str2list(s), str2list(s, 1))
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
82 call assert_equal(list2str(l), list2str(l, 1))
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
83 endif
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
84
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
85 " With composing characters
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
86 let s = "\u304b\u3099\u3044"
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
87 let l = [0x304b, 0x3099, 0x3044]
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
88 call assert_equal(l, str2list(s, 1))
17916
2e53305f2239 patch 8.1.1954: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 16235
diff changeset
89 call assert_equal(s, l->list2str(1))
16235
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
90 if &enc ==# 'utf-8'
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
91 call assert_equal(str2list(s), str2list(s, 1))
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
92 call assert_equal(list2str(l), list2str(l, 1))
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
93 endif
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
94
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
95 " Null list is the same as an empty list
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
96 call assert_equal('', list2str([]))
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
97 call assert_equal('', list2str(test_null_list()))
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
98 endfunc
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
99
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
100 func Test_list2str_str2list_latin1()
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
101 " When 'encoding' is not multi-byte can still get utf-8 string.
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
102 " But we need to create the utf-8 string while 'encoding' is utf-8.
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
103 let s = "\u3042\u3044"
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
104 let l = [0x3042, 0x3044]
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
105
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
106 let save_encoding = &encoding
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
107 set encoding=latin1
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
108
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
109 let lres = str2list(s, 1)
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
110 let sres = list2str(l, 1)
19783
546bdeef35f1 patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 18017
diff changeset
111 call assert_equal([65, 66, 67], str2list("ABC"))
16235
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
112
20109
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
113 " Try converting a list to a string in latin-1 encoding
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
114 call assert_equal([1, 2, 3], str2list(list2str([1, 2, 3])))
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
115
16235
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
116 let &encoding = save_encoding
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
117 call assert_equal(l, lres)
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
118 call assert_equal(s, sres)
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
119 endfunc
219c58b3879c patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents: 16148
diff changeset
120
16133
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
121 func Test_screenchar_utf8()
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
122 new
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
123
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
124 " 1-cell, with composing characters
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
125 call setline(1, ["ABC\u0308"])
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
126 redraw
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
127 call assert_equal([0x0041], screenchars(1, 1))
17994
0dcc2ee838dd patch 8.1.1993: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
128 call assert_equal([0x0042], 1->screenchars(2))
16133
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
129 call assert_equal([0x0043, 0x0308], screenchars(1, 3))
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
130 call assert_equal("A", screenstring(1, 1))
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
131 call assert_equal("B", screenstring(1, 2))
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
132 call assert_equal("C\u0308", screenstring(1, 3))
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
133
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
134 " 2-cells, with composing characters
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
135 let text = "\u3042\u3044\u3046\u3099"
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
136 call setline(1, text)
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
137 redraw
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
138 call assert_equal([0x3042], screenchars(1, 1))
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
139 call assert_equal([0], screenchars(1, 2))
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
140 call assert_equal([0x3044], screenchars(1, 3))
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
141 call assert_equal([0], screenchars(1, 4))
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
142 call assert_equal([0x3046, 0x3099], screenchars(1, 5))
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
143
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
144 call assert_equal("\u3042", screenstring(1, 1))
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
145 call assert_equal("", screenstring(1, 2))
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
146 call assert_equal("\u3044", screenstring(1, 3))
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
147 call assert_equal("", screenstring(1, 4))
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
148 call assert_equal("\u3046\u3099", screenstring(1, 5))
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
149
16148
90b0f2227d73 patch 8.1.1079: no need for a separate ScreenLinesUtf8() test function
Bram Moolenaar <Bram@vim.org>
parents: 16133
diff changeset
150 call assert_equal([text . ' '], ScreenLines(1, 8))
16133
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
151
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
152 bwipe!
eb087f8a26a8 patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
153 endfunc
19783
546bdeef35f1 patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 18017
diff changeset
154
21971
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
155 func Test_setcellwidths()
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
156 call setcellwidths([
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
157 \ [0x1330, 0x1330, 2],
21975
2030f8267db9 patch 8.2.1537: memory acccess error when using setcellwidths()
Bram Moolenaar <Bram@vim.org>
parents: 21971
diff changeset
158 \ [9999, 10000, 1],
21971
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
159 \ [0x1337, 0x1339, 2],
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
160 \])
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
161
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
162 call assert_equal(2, strwidth("\u1330"))
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
163 call assert_equal(1, strwidth("\u1336"))
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
164 call assert_equal(2, strwidth("\u1337"))
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
165 call assert_equal(2, strwidth("\u1339"))
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
166 call assert_equal(1, strwidth("\u133a"))
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
167
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
168 call setcellwidths([])
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
169
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
170 call assert_fails('call setcellwidths(1)', 'E714:')
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
171
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
172 call assert_fails('call setcellwidths([1, 2, 0])', 'E1109:')
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
173
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
174 call assert_fails('call setcellwidths([[0x101]])', 'E1110:')
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
175 call assert_fails('call setcellwidths([[0x101, 0x102]])', 'E1110:')
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
176 call assert_fails('call setcellwidths([[0x101, 0x102, 1, 4]])', 'E1110:')
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
177 call assert_fails('call setcellwidths([["a"]])', 'E1110:')
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
178
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
179 call assert_fails('call setcellwidths([[0x102, 0x101, 1]])', 'E1111:')
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
180
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
181 call assert_fails('call setcellwidths([[0x101, 0x102, 0]])', 'E1112:')
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
182 call assert_fails('call setcellwidths([[0x101, 0x102, 3]])', 'E1112:')
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
183
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
184 call assert_fails('call setcellwidths([[0x111, 0x122, 1], [0x115, 0x116, 2]])', 'E1113:')
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
185 call assert_fails('call setcellwidths([[0x111, 0x122, 1], [0x122, 0x123, 2]])', 'E1113:')
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
186
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
187 call assert_fails('call setcellwidths([[0x33, 0x44, 2]])', 'E1114:')
26022
30e60bfd5fb3 patch 8.2.3545: setcellwidths() may make 'listchars' or 'fillchars' invalid
Bram Moolenaar <Bram@vim.org>
parents: 24130
diff changeset
188
30e60bfd5fb3 patch 8.2.3545: setcellwidths() may make 'listchars' or 'fillchars' invalid
Bram Moolenaar <Bram@vim.org>
parents: 24130
diff changeset
189 set listchars=tab:--\\u2192
30e60bfd5fb3 patch 8.2.3545: setcellwidths() may make 'listchars' or 'fillchars' invalid
Bram Moolenaar <Bram@vim.org>
parents: 24130
diff changeset
190 call assert_fails('call setcellwidths([[0x2192, 0x2192, 2]])', 'E834:')
30e60bfd5fb3 patch 8.2.3545: setcellwidths() may make 'listchars' or 'fillchars' invalid
Bram Moolenaar <Bram@vim.org>
parents: 24130
diff changeset
191
30e60bfd5fb3 patch 8.2.3545: setcellwidths() may make 'listchars' or 'fillchars' invalid
Bram Moolenaar <Bram@vim.org>
parents: 24130
diff changeset
192 set fillchars=stl:\\u2501
30e60bfd5fb3 patch 8.2.3545: setcellwidths() may make 'listchars' or 'fillchars' invalid
Bram Moolenaar <Bram@vim.org>
parents: 24130
diff changeset
193 call assert_fails('call setcellwidths([[0x2501, 0x2501, 2]])', 'E835:')
30e60bfd5fb3 patch 8.2.3545: setcellwidths() may make 'listchars' or 'fillchars' invalid
Bram Moolenaar <Bram@vim.org>
parents: 24130
diff changeset
194
30e60bfd5fb3 patch 8.2.3545: setcellwidths() may make 'listchars' or 'fillchars' invalid
Bram Moolenaar <Bram@vim.org>
parents: 24130
diff changeset
195 set listchars&
30e60bfd5fb3 patch 8.2.3545: setcellwidths() may make 'listchars' or 'fillchars' invalid
Bram Moolenaar <Bram@vim.org>
parents: 24130
diff changeset
196 set fillchars&
30e60bfd5fb3 patch 8.2.3545: setcellwidths() may make 'listchars' or 'fillchars' invalid
Bram Moolenaar <Bram@vim.org>
parents: 24130
diff changeset
197 call setcellwidths([])
21971
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
198 endfunc
0bc43a704f56 patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
199
23064
89c324e327c0 patch 8.2.2078: illegal memory access when using :print on invalid text
Bram Moolenaar <Bram@vim.org>
parents: 22153
diff changeset
200 func Test_print_overlong()
89c324e327c0 patch 8.2.2078: illegal memory access when using :print on invalid text
Bram Moolenaar <Bram@vim.org>
parents: 22153
diff changeset
201 " Text with more composing characters than MB_MAXBYTES.
89c324e327c0 patch 8.2.2078: illegal memory access when using :print on invalid text
Bram Moolenaar <Bram@vim.org>
parents: 22153
diff changeset
202 new
89c324e327c0 patch 8.2.2078: illegal memory access when using :print on invalid text
Bram Moolenaar <Bram@vim.org>
parents: 22153
diff changeset
203 call setline(1, 'axxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
89c324e327c0 patch 8.2.2078: illegal memory access when using :print on invalid text
Bram Moolenaar <Bram@vim.org>
parents: 22153
diff changeset
204 s/x/\=nr2char(1629)/g
89c324e327c0 patch 8.2.2078: illegal memory access when using :print on invalid text
Bram Moolenaar <Bram@vim.org>
parents: 22153
diff changeset
205 print
89c324e327c0 patch 8.2.2078: illegal memory access when using :print on invalid text
Bram Moolenaar <Bram@vim.org>
parents: 22153
diff changeset
206 bwipe!
89c324e327c0 patch 8.2.2078: illegal memory access when using :print on invalid text
Bram Moolenaar <Bram@vim.org>
parents: 22153
diff changeset
207 endfunc
89c324e327c0 patch 8.2.2078: illegal memory access when using :print on invalid text
Bram Moolenaar <Bram@vim.org>
parents: 22153
diff changeset
208
19783
546bdeef35f1 patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 18017
diff changeset
209 " vim: shiftwidth=2 sts=2 expandtab