From b03bb134234ddfec49715289d932d6da23fef487 Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Fri, 21 Jun 2013 22:12:39 +0200 Subject: [PATCH] TestCase for b1191617 and slightly more stable way to execute python in test cases. --- test.py | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/test.py b/test.py index 3f62539..dd6addd 100755 --- a/test.py +++ b/test.py @@ -217,10 +217,17 @@ class _VimTest(unittest.TestCase): self.vim.send(s) def send_py(self,s): - if sys.version_info < (3,0): - self.send(":py << EOF\n%s\nEOF\n" % s) - else: - self.send(":py3 << EOF\n%s\nEOF\n" % s) + # Do not delete the file so that Vim can safely read it. + with tempfile.NamedTemporaryFile( + prefix="UltiSnips_Python",suffix=".py", delete=False + ) 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): self.vim.send_keystrokes(s, self.sleeptime) @@ -1868,6 +1875,37 @@ class RecTabStops_MirroredZeroTS_ECR(_VimTest): keys = "m" + EX + "m1" + EX + "one" + JF + "two" + \ JF + "three" + JF + "four" + JF + "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 #}}} # List Snippets {{{# class _ListAllSnippets(_VimTest):