annotate src/testdir/test_cursor_func.vim @ 31479:0c0b78aa7ae3 v9.0.1072

patch 9.0.1072: screenpos() column result in fold may be too small Commit: https://github.com/vim/vim/commit/ba2d19193201277397c25c1f5a134ea042542555 Author: zeertzjq <zeertzjq@outlook.com> Date: Sun Dec 18 12:28:59 2022 +0000 patch 9.0.1072: screenpos() column result in fold may be too small Problem: screenpos() column result in fold may be too small. Solution: Add space of 'number', sign column, etc. (closes https://github.com/vim/vim/issues/11715)
author Bram Moolenaar <Bram@vim.org>
date Sun, 18 Dec 2022 13:30:05 +0100
parents 040b59b92dca
children da44475fb8f5
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
27726
d3ed8b1a7bde patch 8.2.4389: screenpos() does not handle a position in a closed fold
Bram Moolenaar <Bram@vim.org>
parents: 27352
diff changeset
3 source check.vim
d3ed8b1a7bde patch 8.2.4389: screenpos() does not handle a position in a closed fold
Bram Moolenaar <Bram@vim.org>
parents: 27352
diff changeset
4
7590
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 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
6 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
7 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
8 endfunc
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 func Test_move_cursor()
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 new
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 call setline(1, ['aaa', 'bbb', 'ccc', 'ddd'])
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 call cursor([1, 1, 0, 1])
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 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
16 call cursor([4, 3, 0, 3])
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 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
18
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 call cursor(2, 2)
8011
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
20 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
21 " line number zero keeps the line number
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 call cursor(0, 1)
8011
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
23 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
24 " col number zero keeps the column
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 call cursor(3, 0)
8011
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
26 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
27 " 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
28 eval [9, 1]->cursor()
8011
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
29 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
30 " 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
31 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
32 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
33
16668
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 15492
diff changeset
34 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
35 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
36 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
37
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
38 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
39
7590
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 quit!
4d9814f9fc39 commit https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 endfunc
8011
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
42
26881
fb67cd7d30a7 patch 8.2.3969: value of MAXCOL not available in Vim script
Bram Moolenaar <Bram@vim.org>
parents: 25312
diff changeset
43 func Test_curswant_maxcol()
fb67cd7d30a7 patch 8.2.3969: value of MAXCOL not available in Vim script
Bram Moolenaar <Bram@vim.org>
parents: 25312
diff changeset
44 new
fb67cd7d30a7 patch 8.2.3969: value of MAXCOL not available in Vim script
Bram Moolenaar <Bram@vim.org>
parents: 25312
diff changeset
45 call setline(1, 'foo')
fb67cd7d30a7 patch 8.2.3969: value of MAXCOL not available in Vim script
Bram Moolenaar <Bram@vim.org>
parents: 25312
diff changeset
46
fb67cd7d30a7 patch 8.2.3969: value of MAXCOL not available in Vim script
Bram Moolenaar <Bram@vim.org>
parents: 25312
diff changeset
47 " Test that after "$" command curswant is set to the same value as v:maxcol.
fb67cd7d30a7 patch 8.2.3969: value of MAXCOL not available in Vim script
Bram Moolenaar <Bram@vim.org>
parents: 25312
diff changeset
48 normal! 1G$
fb67cd7d30a7 patch 8.2.3969: value of MAXCOL not available in Vim script
Bram Moolenaar <Bram@vim.org>
parents: 25312
diff changeset
49 call assert_equal(v:maxcol, getcurpos()[4])
fb67cd7d30a7 patch 8.2.3969: value of MAXCOL not available in Vim script
Bram Moolenaar <Bram@vim.org>
parents: 25312
diff changeset
50 call assert_equal(v:maxcol, winsaveview().curswant)
fb67cd7d30a7 patch 8.2.3969: value of MAXCOL not available in Vim script
Bram Moolenaar <Bram@vim.org>
parents: 25312
diff changeset
51
fb67cd7d30a7 patch 8.2.3969: value of MAXCOL not available in Vim script
Bram Moolenaar <Bram@vim.org>
parents: 25312
diff changeset
52 quit!
fb67cd7d30a7 patch 8.2.3969: value of MAXCOL not available in Vim script
Bram Moolenaar <Bram@vim.org>
parents: 25312
diff changeset
53 endfunc
fb67cd7d30a7 patch 8.2.3969: value of MAXCOL not available in Vim script
Bram Moolenaar <Bram@vim.org>
parents: 25312
diff changeset
54
8011
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
55 " 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
56 function s:Highlight_Matching_Pair()
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
57 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
58 eval save_cursor->setpos('.')
8011
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
59 endfunc
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
60
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
61 func Test_curswant_with_autocommand()
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
62 new
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
63 call setline(1, ['func()', '{', '}', '----'])
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
64 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
65 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
66 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
67 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
68 call assert_equal('-X---', getline(4))
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
69 autocmd! CursorMovedI *
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
70 quit!
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
71 endfunc
26f555e9aab1 commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents: 7590
diff changeset
72
15492
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
73 " 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
74 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
75 new
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
76 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
77 exe "normal! ggf6j"
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
78 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
79 set cursorcolumn
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
80 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
81 quit!
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
82 endfunc
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
83
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
84 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
85 new
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
86 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
87 exe "normal! ggf6j"
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
88 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
89 set cursorline
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
90 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
91 quit!
126cdab63a83 patch 8.1.0754: preferred column is lost when setting 'cursorcolumn'
Bram Moolenaar <Bram@vim.org>
parents: 11183
diff changeset
92 endfunc
17292
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
93
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
94 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
95 rightbelow new
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
96 rightbelow 20vsplit
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
97 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
98 redraw
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
99 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
100 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
101 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
102 \ '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
103 \ '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
104 \ '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
105 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
106 \ '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
107 \ '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
108 \ '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
109 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
110 \ '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
111 \ '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
112 \ '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
113 setlocal number
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
114 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
115 \ '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
116 \ '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
117 \ '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
118
7a254d0705e2 patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents: 23642
diff changeset
119 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
120 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
121 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
122 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
123 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
124 redraw
7a254d0705e2 patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents: 23642
diff changeset
125 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
126 \ 'col': wincol + 7,
7a254d0705e2 patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents: 23642
diff changeset
127 \ 'curscol': wincol + 7,
7a254d0705e2 patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents: 23642
diff changeset
128 \ 'endcol': wincol + 7}, winid->screenpos(line('$'), 8))
27352
2bec1976362c patch 8.2.4204: screenpos() has non-zero row for invisible text
Bram Moolenaar <Bram@vim.org>
parents: 26881
diff changeset
129 call assert_equal({'row': 0, 'col': 0, 'curscol': 0, 'endcol': 0},
25312
7a254d0705e2 patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents: 23642
diff changeset
130 \ 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
131
17292
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
132 close
20978
2c3e7a6bd6c6 patch 8.2.1040: not enough testing for movement commands
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
133 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
134
17292
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
135 bwipe!
25312
7a254d0705e2 patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents: 23642
diff changeset
136 set display&
23213
477f1b4c6826 patch 8.2.2152: screenpos() does not include the WinBar offset
Bram Moolenaar <Bram@vim.org>
parents: 20978
diff changeset
137
27726
d3ed8b1a7bde patch 8.2.4389: screenpos() does not handle a position in a closed fold
Bram Moolenaar <Bram@vim.org>
parents: 27352
diff changeset
138 call assert_equal(#{col: 1, row: 1, endcol: 1, curscol: 1}, screenpos(win_getid(), 1, 1))
23213
477f1b4c6826 patch 8.2.2152: screenpos() does not include the WinBar offset
Bram Moolenaar <Bram@vim.org>
parents: 20978
diff changeset
139 nmenu WinBar.TEST :
27726
d3ed8b1a7bde patch 8.2.4389: screenpos() does not handle a position in a closed fold
Bram Moolenaar <Bram@vim.org>
parents: 27352
diff changeset
140 call assert_equal(#{col: 1, row: 2, endcol: 1, curscol: 1}, screenpos(win_getid(), 1, 1))
23213
477f1b4c6826 patch 8.2.2152: screenpos() does not include the WinBar offset
Bram Moolenaar <Bram@vim.org>
parents: 20978
diff changeset
141 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
142 endfunc
18469
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
143
27726
d3ed8b1a7bde patch 8.2.4389: screenpos() does not handle a position in a closed fold
Bram Moolenaar <Bram@vim.org>
parents: 27352
diff changeset
144 func Test_screenpos_fold()
d3ed8b1a7bde patch 8.2.4389: screenpos() does not handle a position in a closed fold
Bram Moolenaar <Bram@vim.org>
parents: 27352
diff changeset
145 CheckFeature folding
d3ed8b1a7bde patch 8.2.4389: screenpos() does not handle a position in a closed fold
Bram Moolenaar <Bram@vim.org>
parents: 27352
diff changeset
146
d3ed8b1a7bde patch 8.2.4389: screenpos() does not handle a position in a closed fold
Bram Moolenaar <Bram@vim.org>
parents: 27352
diff changeset
147 enew!
d3ed8b1a7bde patch 8.2.4389: screenpos() does not handle a position in a closed fold
Bram Moolenaar <Bram@vim.org>
parents: 27352
diff changeset
148 call setline(1, range(10))
d3ed8b1a7bde patch 8.2.4389: screenpos() does not handle a position in a closed fold
Bram Moolenaar <Bram@vim.org>
parents: 27352
diff changeset
149 3,5fold
d3ed8b1a7bde patch 8.2.4389: screenpos() does not handle a position in a closed fold
Bram Moolenaar <Bram@vim.org>
parents: 27352
diff changeset
150 redraw
d3ed8b1a7bde patch 8.2.4389: screenpos() does not handle a position in a closed fold
Bram Moolenaar <Bram@vim.org>
parents: 27352
diff changeset
151 call assert_equal(2, screenpos(1, 2, 1).row)
d3ed8b1a7bde patch 8.2.4389: screenpos() does not handle a position in a closed fold
Bram Moolenaar <Bram@vim.org>
parents: 27352
diff changeset
152 call assert_equal(#{col: 1, row: 3, endcol: 1, curscol: 1}, screenpos(1, 3, 1))
31479
0c0b78aa7ae3 patch 9.0.1072: screenpos() column result in fold may be too small
Bram Moolenaar <Bram@vim.org>
parents: 31365
diff changeset
153 call assert_equal(#{col: 1, row: 3, endcol: 1, curscol: 1}, screenpos(1, 4, 1))
0c0b78aa7ae3 patch 9.0.1072: screenpos() column result in fold may be too small
Bram Moolenaar <Bram@vim.org>
parents: 31365
diff changeset
154 call assert_equal(#{col: 1, row: 3, endcol: 1, curscol: 1}, screenpos(1, 5, 1))
0c0b78aa7ae3 patch 9.0.1072: screenpos() column result in fold may be too small
Bram Moolenaar <Bram@vim.org>
parents: 31365
diff changeset
155 setlocal number
0c0b78aa7ae3 patch 9.0.1072: screenpos() column result in fold may be too small
Bram Moolenaar <Bram@vim.org>
parents: 31365
diff changeset
156 call assert_equal(#{col: 5, row: 3, endcol: 5, curscol: 5}, screenpos(1, 3, 1))
0c0b78aa7ae3 patch 9.0.1072: screenpos() column result in fold may be too small
Bram Moolenaar <Bram@vim.org>
parents: 31365
diff changeset
157 call assert_equal(#{col: 5, row: 3, endcol: 5, curscol: 5}, screenpos(1, 4, 1))
0c0b78aa7ae3 patch 9.0.1072: screenpos() column result in fold may be too small
Bram Moolenaar <Bram@vim.org>
parents: 31365
diff changeset
158 call assert_equal(#{col: 5, row: 3, endcol: 5, curscol: 5}, screenpos(1, 5, 1))
27726
d3ed8b1a7bde patch 8.2.4389: screenpos() does not handle a position in a closed fold
Bram Moolenaar <Bram@vim.org>
parents: 27352
diff changeset
159 call assert_equal(4, screenpos(1, 6, 1).row)
d3ed8b1a7bde patch 8.2.4389: screenpos() does not handle a position in a closed fold
Bram Moolenaar <Bram@vim.org>
parents: 27352
diff changeset
160 bwipe!
d3ed8b1a7bde patch 8.2.4389: screenpos() does not handle a position in a closed fold
Bram Moolenaar <Bram@vim.org>
parents: 27352
diff changeset
161 endfunc
d3ed8b1a7bde patch 8.2.4389: screenpos() does not handle a position in a closed fold
Bram Moolenaar <Bram@vim.org>
parents: 27352
diff changeset
162
31365
040b59b92dca patch 9.0.1016: screenpos() does not count filler lines for diff mode
Bram Moolenaar <Bram@vim.org>
parents: 31355
diff changeset
163 func Test_screenpos_diff()
040b59b92dca patch 9.0.1016: screenpos() does not count filler lines for diff mode
Bram Moolenaar <Bram@vim.org>
parents: 31355
diff changeset
164 CheckFeature diff
040b59b92dca patch 9.0.1016: screenpos() does not count filler lines for diff mode
Bram Moolenaar <Bram@vim.org>
parents: 31355
diff changeset
165
040b59b92dca patch 9.0.1016: screenpos() does not count filler lines for diff mode
Bram Moolenaar <Bram@vim.org>
parents: 31355
diff changeset
166 enew!
040b59b92dca patch 9.0.1016: screenpos() does not count filler lines for diff mode
Bram Moolenaar <Bram@vim.org>
parents: 31355
diff changeset
167 call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'])
040b59b92dca patch 9.0.1016: screenpos() does not count filler lines for diff mode
Bram Moolenaar <Bram@vim.org>
parents: 31355
diff changeset
168 vnew
040b59b92dca patch 9.0.1016: screenpos() does not count filler lines for diff mode
Bram Moolenaar <Bram@vim.org>
parents: 31355
diff changeset
169 call setline(1, ['a', 'b', 'c', 'g', 'h', 'i'])
040b59b92dca patch 9.0.1016: screenpos() does not count filler lines for diff mode
Bram Moolenaar <Bram@vim.org>
parents: 31355
diff changeset
170 windo diffthis
040b59b92dca patch 9.0.1016: screenpos() does not count filler lines for diff mode
Bram Moolenaar <Bram@vim.org>
parents: 31355
diff changeset
171 wincmd w
040b59b92dca patch 9.0.1016: screenpos() does not count filler lines for diff mode
Bram Moolenaar <Bram@vim.org>
parents: 31355
diff changeset
172 call assert_equal(#{col: 3, row: 7, endcol: 3, curscol: 3}, screenpos(0, 4, 1))
040b59b92dca patch 9.0.1016: screenpos() does not count filler lines for diff mode
Bram Moolenaar <Bram@vim.org>
parents: 31355
diff changeset
173
040b59b92dca patch 9.0.1016: screenpos() does not count filler lines for diff mode
Bram Moolenaar <Bram@vim.org>
parents: 31355
diff changeset
174 windo diffoff
040b59b92dca patch 9.0.1016: screenpos() does not count filler lines for diff mode
Bram Moolenaar <Bram@vim.org>
parents: 31355
diff changeset
175 bwipe!
040b59b92dca patch 9.0.1016: screenpos() does not count filler lines for diff mode
Bram Moolenaar <Bram@vim.org>
parents: 31355
diff changeset
176 bwipe!
040b59b92dca patch 9.0.1016: screenpos() does not count filler lines for diff mode
Bram Moolenaar <Bram@vim.org>
parents: 31355
diff changeset
177 endfunc
040b59b92dca patch 9.0.1016: screenpos() does not count filler lines for diff mode
Bram Moolenaar <Bram@vim.org>
parents: 31355
diff changeset
178
18469
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
179 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
180 rightbelow new
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
181 rightbelow 73vsplit
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
182 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
183 setlocal number
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
184 redraw
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
185 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
186 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
187 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
188 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
189 call assert_equal(wincol + 66 + 3, pos.col)
31355
45a03dd92f28 patch 9.0.1011: ml_get error when using screenpos()
Bram Moolenaar <Bram@vim.org>
parents: 31057
diff changeset
190
45a03dd92f28 patch 9.0.1011: ml_get error when using screenpos()
Bram Moolenaar <Bram@vim.org>
parents: 31057
diff changeset
191 call assert_fails('echo screenpos(0, 2, 1)', 'E966:')
45a03dd92f28 patch 9.0.1011: ml_get error when using screenpos()
Bram Moolenaar <Bram@vim.org>
parents: 31057
diff changeset
192
18469
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
193 close
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
194 bwipe!
66964658cc3c patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
195 endfunc
20109
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 18469
diff changeset
196
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
197 " 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
198 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
199 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
200 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
201 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
202
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
203 " 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
204 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
205 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
206 return ''
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
207 endfunc
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
208
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
209 " 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
210 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
211 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
212 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
213 new
28419
6e501ecd1bb7 patch 8.2.4734: getcharpos() may change a mark position
Bram Moolenaar <Bram@vim.org>
parents: 27726
diff changeset
214 call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678', ' │ x'])
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
215
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 " 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
217 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
218 call assert_equal([0, 1, 1, 0], getcharpos('.'))
28419
6e501ecd1bb7 patch 8.2.4734: getcharpos() may change a mark position
Bram Moolenaar <Bram@vim.org>
parents: 27726
diff changeset
219 call assert_equal([0, 5, 1, 0], getcharpos('$'))
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
220 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
221 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
222 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
223 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
224 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
225 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
226
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 " 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
228 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
229 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
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 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
232
28419
6e501ecd1bb7 patch 8.2.4734: getcharpos() may change a mark position
Bram Moolenaar <Bram@vim.org>
parents: 27726
diff changeset
233 " Check mark does not move
6e501ecd1bb7 patch 8.2.4734: getcharpos() may change a mark position
Bram Moolenaar <Bram@vim.org>
parents: 27726
diff changeset
234 normal 5Gfxma
6e501ecd1bb7 patch 8.2.4734: getcharpos() may change a mark position
Bram Moolenaar <Bram@vim.org>
parents: 27726
diff changeset
235 call assert_equal([0, 5, 5, 0], getcharpos("'a"))
6e501ecd1bb7 patch 8.2.4734: getcharpos() may change a mark position
Bram Moolenaar <Bram@vim.org>
parents: 27726
diff changeset
236 call assert_equal([0, 5, 5, 0], getcharpos("'a"))
6e501ecd1bb7 patch 8.2.4734: getcharpos() may change a mark position
Bram Moolenaar <Bram@vim.org>
parents: 27726
diff changeset
237 call assert_equal([0, 5, 5, 0], getcharpos("'a"))
6e501ecd1bb7 patch 8.2.4734: getcharpos() may change a mark position
Bram Moolenaar <Bram@vim.org>
parents: 27726
diff changeset
238
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
239 " 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
240 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
241 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
242 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
243 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
244 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
245 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
246 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
247 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
248 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
249 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
250 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
251 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
252
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
253 " 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
254 " 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
255 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
256 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
257 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
258 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
259 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
260 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
261 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
262 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
263 \ [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
264 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
265
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
266 %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
267 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
268
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 " 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
270 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
271 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
272 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
273 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
274 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
275 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
276 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
277 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
278 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
279 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
280 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
281 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
282 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
283 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
284 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
285 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
286
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 " 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
288 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
289 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
290 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
291 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
292 " 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
293 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
294 enew!
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
295 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
296
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 %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
298 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
299 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
300
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
301 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
302 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
303 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
304 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
305
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
306 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
307 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
308 return ''
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
309 endfunc
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
310
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
311 " 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
312 func Test_charcol()
31057
1a32f1a4f823 patch 9.0.0863: col() and charcol() only work for the current window
Bram Moolenaar <Bram@vim.org>
parents: 30755
diff changeset
313 call assert_fails('call charcol({})', 'E1222:')
1a32f1a4f823 patch 9.0.0863: col() and charcol() only work for the current window
Bram Moolenaar <Bram@vim.org>
parents: 30755
diff changeset
314 call assert_fails('call charcol(".", [])', 'E1210:')
1a32f1a4f823 patch 9.0.0863: col() and charcol() only work for the current window
Bram Moolenaar <Bram@vim.org>
parents: 30755
diff changeset
315 call assert_fails('call charcol(0)', 'E1222:')
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
316 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
317 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
318
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
319 " 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
320 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
321 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
322 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
323 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
324 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
325 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
326 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
327 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
328 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
329 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
330 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
331 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
332
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 " 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
334 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
335 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
336 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
337 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
338
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
339 " 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
340 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
341 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
342 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
343 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
344
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
345 " 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
346 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
347 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
348 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
349 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
350 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
351 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
352 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
353 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
354 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
355 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
356 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
357 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
358
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
359 " 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
360 " 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
361 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
362 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
363 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
364 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
365 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
366 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
367 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
368 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
369 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
370
31057
1a32f1a4f823 patch 9.0.0863: col() and charcol() only work for the current window
Bram Moolenaar <Bram@vim.org>
parents: 30755
diff changeset
371 " Test for getting the column number in another window.
1a32f1a4f823 patch 9.0.0863: col() and charcol() only work for the current window
Bram Moolenaar <Bram@vim.org>
parents: 30755
diff changeset
372 let winid = win_getid()
1a32f1a4f823 patch 9.0.0863: col() and charcol() only work for the current window
Bram Moolenaar <Bram@vim.org>
parents: 30755
diff changeset
373 new
1a32f1a4f823 patch 9.0.0863: col() and charcol() only work for the current window
Bram Moolenaar <Bram@vim.org>
parents: 30755
diff changeset
374 call win_execute(winid, 'normal 1G')
1a32f1a4f823 patch 9.0.0863: col() and charcol() only work for the current window
Bram Moolenaar <Bram@vim.org>
parents: 30755
diff changeset
375 call assert_equal(1, charcol('.', winid))
1a32f1a4f823 patch 9.0.0863: col() and charcol() only work for the current window
Bram Moolenaar <Bram@vim.org>
parents: 30755
diff changeset
376 call assert_equal(1, charcol('$', winid))
1a32f1a4f823 patch 9.0.0863: col() and charcol() only work for the current window
Bram Moolenaar <Bram@vim.org>
parents: 30755
diff changeset
377 call win_execute(winid, 'normal 2G6l')
1a32f1a4f823 patch 9.0.0863: col() and charcol() only work for the current window
Bram Moolenaar <Bram@vim.org>
parents: 30755
diff changeset
378 call assert_equal(7, charcol('.', winid))
1a32f1a4f823 patch 9.0.0863: col() and charcol() only work for the current window
Bram Moolenaar <Bram@vim.org>
parents: 30755
diff changeset
379 call assert_equal(10, charcol('$', winid))
1a32f1a4f823 patch 9.0.0863: col() and charcol() only work for the current window
Bram Moolenaar <Bram@vim.org>
parents: 30755
diff changeset
380
1a32f1a4f823 patch 9.0.0863: col() and charcol() only work for the current window
Bram Moolenaar <Bram@vim.org>
parents: 30755
diff changeset
381 " calling from another tab page also works
1a32f1a4f823 patch 9.0.0863: col() and charcol() only work for the current window
Bram Moolenaar <Bram@vim.org>
parents: 30755
diff changeset
382 tabnew
1a32f1a4f823 patch 9.0.0863: col() and charcol() only work for the current window
Bram Moolenaar <Bram@vim.org>
parents: 30755
diff changeset
383 call assert_equal(7, charcol('.', winid))
1a32f1a4f823 patch 9.0.0863: col() and charcol() only work for the current window
Bram Moolenaar <Bram@vim.org>
parents: 30755
diff changeset
384 call assert_equal(10, charcol('$', winid))
1a32f1a4f823 patch 9.0.0863: col() and charcol() only work for the current window
Bram Moolenaar <Bram@vim.org>
parents: 30755
diff changeset
385 tabclose
1a32f1a4f823 patch 9.0.0863: col() and charcol() only work for the current window
Bram Moolenaar <Bram@vim.org>
parents: 30755
diff changeset
386
1a32f1a4f823 patch 9.0.0863: col() and charcol() only work for the current window
Bram Moolenaar <Bram@vim.org>
parents: 30755
diff changeset
387 " unknown window ID
1a32f1a4f823 patch 9.0.0863: col() and charcol() only work for the current window
Bram Moolenaar <Bram@vim.org>
parents: 30755
diff changeset
388 call assert_equal(0, charcol('.', 10001))
1a32f1a4f823 patch 9.0.0863: col() and charcol() only work for the current window
Bram Moolenaar <Bram@vim.org>
parents: 30755
diff changeset
389
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
390 %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
391 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
392
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
393 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
394 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
395 return ''
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
396 endfunc
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
397
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
398 " 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
399 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
400 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
401 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
402 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
403
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
404 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
405 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
406 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
407 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
408 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
409 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
410 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
411 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
412 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
413 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
414
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
415 " 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
416 " 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
417 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
418 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
419 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
420 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
421 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
422 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
423 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
424 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
425 \ [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
426 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
427
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
428 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
429 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
430 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
431 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
432 %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
433 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
434
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
435 " 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
436 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
437 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
438 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
439 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
440 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
441 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
442 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
443 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
444 call assert_equal([1, 1], [line('.'), col('.')])
30755
b7efd41d43b8 patch 9.0.0712: wrong column when calling setcursorcharpos() with zero lnum
Bram Moolenaar <Bram@vim.org>
parents: 29024
diff changeset
445
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
446 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
447 call assert_equal([2, 9], [line('.'), col('.')])
30755
b7efd41d43b8 patch 9.0.0712: wrong column when calling setcursorcharpos() with zero lnum
Bram Moolenaar <Bram@vim.org>
parents: 29024
diff changeset
448 call setcursorcharpos([0, 7, 0])
b7efd41d43b8 patch 9.0.0712: wrong column when calling setcursorcharpos() with zero lnum
Bram Moolenaar <Bram@vim.org>
parents: 29024
diff changeset
449 call assert_equal([2, 9], [line('.'), col('.')])
b7efd41d43b8 patch 9.0.0712: wrong column when calling setcursorcharpos() with zero lnum
Bram Moolenaar <Bram@vim.org>
parents: 29024
diff changeset
450 call setcursorcharpos(0, 7, 0)
b7efd41d43b8 patch 9.0.0712: wrong column when calling setcursorcharpos() with zero lnum
Bram Moolenaar <Bram@vim.org>
parents: 29024
diff changeset
451 call assert_equal([2, 9], [line('.'), col('.')])
b7efd41d43b8 patch 9.0.0712: wrong column when calling setcursorcharpos() with zero lnum
Bram Moolenaar <Bram@vim.org>
parents: 29024
diff changeset
452
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
453 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
454 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
455 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
456 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
457 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
458 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
459 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
460 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
461 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
462 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
463 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
464 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
465 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
466 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
467
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
468 %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
469 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
470
29024
9f25e0ed831d patch 8.2.5034: there is no way to get the byte index from a virtual column
Bram Moolenaar <Bram@vim.org>
parents: 28419
diff changeset
471 " Test for virtcol2col()
9f25e0ed831d patch 8.2.5034: there is no way to get the byte index from a virtual column
Bram Moolenaar <Bram@vim.org>
parents: 28419
diff changeset
472 func Test_virtcol2col()
9f25e0ed831d patch 8.2.5034: there is no way to get the byte index from a virtual column
Bram Moolenaar <Bram@vim.org>
parents: 28419
diff changeset
473 new
9f25e0ed831d patch 8.2.5034: there is no way to get the byte index from a virtual column
Bram Moolenaar <Bram@vim.org>
parents: 28419
diff changeset
474 call setline(1, ["a\tb\tc"])
9f25e0ed831d patch 8.2.5034: there is no way to get the byte index from a virtual column
Bram Moolenaar <Bram@vim.org>
parents: 28419
diff changeset
475 call assert_equal(1, virtcol2col(0, 1, 1))
9f25e0ed831d patch 8.2.5034: there is no way to get the byte index from a virtual column
Bram Moolenaar <Bram@vim.org>
parents: 28419
diff changeset
476 call assert_equal(2, virtcol2col(0, 1, 2))
9f25e0ed831d patch 8.2.5034: there is no way to get the byte index from a virtual column
Bram Moolenaar <Bram@vim.org>
parents: 28419
diff changeset
477 call assert_equal(2, virtcol2col(0, 1, 8))
9f25e0ed831d patch 8.2.5034: there is no way to get the byte index from a virtual column
Bram Moolenaar <Bram@vim.org>
parents: 28419
diff changeset
478 call assert_equal(3, virtcol2col(0, 1, 9))
9f25e0ed831d patch 8.2.5034: there is no way to get the byte index from a virtual column
Bram Moolenaar <Bram@vim.org>
parents: 28419
diff changeset
479 call assert_equal(4, virtcol2col(0, 1, 10))
9f25e0ed831d patch 8.2.5034: there is no way to get the byte index from a virtual column
Bram Moolenaar <Bram@vim.org>
parents: 28419
diff changeset
480 call assert_equal(4, virtcol2col(0, 1, 16))
9f25e0ed831d patch 8.2.5034: there is no way to get the byte index from a virtual column
Bram Moolenaar <Bram@vim.org>
parents: 28419
diff changeset
481 call assert_equal(5, virtcol2col(0, 1, 17))
9f25e0ed831d patch 8.2.5034: there is no way to get the byte index from a virtual column
Bram Moolenaar <Bram@vim.org>
parents: 28419
diff changeset
482 call assert_equal(-1, virtcol2col(10, 1, 1))
9f25e0ed831d patch 8.2.5034: there is no way to get the byte index from a virtual column
Bram Moolenaar <Bram@vim.org>
parents: 28419
diff changeset
483 call assert_equal(-1, virtcol2col(0, 10, 1))
9f25e0ed831d patch 8.2.5034: there is no way to get the byte index from a virtual column
Bram Moolenaar <Bram@vim.org>
parents: 28419
diff changeset
484 call assert_equal(-1, virtcol2col(0, -1, 1))
9f25e0ed831d patch 8.2.5034: there is no way to get the byte index from a virtual column
Bram Moolenaar <Bram@vim.org>
parents: 28419
diff changeset
485 call assert_equal(-1, virtcol2col(0, 1, -1))
9f25e0ed831d patch 8.2.5034: there is no way to get the byte index from a virtual column
Bram Moolenaar <Bram@vim.org>
parents: 28419
diff changeset
486 call assert_equal(5, virtcol2col(0, 1, 20))
9f25e0ed831d patch 8.2.5034: there is no way to get the byte index from a virtual column
Bram Moolenaar <Bram@vim.org>
parents: 28419
diff changeset
487 call assert_fails('echo virtcol2col("0", 1, 20)', 'E1210:')
9f25e0ed831d patch 8.2.5034: there is no way to get the byte index from a virtual column
Bram Moolenaar <Bram@vim.org>
parents: 28419
diff changeset
488 call assert_fails('echo virtcol2col(0, "1", 20)', 'E1210:')
9f25e0ed831d patch 8.2.5034: there is no way to get the byte index from a virtual column
Bram Moolenaar <Bram@vim.org>
parents: 28419
diff changeset
489 call assert_fails('echo virtcol2col(0, 1, "1")', 'E1210:')
9f25e0ed831d patch 8.2.5034: there is no way to get the byte index from a virtual column
Bram Moolenaar <Bram@vim.org>
parents: 28419
diff changeset
490 bw!
9f25e0ed831d patch 8.2.5034: there is no way to get the byte index from a virtual column
Bram Moolenaar <Bram@vim.org>
parents: 28419
diff changeset
491 endfunc
9f25e0ed831d patch 8.2.5034: there is no way to get the byte index from a virtual column
Bram Moolenaar <Bram@vim.org>
parents: 28419
diff changeset
492
20109
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 18469
diff changeset
493 " vim: shiftwidth=2 sts=2 expandtab