@@ -8,36 +8,71 @@ func Test_sign()
88 new
99 call setline (1 , [' a' , ' b' , ' c' , ' d' ])
1010
11+ " Define some signs.
12+ " We can specify icons even if not all versions of vim support icons as
13+ " icon is ignored when not supported. "(not supported)" is shown after
14+ " the icon name when listing signs.
1115 sign define Sign1 text= x
12- sign define Sign2 text= y
16+ try
17+ sign define Sign2 text= xy texthl= Title linehl= Error icon = ../../ pixmaps/stock_vim_find_help.png
18+ catch /E255:/
19+ " ignore error: E255: Couldn't read in sign data!
20+ " This error can happen when running in gui.
21+ " Some gui like Motif do not support the png icon format.
22+ endtry
1323
1424 " Test listing signs.
1525 let a = execute (' sign list' )
16- call assert_equal ( " \n sign Sign1 text=x \n sign Sign2 text=y " , a )
26+ call assert_match ( " ^ \n sign Sign1 text=x \n sign Sign2 icon=../../pixmaps/stock_vim_find_help.png .* text=xy linehl=Error texthl=Title$ " , a )
1727
1828 let a = execute (' sign list Sign1' )
1929 call assert_equal (" \n sign Sign1 text=x " , a )
2030
21- " Place the sign at line 3,then check that we can jump to it.
22- exe ' sign place 42 line=3 name=Sign1 buffer=' . bufnr (' ' )
31+ " Split the window to the bottom to verify sign jump will stay in the current window
32+ " if the buffer is displayed there.
33+ let bn = bufnr (' %' )
34+ let wn = winnr ()
35+ exe ' sign place 41 line=3 name=Sign1 buffer=' . bn
36+ 1
37+ bot split
38+ exe ' sign jump 41 buffer=' . bufnr (' %' )
39+ call assert_equal (' c' , getline (' .' ))
40+ call assert_equal (3 , winnr ())
41+ call assert_equal (bn , bufnr (' %' ))
42+ call assert_notequal (wn , winnr ())
43+
44+ " Create a new buffer and check that ":sign jump" switches to the old buffer.
2345 1
24- exe ' sign jump 42 buffer=' . bufnr (' ' )
46+ new foo
47+ call assert_notequal (bn , bufnr (' %' ))
48+ exe ' sign jump 41 buffer=' . bn
49+ call assert_equal (bn , bufnr (' %' ))
2550 call assert_equal (' c' , getline (' .' ))
2651
27- " Can't change sign.
28- call assert_fails (" exe 'sign place 43 name=Sign1 buffer=' . bufnr('')" , ' E885:' )
52+ " Redraw to make sure that screen redraw with sign gets exercised,
53+ " with and without 'rightleft'.
54+ if has (' rightleft' )
55+ set rightleft
56+ redraw
57+ set norightleft
58+ endif
59+ redraw
2960
61+ " Check that we can't change sign.
62+ call assert_fails (" exe 'sign place 40 name=Sign1 buffer=' . bufnr('%')" , ' E885:' )
63+
64+ " Check placed signs
3065 let a = execute (' sign place' )
31- call assert_equal (" \n --- Signs ---\n Signs for [NULL]:\n line=3 id=42 name=Sign1\n " , a )
66+ call assert_equal (" \n --- Signs ---\n Signs for [NULL]:\n line=3 id=41 name=Sign1\n " , a )
3267
33- " Unplace the sign and try jumping to it again should now fail.
34- sign unplace 42
68+ " Unplace the sign and try jumping to it again should fail.
69+ sign unplace 41
3570 1
36- call assert_fails (" exe 'sign jump 42 buffer=' . bufnr('')" , ' E157:' )
71+ call assert_fails (" exe 'sign jump 41 buffer=' . bufnr('% ')" , ' E157:' )
3772 call assert_equal (' a' , getline (' .' ))
3873
3974 " Unplace sign on current line.
40- exe ' sign place 43 line=4 name=Sign2 buffer=' . bufnr (' ' )
75+ exe ' sign place 42 line=4 name=Sign2 buffer=' . bufnr (' % ' )
4176 4
4277 sign unplace
4378 let a = execute (' sign place' )
@@ -47,16 +82,54 @@ func Test_sign()
4782 call assert_fails (' sign unplace' , ' E159:' )
4883
4984 " Unplace all signs.
50- exe ' sign place 42 line=3 name=Sign1 buffer=' . bufnr (' ' )
85+ exe ' sign place 41 line=3 name=Sign1 buffer=' . bufnr (' % ' )
5186 sign unplace *
5287 let a = execute (' sign place' )
5388 call assert_equal (" \n --- Signs ---\n " , a )
5489
90+ " Check :jump with file=...
91+ edit foo
92+ call setline (1 , [' A' , ' B' , ' C' , ' D' ])
93+
94+ try
95+ sign define Sign3 text= y texthl= DoesNotExist linehl= DoesNotExist icon = doesnotexist.xpm
96+ catch /E255:/
97+ " ignore error: E255: it can happens for guis.
98+ endtry
99+
100+ let fn = expand (' %:p' )
101+ exe ' sign place 43 line=2 name=Sign3 file=' . fn
102+ edit bar
103+ call assert_notequal (fn, expand (' %:p' ))
104+ exe ' sign jump 43 file=' . fn
105+ call assert_equal (' B' , getline (' .' ))
106+
55107 " After undefining the sign, we should no longer be able to place it.
56108 sign undefine Sign1
57109 sign undefine Sign2
58- call assert_fails (" exe 'sign place 42 line=3 name=Sign1 buffer=' . bufnr('')" , ' E155:' )
110+ sign undefine Sign3
111+ call assert_fails (" exe 'sign place 41 line=3 name=Sign1 buffer=' . bufnr('%')" , ' E155:' )
112+ endfunc
113+
114+ " Undefining placed sign is not recommended.
115+ " Quoting :help sign
116+ "
117+ " :sign undefine {name}
118+ " Deletes a previously defined sign. If signs with this {name}
119+ " are still placed this will cause trouble.
120+ func Test_sign_undefine_still_placed ()
121+ new foobar
122+ sign define Sign text= x
123+ exe ' sign place 41 line=1 name=Sign buffer=' . bufnr (' %' )
124+ sign undefine Sign
125+
126+ " Listing placed sign should show that sign is deleted.
127+ let a = execute (' sign place' )
128+ call assert_equal (" \n --- Signs ---\n Signs for foobar:\n line=1 id=41 name=[Deleted]\n " , a )
59129
130+ sign unplace 41
131+ let a = execute (' sign place' )
132+ call assert_equal (" \n --- Signs ---\n " , a )
60133endfunc
61134
62135func Test_sign_completion ()
@@ -72,6 +145,9 @@ func Test_sign_completion()
72145 call feedkeys (" :sign define Sign linehl=Spell\<C-A>\<C-B> \" \<CR> " , ' tx' )
73146 call assert_equal (' "sign define Sign linehl=SpellBad SpellCap SpellLocal SpellRare' , @: )
74147
148+ call feedkeys (" :sign define Sign icon=../../pixmaps/tb_p\<C-A>\<C-B> \" \<CR> " , ' tx' )
149+ call assert_equal (' "sign define Sign icon=../../pixmaps/tb_paste.xpm ../../pixmaps/tb_print.xpm' , @: )
150+
75151 call feedkeys (" :sign undefine \<C-A>\<C-B> \" \<CR> " , ' tx' )
76152 call assert_equal (' "sign undefine Sign1 Sign2' , @: )
77153
@@ -92,13 +168,14 @@ func Test_sign_completion()
92168
93169 sign undefine Sign1
94170 sign undefine Sign2
95-
96171endfunc
97172
98173func Test_sign_invalid_commands ()
99174 call assert_fails (' sign' , ' E471:' )
175+ call assert_fails (' sign jump' , ' E471:' )
100176 call assert_fails (' sign xxx' , ' E160:' )
101177 call assert_fails (' sign define' , ' E156:' )
178+ call assert_fails (' sign define Sign1 xxx' , ' E475:' )
102179 call assert_fails (' sign undefine' , ' E156:' )
103180 call assert_fails (' sign list xxx' , ' E155:' )
104181 call assert_fails (' sign place 1 buffer=' , ' E158:' )
0 commit comments