annotate src/testdir/test_syntax.vim @ 8937:da4f6e238374 v7.4.1754

commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Apr 20 12:49:49 2016 +0200 patch 7.4.1754 Problem: When 'filetype' was set and reloading a buffer which does not cause it to be set, the syntax isn't loaded. (KillTheMule) Solution: Remember whether the FileType event was fired and fire it if not. (Anton Lindqvist, closes #747)
author Christian Brabandt <cb@256bit.org>
date Wed, 20 Apr 2016 13:00:06 +0200
parents 61354fabf8a2
children 751851a84c41
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7687
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Test for syntax and syntax iskeyword option
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 if !has("syntax")
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 finish
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 endif
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 func GetSyntaxItem(pat)
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 let c = ''
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 let a = ['a', getreg('a'), getregtype('a')]
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 0
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 redraw!
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 call search(a:pat, 'W')
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 let synid = synID(line('.'), col('.'), 1)
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 while synid == synID(line('.'), col('.'), 1)
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 norm! v"ay
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 " stop at whitespace
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 if @a =~# '\s'
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 break
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 endif
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 let c .= @a
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 norm! l
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 endw
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 call call('setreg', a)
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 0
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 return c
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 endfunc
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 func Test_syn_iskeyword()
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 new
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 call setline(1, [
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 \ 'CREATE TABLE FOOBAR(',
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 \ ' DLTD_BY VARCHAR2(100)',
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 \ ');',
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 \ ''])
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 syntax on
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 set ft=sql
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 syn match SYN /C\k\+\>/
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 hi link SYN ErrorMsg
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 call assert_equal('DLTD_BY', GetSyntaxItem('DLTD'))
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 /\<D\k\+\>/:norm! ygn
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 call assert_equal('DLTD_BY', @0)
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 redir @c
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 syn iskeyword
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 redir END
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 call assert_equal("\nsyntax iskeyword not set", @c)
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 syn iskeyword @,48-57,_,192-255
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 redir @c
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 syn iskeyword
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 redir END
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 call assert_equal("\nsyntax iskeyword @,48-57,_,192-255", @c)
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 setlocal isk-=_
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 call assert_equal('DLTD_BY', GetSyntaxItem('DLTD'))
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 /\<D\k\+\>/:norm! ygn
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 let b2=@0
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 call assert_equal('DLTD', @0)
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 syn iskeyword clear
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 redir @c
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 syn iskeyword
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 redir END
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 call assert_equal("\nsyntax iskeyword not set", @c)
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 quit!
61354fabf8a2 commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 endfunc
8937
da4f6e238374 commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents: 7687
diff changeset
68
da4f6e238374 commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents: 7687
diff changeset
69 func Test_syntax_after_reload()
da4f6e238374 commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents: 7687
diff changeset
70 split Xsomefile
da4f6e238374 commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents: 7687
diff changeset
71 call setline(1, ['hello', 'there'])
da4f6e238374 commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents: 7687
diff changeset
72 w!
da4f6e238374 commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents: 7687
diff changeset
73 only!
da4f6e238374 commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents: 7687
diff changeset
74 setl filetype=hello
da4f6e238374 commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents: 7687
diff changeset
75 au FileType hello let g:gotit = 1
da4f6e238374 commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents: 7687
diff changeset
76 call assert_false(exists('g:gotit'))
da4f6e238374 commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents: 7687
diff changeset
77 edit other
da4f6e238374 commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents: 7687
diff changeset
78 buf Xsomefile
da4f6e238374 commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents: 7687
diff changeset
79 call assert_equal('hello', &filetype)
da4f6e238374 commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents: 7687
diff changeset
80 call assert_true(exists('g:gotit'))
da4f6e238374 commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents: 7687
diff changeset
81 call delete('Xsomefile')
da4f6e238374 commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents: 7687
diff changeset
82 endfunc