TestCase for b1191617 and slightly more stable way to execute python in test cases.

This commit is contained in:
Holger Rapp 2013-06-21 22:12:39 +02:00
parent 3b2eb436b7
commit b03bb13423

46
test.py
View File

@ -217,10 +217,17 @@ class _VimTest(unittest.TestCase):
self.vim.send(s) self.vim.send(s)
def send_py(self,s): def send_py(self,s):
if sys.version_info < (3,0): # Do not delete the file so that Vim can safely read it.
self.send(":py << EOF\n%s\nEOF\n" % s) with tempfile.NamedTemporaryFile(
else: prefix="UltiSnips_Python",suffix=".py", delete=False
self.send(":py3 << EOF\n%s\nEOF\n" % s) ) as temporary_file:
temporary_file.write(s)
temporary_file.close()
if sys.version_info < (3,0):
self.send(":pyfile %s\n" % temporary_file.name)
else:
self.send(":py3file %s\n" % temporary_file.name)
def send_keystrokes(self,s): def send_keystrokes(self,s):
self.vim.send_keystrokes(s, self.sleeptime) self.vim.send_keystrokes(s, self.sleeptime)
@ -1868,6 +1875,37 @@ class RecTabStops_MirroredZeroTS_ECR(_VimTest):
keys = "m" + EX + "m1" + EX + "one" + JF + "two" + \ keys = "m" + EX + "m1" + EX + "one" + JF + "two" + \
JF + "three" + JF + "four" + JF + "end" JF + "three" + JF + "four" + JF + "end"
wanted = "[ [ one three three two ] four ]end" wanted = "[ [ one three three two ] four ]end"
class RecTabStops_ComplexBug1191617(_PS_Base):
# https://bugs.launchpad.net/ultisnips/+bug/1191617
snippets_test_file = ("all", "test_file", r"""
global !p
def complete(t, opts):
if t:
opts = [ q[len(t):] for q in opts if q.startswith(t) ]
if len(opts) == 0:
return ''
return opts[0] if len(opts) == 1 else "(" + '|'.join(opts) + ')'
def autocomplete_options(t, string, attr=None):
return complete(t[1], [opt for opt in attr if opt not in string])
endglobal
snippet ff "form_for" w
form_for ${1:record}${0:, options = \{\}} do |${2:f}|
endsnippet
snippet /form_for(?!.*\{.*$)(.*,)/ "form_for options" rw!
`!p
auto = autocomplete_options(t, match.group(1), attr=["url: ", "namespace: ", "html: {"])
snip.rv = "form_for" + match.group(1) + " "`$1`!p if (snip.c != auto) : snip.rv=auto`
endsnippet
snippet /form_for(.*){([^|]*)/ "form_for html options" rw!
`!p
auto = autocomplete_options(t, match.group(2), attr=["id: ", "class: ", "title: "])
snip.rv = "form_for" + match.group(1) + "{"`$1`!p if (snip.c != auto) : snip.rv=auto`
endsnippet
""")
keys = "ff" + EX + "user" + JF + "u" + JF + "," + EX + "n" + JF + \
"some_namespace," + EX + "h" + JF + "i" + EX + "i" + EX
wanted = "x a bob b y\nx a jon b y"
# End: Recursive (Nested) Snippets #}}} # End: Recursive (Nested) Snippets #}}}
# List Snippets {{{# # List Snippets {{{#
class _ListAllSnippets(_VimTest): class _ListAllSnippets(_VimTest):