Bram Moolenaar | b8060fe | 2016-01-19 22:29:28 +0100 | [diff] [blame] | 1 | " Test for syntax and syntax iskeyword option |
| 2 | |
| 3 | if !has("syntax") |
| 4 | finish |
| 5 | endif |
| 6 | |
Bram Moolenaar | 4d78589 | 2017-06-22 22:00:50 +0200 | [diff] [blame] | 7 | source view_util.vim |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 8 | if has('terminal') |
| 9 | source screendump.vim |
| 10 | endif |
Bram Moolenaar | 4d78589 | 2017-06-22 22:00:50 +0200 | [diff] [blame] | 11 | |
Bram Moolenaar | b8060fe | 2016-01-19 22:29:28 +0100 | [diff] [blame] | 12 | func GetSyntaxItem(pat) |
| 13 | let c = '' |
| 14 | let a = ['a', getreg('a'), getregtype('a')] |
| 15 | 0 |
| 16 | redraw! |
| 17 | call search(a:pat, 'W') |
| 18 | let synid = synID(line('.'), col('.'), 1) |
| 19 | while synid == synID(line('.'), col('.'), 1) |
| 20 | norm! v"ay |
| 21 | " stop at whitespace |
| 22 | if @a =~# '\s' |
| 23 | break |
| 24 | endif |
| 25 | let c .= @a |
| 26 | norm! l |
| 27 | endw |
| 28 | call call('setreg', a) |
| 29 | 0 |
| 30 | return c |
| 31 | endfunc |
| 32 | |
| 33 | func Test_syn_iskeyword() |
| 34 | new |
| 35 | call setline(1, [ |
| 36 | \ 'CREATE TABLE FOOBAR(', |
| 37 | \ ' DLTD_BY VARCHAR2(100)', |
| 38 | \ ');', |
| 39 | \ '']) |
| 40 | |
| 41 | syntax on |
| 42 | set ft=sql |
| 43 | syn match SYN /C\k\+\>/ |
| 44 | hi link SYN ErrorMsg |
| 45 | call assert_equal('DLTD_BY', GetSyntaxItem('DLTD')) |
| 46 | /\<D\k\+\>/:norm! ygn |
| 47 | call assert_equal('DLTD_BY', @0) |
| 48 | redir @c |
| 49 | syn iskeyword |
| 50 | redir END |
| 51 | call assert_equal("\nsyntax iskeyword not set", @c) |
| 52 | |
| 53 | syn iskeyword @,48-57,_,192-255 |
| 54 | redir @c |
| 55 | syn iskeyword |
| 56 | redir END |
| 57 | call assert_equal("\nsyntax iskeyword @,48-57,_,192-255", @c) |
| 58 | |
| 59 | setlocal isk-=_ |
| 60 | call assert_equal('DLTD_BY', GetSyntaxItem('DLTD')) |
| 61 | /\<D\k\+\>/:norm! ygn |
Bram Moolenaar | 73b484c | 2016-12-11 15:11:17 +0100 | [diff] [blame] | 62 | let b2 = @0 |
Bram Moolenaar | b8060fe | 2016-01-19 22:29:28 +0100 | [diff] [blame] | 63 | call assert_equal('DLTD', @0) |
| 64 | |
| 65 | syn iskeyword clear |
| 66 | redir @c |
| 67 | syn iskeyword |
| 68 | redir END |
| 69 | call assert_equal("\nsyntax iskeyword not set", @c) |
| 70 | |
| 71 | quit! |
| 72 | endfunc |
Bram Moolenaar | c369133 | 2016-04-20 12:49:49 +0200 | [diff] [blame] | 73 | |
| 74 | func Test_syntax_after_reload() |
| 75 | split Xsomefile |
| 76 | call setline(1, ['hello', 'there']) |
| 77 | w! |
| 78 | only! |
| 79 | setl filetype=hello |
| 80 | au FileType hello let g:gotit = 1 |
| 81 | call assert_false(exists('g:gotit')) |
| 82 | edit other |
| 83 | buf Xsomefile |
| 84 | call assert_equal('hello', &filetype) |
| 85 | call assert_true(exists('g:gotit')) |
| 86 | call delete('Xsomefile') |
| 87 | endfunc |
Bram Moolenaar | 73b484c | 2016-12-11 15:11:17 +0100 | [diff] [blame] | 88 | |
| 89 | func Test_syntime() |
| 90 | if !has('profile') |
Bram Moolenaar | 4c8980b | 2016-12-11 15:24:48 +0100 | [diff] [blame] | 91 | return |
Bram Moolenaar | 73b484c | 2016-12-11 15:11:17 +0100 | [diff] [blame] | 92 | endif |
| 93 | |
| 94 | syntax on |
| 95 | syntime on |
| 96 | let a = execute('syntime report') |
| 97 | call assert_equal("\nNo Syntax items defined for this buffer", a) |
| 98 | |
| 99 | view ../memfile_test.c |
| 100 | setfiletype cpp |
| 101 | redraw |
| 102 | let a = execute('syntime report') |
| 103 | call assert_match('^ TOTAL *COUNT *MATCH *SLOWEST *AVERAGE *NAME *PATTERN', a) |
| 104 | call assert_match(' \d*\.\d* \+[^0]\d* .* cppRawString ', a) |
| 105 | call assert_match(' \d*\.\d* \+[^0]\d* .* cppNumber ', a) |
| 106 | |
| 107 | syntime off |
| 108 | syntime clear |
| 109 | let a = execute('syntime report') |
| 110 | call assert_match('^ TOTAL *COUNT *MATCH *SLOWEST *AVERAGE *NAME *PATTERN', a) |
| 111 | call assert_notmatch('.* cppRawString *', a) |
| 112 | call assert_notmatch('.* cppNumber*', a) |
| 113 | call assert_notmatch('[1-9]', a) |
| 114 | |
| 115 | call assert_fails('syntime abc', 'E475') |
| 116 | |
| 117 | syntax clear |
| 118 | let a = execute('syntime report') |
| 119 | call assert_equal("\nNo Syntax items defined for this buffer", a) |
| 120 | |
| 121 | bd |
| 122 | endfunc |
| 123 | |
| 124 | func Test_syntax_list() |
| 125 | syntax on |
| 126 | let a = execute('syntax list') |
| 127 | call assert_equal("\nNo Syntax items defined for this buffer", a) |
| 128 | |
| 129 | view ../memfile_test.c |
| 130 | setfiletype c |
| 131 | |
| 132 | let a = execute('syntax list') |
| 133 | call assert_match('cInclude*', a) |
| 134 | call assert_match('cDefine', a) |
| 135 | |
| 136 | let a = execute('syntax list cDefine') |
| 137 | call assert_notmatch('cInclude*', a) |
| 138 | call assert_match('cDefine', a) |
| 139 | call assert_match(' links to Macro$', a) |
| 140 | |
| 141 | call assert_fails('syntax list ABCD', 'E28:') |
| 142 | call assert_fails('syntax list @ABCD', 'E392:') |
| 143 | |
| 144 | syntax clear |
| 145 | let a = execute('syntax list') |
| 146 | call assert_equal("\nNo Syntax items defined for this buffer", a) |
| 147 | |
| 148 | bd |
| 149 | endfunc |
| 150 | |
| 151 | func Test_syntax_completion() |
| 152 | call feedkeys(":syn \<C-A>\<C-B>\"\<CR>", 'tx') |
| 153 | call assert_equal('"syn case clear cluster conceal enable include iskeyword keyword list manual match off on region reset spell sync', @:) |
| 154 | |
| 155 | call feedkeys(":syn case \<C-A>\<C-B>\"\<CR>", 'tx') |
| 156 | call assert_equal('"syn case ignore match', @:) |
| 157 | |
Bram Moolenaar | 2d02839 | 2017-01-08 18:28:22 +0100 | [diff] [blame] | 158 | call feedkeys(":syn spell \<C-A>\<C-B>\"\<CR>", 'tx') |
| 159 | call assert_equal('"syn spell default notoplevel toplevel', @:) |
| 160 | |
| 161 | call feedkeys(":syn sync \<C-A>\<C-B>\"\<CR>", 'tx') |
| 162 | call assert_equal('"syn sync ccomment clear fromstart linebreaks= linecont lines= match maxlines= minlines= region', @:) |
| 163 | |
Bram Moolenaar | d61e8aa | 2017-01-17 17:44:46 +0100 | [diff] [blame] | 164 | " Check that clearing "Aap" avoids it showing up before Boolean. |
| 165 | hi Aap ctermfg=blue |
| 166 | call feedkeys(":syn list \<C-A>\<C-B>\"\<CR>", 'tx') |
| 167 | call assert_match('^"syn list Aap Boolean Character ', @:) |
| 168 | hi clear Aap |
| 169 | |
Bram Moolenaar | 73b484c | 2016-12-11 15:11:17 +0100 | [diff] [blame] | 170 | call feedkeys(":syn list \<C-A>\<C-B>\"\<CR>", 'tx') |
| 171 | call assert_match('^"syn list Boolean Character ', @:) |
| 172 | |
| 173 | call feedkeys(":syn match \<C-A>\<C-B>\"\<CR>", 'tx') |
| 174 | call assert_match('^"syn match Boolean Character ', @:) |
| 175 | endfunc |
Bram Moolenaar | de318c5 | 2017-01-17 16:27:10 +0100 | [diff] [blame] | 176 | |
| 177 | func Test_syntax_arg_skipped() |
| 178 | syn clear |
| 179 | syntax case ignore |
| 180 | if 0 |
| 181 | syntax case match |
| 182 | endif |
| 183 | call assert_match('case ignore', execute('syntax case')) |
| 184 | |
| 185 | syn keyword Foo foo |
| 186 | call assert_match('Foo', execute('syntax')) |
| 187 | syn clear |
| 188 | call assert_match('case match', execute('syntax case')) |
| 189 | call assert_notmatch('Foo', execute('syntax')) |
| 190 | |
| 191 | if has('conceal') |
| 192 | syn clear |
| 193 | syntax conceal on |
| 194 | if 0 |
| 195 | syntax conceal off |
| 196 | endif |
| 197 | call assert_match('conceal on', execute('syntax conceal')) |
| 198 | syn clear |
| 199 | call assert_match('conceal off', execute('syntax conceal')) |
Bram Moolenaar | 58f60ca | 2017-01-17 17:19:00 +0100 | [diff] [blame] | 200 | |
| 201 | syntax conceal on |
| 202 | syntax conceal off |
| 203 | call assert_match('conceal off', execute('syntax conceal')) |
Bram Moolenaar | de318c5 | 2017-01-17 16:27:10 +0100 | [diff] [blame] | 204 | endif |
| 205 | |
Bram Moolenaar | d61e8aa | 2017-01-17 17:44:46 +0100 | [diff] [blame] | 206 | syntax region Bar start=/</ end=/>/ |
Bram Moolenaar | de318c5 | 2017-01-17 16:27:10 +0100 | [diff] [blame] | 207 | if 0 |
| 208 | syntax region NotTest start=/</ end=/>/ contains=@Spell |
| 209 | endif |
Bram Moolenaar | d61e8aa | 2017-01-17 17:44:46 +0100 | [diff] [blame] | 210 | call assert_match('Bar', execute('syntax')) |
Bram Moolenaar | de318c5 | 2017-01-17 16:27:10 +0100 | [diff] [blame] | 211 | call assert_notmatch('NotTest', execute('syntax')) |
| 212 | call assert_notmatch('Spell', execute('syntax')) |
| 213 | |
| 214 | hi Foo ctermfg=blue |
| 215 | let a = execute('hi Foo') |
| 216 | if 0 |
| 217 | syntax rest |
| 218 | endif |
| 219 | call assert_equal(a, execute('hi Foo')) |
Bram Moolenaar | d61e8aa | 2017-01-17 17:44:46 +0100 | [diff] [blame] | 220 | hi clear Bar |
| 221 | hi clear Foo |
Bram Moolenaar | de318c5 | 2017-01-17 16:27:10 +0100 | [diff] [blame] | 222 | |
| 223 | set ft=tags |
| 224 | syn off |
| 225 | if 0 |
| 226 | syntax enable |
| 227 | endif |
| 228 | call assert_match('No Syntax items defined', execute('syntax')) |
| 229 | syntax enable |
| 230 | call assert_match('tagComment', execute('syntax')) |
| 231 | set ft= |
| 232 | |
| 233 | syn clear |
| 234 | if 0 |
| 235 | syntax include @Spell nothing |
| 236 | endif |
| 237 | call assert_notmatch('Spell', execute('syntax')) |
| 238 | |
| 239 | syn clear |
| 240 | syn iskeyword 48-57,$,_ |
| 241 | call assert_match('48-57,$,_', execute('syntax iskeyword')) |
| 242 | if 0 |
| 243 | syn clear |
| 244 | syn iskeyword clear |
| 245 | endif |
| 246 | call assert_match('48-57,$,_', execute('syntax iskeyword')) |
| 247 | syn iskeyword clear |
| 248 | call assert_match('not set', execute('syntax iskeyword')) |
| 249 | syn iskeyword 48-57,$,_ |
| 250 | syn clear |
| 251 | call assert_match('not set', execute('syntax iskeyword')) |
| 252 | |
| 253 | syn clear |
| 254 | syn keyword Foo foo |
| 255 | if 0 |
| 256 | syn keyword NotAdded bar |
| 257 | endif |
| 258 | call assert_match('Foo', execute('syntax')) |
| 259 | call assert_notmatch('NotAdded', execute('highlight')) |
| 260 | |
| 261 | syn clear |
| 262 | syn keyword Foo foo |
| 263 | call assert_match('Foo', execute('syntax')) |
| 264 | call assert_match('Foo', execute('syntax list')) |
| 265 | call assert_notmatch('Foo', execute('if 0 | syntax | endif')) |
| 266 | call assert_notmatch('Foo', execute('if 0 | syntax list | endif')) |
| 267 | |
| 268 | syn clear |
| 269 | syn match Fopi /asdf/ |
| 270 | if 0 |
| 271 | syn match Fopx /asdf/ |
| 272 | endif |
| 273 | call assert_match('Fopi', execute('syntax')) |
| 274 | call assert_notmatch('Fopx', execute('syntax')) |
| 275 | |
| 276 | syn clear |
| 277 | syn spell toplevel |
| 278 | call assert_match('spell toplevel', execute('syntax spell')) |
| 279 | if 0 |
| 280 | syn spell notoplevel |
| 281 | endif |
| 282 | call assert_match('spell toplevel', execute('syntax spell')) |
| 283 | syn spell notoplevel |
| 284 | call assert_match('spell notoplevel', execute('syntax spell')) |
| 285 | syn spell default |
| 286 | call assert_match('spell default', execute('syntax spell')) |
| 287 | |
| 288 | syn clear |
| 289 | if 0 |
| 290 | syntax cluster Spell |
| 291 | endif |
| 292 | call assert_notmatch('Spell', execute('syntax')) |
| 293 | |
| 294 | syn clear |
| 295 | syn keyword Foo foo |
| 296 | syn sync ccomment |
| 297 | syn sync maxlines=5 |
| 298 | if 0 |
| 299 | syn sync maxlines=11 |
| 300 | endif |
| 301 | call assert_match('on C-style comments', execute('syntax sync')) |
| 302 | call assert_match('maximal 5 lines', execute('syntax sync')) |
Bram Moolenaar | 58f60ca | 2017-01-17 17:19:00 +0100 | [diff] [blame] | 303 | syn sync clear |
Bram Moolenaar | de318c5 | 2017-01-17 16:27:10 +0100 | [diff] [blame] | 304 | if 0 |
| 305 | syn sync ccomment |
| 306 | endif |
| 307 | call assert_notmatch('on C-style comments', execute('syntax sync')) |
| 308 | |
| 309 | syn clear |
| 310 | endfunc |
| 311 | |
Bram Moolenaar | ea58815 | 2017-04-10 22:45:30 +0200 | [diff] [blame] | 312 | func Test_syntax_invalid_arg() |
Bram Moolenaar | 58f60ca | 2017-01-17 17:19:00 +0100 | [diff] [blame] | 313 | call assert_fails('syntax case asdf', 'E390:') |
Bram Moolenaar | d61e8aa | 2017-01-17 17:44:46 +0100 | [diff] [blame] | 314 | if has('conceal') |
| 315 | call assert_fails('syntax conceal asdf', 'E390:') |
| 316 | endif |
Bram Moolenaar | 58f60ca | 2017-01-17 17:19:00 +0100 | [diff] [blame] | 317 | call assert_fails('syntax spell asdf', 'E390:') |
Bram Moolenaar | ea58815 | 2017-04-10 22:45:30 +0200 | [diff] [blame] | 318 | call assert_fails('syntax clear @ABCD', 'E391:') |
| 319 | call assert_fails('syntax include @Xxx', 'E397:') |
| 320 | call assert_fails('syntax region X start="{"', 'E399:') |
| 321 | call assert_fails('syntax sync x', 'E404:') |
| 322 | call assert_fails('syntax keyword Abc a[', 'E789:') |
| 323 | call assert_fails('syntax keyword Abc a[bc]d', 'E890:') |
Bram Moolenaar | 58f60ca | 2017-01-17 17:19:00 +0100 | [diff] [blame] | 324 | endfunc |
| 325 | |
| 326 | func Test_syn_sync() |
| 327 | syntax region HereGroup start=/this/ end=/that/ |
| 328 | syntax sync match SyncHere grouphere HereGroup "pattern" |
| 329 | call assert_match('SyncHere', execute('syntax sync')) |
| 330 | syn sync clear |
| 331 | call assert_notmatch('SyncHere', execute('syntax sync')) |
| 332 | syn clear |
| 333 | endfunc |
| 334 | |
| 335 | func Test_syn_clear() |
| 336 | syntax keyword Foo foo |
Bram Moolenaar | d61e8aa | 2017-01-17 17:44:46 +0100 | [diff] [blame] | 337 | syntax keyword Bar tar |
Bram Moolenaar | 58f60ca | 2017-01-17 17:19:00 +0100 | [diff] [blame] | 338 | call assert_match('Foo', execute('syntax')) |
Bram Moolenaar | d61e8aa | 2017-01-17 17:44:46 +0100 | [diff] [blame] | 339 | call assert_match('Bar', execute('syntax')) |
Bram Moolenaar | c96272e | 2017-03-26 13:50:09 +0200 | [diff] [blame] | 340 | call assert_equal('Foo', synIDattr(hlID("Foo"), "name")) |
Bram Moolenaar | 58f60ca | 2017-01-17 17:19:00 +0100 | [diff] [blame] | 341 | syn clear Foo |
| 342 | call assert_notmatch('Foo', execute('syntax')) |
Bram Moolenaar | d61e8aa | 2017-01-17 17:44:46 +0100 | [diff] [blame] | 343 | call assert_match('Bar', execute('syntax')) |
Bram Moolenaar | c96272e | 2017-03-26 13:50:09 +0200 | [diff] [blame] | 344 | call assert_equal('Foo', synIDattr(hlID("Foo"), "name")) |
Bram Moolenaar | d61e8aa | 2017-01-17 17:44:46 +0100 | [diff] [blame] | 345 | syn clear Foo Bar |
Bram Moolenaar | 58f60ca | 2017-01-17 17:19:00 +0100 | [diff] [blame] | 346 | call assert_notmatch('Foo', execute('syntax')) |
Bram Moolenaar | d61e8aa | 2017-01-17 17:44:46 +0100 | [diff] [blame] | 347 | call assert_notmatch('Bar', execute('syntax')) |
| 348 | hi clear Foo |
Bram Moolenaar | c96272e | 2017-03-26 13:50:09 +0200 | [diff] [blame] | 349 | call assert_equal('Foo', synIDattr(hlID("Foo"), "name")) |
Bram Moolenaar | d61e8aa | 2017-01-17 17:44:46 +0100 | [diff] [blame] | 350 | hi clear Bar |
Bram Moolenaar | 58f60ca | 2017-01-17 17:19:00 +0100 | [diff] [blame] | 351 | endfunc |
Bram Moolenaar | 4007ed4 | 2017-01-17 18:14:54 +0100 | [diff] [blame] | 352 | |
| 353 | func Test_invalid_name() |
| 354 | syn clear |
| 355 | syn keyword Nop yes |
| 356 | call assert_fails("syntax keyword Wr\x17ong bar", 'E669:') |
| 357 | syntax keyword @Wrong bar |
| 358 | call assert_match('W18:', execute('1messages')) |
| 359 | syn clear |
| 360 | hi clear Nop |
| 361 | hi clear @Wrong |
| 362 | endfunc |
Bram Moolenaar | f8ec998 | 2017-04-09 15:41:31 +0200 | [diff] [blame] | 363 | |
| 364 | func Test_ownsyntax() |
| 365 | new Xfoo |
| 366 | call setline(1, '#define FOO') |
| 367 | syntax on |
| 368 | set filetype=c |
| 369 | ownsyntax perl |
| 370 | call assert_equal('perlComment', synIDattr(synID(line('.'), col('.'), 1), 'name')) |
| 371 | call assert_equal('c', b:current_syntax) |
| 372 | call assert_equal('perl', w:current_syntax) |
| 373 | |
| 374 | " A new split window should have the original syntax. |
| 375 | split |
| 376 | call assert_equal('cDefine', synIDattr(synID(line('.'), col('.'), 1), 'name')) |
| 377 | call assert_equal('c', b:current_syntax) |
| 378 | call assert_equal(0, exists('w:current_syntax')) |
| 379 | |
| 380 | wincmd x |
| 381 | call assert_equal('perlComment', synIDattr(synID(line("."), col("."), 1), "name")) |
| 382 | |
| 383 | syntax off |
| 384 | set filetype& |
| 385 | %bw! |
| 386 | endfunc |
| 387 | |
| 388 | func Test_ownsyntax_completion() |
| 389 | call feedkeys(":ownsyntax java\<C-A>\<C-B>\"\<CR>", 'tx') |
| 390 | call assert_equal('"ownsyntax java javacc javascript', @:) |
| 391 | endfunc |
Bram Moolenaar | ea58815 | 2017-04-10 22:45:30 +0200 | [diff] [blame] | 392 | |
| 393 | func Test_highlight_invalid_arg() |
| 394 | if has('gui_running') |
| 395 | call assert_fails('hi XXX guifg=xxx', 'E254:') |
| 396 | endif |
| 397 | call assert_fails('hi DoesNotExist', 'E411:') |
| 398 | call assert_fails('hi link', 'E412:') |
| 399 | call assert_fails('hi link a', 'E412:') |
| 400 | call assert_fails('hi link a b c', 'E413:') |
| 401 | call assert_fails('hi XXX =', 'E415:') |
| 402 | call assert_fails('hi XXX cterm', 'E416:') |
| 403 | call assert_fails('hi XXX cterm=', 'E417:') |
| 404 | call assert_fails('hi XXX cterm=DoesNotExist', 'E418:') |
| 405 | call assert_fails('hi XXX ctermfg=DoesNotExist', 'E421:') |
| 406 | call assert_fails('hi XXX xxx=White', 'E423:') |
| 407 | endfunc |
| 408 | |
Bram Moolenaar | 1615b36 | 2017-06-04 21:06:09 +0200 | [diff] [blame] | 409 | func Test_bg_detection() |
| 410 | if has('gui_running') |
| 411 | return |
| 412 | endif |
| 413 | " auto-detection of &bg, make sure sure it isn't set anywhere before |
| 414 | " this test |
| 415 | hi Normal ctermbg=0 |
| 416 | call assert_equal('dark', &bg) |
| 417 | hi Normal ctermbg=4 |
| 418 | call assert_equal('dark', &bg) |
| 419 | hi Normal ctermbg=12 |
| 420 | call assert_equal('light', &bg) |
| 421 | hi Normal ctermbg=15 |
| 422 | call assert_equal('light', &bg) |
| 423 | |
Bram Moolenaar | 0b2eef2 | 2017-06-27 15:43:49 +0200 | [diff] [blame] | 424 | " manually-set &bg takes precedence over auto-detection |
Bram Moolenaar | 1615b36 | 2017-06-04 21:06:09 +0200 | [diff] [blame] | 425 | set bg=light |
| 426 | hi Normal ctermbg=4 |
| 427 | call assert_equal('light', &bg) |
| 428 | set bg=dark |
| 429 | hi Normal ctermbg=12 |
| 430 | call assert_equal('dark', &bg) |
Bram Moolenaar | 6acadda | 2018-02-24 16:51:32 +0100 | [diff] [blame] | 431 | |
| 432 | hi Normal ctermbg=NONE |
Bram Moolenaar | 1615b36 | 2017-06-04 21:06:09 +0200 | [diff] [blame] | 433 | endfunc |
Bram Moolenaar | 06f1ed2 | 2017-06-18 22:41:03 +0200 | [diff] [blame] | 434 | |
| 435 | func Test_syntax_hangs() |
| 436 | if !has('reltime') || !has('float') || !has('syntax') |
| 437 | return |
| 438 | endif |
| 439 | |
| 440 | " This pattern takes a long time to match, it should timeout. |
| 441 | new |
| 442 | call setline(1, ['aaa', repeat('abc ', 1000), 'ccc']) |
| 443 | let start = reltime() |
| 444 | set nolazyredraw redrawtime=101 |
| 445 | syn match Error /\%#=1a*.*X\@<=b*/ |
| 446 | redraw |
| 447 | let elapsed = reltimefloat(reltime(start)) |
| 448 | call assert_true(elapsed > 0.1) |
| 449 | call assert_true(elapsed < 1.0) |
| 450 | |
| 451 | " second time syntax HL is disabled |
| 452 | let start = reltime() |
| 453 | redraw |
| 454 | let elapsed = reltimefloat(reltime(start)) |
| 455 | call assert_true(elapsed < 0.1) |
| 456 | |
| 457 | " after CTRL-L the timeout flag is reset |
| 458 | let start = reltime() |
| 459 | exe "normal \<C-L>" |
| 460 | redraw |
| 461 | let elapsed = reltimefloat(reltime(start)) |
| 462 | call assert_true(elapsed > 0.1) |
| 463 | call assert_true(elapsed < 1.0) |
| 464 | |
| 465 | set redrawtime& |
| 466 | bwipe! |
| 467 | endfunc |
Bram Moolenaar | 4d78589 | 2017-06-22 22:00:50 +0200 | [diff] [blame] | 468 | |
Bram Moolenaar | 4d78589 | 2017-06-22 22:00:50 +0200 | [diff] [blame] | 469 | func Test_conceal() |
| 470 | if !has('conceal') |
| 471 | return |
| 472 | endif |
| 473 | |
| 474 | new |
| 475 | call setline(1, ['', '123456']) |
| 476 | syn match test23 "23" conceal cchar=X |
| 477 | syn match test45 "45" conceal |
| 478 | |
| 479 | set conceallevel=0 |
| 480 | call assert_equal('123456 ', ScreenLines(2, 7)[0]) |
Bram Moolenaar | cc0750d | 2017-06-24 22:29:24 +0200 | [diff] [blame] | 481 | call assert_equal([[0, '', 0], [0, '', 0], [0, '', 0], [0, '', 0], [0, '', 0], [0, '', 0]], map(range(1, 6), 'synconcealed(2, v:val)')) |
Bram Moolenaar | 4d78589 | 2017-06-22 22:00:50 +0200 | [diff] [blame] | 482 | |
| 483 | set conceallevel=1 |
| 484 | call assert_equal('1X 6 ', ScreenLines(2, 7)[0]) |
Bram Moolenaar | cc0750d | 2017-06-24 22:29:24 +0200 | [diff] [blame] | 485 | call assert_equal([[0, '', 0], [1, 'X', 1], [1, 'X', 1], [1, ' ', 2], [1, ' ', 2], [0, '', 0]], map(range(1, 6), 'synconcealed(2, v:val)')) |
Bram Moolenaar | 4d78589 | 2017-06-22 22:00:50 +0200 | [diff] [blame] | 486 | |
| 487 | set conceallevel=1 |
| 488 | set listchars=conceal:Y |
Bram Moolenaar | cc0750d | 2017-06-24 22:29:24 +0200 | [diff] [blame] | 489 | call assert_equal([[0, '', 0], [1, 'X', 1], [1, 'X', 1], [1, 'Y', 2], [1, 'Y', 2], [0, '', 0]], map(range(1, 6), 'synconcealed(2, v:val)')) |
Bram Moolenaar | 4d78589 | 2017-06-22 22:00:50 +0200 | [diff] [blame] | 490 | call assert_equal('1XY6 ', ScreenLines(2, 7)[0]) |
| 491 | |
| 492 | set conceallevel=2 |
| 493 | call assert_match('1X6 ', ScreenLines(2, 7)[0]) |
Bram Moolenaar | cc0750d | 2017-06-24 22:29:24 +0200 | [diff] [blame] | 494 | call assert_equal([[0, '', 0], [1, 'X', 1], [1, 'X', 1], [1, '', 2], [1, '', 2], [0, '', 0]], map(range(1, 6), 'synconcealed(2, v:val)')) |
Bram Moolenaar | 4d78589 | 2017-06-22 22:00:50 +0200 | [diff] [blame] | 495 | |
| 496 | set conceallevel=3 |
| 497 | call assert_match('16 ', ScreenLines(2, 7)[0]) |
Bram Moolenaar | cc0750d | 2017-06-24 22:29:24 +0200 | [diff] [blame] | 498 | call assert_equal([[0, '', 0], [1, '', 1], [1, '', 1], [1, '', 2], [1, '', 2], [0, '', 0]], map(range(1, 6), 'synconcealed(2, v:val)')) |
Bram Moolenaar | 4d78589 | 2017-06-22 22:00:50 +0200 | [diff] [blame] | 499 | |
| 500 | syn clear |
| 501 | set conceallevel& |
| 502 | bw! |
| 503 | endfunc |
Bram Moolenaar | 0b2eef2 | 2017-06-27 15:43:49 +0200 | [diff] [blame] | 504 | |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 505 | func Test_synstack_synIDtrans() |
Bram Moolenaar | 0b2eef2 | 2017-06-27 15:43:49 +0200 | [diff] [blame] | 506 | new |
| 507 | setfiletype c |
| 508 | syntax on |
| 509 | call setline(1, ' /* A comment with a TODO */') |
| 510 | |
| 511 | call assert_equal([], synstack(1, 1)) |
| 512 | |
| 513 | norm f/ |
| 514 | call assert_equal(['cComment', 'cCommentStart'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")')) |
| 515 | call assert_equal(['Comment', 'Comment'], map(synstack(line("."), col(".")), 'synIDattr(synIDtrans(v:val), "name")')) |
| 516 | |
| 517 | norm fA |
| 518 | call assert_equal(['cComment'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")')) |
| 519 | call assert_equal(['Comment'], map(synstack(line("."), col(".")), 'synIDattr(synIDtrans(v:val), "name")')) |
| 520 | |
| 521 | norm fT |
| 522 | call assert_equal(['cComment', 'cTodo'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")')) |
| 523 | call assert_equal(['Comment', 'Todo'], map(synstack(line("."), col(".")), 'synIDattr(synIDtrans(v:val), "name")')) |
| 524 | |
| 525 | syn clear |
| 526 | bw! |
| 527 | endfunc |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 528 | |
| 529 | " Check highlighting for a small piece of C code with a screen dump. |
| 530 | func Test_syntax_c() |
Bram Moolenaar | 3cc9f74 | 2018-02-20 17:09:16 +0100 | [diff] [blame] | 531 | " Need to be able to run terminal Vim with 256 colors. |
Bram Moolenaar | b7ea7cb | 2018-02-24 14:38:51 +0100 | [diff] [blame] | 532 | " On MS-Windows the console only has 16 colors and the GUI can't run in a |
| 533 | " terminal. |
Bram Moolenaar | 3cc9f74 | 2018-02-20 17:09:16 +0100 | [diff] [blame] | 534 | if !has('terminal') || has('win32') |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 535 | return |
| 536 | endif |
| 537 | call writefile([ |
| 538 | \ '/* comment line at the top */', |
| 539 | \ ' int', |
| 540 | \ 'main(int argc, char **argv)// another comment', |
| 541 | \ '{', |
| 542 | \ '#if 0', |
| 543 | \ ' int not_used;', |
| 544 | \ '#else', |
| 545 | \ ' int used;', |
| 546 | \ '#endif', |
| 547 | \ ' printf("Just an example piece of C code\n");', |
| 548 | \ ' return 0x0ff;', |
| 549 | \ '}', |
| 550 | \ ' static void', |
| 551 | \ 'myFunction(const double count, struct nothing, long there) {', |
| 552 | \ ' // 123: nothing to read here', |
| 553 | \ ' for (int i = 0; i < count; ++i) {', |
| 554 | \ ' break;', |
| 555 | \ ' }', |
| 556 | \ '}', |
| 557 | \ ], 'Xtest.c') |
Bram Moolenaar | b7ea7cb | 2018-02-24 14:38:51 +0100 | [diff] [blame] | 558 | |
| 559 | " This makes the default for 'background' use "dark", check that the |
| 560 | " response to t_RB corrects it to "light". |
| 561 | let $COLORFGBG = '15;0' |
| 562 | |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 563 | let buf = RunVimInTerminal('Xtest.c', {}) |
| 564 | call VerifyScreenDump(buf, 'Test_syntax_c_01') |
| 565 | call StopVimInTerminal(buf) |
| 566 | |
Bram Moolenaar | b7ea7cb | 2018-02-24 14:38:51 +0100 | [diff] [blame] | 567 | let $COLORFGBG = '' |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 568 | call delete('Xtest.c') |
| 569 | endfun |