2015-04-25 11:38:22 -04:00
|
|
|
from test.constant import *
|
2015-07-14 15:58:30 -04:00
|
|
|
from test.vim_test_case import VimTestCase as _VimTest
|
2015-04-25 11:38:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
class ContextSnippets_SimpleSnippet(_VimTest):
|
|
|
|
files = { 'us/all.snippets': r"""
|
|
|
|
snippet a "desc" "True" e
|
|
|
|
abc
|
|
|
|
endsnippet
|
|
|
|
"""}
|
|
|
|
keys = 'a' + EX
|
|
|
|
wanted = 'abc'
|
|
|
|
|
|
|
|
class ContextSnippets_ExpandOnTrue(_VimTest):
|
|
|
|
files = { 'us/all.snippets': r"""
|
|
|
|
global !p
|
|
|
|
def check_context():
|
|
|
|
return True
|
|
|
|
endglobal
|
|
|
|
|
|
|
|
snippet a "desc" "check_context()" e
|
|
|
|
abc
|
|
|
|
endsnippet
|
|
|
|
"""}
|
|
|
|
keys = 'a' + EX
|
|
|
|
wanted = 'abc'
|
|
|
|
|
|
|
|
|
|
|
|
class ContextSnippets_DoNotExpandOnFalse(_VimTest):
|
|
|
|
files = { 'us/all.snippets': r"""
|
|
|
|
global !p
|
|
|
|
def check_context():
|
|
|
|
return False
|
|
|
|
endglobal
|
|
|
|
|
|
|
|
snippet a "desc" "check_context()" e
|
|
|
|
abc
|
|
|
|
endsnippet
|
|
|
|
"""}
|
|
|
|
keys = 'a' + EX
|
|
|
|
wanted = keys
|
|
|
|
|
|
|
|
|
|
|
|
class ContextSnippets_UseContext(_VimTest):
|
|
|
|
files = { 'us/all.snippets': r"""
|
|
|
|
global !p
|
|
|
|
def wrap(ins):
|
|
|
|
return "< " + ins + " >"
|
|
|
|
endglobal
|
|
|
|
|
2015-06-08 08:28:21 -04:00
|
|
|
snippet a "desc" "wrap(snip.buffer[snip.line])" e
|
2015-04-25 11:38:22 -04:00
|
|
|
{ `!p snip.rv = context` }
|
|
|
|
endsnippet
|
|
|
|
"""}
|
|
|
|
keys = 'a' + EX
|
|
|
|
wanted = '{ < a > }'
|
|
|
|
|
|
|
|
|
|
|
|
class ContextSnippets_SnippetPriority(_VimTest):
|
|
|
|
files = { 'us/all.snippets': r"""
|
2015-06-08 08:28:21 -04:00
|
|
|
snippet i "desc" "re.search('err :=', snip.buffer[snip.line-1])" e
|
2015-04-25 11:38:22 -04:00
|
|
|
if err != nil {
|
|
|
|
${1:// pass}
|
|
|
|
}
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet i
|
|
|
|
if ${1:true} {
|
|
|
|
${2:// pass}
|
|
|
|
}
|
|
|
|
endsnippet
|
|
|
|
"""}
|
|
|
|
|
|
|
|
keys = r"""
|
|
|
|
err := some_call()
|
|
|
|
i""" + EX + JF + """
|
|
|
|
i""" + EX
|
|
|
|
wanted = r"""
|
|
|
|
err := some_call()
|
|
|
|
if err != nil {
|
|
|
|
// pass
|
|
|
|
}
|
|
|
|
if true {
|
|
|
|
// pass
|
|
|
|
}"""
|
2015-04-27 05:42:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
class ContextSnippets_PriorityKeyword(_VimTest):
|
|
|
|
files = { 'us/all.snippets': r"""
|
|
|
|
snippet i "desc" "True" e
|
|
|
|
a
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
priority 100
|
|
|
|
snippet i
|
|
|
|
b
|
|
|
|
endsnippet
|
|
|
|
"""}
|
|
|
|
|
2015-07-14 15:58:30 -04:00
|
|
|
keys = 'i' + EX
|
|
|
|
wanted = 'b'
|
2015-05-01 08:02:20 -04:00
|
|
|
|
|
|
|
|
|
|
|
class ContextSnippets_ReportError(_VimTest):
|
|
|
|
files = { 'us/all.snippets': r"""
|
|
|
|
snippet e "desc" "Tru" e
|
|
|
|
error
|
|
|
|
endsnippet
|
|
|
|
"""}
|
|
|
|
|
2015-07-14 15:58:30 -04:00
|
|
|
keys = 'e' + EX
|
|
|
|
wanted = 'e' + EX
|
2015-05-01 08:02:20 -04:00
|
|
|
expected_error = r"NameError: name 'Tru' is not defined"
|
2015-05-01 08:07:59 -04:00
|
|
|
|
|
|
|
|
|
|
|
class ContextSnippets_ReportErrorOnIndexOutOfRange(_VimTest):
|
2015-07-14 15:58:30 -04:00
|
|
|
# Working around: https://github.com/neovim/python-client/issues/128.
|
|
|
|
skip_if = lambda self: 'Bug in Neovim.' \
|
|
|
|
if self.vim_flavor == 'neovim' else None
|
2015-05-01 08:07:59 -04:00
|
|
|
files = { 'us/all.snippets': r"""
|
2015-06-08 08:28:21 -04:00
|
|
|
snippet e "desc" "snip.buffer[123]" e
|
2015-05-01 08:07:59 -04:00
|
|
|
error
|
|
|
|
endsnippet
|
|
|
|
"""}
|
|
|
|
|
2015-07-14 15:58:30 -04:00
|
|
|
keys = 'e' + EX
|
|
|
|
wanted = 'e' + EX
|
2015-05-01 08:07:59 -04:00
|
|
|
expected_error = r"IndexError: line number out of range"
|
2015-05-04 14:17:58 -04:00
|
|
|
|
|
|
|
|
|
|
|
class ContextSnippets_CursorIsZeroBased(_VimTest):
|
|
|
|
files = { 'us/all.snippets': r"""
|
2015-06-08 08:28:21 -04:00
|
|
|
snippet e "desc" "snip.cursor" e
|
2015-06-10 13:32:36 -04:00
|
|
|
`!p snip.rv = str(snip.context)`
|
2015-05-04 14:17:58 -04:00
|
|
|
endsnippet
|
|
|
|
"""}
|
|
|
|
|
|
|
|
keys = "e" + EX
|
2015-06-08 08:28:21 -04:00
|
|
|
wanted = "(2, 1)"
|
2015-07-09 07:26:56 -04:00
|
|
|
|
2016-04-13 07:15:20 -04:00
|
|
|
|
2015-07-09 07:26:56 -04:00
|
|
|
class ContextSnippets_ContextIsClearedBeforeExpand(_VimTest):
|
|
|
|
files = { 'us/all.snippets': r"""
|
|
|
|
pre_expand "snip.context = 1 if snip.context is None else 2"
|
|
|
|
snippet e "desc" w
|
|
|
|
`!p snip.rv = str(snip.context)`
|
|
|
|
endsnippet
|
|
|
|
"""}
|
|
|
|
|
|
|
|
keys = "e" + EX + " " + "e" + EX
|
|
|
|
wanted = "1 1"
|
2016-03-29 06:48:41 -04:00
|
|
|
|
|
|
|
class ContextSnippets_ContextHasAccessToVisual(_VimTest):
|
|
|
|
files = { 'us/all.snippets': r"""
|
|
|
|
snippet test "desc" "snip.visual_text == '123'" we
|
|
|
|
Yes
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet test "desc" w
|
|
|
|
No
|
|
|
|
endsnippet
|
|
|
|
"""}
|
|
|
|
|
|
|
|
keys = "123" + ESC + "vhh" + EX + "test" + EX + " zzz" + ESC + \
|
|
|
|
"vhh" + EX + "test" + EX
|
|
|
|
wanted = "Yes No"
|
2016-04-13 07:15:20 -04:00
|
|
|
|
|
|
|
|
|
|
|
class ContextSnippets_Header_ExpandOnTrue(_VimTest):
|
|
|
|
files = { 'us/all.snippets': r"""
|
|
|
|
global !p
|
|
|
|
def check_context():
|
|
|
|
return True
|
|
|
|
endglobal
|
|
|
|
|
|
|
|
context "check_context()"
|
|
|
|
snippet a "desc" e
|
|
|
|
abc
|
|
|
|
endsnippet
|
|
|
|
"""}
|
|
|
|
keys = 'a' + EX
|
|
|
|
wanted = 'abc'
|
|
|
|
|
|
|
|
|
|
|
|
class ContextSnippets_Header_DoNotExpandOnFalse(_VimTest):
|
|
|
|
files = { 'us/all.snippets': r"""
|
|
|
|
global !p
|
|
|
|
def check_context():
|
|
|
|
return False
|
|
|
|
endglobal
|
|
|
|
|
|
|
|
context "check_context()"
|
|
|
|
snippet a "desc" e
|
|
|
|
abc
|
|
|
|
endsnippet
|
|
|
|
"""}
|
|
|
|
keys = 'a' + EX
|
|
|
|
wanted = keys
|