annotate src/testdir/test_cursor_func.vim @ 25409:e3f1086429d8 v8.2.3241

patch 8.2.3241: Vim9: memory leak when function reports an error Commit: https://github.com/vim/vim/commit/6e850a6900793e215c08b39d6490173488cb05ce Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jul 28 22:21:23 2021 +0200 patch 8.2.3241: Vim9: memory leak when function reports an error Problem: Vim9: memory leak when function reports an error. Solution: Clear the return value.
author Bram Moolenaar <Bram@vim.org>
date Wed, 28 Jul 2021 22:30:04 +0200
parents 7a254d0705e2
children fb67cd7d30a7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1 " Tests for cursor() and other functions that get/set the cursor position
7590
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 func Test_wrong_arguments()
11183
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 11105
diff changeset
4 call assert_fails('call cursor(1. 3)', 'E474:')
20158
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
5 call assert_fails('call cursor(test_null_list())', 'E474:')
7590
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 endfunc
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 func Test_move_cursor()
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 new
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 call setline(1, ['aaa', 'bbb', 'ccc', 'ddd'])
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 call cursor([1, 1, 0, 1])
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 call assert_equal([1, 1, 0, 1], getcurpos()[1:])
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 call cursor([4, 3, 0, 3])
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 call assert_equal([4, 3, 0, 3], getcurpos()[1:])
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 call cursor(2, 2)
8011
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
18 call assert_equal([2, 2, 0, 2], getcurpos()[1:])
7590
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 " line number zero keeps the line number
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 call cursor(0, 1)
8011
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
21 call assert_equal([2, 1, 0, 1], getcurpos()[1:])
7590
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 " col number zero keeps the column
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 call cursor(3, 0)
8011
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
24 call assert_equal([3, 1, 0, 1], getcurpos()[1:])
7590
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 " below last line goes to last line
17837
f71ee7b04f0b patch 8.1.1915: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17292
diff changeset
26 eval [9, 1]->cursor()
8011
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
27 call assert_equal([4, 1, 0, 1], getcurpos()[1:])
23642
8df4e9e2394f patch 8.2.2363: curpos() does not accept a string argument as before
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
28 " pass string arguments
8df4e9e2394f patch 8.2.2363: curpos() does not accept a string argument as before
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
29 call cursor('3', '3')
8df4e9e2394f patch 8.2.2363: curpos() does not accept a string argument as before
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
30 call assert_equal([3, 3, 0, 3], getcurpos()[1:])
7590
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31
16668
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 15492
diff changeset
32 call setline(1, ["\<TAB>"])
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 15492
diff changeset
33 call cursor(1, 1, 1)
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 15492
diff changeset
34 call assert_equal([1, 1, 1], getcurpos()[1:3])
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 15492
diff changeset
35
23276
b79cdad3ea2e patch 8.2.2184: Vim9: no error when using "2" for a line number
Bram Moolenaar <Bram@vim.org>
parents: 23213
diff changeset
36 call assert_fails('call cursor(-1, -1)', 'E475:')
16668
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 15492
diff changeset
37
7590
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 quit!
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 endfunc
8011
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
40
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
41 " Very short version of what matchparen does.
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
42 function s:Highlight_Matching_Pair()
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
43 let save_cursor = getcurpos()
18000
7a19c8d6bb9e patch 8.1.1996: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17994
diff changeset
44 eval save_cursor->setpos('.')
8011
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
45 endfunc
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
46
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
47 func Test_curswant_with_autocommand()
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
48 new
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
49 call setline(1, ['func()', '{', '}', '----'])
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
50 autocmd! CursorMovedI * call s:Highlight_Matching_Pair()
11105
7c7e496e625d patch 8.0.0440: not enough test coverage in Insert mode
Christian Brabandt <cb@256bit.org>
parents: 9121
diff changeset
51 call test_override("char_avail", 1)
8011
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
52 exe "normal! 3Ga\<Down>X\<Esc>"
11105
7c7e496e625d patch 8.0.0440: not enough test coverage in Insert mode
Christian Brabandt <cb@256bit.org>
parents: 9121
diff changeset
53 call test_override("char_avail", 0)
8011
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
54 call assert_equal('-X---', getline(4))
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
55 autocmd! CursorMovedI *
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
56 quit!
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
57 endfunc
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
58
15492
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
59 " Tests for behavior of curswant with cursorcolumn/line
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
60 func Test_curswant_with_cursorcolumn()
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
61 new
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
62 call setline(1, ['01234567', ''])
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
63 exe "normal! ggf6j"
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
64 call assert_equal(6, winsaveview().curswant)
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
65 set cursorcolumn
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
66 call assert_equal(6, winsaveview().curswant)
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
67 quit!
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
68 endfunc
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
69
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
70 func Test_curswant_with_cursorline()
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
71 new
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
72 call setline(1, ['01234567', ''])
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
73 exe "normal! ggf6j"
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
74 call assert_equal(6, winsaveview().curswant)
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
75 set cursorline
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
76 call assert_equal(6, winsaveview().curswant)
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
77 quit!
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
78 endfunc
17292
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
79
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
80 func Test_screenpos()
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
81 rightbelow new
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
82 rightbelow 20vsplit
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
83 call setline(1, ["\tsome text", "long wrapping line here", "next line"])
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
84 redraw
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
85 let winid = win_getid()
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
86 let [winrow, wincol] = win_screenpos(winid)
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
87 call assert_equal({'row': winrow,
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
88 \ 'col': wincol + 0,
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
89 \ 'curscol': wincol + 7,
18035
11dca9732a48 patch 8.1.2013: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 18000
diff changeset
90 \ 'endcol': wincol + 7}, winid->screenpos(1, 1))
17292
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
91 call assert_equal({'row': winrow,
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
92 \ 'col': wincol + 13,
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
93 \ 'curscol': wincol + 13,
17994
0dcc2ee838dd patch 8.1.1993: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17837
diff changeset
94 \ 'endcol': wincol + 13}, winid->screenpos(1, 7))
17292
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
95 call assert_equal({'row': winrow + 2,
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
96 \ 'col': wincol + 1,
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
97 \ 'curscol': wincol + 1,
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
98 \ 'endcol': wincol + 1}, screenpos(winid, 2, 22))
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
99 setlocal number
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
100 call assert_equal({'row': winrow + 3,
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
101 \ 'col': wincol + 9,
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
102 \ 'curscol': wincol + 9,
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
103 \ 'endcol': wincol + 9}, screenpos(winid, 2, 22))
25312
7a254d0705e2 patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents: 23642
diff changeset
104
7a254d0705e2 patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents: 23642
diff changeset
105 let wininfo = getwininfo(winid)[0]
7a254d0705e2 patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents: 23642
diff changeset
106 call setline(3, ['x']->repeat(wininfo.height))
7a254d0705e2 patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents: 23642
diff changeset
107 call setline(line('$') + 1, 'x'->repeat(wininfo.width * 3))
7a254d0705e2 patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents: 23642
diff changeset
108 setlocal nonumber display=lastline so=0
7a254d0705e2 patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents: 23642
diff changeset
109 exe "normal G\<C-Y>\<C-Y>"
7a254d0705e2 patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents: 23642
diff changeset
110 redraw
7a254d0705e2 patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents: 23642
diff changeset
111 call assert_equal({'row': winrow + wininfo.height - 1,
7a254d0705e2 patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents: 23642
diff changeset
112 \ 'col': wincol + 7,
7a254d0705e2 patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents: 23642
diff changeset
113 \ 'curscol': wincol + 7,
7a254d0705e2 patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents: 23642
diff changeset
114 \ 'endcol': wincol + 7}, winid->screenpos(line('$'), 8))
7a254d0705e2 patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents: 23642
diff changeset
115 call assert_equal({'row': winrow - 1, 'col': 0, 'curscol': 0, 'endcol': 0},
7a254d0705e2 patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents: 23642
diff changeset
116 \ winid->screenpos(line('$'), 22))
7a254d0705e2 patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents: 23642
diff changeset
117
17292
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
118 close
20978
2c3e7a6bd6c6 patch 8.2.1040: not enough testing for movement commands
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
119 call assert_equal({}, screenpos(999, 1, 1))
25312
7a254d0705e2 patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents: 23642
diff changeset
120
17292
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
121 bwipe!
25312
7a254d0705e2 patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents: 23642
diff changeset
122 set display&
23213
477f1b4c6826 patch 8.2.2152: screenpos() does not include the WinBar offset
Bram Moolenaar <Bram@vim.org>
parents: 20978
diff changeset
123
477f1b4c6826 patch 8.2.2152: screenpos() does not include the WinBar offset
Bram Moolenaar <Bram@vim.org>
parents: 20978
diff changeset
124 call assert_equal({'col': 1, 'row': 1, 'endcol': 1, 'curscol': 1}, screenpos(win_getid(), 1, 1))
477f1b4c6826 patch 8.2.2152: screenpos() does not include the WinBar offset
Bram Moolenaar <Bram@vim.org>
parents: 20978
diff changeset
125 nmenu WinBar.TEST :
477f1b4c6826 patch 8.2.2152: screenpos() does not include the WinBar offset
Bram Moolenaar <Bram@vim.org>
parents: 20978
diff changeset
126 call assert_equal({'col': 1, 'row': 2, 'endcol': 1, 'curscol': 1}, screenpos(win_getid(), 1, 1))
477f1b4c6826 patch 8.2.2152: screenpos() does not include the WinBar offset
Bram Moolenaar <Bram@vim.org>
parents: 20978
diff changeset
127 nunmenu WinBar.TEST
17292
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
128 endfunc
18469
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
129
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
130 func Test_screenpos_number()
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
131 rightbelow new
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
132 rightbelow 73vsplit
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
133 call setline (1, repeat('x', 66))
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
134 setlocal number
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
135 redraw
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
136 let winid = win_getid()
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
137 let [winrow, wincol] = win_screenpos(winid)
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
138 let pos = screenpos(winid, 1, 66)
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
139 call assert_equal(winrow, pos.row)
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
140 call assert_equal(wincol + 66 + 3, pos.col)
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
141 close
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
142 bwipe!
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
143 endfunc
20109
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 18469
diff changeset
144
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
145 " Save the visual start character position
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
146 func SaveVisualStartCharPos()
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
147 call add(g:VisualStartPos, getcharpos('v'))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
148 return ''
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
149 endfunc
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
150
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
151 " Save the current cursor character position in insert mode
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
152 func SaveInsertCurrentCharPos()
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
153 call add(g:InsertCurrentPos, getcharpos('.'))
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
154 return ''
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
155 endfunc
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
156
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
157 " Test for the getcharpos() function
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
158 func Test_getcharpos()
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
159 call assert_fails('call getcharpos({})', 'E731:')
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
160 call assert_equal([0, 0, 0, 0], getcharpos(0))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
161 new
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
162 call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678'])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
163
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
164 " Test for '.' and '$'
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
165 normal 1G
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
166 call assert_equal([0, 1, 1, 0], getcharpos('.'))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
167 call assert_equal([0, 4, 1, 0], getcharpos('$'))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
168 normal 2G6l
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
169 call assert_equal([0, 2, 7, 0], getcharpos('.'))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
170 normal 3G$
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
171 call assert_equal([0, 3, 1, 0], getcharpos('.'))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
172 normal 4G$
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
173 call assert_equal([0, 4, 9, 0], getcharpos('.'))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
174
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
175 " Test for a mark
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
176 normal 2G7lmmgg
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
177 call assert_equal([0, 2, 8, 0], getcharpos("'m"))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
178 delmarks m
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
179 call assert_equal([0, 0, 0, 0], getcharpos("'m"))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
180
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
181 " Test for the visual start column
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
182 vnoremap <expr> <F3> SaveVisualStartCharPos()
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
183 let g:VisualStartPos = []
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
184 exe "normal 2G6lv$\<F3>ohh\<F3>o\<F3>"
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
185 call assert_equal([[0, 2, 7, 0], [0, 2, 10, 0], [0, 2, 5, 0]], g:VisualStartPos)
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
186 call assert_equal([0, 2, 9, 0], getcharpos('v'))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
187 let g:VisualStartPos = []
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
188 exe "normal 3Gv$\<F3>o\<F3>"
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
189 call assert_equal([[0, 3, 1, 0], [0, 3, 2, 0]], g:VisualStartPos)
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
190 let g:VisualStartPos = []
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
191 exe "normal 1Gv$\<F3>o\<F3>"
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
192 call assert_equal([[0, 1, 1, 0], [0, 1, 1, 0]], g:VisualStartPos)
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
193 vunmap <F3>
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
194
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
195 " Test for getting the position in insert mode with the cursor after the
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
196 " last character in a line
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
197 inoremap <expr> <F3> SaveInsertCurrentCharPos()
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
198 let g:InsertCurrentPos = []
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
199 exe "normal 1GA\<F3>"
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
200 exe "normal 2GA\<F3>"
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
201 exe "normal 3GA\<F3>"
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
202 exe "normal 4GA\<F3>"
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
203 exe "normal 2G6li\<F3>"
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
204 call assert_equal([[0, 1, 1, 0], [0, 2, 10, 0], [0, 3, 2, 0], [0, 4, 10, 0],
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
205 \ [0, 2, 7, 0]], g:InsertCurrentPos)
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
206 iunmap <F3>
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
207
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
208 %bw!
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
209 endfunc
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
210
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
211 " Test for the setcharpos() function
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
212 func Test_setcharpos()
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
213 call assert_equal(-1, setcharpos('.', test_null_list()))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
214 new
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
215 call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678'])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
216 call setcharpos('.', [0, 1, 1, 0])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
217 call assert_equal([1, 1], [line('.'), col('.')])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
218 call setcharpos('.', [0, 2, 7, 0])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
219 call assert_equal([2, 9], [line('.'), col('.')])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
220 call setcharpos('.', [0, 3, 4, 0])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
221 call assert_equal([3, 1], [line('.'), col('.')])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
222 call setcharpos('.', [0, 3, 1, 0])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
223 call assert_equal([3, 1], [line('.'), col('.')])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
224 call setcharpos('.', [0, 4, 0, 0])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
225 call assert_equal([4, 1], [line('.'), col('.')])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
226 call setcharpos('.', [0, 4, 20, 0])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
227 call assert_equal([4, 9], [line('.'), col('.')])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
228
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
229 " Test for mark
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
230 delmarks m
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
231 call setcharpos("'m", [0, 2, 9, 0])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
232 normal `m
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
233 call assert_equal([2, 11], [line('.'), col('.')])
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
234 " unload the buffer and try to set the mark
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
235 let bnr = bufnr()
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
236 enew!
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
237 call assert_equal(-1, setcharpos("'m", [bnr, 2, 2, 0]))
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
238
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
239 %bw!
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
240 call assert_equal(-1, setcharpos('.', [10, 3, 1, 0]))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
241 endfunc
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
242
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
243 func SaveVisualStartCharCol()
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
244 call add(g:VisualStartCol, charcol('v'))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
245 return ''
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
246 endfunc
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
247
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
248 func SaveInsertCurrentCharCol()
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
249 call add(g:InsertCurrentCol, charcol('.'))
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
250 return ''
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
251 endfunc
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
252
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
253 " Test for the charcol() function
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
254 func Test_charcol()
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
255 call assert_fails('call charcol({})', 'E731:')
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
256 call assert_equal(0, charcol(0))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
257 new
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
258 call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678'])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
259
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
260 " Test for '.' and '$'
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
261 normal 1G
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
262 call assert_equal(1, charcol('.'))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
263 call assert_equal(1, charcol('$'))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
264 normal 2G6l
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
265 call assert_equal(7, charcol('.'))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
266 call assert_equal(10, charcol('$'))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
267 normal 3G$
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
268 call assert_equal(1, charcol('.'))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
269 call assert_equal(2, charcol('$'))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
270 normal 4G$
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
271 call assert_equal(9, charcol('.'))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
272 call assert_equal(10, charcol('$'))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
273
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
274 " Test for [lnum, '$']
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
275 call assert_equal(1, charcol([1, '$']))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
276 call assert_equal(10, charcol([2, '$']))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
277 call assert_equal(2, charcol([3, '$']))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
278 call assert_equal(0, charcol([5, '$']))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
279
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
280 " Test for a mark
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
281 normal 2G7lmmgg
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
282 call assert_equal(8, charcol("'m"))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
283 delmarks m
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
284 call assert_equal(0, charcol("'m"))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
285
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
286 " Test for the visual start column
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
287 vnoremap <expr> <F3> SaveVisualStartCharCol()
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
288 let g:VisualStartCol = []
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
289 exe "normal 2G6lv$\<F3>ohh\<F3>o\<F3>"
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
290 call assert_equal([7, 10, 5], g:VisualStartCol)
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
291 call assert_equal(9, charcol('v'))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
292 let g:VisualStartCol = []
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
293 exe "normal 3Gv$\<F3>o\<F3>"
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
294 call assert_equal([1, 2], g:VisualStartCol)
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
295 let g:VisualStartCol = []
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
296 exe "normal 1Gv$\<F3>o\<F3>"
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
297 call assert_equal([1, 1], g:VisualStartCol)
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
298 vunmap <F3>
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
299
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
300 " Test for getting the column number in insert mode with the cursor after
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
301 " the last character in a line
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
302 inoremap <expr> <F3> SaveInsertCurrentCharCol()
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
303 let g:InsertCurrentCol = []
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
304 exe "normal 1GA\<F3>"
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
305 exe "normal 2GA\<F3>"
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
306 exe "normal 3GA\<F3>"
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
307 exe "normal 4GA\<F3>"
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
308 exe "normal 2G6li\<F3>"
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
309 call assert_equal([1, 10, 2, 10, 7], g:InsertCurrentCol)
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
310 iunmap <F3>
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
311
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
312 %bw!
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
313 endfunc
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
314
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
315 func SaveInsertCursorCharPos()
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
316 call add(g:InsertCursorPos, getcursorcharpos('.'))
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
317 return ''
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
318 endfunc
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
319
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
320 " Test for getcursorcharpos()
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
321 func Test_getcursorcharpos()
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
322 call assert_equal(getcursorcharpos(), getcursorcharpos(0))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
323 call assert_equal([0, 0, 0, 0, 0], getcursorcharpos(-1))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
324 call assert_equal([0, 0, 0, 0, 0], getcursorcharpos(1999))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
325
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
326 new
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
327 call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678'])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
328 normal 1G9l
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
329 call assert_equal([0, 1, 1, 0, 1], getcursorcharpos())
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
330 normal 2G9l
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
331 call assert_equal([0, 2, 9, 0, 14], getcursorcharpos())
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
332 normal 3G9l
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
333 call assert_equal([0, 3, 1, 0, 1], getcursorcharpos())
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
334 normal 4G9l
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
335 call assert_equal([0, 4, 9, 0, 9], getcursorcharpos())
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
336
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
337 " Test for getting the cursor position in insert mode with the cursor after
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
338 " the last character in a line
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
339 inoremap <expr> <F3> SaveInsertCursorCharPos()
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
340 let g:InsertCursorPos = []
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
341 exe "normal 1GA\<F3>"
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
342 exe "normal 2GA\<F3>"
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
343 exe "normal 3GA\<F3>"
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
344 exe "normal 4GA\<F3>"
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
345 exe "normal 2G6li\<F3>"
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
346 call assert_equal([[0, 1, 1, 0, 1], [0, 2, 10, 0, 15], [0, 3, 2, 0, 2],
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
347 \ [0, 4, 10, 0, 10], [0, 2, 7, 0, 12]], g:InsertCursorPos)
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
348 iunmap <F3>
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
349
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
350 let winid = win_getid()
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
351 normal 2G5l
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
352 wincmd w
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
353 call assert_equal([0, 2, 6, 0, 11], getcursorcharpos(winid))
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
354 %bw!
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
355 endfunc
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
356
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
357 " Test for setcursorcharpos()
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
358 func Test_setcursorcharpos()
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
359 call assert_fails('call setcursorcharpos(test_null_list())', 'E474:')
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
360 call assert_fails('call setcursorcharpos([1])', 'E474:')
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
361 call assert_fails('call setcursorcharpos([1, 1, 1, 1, 1])', 'E474:')
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
362 new
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
363 call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678'])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
364 normal G
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
365 call setcursorcharpos([1, 1])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
366 call assert_equal([1, 1], [line('.'), col('.')])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
367 call setcursorcharpos([2, 7, 0])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
368 call assert_equal([2, 9], [line('.'), col('.')])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
369 call setcursorcharpos(3, 4)
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
370 call assert_equal([3, 1], [line('.'), col('.')])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
371 call setcursorcharpos([3, 1])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
372 call assert_equal([3, 1], [line('.'), col('.')])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
373 call setcursorcharpos([4, 0, 0, 0])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
374 call assert_equal([4, 1], [line('.'), col('.')])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
375 call setcursorcharpos([4, 20])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
376 call assert_equal([4, 9], [line('.'), col('.')])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
377 normal 1G
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
378 call setcursorcharpos([100, 100, 100, 100])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
379 call assert_equal([4, 9], [line('.'), col('.')])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
380 normal 1G
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
381 call setcursorcharpos('$', 1)
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
382 call assert_equal([4, 1], [line('.'), col('.')])
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
383
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
384 %bw!
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
385 endfunc
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
386
20109
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 18469
diff changeset
387 " vim: shiftwidth=2 sts=2 expandtab