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 | |
| 7 | func GetSyntaxItem(pat) |
| 8 | let c = '' |
| 9 | let a = ['a', getreg('a'), getregtype('a')] |
| 10 | 0 |
| 11 | redraw! |
| 12 | call search(a:pat, 'W') |
| 13 | let synid = synID(line('.'), col('.'), 1) |
| 14 | while synid == synID(line('.'), col('.'), 1) |
| 15 | norm! v"ay |
| 16 | " stop at whitespace |
| 17 | if @a =~# '\s' |
| 18 | break |
| 19 | endif |
| 20 | let c .= @a |
| 21 | norm! l |
| 22 | endw |
| 23 | call call('setreg', a) |
| 24 | 0 |
| 25 | return c |
| 26 | endfunc |
| 27 | |
| 28 | func Test_syn_iskeyword() |
| 29 | new |
| 30 | call setline(1, [ |
| 31 | \ 'CREATE TABLE FOOBAR(', |
| 32 | \ ' DLTD_BY VARCHAR2(100)', |
| 33 | \ ');', |
| 34 | \ '']) |
| 35 | |
| 36 | syntax on |
| 37 | set ft=sql |
| 38 | syn match SYN /C\k\+\>/ |
| 39 | hi link SYN ErrorMsg |
| 40 | call assert_equal('DLTD_BY', GetSyntaxItem('DLTD')) |
| 41 | /\<D\k\+\>/:norm! ygn |
| 42 | call assert_equal('DLTD_BY', @0) |
| 43 | redir @c |
| 44 | syn iskeyword |
| 45 | redir END |
| 46 | call assert_equal("\nsyntax iskeyword not set", @c) |
| 47 | |
| 48 | syn iskeyword @,48-57,_,192-255 |
| 49 | redir @c |
| 50 | syn iskeyword |
| 51 | redir END |
| 52 | call assert_equal("\nsyntax iskeyword @,48-57,_,192-255", @c) |
| 53 | |
| 54 | setlocal isk-=_ |
| 55 | call assert_equal('DLTD_BY', GetSyntaxItem('DLTD')) |
| 56 | /\<D\k\+\>/:norm! ygn |
Bram Moolenaar | 73b484c | 2016-12-11 15:11:17 +0100 | [diff] [blame] | 57 | let b2 = @0 |
Bram Moolenaar | b8060fe | 2016-01-19 22:29:28 +0100 | [diff] [blame] | 58 | call assert_equal('DLTD', @0) |
| 59 | |
| 60 | syn iskeyword clear |
| 61 | redir @c |
| 62 | syn iskeyword |
| 63 | redir END |
| 64 | call assert_equal("\nsyntax iskeyword not set", @c) |
| 65 | |
| 66 | quit! |
| 67 | endfunc |
Bram Moolenaar | c369133 | 2016-04-20 12:49:49 +0200 | [diff] [blame] | 68 | |
| 69 | func Test_syntax_after_reload() |
| 70 | split Xsomefile |
| 71 | call setline(1, ['hello', 'there']) |
| 72 | w! |
| 73 | only! |
| 74 | setl filetype=hello |
| 75 | au FileType hello let g:gotit = 1 |
| 76 | call assert_false(exists('g:gotit')) |
| 77 | edit other |
| 78 | buf Xsomefile |
| 79 | call assert_equal('hello', &filetype) |
| 80 | call assert_true(exists('g:gotit')) |
| 81 | call delete('Xsomefile') |
| 82 | endfunc |
Bram Moolenaar | 73b484c | 2016-12-11 15:11:17 +0100 | [diff] [blame] | 83 | |
| 84 | func Test_syntime() |
| 85 | if !has('profile') |
Bram Moolenaar | 4c8980b | 2016-12-11 15:24:48 +0100 | [diff] [blame] | 86 | return |
Bram Moolenaar | 73b484c | 2016-12-11 15:11:17 +0100 | [diff] [blame] | 87 | endif |
| 88 | |
| 89 | syntax on |
| 90 | syntime on |
| 91 | let a = execute('syntime report') |
| 92 | call assert_equal("\nNo Syntax items defined for this buffer", a) |
| 93 | |
| 94 | view ../memfile_test.c |
| 95 | setfiletype cpp |
| 96 | redraw |
| 97 | let a = execute('syntime report') |
| 98 | call assert_match('^ TOTAL *COUNT *MATCH *SLOWEST *AVERAGE *NAME *PATTERN', a) |
| 99 | call assert_match(' \d*\.\d* \+[^0]\d* .* cppRawString ', a) |
| 100 | call assert_match(' \d*\.\d* \+[^0]\d* .* cppNumber ', a) |
| 101 | |
| 102 | syntime off |
| 103 | syntime clear |
| 104 | let a = execute('syntime report') |
| 105 | call assert_match('^ TOTAL *COUNT *MATCH *SLOWEST *AVERAGE *NAME *PATTERN', a) |
| 106 | call assert_notmatch('.* cppRawString *', a) |
| 107 | call assert_notmatch('.* cppNumber*', a) |
| 108 | call assert_notmatch('[1-9]', a) |
| 109 | |
| 110 | call assert_fails('syntime abc', 'E475') |
| 111 | |
| 112 | syntax clear |
| 113 | let a = execute('syntime report') |
| 114 | call assert_equal("\nNo Syntax items defined for this buffer", a) |
| 115 | |
| 116 | bd |
| 117 | endfunc |
| 118 | |
| 119 | func Test_syntax_list() |
| 120 | syntax on |
| 121 | let a = execute('syntax list') |
| 122 | call assert_equal("\nNo Syntax items defined for this buffer", a) |
| 123 | |
| 124 | view ../memfile_test.c |
| 125 | setfiletype c |
| 126 | |
| 127 | let a = execute('syntax list') |
| 128 | call assert_match('cInclude*', a) |
| 129 | call assert_match('cDefine', a) |
| 130 | |
| 131 | let a = execute('syntax list cDefine') |
| 132 | call assert_notmatch('cInclude*', a) |
| 133 | call assert_match('cDefine', a) |
| 134 | call assert_match(' links to Macro$', a) |
| 135 | |
| 136 | call assert_fails('syntax list ABCD', 'E28:') |
| 137 | call assert_fails('syntax list @ABCD', 'E392:') |
| 138 | |
| 139 | syntax clear |
| 140 | let a = execute('syntax list') |
| 141 | call assert_equal("\nNo Syntax items defined for this buffer", a) |
| 142 | |
| 143 | bd |
| 144 | endfunc |
| 145 | |
| 146 | func Test_syntax_completion() |
| 147 | call feedkeys(":syn \<C-A>\<C-B>\"\<CR>", 'tx') |
| 148 | call assert_equal('"syn case clear cluster conceal enable include iskeyword keyword list manual match off on region reset spell sync', @:) |
| 149 | |
| 150 | call feedkeys(":syn case \<C-A>\<C-B>\"\<CR>", 'tx') |
| 151 | call assert_equal('"syn case ignore match', @:) |
| 152 | |
Bram Moolenaar | 2d02839 | 2017-01-08 18:28:22 +0100 | [diff] [blame] | 153 | call feedkeys(":syn spell \<C-A>\<C-B>\"\<CR>", 'tx') |
| 154 | call assert_equal('"syn spell default notoplevel toplevel', @:) |
| 155 | |
| 156 | call feedkeys(":syn sync \<C-A>\<C-B>\"\<CR>", 'tx') |
| 157 | call assert_equal('"syn sync ccomment clear fromstart linebreaks= linecont lines= match maxlines= minlines= region', @:) |
| 158 | |
Bram Moolenaar | 73b484c | 2016-12-11 15:11:17 +0100 | [diff] [blame] | 159 | call feedkeys(":syn list \<C-A>\<C-B>\"\<CR>", 'tx') |
| 160 | call assert_match('^"syn list Boolean Character ', @:) |
| 161 | |
| 162 | call feedkeys(":syn match \<C-A>\<C-B>\"\<CR>", 'tx') |
| 163 | call assert_match('^"syn match Boolean Character ', @:) |
| 164 | endfunc |