2009-06-23 08:45:04 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# encoding: utf-8
|
|
|
|
#
|
|
|
|
|
2009-07-01 04:39:46 -04:00
|
|
|
import os
|
|
|
|
import tempfile
|
2009-06-23 08:45:04 -04:00
|
|
|
import unittest
|
2009-07-01 04:39:46 -04:00
|
|
|
import time
|
2009-06-23 08:45:04 -04:00
|
|
|
|
2009-07-01 04:39:46 -04:00
|
|
|
class _VimTest(unittest.TestCase):
|
2009-07-02 03:49:42 -04:00
|
|
|
text_before = " --- some text before --- "
|
|
|
|
text_after = " --- some text after --- "
|
2009-07-01 11:11:33 -04:00
|
|
|
def send(self, s):
|
|
|
|
os.system("screen -x %s -X stuff '%s'" % (self.session,s))
|
|
|
|
|
2009-07-01 04:39:46 -04:00
|
|
|
def type(self, str):
|
|
|
|
"""
|
2009-07-01 11:11:33 -04:00
|
|
|
Send the keystrokes to vim via screen. Pause after each char, so
|
|
|
|
vim can handle this
|
2009-07-01 04:39:46 -04:00
|
|
|
"""
|
2009-07-01 11:11:33 -04:00
|
|
|
for c in str:
|
|
|
|
self.send(c)
|
2009-06-23 08:45:04 -04:00
|
|
|
|
2009-07-02 03:49:42 -04:00
|
|
|
def check_output(self):
|
|
|
|
wanted = self.text_before + '\n\n' + self.wanted + \
|
|
|
|
'\n\n' + self.text_after
|
|
|
|
self.assertEqual(self.output, wanted)
|
|
|
|
|
2009-07-01 04:39:46 -04:00
|
|
|
def escape(self):
|
|
|
|
self.type("\x1b")
|
2009-06-23 08:45:04 -04:00
|
|
|
|
|
|
|
def setUp(self):
|
2009-07-01 04:39:46 -04:00
|
|
|
self.escape()
|
|
|
|
|
2009-07-01 11:11:33 -04:00
|
|
|
self.send(":py PySnipSnippets.reset()\n")
|
2009-06-28 16:22:19 -04:00
|
|
|
|
2009-07-01 14:03:29 -04:00
|
|
|
if not isinstance(self.snippets[0],tuple):
|
|
|
|
self.snippets = ( self.snippets, )
|
|
|
|
|
2009-06-28 16:22:19 -04:00
|
|
|
for sv,content in self.snippets:
|
2009-07-01 11:11:33 -04:00
|
|
|
self.send(''':py << EOF
|
2009-07-01 04:39:46 -04:00
|
|
|
PySnipSnippets.add_snippet("%s","""%s""")
|
|
|
|
EOF
|
|
|
|
''' % (sv,content))
|
2009-07-01 11:11:33 -04:00
|
|
|
|
2009-07-01 04:39:46 -04:00
|
|
|
# Clear the buffer
|
2009-07-01 11:11:33 -04:00
|
|
|
self.send("bggVGd")
|
2009-07-01 04:39:46 -04:00
|
|
|
|
2009-07-01 09:20:40 -04:00
|
|
|
if not self.interrupt:
|
|
|
|
# Enter insert mode
|
2009-07-01 11:11:33 -04:00
|
|
|
self.send("i")
|
2009-06-28 16:22:19 -04:00
|
|
|
|
2009-07-02 03:49:42 -04:00
|
|
|
self.send(self.text_before + '\n\n')
|
|
|
|
self.send('\n\n' + self.text_after)
|
|
|
|
|
|
|
|
# Go to the middle of the buffer
|
|
|
|
self.escape()
|
|
|
|
self.send("ggjji")
|
|
|
|
|
2009-07-01 09:20:40 -04:00
|
|
|
# Execute the command
|
|
|
|
self.cmd()
|
2009-06-28 16:22:19 -04:00
|
|
|
|
2009-07-02 03:49:42 -04:00
|
|
|
|
2009-07-01 09:20:40 -04:00
|
|
|
handle, fn = tempfile.mkstemp(prefix="PySnipEmuTest",suffix=".txt")
|
|
|
|
os.close(handle)
|
2009-06-23 08:45:04 -04:00
|
|
|
|
2009-07-01 09:20:40 -04:00
|
|
|
self.escape()
|
2009-07-01 11:11:33 -04:00
|
|
|
self.send(":w! %s\n" % fn)
|
2009-06-23 08:45:04 -04:00
|
|
|
|
2009-07-01 09:20:40 -04:00
|
|
|
# Give screen a chance to send the cmd and vim to write the file
|
2009-07-02 03:49:42 -04:00
|
|
|
time.sleep(.10)
|
2009-07-01 04:39:46 -04:00
|
|
|
|
2009-07-01 09:20:40 -04:00
|
|
|
# Read the output, chop the trailing newline
|
|
|
|
self.output = open(fn,"r").read()[:-1]
|
2009-06-23 08:45:04 -04:00
|
|
|
|
2009-07-02 03:49:42 -04:00
|
|
|
|
2009-06-23 08:45:04 -04:00
|
|
|
def cmd(self):
|
|
|
|
"""Overwrite these in the children"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
##################
|
|
|
|
# Simple Expands #
|
|
|
|
##################
|
|
|
|
class _SimpleExpands(_VimTest):
|
2009-07-01 14:03:29 -04:00
|
|
|
snippets = ("hallo", "Hallo Welt!")
|
2009-06-23 08:45:04 -04:00
|
|
|
|
|
|
|
class SimpleExpand_ExceptCorrectResult(_SimpleExpands):
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "Hallo Welt!"
|
|
|
|
def cmd(self): self.type("hallo\t")
|
|
|
|
def runTest(self): self.check_output()
|
2009-06-23 08:45:04 -04:00
|
|
|
|
|
|
|
class SimpleExpandTypeAfterExpand_ExceptCorrectResult(_SimpleExpands):
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "Hallo Welt!and again"
|
|
|
|
def cmd(self): self.type("hallo\tand again")
|
|
|
|
def runTest(self): self.check_output()
|
2009-06-23 08:45:04 -04:00
|
|
|
|
|
|
|
class SimpleExpandTypeAfterExpand1_ExceptCorrectResult(_SimpleExpands):
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "na du Hallo Welt!and again"
|
|
|
|
def cmd(self): self.type("na du hallo\tand again")
|
|
|
|
def runTest(self): self.check_output()
|
2009-06-23 08:45:04 -04:00
|
|
|
|
|
|
|
class DoNotExpandAfterSpace_ExceptCorrectResult(_SimpleExpands):
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "hallo "
|
|
|
|
def cmd(self): self.type("hallo \t")
|
|
|
|
def runTest(self): self.check_output()
|
2009-06-23 08:45:04 -04:00
|
|
|
|
|
|
|
class ExpandInTheMiddleOfLine_ExceptCorrectResult(_SimpleExpands):
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "Wie Hallo Welt! gehts?"
|
2009-06-23 08:45:04 -04:00
|
|
|
def cmd(self):
|
2009-07-01 04:39:46 -04:00
|
|
|
self.type("Wie hallo gehts?")
|
|
|
|
self.escape()
|
|
|
|
self.type("bhi\t")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-06-23 08:45:04 -04:00
|
|
|
|
|
|
|
class MultilineExpand_ExceptCorrectResult(_VimTest):
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "Wie Hallo Welt!\nUnd Wie gehts? gehts?"
|
2009-07-01 14:22:12 -04:00
|
|
|
snippets = ("hallo", "Hallo Welt!\nUnd Wie gehts?")
|
2009-06-23 08:45:04 -04:00
|
|
|
def cmd(self):
|
2009-07-01 04:39:46 -04:00
|
|
|
self.type("Wie hallo gehts?")
|
|
|
|
self.escape()
|
|
|
|
self.type("bhi\t")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-06-28 08:51:27 -04:00
|
|
|
class MultilineExpandTestTyping_ExceptCorrectResult(_VimTest):
|
2009-07-01 14:22:12 -04:00
|
|
|
snippets = ("hallo", "Hallo Welt!\nUnd Wie gehts?")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "Wie Hallo Welt!\nUnd Wie gehts?Huiui! gehts?"
|
2009-06-28 08:51:27 -04:00
|
|
|
def cmd(self):
|
2009-07-01 04:39:46 -04:00
|
|
|
self.type("Wie hallo gehts?")
|
|
|
|
self.escape()
|
|
|
|
self.type("bhi\tHuiui!")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-06-23 08:45:04 -04:00
|
|
|
|
|
|
|
############
|
|
|
|
# TabStops #
|
|
|
|
############
|
2009-07-01 14:03:29 -04:00
|
|
|
class TabStopSimpleReplace_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("hallo", "hallo ${0:End} ${1:Beginning}")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "hallo Du Nase na"
|
2009-07-01 14:03:29 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.type("hallo\tna\tDu Nase")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-06-28 16:22:19 -04:00
|
|
|
|
2009-07-01 14:03:29 -04:00
|
|
|
class TabStopSimpleReplaceSurrounded_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("hallo", "hallo ${0:End} a small feed")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "hallo Nase a small feed"
|
2009-06-23 08:45:04 -04:00
|
|
|
def cmd(self):
|
2009-07-01 14:03:29 -04:00
|
|
|
self.type("hallo\tNase")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-07-01 14:03:29 -04:00
|
|
|
class TabStopSimpleReplaceSurrounded1_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("hallo", "hallo $0 a small feed")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "hallo Nase a small feed"
|
2009-07-01 14:03:29 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.type("hallo\tNase")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-06-23 08:45:04 -04:00
|
|
|
|
2009-07-01 14:03:29 -04:00
|
|
|
|
|
|
|
class ExitTabStop_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("echo", "$0 run")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "test run"
|
2009-07-01 14:03:29 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.type("echo\ttest")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-06-28 08:51:27 -04:00
|
|
|
|
2009-07-01 14:03:29 -04:00
|
|
|
class TabStopNoReplace_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("echo", "echo ${1:Hallo}")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "echo Hallo"
|
2009-06-28 08:51:27 -04:00
|
|
|
def cmd(self):
|
2009-07-01 04:39:46 -04:00
|
|
|
self.type("echo\t")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-06-28 16:22:19 -04:00
|
|
|
|
2009-07-01 14:03:29 -04:00
|
|
|
class TabStopTestJumping_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("hallo", "hallo ${0:End} mitte ${1:Beginning}")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "hallo TestHi mitte Beginning"
|
2009-06-28 16:22:19 -04:00
|
|
|
def cmd(self):
|
2009-07-01 14:03:29 -04:00
|
|
|
self.type("hallo\t\tTest\tHi")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-07-01 14:03:29 -04:00
|
|
|
class TabStopTestJumping2_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("hallo", "hallo $0 $1")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "hallo TestHi "
|
2009-07-01 14:03:29 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.type("hallo\t\tTest\tHi")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-07-01 09:20:40 -04:00
|
|
|
|
2009-07-01 14:03:29 -04:00
|
|
|
class TabStopTestBackwardJumping_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("hallo", "hallo ${0:End} mitte${1:Beginning}")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "hallo Blah mitteLets replace it again"
|
2009-07-01 09:20:40 -04:00
|
|
|
def cmd(self):
|
2009-07-02 05:48:35 -04:00
|
|
|
self.type(
|
|
|
|
"hallo\tSomelengthy Text\tHi+Lets replace it again\tBlah\t++\t")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-07-01 14:03:29 -04:00
|
|
|
class TabStopTestBackwardJumping2_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("hallo", "hallo $0 $1")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "hallo Blah Lets replace it again"
|
2009-07-01 14:03:29 -04:00
|
|
|
def cmd(self):
|
2009-07-02 05:48:35 -04:00
|
|
|
self.type(
|
|
|
|
"hallo\tSomelengthy Text\tHi+Lets replace it again\tBlah\t++\t")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-07-01 14:03:29 -04:00
|
|
|
|
2009-07-01 14:22:12 -04:00
|
|
|
class TabStopTestMultilineExpand_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("hallo", "hallo $0\nnice $1 work\n$3 $2\nSeem to work")
|
2009-07-02 05:48:35 -04:00
|
|
|
wanted = "test hallo one more\nnice world work\n" \
|
|
|
|
"test try\nSeem to work World"
|
2009-07-01 14:22:12 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.type("test hallo World")
|
|
|
|
self.escape()
|
2009-07-02 09:41:58 -04:00
|
|
|
self.type("02f i\t")
|
|
|
|
self.type("world\ttry\ttest\tone more\t\t")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-07-01 14:22:12 -04:00
|
|
|
|
2009-07-01 14:03:29 -04:00
|
|
|
# TODO: pasting with <C-R> while mirroring
|
|
|
|
###########
|
|
|
|
# MIRRORS #
|
|
|
|
###########
|
|
|
|
class TextTabStopTextAfterTab_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1 Hinten\n$1")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "hallo Hinten\nhallo"
|
2009-07-01 14:03:29 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.type("test\thallo")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-07-01 14:03:29 -04:00
|
|
|
class TextTabStopTextBeforeTab_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "Vorne $1\n$1")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "Vorne hallo\nhallo"
|
2009-07-01 14:03:29 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.type("test\thallo")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-07-01 14:03:29 -04:00
|
|
|
class TextTabStopTextSurroundedTab_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "Vorne $1 Hinten\n$1")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "Vorne hallo test Hinten\nhallo test"
|
2009-07-01 14:03:29 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.type("test\thallo test")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-07-01 09:20:40 -04:00
|
|
|
|
2009-07-01 14:03:29 -04:00
|
|
|
class TextTabStopTextBeforeMirror_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1\nVorne $1")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "hallo\nVorne hallo"
|
2009-07-01 14:03:29 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.type("test\thallo")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-07-01 14:03:29 -04:00
|
|
|
class TextTabStopAfterMirror_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1\n$1 Hinten")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "hallo\nhallo Hinten"
|
2009-07-01 14:03:29 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.type("test\thallo")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-07-01 14:03:29 -04:00
|
|
|
class TextTabStopSurroundMirror_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1\nVorne $1 Hinten")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "hallo welt\nVorne hallo welt Hinten"
|
2009-07-01 14:03:29 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.type("test\thallo welt")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-07-01 14:03:29 -04:00
|
|
|
class TextTabStopAllSurrounded_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "ObenVorne $1 ObenHinten\nVorne $1 Hinten")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "ObenVorne hallo welt ObenHinten\nVorne hallo welt Hinten"
|
2009-07-01 14:03:29 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.type("test\thallo welt")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-07-01 09:20:40 -04:00
|
|
|
|
|
|
|
|
2009-07-01 14:03:29 -04:00
|
|
|
class TextTabStopSimpleMirrorMultiline_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1\n$1")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "hallo\nhallo"
|
2009-07-01 09:20:40 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.type("test\thallo")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
|
|
|
class SimpleMirrorMultilineMany_ExceptCorrectResult(_VimTest):
|
2009-07-01 14:03:29 -04:00
|
|
|
snippets = ("test", " $1\n$1\na$1b\n$1\ntest $1 mich")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = " hallo\nhallo\nahallob\nhallo\ntest hallo mich"
|
2009-07-01 14:03:29 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.type("test\thallo")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-07-02 05:48:35 -04:00
|
|
|
class MultilineTabStopSimpleMirrorMultiline_ExceptCorrectResult(_VimTest):
|
2009-07-02 08:22:13 -04:00
|
|
|
snippets = ("test", "$1\n\n$1\n\n$1")
|
|
|
|
wanted = "hallo Du\nHi\n\nhallo Du\nHi\n\nhallo Du\nHi"
|
2009-07-02 05:48:35 -04:00
|
|
|
def cmd(self):
|
2009-07-02 08:22:13 -04:00
|
|
|
self.type("test\thallo Du\nHi")
|
|
|
|
def runTest(self): self.check_output()
|
|
|
|
class MultilineTabStopSimpleMirrorMultiline1_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1\n$1\n$1")
|
|
|
|
wanted = "hallo Du\nHi\nhallo Du\nHi\nhallo Du\nHi"
|
|
|
|
def cmd(self):
|
|
|
|
self.type("test\thallo Du\nHi")
|
|
|
|
def runTest(self): self.check_output()
|
|
|
|
# TODO: Multiline delete over line endings
|
|
|
|
class MultilineTabStopSimpleMirrorDeleteInLine_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1\n$1\n$1")
|
|
|
|
wanted = "hallo Du\nAch Blah\nhallo Du\nAch Blah\nhallo Du\nAch Blah"
|
|
|
|
def cmd(self):
|
|
|
|
self.type("test\thallo Du\nHi\b\bAch Blah")
|
2009-07-02 05:48:35 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-07-01 14:03:29 -04:00
|
|
|
|
2009-07-01 09:20:40 -04:00
|
|
|
|
2009-07-02 03:49:42 -04:00
|
|
|
class SimpleMirrorDelete_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1\n$1")
|
|
|
|
wanted = "hal\nhal"
|
2009-07-01 09:20:40 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.type("test\thallo")
|
|
|
|
self.type("\b\b")
|
|
|
|
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-07-01 09:20:40 -04:00
|
|
|
|
2009-07-02 03:49:42 -04:00
|
|
|
class SimpleMirrorSameLine_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1 $1")
|
|
|
|
wanted = "hallo hallo"
|
2009-07-01 09:20:40 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.type("test\thallo")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
|
|
|
class SimpleMirrorSameLineMany_ExceptCorrectResult(_VimTest):
|
2009-07-02 10:20:13 -04:00
|
|
|
snippets = ("test", "$1 $1 $1")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "hallo du hallo du hallo du hallo du"
|
2009-07-01 14:03:29 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.type("test\thallo du")
|
2009-07-02 10:02:02 -04:00
|
|
|
class SimpleMirrorSameLineManyMultiline_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1 $1 $1 $1")
|
|
|
|
wanted = "hallo du\nwie gehts? hallo du\nwie gehts? hallo du\nwie gehts."
|
|
|
|
def cmd(self):
|
|
|
|
self.type("test\thallo du\nwie gehts?")
|
2009-07-01 14:03:29 -04:00
|
|
|
|
2009-07-01 09:20:40 -04:00
|
|
|
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
|
|
|
class SimpleMirrorDeleteSomeEnterSome_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1\n$1")
|
|
|
|
wanted = "halhups\nhalhups"
|
2009-07-01 09:20:40 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.type("test\thallo\b\bhups")
|
|
|
|
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-07-01 09:20:40 -04:00
|
|
|
|
2009-07-01 14:03:29 -04:00
|
|
|
|
2009-07-02 03:49:42 -04:00
|
|
|
class SimpleTabstopWithDefaultSimpelType_ExceptCorrectResult(_VimTest):
|
2009-07-01 14:03:29 -04:00
|
|
|
snippets = ("test", "ha ${1:defa}\n$1")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "ha world\nworld"
|
2009-07-01 14:03:29 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.type("test\tworld")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
|
|
|
class SimpleTabstopWithDefaultComplexType_ExceptCorrectResult(_VimTest):
|
2009-07-01 14:03:29 -04:00
|
|
|
snippets = ("test", "ha ${1:default value} $1\nanother: $1 mirror")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "ha world world\nanother: world mirror"
|
2009-07-01 14:03:29 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.type("test\tworld")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
|
|
|
class SimpleTabstopWithDefaultSimpelKeep_ExceptCorrectResult(_VimTest):
|
2009-07-01 14:03:29 -04:00
|
|
|
snippets = ("test", "ha ${1:defa}\n$1")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "ha defa\ndefa"
|
2009-07-01 14:03:29 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.type("test\t")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
|
|
|
class SimpleTabstopWithDefaultComplexKeep_ExceptCorrectResult(_VimTest):
|
2009-07-01 14:03:29 -04:00
|
|
|
snippets = ("test", "ha ${1:default value} $1\nanother: $1 mirror")
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "ha default value default value\nanother: default value mirror"
|
2009-07-01 14:03:29 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.type("test\t")
|
2009-07-02 03:49:42 -04:00
|
|
|
def runTest(self): self.check_output()
|
2009-07-01 14:03:29 -04:00
|
|
|
|
2009-07-02 10:02:02 -04:00
|
|
|
# TODO: Mehrer tabs und mehrere mirrors
|
2009-07-01 14:03:29 -04:00
|
|
|
|
|
|
|
|
2009-07-02 03:49:42 -04:00
|
|
|
# class MirrorMoreInvolved_ExceptCorrectResult(_VimTest):
|
2009-07-01 09:29:14 -04:00
|
|
|
# snippets = (
|
|
|
|
# ("for", "for(size_t ${2:i} = 0; $2 < ${1:count}; ${3:++$2})\n{\n\t${0:/* code */}\n}"),
|
|
|
|
# )
|
|
|
|
#
|
|
|
|
# def cmd(self):
|
|
|
|
# self.type("for\t")
|
|
|
|
#
|
|
|
|
# def runTest(self):
|
|
|
|
# self.assertEqual(self.output,"hallo Du Nase na")
|
2009-07-01 14:03:29 -04:00
|
|
|
# TODO: recursive expansion
|
|
|
|
# TODO: mirrors in default expansion
|
|
|
|
# TODO: $1 ${1:This is the tabstop}
|
2009-07-01 09:20:40 -04:00
|
|
|
|
2009-06-23 08:45:04 -04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
2009-07-01 09:20:40 -04:00
|
|
|
import optparse
|
|
|
|
|
|
|
|
def parse_args():
|
|
|
|
p = optparse.OptionParser("%prog [OPTIONS] <test case names to run>")
|
|
|
|
|
|
|
|
p.set_defaults(session="vim", interrupt=False)
|
|
|
|
|
|
|
|
p.add_option("-s", "--session", dest="session", metavar="SESSION",
|
|
|
|
help="send commands to screen session SESSION [%default]")
|
|
|
|
p.add_option("-i", "--interrupt", dest="interrupt",
|
|
|
|
action="store_true",
|
|
|
|
help="Stop after defining the snippet. This allows the user" \
|
|
|
|
"to interactively test the snippet in vim. You must give exactly" \
|
|
|
|
"one test case on the cmdline. The test will always fail."
|
|
|
|
)
|
2009-06-28 08:51:27 -04:00
|
|
|
|
2009-07-01 09:20:40 -04:00
|
|
|
o, args = p.parse_args()
|
|
|
|
return o, args
|
|
|
|
|
|
|
|
options,selected_tests = parse_args()
|
|
|
|
|
|
|
|
# The next line doesn't work in python 2.3
|
2009-07-02 05:48:35 -04:00
|
|
|
test_loader = unittest.TestLoader()
|
|
|
|
all_test_suites = test_loader.loadTestsFromModule(__import__("test"))
|
2009-07-01 09:20:40 -04:00
|
|
|
|
|
|
|
# Inform all test case which screen session to use
|
2009-06-28 08:51:27 -04:00
|
|
|
suite = unittest.TestSuite()
|
2009-07-01 09:20:40 -04:00
|
|
|
for s in all_test_suites:
|
|
|
|
for test in s:
|
|
|
|
test.session = options.session
|
|
|
|
test.interrupt = options.interrupt
|
|
|
|
if len(selected_tests):
|
|
|
|
id = test.id().split('.')[1]
|
|
|
|
if id not in selected_tests:
|
|
|
|
continue
|
|
|
|
suite.addTest(test)
|
|
|
|
|
|
|
|
|
2009-07-01 04:39:46 -04:00
|
|
|
res = unittest.TextTestRunner().run(suite)
|
2009-07-01 09:20:40 -04:00
|
|
|
|