From 461e81d6a2ffed4a6082ede80881ed9c7b9da3ac Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Sun, 20 Feb 2011 20:49:32 +0100 Subject: [PATCH 01/10] Added stricter test case that show the problem and implement fixes for them --- plugin/UltiSnips/__init__.py | 4 ++-- test.py | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/plugin/UltiSnips/__init__.py b/plugin/UltiSnips/__init__.py index 9b98c27..fdc9dc9 100644 --- a/plugin/UltiSnips/__init__.py +++ b/plugin/UltiSnips/__init__.py @@ -694,8 +694,8 @@ class SnippetManager(object): this_entered = vim.current.line[:self._vstate.pos.col] self._chars_entered('\n' + cline + this_entered, 1) if line_was_shortened and user_didnt_enter_newline: - self._backspace(len(self._vstate.last_line)-len(lline)) - self._chars_entered('\n' + cline, 1) + self._backspace(self._vstate.ppos.col-len(lline)) + self._chars_entered('\n' + cline[:len(cline)-(len(self._vstate.last_line)-self._vstate.ppos.col)], 1) else: pentered = lline[self._vstate.ppos.col:] this_entered = vim.current.line[:self._vstate.pos.col] diff --git a/test.py b/test.py index a650c4a..60720bb 100755 --- a/test.py +++ b/test.py @@ -226,6 +226,43 @@ class MultilineExpandWithFormatoptionsOn_ExceptCorrectResult(_VimTest): def _options_off(self): self.send(":set tw=0\n") +class MultilineExpandWithFormatoptionsOnTextAfter_ExceptCorrectResult(_VimTest): + """Testcase for lp:719998""" + snippets = ("test", "${1:longer expand}after\nstart$1end") + keys = ("test" + EX + "This is a longer snippet that should wrap properly " + "and the mirror below should work as well") + wanted = \ +"""This is a longer +snippet that should +wrap properly and +the mirror below +should work as wellafter +startThis is a longer +snippet that should +wrap properly and +the mirror below +should work as wellend""" + def _options_on(self): + self.send(":set tw=20\n") + def _options_off(self): + self.send(":set tw=0\n") + +class MultilineExpandWithFormatoptionsWrapOnLongWord_ExceptCorrectResult(_VimTest): + """Testcase for lp:719998""" + snippets = ("test", "${1:longer expand}after\nstart$1end") + keys = ("test" + EX + "This is a longersnippet that should wrap properly") + wanted = \ +"""This is a +longersnippet that +should wrap properlyafter +startThis is a +longersnippet that +should wrap properlyend""" + + def _options_on(self): + self.send(":set tw=20\n") + def _options_off(self): + self.send(":set tw=0\n") ############ # TabStops # From 70ba6f0083265b98a492677832d842eca09d7a9f Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Sun, 20 Feb 2011 20:54:16 +0100 Subject: [PATCH 02/10] Added another test case that encloses the snippet --- test.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test.py b/test.py index 60720bb..cc2f8f0 100755 --- a/test.py +++ b/test.py @@ -217,6 +217,23 @@ class MultilineExpandTestTyping_ExceptCorrectResult(_VimTest): wanted = "Wie Hallo Welt!\nUnd Wie gehtsHuiui! gehts" keys = "Wie hallo gehts" + ESC + "bhi" + EX + "Huiui!" + +class MultilineExpandWithFormatoptionsOnTextBeforeAndAfter_ExceptCorrectResult(_VimTest): + snippets = ("test", "Before${1:longer expand}After\nstart$1end") + keys = "test" + EX + "This is a longer text that should wrap" + wanted = \ +"""BeforeThis is a +longer text that +should wrapAfter +startThis is a +longer text that +should wrapend""" + + def _options_on(self): + self.send(":set tw=20\n") + def _options_off(self): + self.send(":set tw=0\n") + class MultilineExpandWithFormatoptionsOn_ExceptCorrectResult(_VimTest): snippets = ("test", "${1:longer expand}\n$0") keys = "test" + EX + "This is a longer text that should wrap" From 91520a21602d1427027a6b6d1d3ba7755d78bff0 Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Sun, 20 Feb 2011 20:58:43 +0100 Subject: [PATCH 03/10] Refactored test cases --- test.py | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/test.py b/test.py index cc2f8f0..3b1789f 100755 --- a/test.py +++ b/test.py @@ -217,8 +217,21 @@ class MultilineExpandTestTyping_ExceptCorrectResult(_VimTest): wanted = "Wie Hallo Welt!\nUnd Wie gehtsHuiui! gehts" keys = "Wie hallo gehts" + ESC + "bhi" + EX + "Huiui!" +######################## +# Format options tests # +######################## +class _FormatoptionsBase(_VimTest): + def _options_on(self): + self.send(":set tw=20\n") + def _options_off(self): + self.send(":set tw=0\n") -class MultilineExpandWithFormatoptionsOnTextBeforeAndAfter_ExceptCorrectResult(_VimTest): +class FOSimple_ExceptCorrectResult(_FormatoptionsBase): + snippets = ("test", "${1:longer expand}\n$0") + keys = "test" + EX + "This is a longer text that should wrap" + wanted = "This is a longer\ntext that should\nwrap\n" + +class FOTextBeforeAndAfter_ExceptCorrectResult(_FormatoptionsBase): snippets = ("test", "Before${1:longer expand}After\nstart$1end") keys = "test" + EX + "This is a longer text that should wrap" wanted = \ @@ -229,21 +242,8 @@ startThis is a longer text that should wrapend""" - def _options_on(self): - self.send(":set tw=20\n") - def _options_off(self): - self.send(":set tw=0\n") -class MultilineExpandWithFormatoptionsOn_ExceptCorrectResult(_VimTest): - snippets = ("test", "${1:longer expand}\n$0") - keys = "test" + EX + "This is a longer text that should wrap" - wanted = "This is a longer\ntext that should\nwrap\n" - def _options_on(self): - self.send(":set tw=20\n") - def _options_off(self): - self.send(":set tw=0\n") - -class MultilineExpandWithFormatoptionsOnTextAfter_ExceptCorrectResult(_VimTest): +class FOTextAfter_ExceptCorrectResult(_FormatoptionsBase): """Testcase for lp:719998""" snippets = ("test", "${1:longer expand}after\nstart$1end") keys = ("test" + EX + "This is a longer snippet that should wrap properly " @@ -259,12 +259,8 @@ snippet that should wrap properly and the mirror below should work as wellend""" - def _options_on(self): - self.send(":set tw=20\n") - def _options_off(self): - self.send(":set tw=0\n") -class MultilineExpandWithFormatoptionsWrapOnLongWord_ExceptCorrectResult(_VimTest): +class FOWrapOnLongWord_ExceptCorrectResult(_FormatoptionsBase): """Testcase for lp:719998""" snippets = ("test", "${1:longer expand}after\nstart$1end") keys = ("test" + EX + "This is a longersnippet that should wrap properly") @@ -276,11 +272,6 @@ startThis is a longersnippet that should wrap properlyend""" - def _options_on(self): - self.send(":set tw=20\n") - def _options_off(self): - self.send(":set tw=0\n") - ############ # TabStops # ############ From 57cf2790cbe7fa8c62166406a2f2e1fdd72a157b Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Sun, 20 Feb 2011 21:16:56 +0100 Subject: [PATCH 04/10] Refactored fix for better understandability --- plugin/UltiSnips/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugin/UltiSnips/__init__.py b/plugin/UltiSnips/__init__.py index fdc9dc9..9709a90 100644 --- a/plugin/UltiSnips/__init__.py +++ b/plugin/UltiSnips/__init__.py @@ -694,8 +694,12 @@ class SnippetManager(object): this_entered = vim.current.line[:self._vstate.pos.col] self._chars_entered('\n' + cline + this_entered, 1) if line_was_shortened and user_didnt_enter_newline: - self._backspace(self._vstate.ppos.col-len(lline)) - self._chars_entered('\n' + cline[:len(cline)-(len(self._vstate.last_line)-self._vstate.ppos.col)], 1) + nchars_deleted_in_lline = self._vstate.ppos.col - len(lline) + self._backspace(nchars_deleted_in_lline) + nchars_wrapped_from_lline_after_cursor = \ + len(self._vstate.last_line) - self._vstate.ppos.col + self._chars_entered('\n' + cline + [:len(cline)-nchars_wrapped_from_lline_after_cursor], 1) else: pentered = lline[self._vstate.ppos.col:] this_entered = vim.current.line[:self._vstate.pos.col] From 37f28fe5801d19a963d8667dfd608dba31b88d62 Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Sun, 20 Feb 2011 21:18:25 +0100 Subject: [PATCH 05/10] Sleep a bit after sourcing widelands in tests. Increases reliability on my system --- test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test.py b/test.py index 3b1789f..39f7428 100755 --- a/test.py +++ b/test.py @@ -2301,6 +2301,7 @@ if __name__ == '__main__': # Now, source our runtime send(":so plugin/UltiSnips.vim\n", options.session) + time.sleep(.4) # Parsing and intializing UltiSnips takes a while. # Inform all test case which screen session to use suite = unittest.TestSuite() From cee3b423fcc0a7c252ad721520f82ee6ceadc9e8 Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Sun, 20 Feb 2011 21:18:45 +0100 Subject: [PATCH 06/10] Fix some 'No such mapping' warnings which led to random test failures on my system --- test.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test.py b/test.py index 39f7428..da03f6b 100755 --- a/test.py +++ b/test.py @@ -1775,8 +1775,7 @@ class _AnonBase(_VimTest): self.send(":inoremap " + EA + ' =UltiSnips_Anon(' + self.args + ')\n') def _options_off(self): - self.send(":iunmap " + EA + ' =UltiSnips_Anon(' - + self.args + ')\n') + self.send(":iunmap " + EA + '\n') class Anon_NoTrigger_Simple(_AnonBase): args = '"simple expand"' From 9eb0e5b810a73e20c361f782fea1a569bf66e99e Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Sun, 20 Feb 2011 21:22:37 +0100 Subject: [PATCH 07/10] Parsing ultisnips takes even longer --- test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.py b/test.py index da03f6b..bc66272 100755 --- a/test.py +++ b/test.py @@ -2300,7 +2300,7 @@ if __name__ == '__main__': # Now, source our runtime send(":so plugin/UltiSnips.vim\n", options.session) - time.sleep(.4) # Parsing and intializing UltiSnips takes a while. + time.sleep(2) # Parsing and initializing UltiSnips takes a while. # Inform all test case which screen session to use suite = unittest.TestSuite() From 81be10835cbd818c0d129ef989e2884792803a90 Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Sun, 20 Feb 2011 23:15:04 +0100 Subject: [PATCH 08/10] Initialize output variable in tests, so that less timing errors occure. This makes testing more stable on my system --- test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test.py b/test.py index bc66272..b93943e 100755 --- a/test.py +++ b/test.py @@ -71,6 +71,7 @@ class _VimTest(unittest.TestCase): wanted = "" keys = "" sleeptime = 0.00 + output = None def send(self,s): send(s, self.session) From e5591e25172a6e8748ec3617ae7bce56fcf0fbdf Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Mon, 21 Feb 2011 09:34:12 +0100 Subject: [PATCH 09/10] Dummy commit to overwrite old tags on launchpad --- test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test.py b/test.py index b93943e..d3b1b53 100755 --- a/test.py +++ b/test.py @@ -23,6 +23,7 @@ # # The testsuite will use ``screen`` to inject commands into the Vim under test, # and will compare the resulting output to expected results. +# import os import tempfile From 07bfcb5f84ef25549e67485de1c1eb81649d992d Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Thu, 24 Feb 2011 23:12:51 +0100 Subject: [PATCH 10/10] Fixed a typo in the documentation --- doc/UltiSnips.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/UltiSnips.txt b/doc/UltiSnips.txt index b08d60a..5149327 100644 --- a/doc/UltiSnips.txt +++ b/doc/UltiSnips.txt @@ -17,7 +17,7 @@ UltiSnips *snippet* *snippets* *UltiSnips* 4. Syntax |UltiSnips-syntax| 4.1 Adding Snippets |UltiSnips-adding-snippets| 4.2 Plaintext Snippets |UltiSnips-plaintext-snippets| - 4.3 Interpolation |UltiSnips-integration| + 4.3 Interpolation |UltiSnips-interpolation| 4.3.1 Shellcode |UltiSnips-shellcode| 4.3.2 VimScript |UltiSnips-vimscript| 4.3.3 Python |UltiSnips-python|