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-05 07:20:58 -04:00
|
|
|
# Some constants for better reading
|
|
|
|
BS = '\x7f'
|
|
|
|
ESC = '\x1b'
|
|
|
|
ARR_L = '\x1bOD'
|
|
|
|
ARR_R = '\x1bOC'
|
|
|
|
ARR_U = '\x1bOA'
|
|
|
|
ARR_D = '\x1bOB'
|
|
|
|
|
2009-07-09 09:30:23 -04:00
|
|
|
# Defined Constants
|
|
|
|
JF = "?" # Jump forwards
|
|
|
|
JB = "+" # Jump backwards
|
|
|
|
EX = "\t" # EXPAND
|
|
|
|
|
2009-07-04 10:08:14 -04:00
|
|
|
def send(s,session):
|
|
|
|
os.system("screen -x %s -X stuff '%s'" % (session,s))
|
|
|
|
|
|
|
|
def type(str, session):
|
|
|
|
"""
|
|
|
|
Send the keystrokes to vim via screen. Pause after each char, so
|
|
|
|
vim can handle this
|
|
|
|
"""
|
|
|
|
for c in str:
|
|
|
|
send(c, session)
|
|
|
|
|
2009-07-01 04:39:46 -04:00
|
|
|
class _VimTest(unittest.TestCase):
|
2009-07-05 12:51:12 -04:00
|
|
|
snippets = ("dummy", "donotdefine")
|
2009-07-02 03:49:42 -04:00
|
|
|
text_before = " --- some text before --- "
|
|
|
|
text_after = " --- some text after --- "
|
2009-07-05 12:51:12 -04:00
|
|
|
wanted = ""
|
|
|
|
keys = ""
|
2009-07-04 18:53:30 -04:00
|
|
|
|
2009-07-04 10:08:14 -04:00
|
|
|
def send(self,s):
|
|
|
|
send(s, self.session)
|
2009-07-01 11:11:33 -04:00
|
|
|
|
2009-07-04 10:08:14 -04:00
|
|
|
def type(self,s):
|
|
|
|
type(s, self.session)
|
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-05 12:51:12 -04:00
|
|
|
def runTest(self): self.check_output()
|
|
|
|
|
2009-06-23 08:45:04 -04:00
|
|
|
def setUp(self):
|
2009-07-05 07:20:58 -04:00
|
|
|
self.send(ESC)
|
2009-07-01 04:39:46 -04:00
|
|
|
|
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-07-04 15:58:13 -04:00
|
|
|
for s in self.snippets:
|
|
|
|
sv,content = s[:2]
|
|
|
|
descr = ""
|
|
|
|
if len(s) == 3:
|
|
|
|
descr = s[-1]
|
2009-07-01 11:11:33 -04:00
|
|
|
self.send(''':py << EOF
|
2009-07-04 15:58:13 -04:00
|
|
|
PySnipSnippets.add_snippet("%s","""%s""", "%s")
|
2009-07-01 04:39:46 -04:00
|
|
|
EOF
|
2009-07-04 15:58:13 -04:00
|
|
|
''' % (sv,content.encode("string-escape"), descr.encode("string-escape"))
|
|
|
|
)
|
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
|
2009-07-05 07:20:58 -04:00
|
|
|
self.send(ESC + "ggjji")
|
2009-07-02 03:49:42 -04:00
|
|
|
|
2009-07-01 09:20:40 -04:00
|
|
|
# Execute the command
|
2009-07-05 12:46:08 -04:00
|
|
|
self.type(self.keys)
|
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-07-04 18:53:30 -04:00
|
|
|
os.unlink(fn)
|
2009-06-23 08:45:04 -04:00
|
|
|
|
2009-07-05 07:20:58 -04:00
|
|
|
self.send(ESC + ":w! %s\n" % fn)
|
2009-06-23 08:45:04 -04:00
|
|
|
|
2009-07-01 09:20:40 -04:00
|
|
|
# Read the output, chop the trailing newline
|
2009-07-04 18:53:30 -04:00
|
|
|
tries = 50
|
|
|
|
while tries:
|
|
|
|
if os.path.exists(fn):
|
|
|
|
self.output = open(fn,"r").read()[:-1]
|
|
|
|
break
|
|
|
|
time.sleep(.05)
|
|
|
|
tries -= 1
|
2009-06-23 08:45:04 -04:00
|
|
|
|
|
|
|
##################
|
|
|
|
# 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-09 09:30:23 -04:00
|
|
|
keys = "hallo" + EX
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "Hallo Welt!"
|
2009-07-09 11:49:59 -04:00
|
|
|
class SimpleExpandTwice_ExceptCorrectResult(_SimpleExpands):
|
|
|
|
keys = "hallo" + EX + '\nhallo' + EX
|
|
|
|
wanted = "Hallo Welt!\nHallo Welt!"
|
2009-06-23 08:45:04 -04:00
|
|
|
|
|
|
|
class SimpleExpandTypeAfterExpand_ExceptCorrectResult(_SimpleExpands):
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "hallo" + EX + "and again"
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "Hallo Welt!and again"
|
2009-06-23 08:45:04 -04:00
|
|
|
|
2009-07-03 04:59:55 -04:00
|
|
|
class SimpleExpandTypeAndDelete_ExceptCorrectResult(_SimpleExpands):
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "na du hallo" + EX + "and again\b\b\b\b\bblub"
|
2009-07-03 04:59:55 -04:00
|
|
|
wanted = "na du Hallo Welt!and blub"
|
2009-06-23 08:45:04 -04:00
|
|
|
|
|
|
|
class DoNotExpandAfterSpace_ExceptCorrectResult(_SimpleExpands):
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "hallo " + EX
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "hallo "
|
2009-06-23 08:45:04 -04:00
|
|
|
|
|
|
|
class ExpandInTheMiddleOfLine_ExceptCorrectResult(_SimpleExpands):
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "Wie hallo gehts" + ESC + "bhi" + EX
|
|
|
|
wanted = "Wie Hallo Welt! gehts"
|
2009-06-23 08:45:04 -04:00
|
|
|
class MultilineExpand_ExceptCorrectResult(_VimTest):
|
2009-07-09 09:30:23 -04:00
|
|
|
snippets = ("hallo", "Hallo Welt!\nUnd Wie gehts")
|
|
|
|
keys = "Wie hallo gehts" + ESC + "bhi" + EX
|
|
|
|
wanted = "Wie Hallo Welt!\nUnd Wie gehts gehts"
|
2009-06-28 08:51:27 -04:00
|
|
|
class MultilineExpandTestTyping_ExceptCorrectResult(_VimTest):
|
2009-07-09 09:30:23 -04:00
|
|
|
snippets = ("hallo", "Hallo Welt!\nUnd Wie gehts")
|
|
|
|
wanted = "Wie Hallo Welt!\nUnd Wie gehtsHuiui! gehts"
|
|
|
|
keys = "Wie hallo gehts" + ESC + "bhi" + EX + "Huiui!"
|
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-09 09:30:23 -04:00
|
|
|
keys = "hallo" + EX + "na" + JF + "Du Nase"
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "hallo Du Nase na"
|
2009-07-01 14:03:29 -04:00
|
|
|
class TabStopSimpleReplaceSurrounded_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("hallo", "hallo ${0:End} a small feed")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "hallo" + EX + "Nase"
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "hallo Nase a small feed"
|
2009-07-01 14:03:29 -04:00
|
|
|
class TabStopSimpleReplaceSurrounded1_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("hallo", "hallo $0 a small feed")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "hallo" + EX + "Nase"
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "hallo Nase a small feed"
|
2009-07-09 04:20:25 -04:00
|
|
|
class TabStopSimpleReplaceEndingWithNewline_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("hallo", "Hallo Welt\n")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "hallo" + EX + "\nAnd more"
|
2009-07-09 04:20:25 -04:00
|
|
|
wanted = "Hallo Welt\n\nAnd more"
|
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-09 09:30:23 -04:00
|
|
|
keys = "echo" + EX + "test"
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "test run"
|
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-09 09:30:23 -04:00
|
|
|
keys = "echo" + EX
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "echo Hallo"
|
2009-06-28 16:22:19 -04:00
|
|
|
|
2009-07-03 07:54:35 -04:00
|
|
|
# TODO: multiline tabstops, maybe?
|
|
|
|
|
2009-07-06 10:55:48 -04:00
|
|
|
class TabStopEscapingWhenSelected_ECR(_VimTest):
|
|
|
|
snippets = ("test", "snip ${1:default}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + ESC + "0ihi"
|
2009-07-06 10:55:48 -04:00
|
|
|
wanted = "hisnip default"
|
2009-07-06 10:57:22 -04:00
|
|
|
class TabStopEscapingWhenSelectedSingleCharTS_ECR(_VimTest):
|
|
|
|
snippets = ("test", "snip ${1:i}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + ESC + "0ihi"
|
2009-07-06 10:57:22 -04:00
|
|
|
wanted = "hisnip i"
|
|
|
|
class TabStopEscapingWhenSelectedNoCharTS_ECR(_VimTest):
|
|
|
|
snippets = ("test", "snip $1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + ESC + "0ihi"
|
2009-07-06 10:57:22 -04:00
|
|
|
wanted = "hisnip "
|
2009-07-06 10:55:48 -04:00
|
|
|
|
2009-07-06 11:44:04 -04:00
|
|
|
class TabStopUsingBackspaceToDeleteDefaultValue_ECR(_VimTest):
|
|
|
|
snippets = ("test", "snip ${1/.+/(?0:matched)/} ${1:default}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + BS
|
2009-07-06 11:44:04 -04:00
|
|
|
wanted = "snip "
|
|
|
|
class TabStopUsingBackspaceToDeleteDefaultValueInFirstTab_ECR(_VimTest):
|
|
|
|
snippets = ("test", "snip ${1/.+/(?0:m1)/} ${2/.+/(?0:m2)/} "
|
|
|
|
"${1:default} ${2:def}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + BS + JF + "hi"
|
2009-07-06 11:44:04 -04:00
|
|
|
wanted = "snip m2 hi"
|
|
|
|
class TabStopUsingBackspaceToDeleteDefaultValueInSecondTab_ECR(_VimTest):
|
|
|
|
snippets = ("test", "snip ${1/.+/(?0:m1)/} ${2/.+/(?0:m2)/} "
|
|
|
|
"${1:default} ${2:def}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hi" + JF + BS
|
2009-07-06 11:44:04 -04:00
|
|
|
wanted = "snip m1 hi "
|
|
|
|
class TabStopUsingBackspaceToDeleteDefaultValueTypeSomethingThen_ECR(_VimTest):
|
|
|
|
snippets = ("test", "snip ${1/.+/(?0:matched)/} ${1:default}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + BS + "hallo"
|
2009-07-06 11:44:04 -04:00
|
|
|
wanted = "snip matched hallo"
|
|
|
|
|
2009-07-03 07:54:35 -04:00
|
|
|
class TabStopWithOneChar_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("hallo", "nothing ${1:i} hups")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "hallo" + EX + "ship"
|
2009-07-03 07:54:35 -04:00
|
|
|
wanted = "nothing ship hups"
|
|
|
|
|
2009-07-01 14:03:29 -04:00
|
|
|
class TabStopTestJumping_ExceptCorrectResult(_VimTest):
|
2009-07-03 07:54:35 -04:00
|
|
|
snippets = ("hallo", "hallo ${2:End} mitte ${1:Beginning}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "hallo" + EX + JF + "Test" + JF + "Hi"
|
2009-07-04 11:36:06 -04:00
|
|
|
wanted = "hallo Test mitte BeginningHi"
|
2009-07-01 14:03:29 -04:00
|
|
|
class TabStopTestJumping2_ExceptCorrectResult(_VimTest):
|
2009-07-06 05:35:18 -04:00
|
|
|
snippets = ("hallo", "hallo $2 $1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "hallo" + EX + JF + "Test" + JF + "Hi"
|
2009-07-04 11:36:06 -04:00
|
|
|
wanted = "hallo Test Hi"
|
2009-07-01 09:20:40 -04:00
|
|
|
|
2009-07-06 05:35:18 -04:00
|
|
|
class TestJumpingDontJumpToEndIfThereIsTabZero_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("hallo", "hallo $0 $1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "hallo" + EX + "Test" + JF + "Hi" + JF + JF + "du"
|
2009-07-06 05:35:18 -04:00
|
|
|
wanted = "hallo Hidu Test"
|
|
|
|
|
2009-07-01 14:03:29 -04:00
|
|
|
class TabStopTestBackwardJumping_ExceptCorrectResult(_VimTest):
|
2009-07-06 05:47:27 -04:00
|
|
|
snippets = ("hallo", "hallo ${2:End} mitte${1:Beginning}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "hallo" + EX + "Somelengthy Text" + JF + "Hi" + JB + \
|
|
|
|
"Lets replace it again" + JF + "Blah" + JF + JB*2 + JF
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "hallo Blah mitteLets replace it again"
|
2009-07-01 14:03:29 -04:00
|
|
|
class TabStopTestBackwardJumping2_ExceptCorrectResult(_VimTest):
|
2009-07-06 05:47:27 -04:00
|
|
|
snippets = ("hallo", "hallo $2 $1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "hallo" + EX + "Somelengthy Text" + JF + "Hi" + JB + \
|
|
|
|
"Lets replace it again" + JF + "Blah" + JF + JB*2 + JF
|
2009-07-02 03:49:42 -04:00
|
|
|
wanted = "hallo Blah Lets replace it again"
|
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-09 09:30:23 -04:00
|
|
|
keys ="test hallo World" + ESC + "02f i" + EX + "world" + JF + "try" + \
|
|
|
|
JF + "test" + JF + "one more" + JF + JF
|
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
|
|
|
|
2009-07-09 11:04:57 -04:00
|
|
|
class TabStop_TSInDefaultTextRLExample_OverwriteNone_ECR(_VimTest):
|
|
|
|
snippets = ("test", """<div${1: id="${2:some_id}"}>\n $0\n</div>""")
|
|
|
|
keys = "test" + EX
|
|
|
|
wanted = """<div id="some_id">\n \n</div>"""
|
|
|
|
class TabStop_TSInDefaultTextRLExample_OverwriteFirst(_VimTest):
|
|
|
|
snippets = ("test", """<div${1: id="${2:some_id}"}>\n $0\n</div>""")
|
|
|
|
keys = "test" + EX + " blah" + JF + "Hallo"
|
|
|
|
wanted = """<div blah>\n Hallo\n</div>"""
|
|
|
|
class TabStop_TSInDefaultTextRLExample_DeleteFirst(_VimTest):
|
|
|
|
snippets = ("test", """<div${1: id="${2:some_id}"}>\n $0\n</div>""")
|
|
|
|
keys = "test" + EX + BS + JF + "Hallo"
|
|
|
|
wanted = """<div>\n Hallo\n</div>"""
|
2009-07-09 11:49:59 -04:00
|
|
|
class TabStop_TSInDefaultTextRLExample_OverwriteFirstJumpBack(_VimTest):
|
|
|
|
snippets = ("test", """<div${1: id="${2:some_id}"}>\n $3 $0\n</div>""")
|
|
|
|
keys = "test" + EX + "Hi" + JF + "Hallo" + JB + "SomethingElse" + JF + \
|
|
|
|
"Nupl" + JF + "Nox"
|
|
|
|
wanted = """<divSomethingElse>\n Nupl Nox\n</div>"""
|
2009-07-09 11:04:57 -04:00
|
|
|
class TabStop_TSInDefaultTextRLExample_OverwriteSecond(_VimTest):
|
|
|
|
snippets = ("test", """<div${1: id="${2:some_id}"}>\n $0\n</div>""")
|
|
|
|
keys = "test" + EX + JF + "no" + JF + "End"
|
|
|
|
wanted = """<div id="no">\n End\n</div>"""
|
2009-07-09 11:49:59 -04:00
|
|
|
class TabStop_TSInDefaultTextRLExample_OverwriteSecondTabBack(_VimTest):
|
|
|
|
snippets = ("test", """<div${1: id="${2:some_id}"}>\n $3 $0\n</div>""")
|
|
|
|
keys = "test" + EX + JF + "no" + JF + "End" + JB + "yes" + JF + "Begin" \
|
|
|
|
+ JF + "Hi"
|
|
|
|
wanted = """<div id="yes">\n Begin Hi\n</div>"""
|
|
|
|
class TabStop_TSInDefaultTextRLExample_OverwriteSecondTabBackTwice(_VimTest):
|
|
|
|
snippets = ("test", """<div${1: id="${2:some_id}"}>\n $3 $0\n</div>""")
|
|
|
|
keys = "test" + EX + JF + "no" + JF + "End" + JB + "yes" + JB + \
|
|
|
|
" allaway" + JF + "Third" + JF + "Last"
|
|
|
|
wanted = """<div allaway>\n Third Last\n</div>"""
|
|
|
|
|
|
|
|
class TabStop_TSInDefaultNested_OverwriteOneJumpBackToOther(_VimTest):
|
|
|
|
snippets = ("test", "hi ${1:this ${2:second ${3:third}}} $4")
|
|
|
|
keys = "test" + EX + JF + "Hallo" + JF + "Ende"
|
|
|
|
wanted = "hi this Hallo Ende"
|
|
|
|
class TabStop_TSInDefaultNested_OverwriteOneJumpToThird(_VimTest):
|
|
|
|
snippets = ("test", "hi ${1:this ${2:second ${3:third}}} $4")
|
|
|
|
keys = "test" + EX + JF + JF + "Hallo" + JF + "Ende"
|
|
|
|
wanted = "hi this second Hallo Ende"
|
|
|
|
class TabStop_TSInDefaultNested_OverwriteOneJumpAround(_VimTest):
|
|
|
|
snippets = ("test", "hi ${1:this ${2:second ${3:third}}} $4")
|
|
|
|
keys = "test" + EX + JF + JF + "Hallo" + JB+JB + "Blah" + JF + "Ende"
|
|
|
|
wanted = "hi Blah Ende"
|
|
|
|
|
|
|
|
class TabStop_TSInDefault_MirrorsOutside_DoNothing(_VimTest):
|
|
|
|
snippets = ("test", "hi ${1:this ${2:second}} $2")
|
|
|
|
keys = "test" + EX
|
|
|
|
wanted = "hi this second second"
|
|
|
|
class TabStop_TSInDefault_MirrorsOutside_OverwriteSecond(_VimTest):
|
|
|
|
snippets = ("test", "hi ${1:this ${2:second}} $2")
|
|
|
|
keys = "test" + EX + JF + "Hallo"
|
2009-07-10 02:46:49 -04:00
|
|
|
wanted = "hi this Hallo Hallo"
|
2009-07-09 11:49:59 -04:00
|
|
|
class TabStop_TSInDefault_MirrorsOutside_Overwrite(_VimTest):
|
|
|
|
snippets = ("test", "hi ${1:this ${2:second}} $2")
|
|
|
|
keys = "test" + EX + "Hallo"
|
|
|
|
wanted = "hi Hallo "
|
|
|
|
|
|
|
|
# TODO: Example with Transformations / Mirrors outside of recursion
|
2009-07-07 16:28:09 -04:00
|
|
|
#
|
2009-07-06 17:29:17 -04:00
|
|
|
print "Shell eval snippets"
|
2009-07-07 03:41:09 -04:00
|
|
|
print "Tabstop in default text of tabstop. Like in Ruby Dir snippet in TextMate"
|
2009-07-06 17:29:17 -04:00
|
|
|
|
2009-07-05 16:25:01 -04:00
|
|
|
# functions
|
|
|
|
# Multiline text pasting
|
2009-07-06 17:29:17 -04:00
|
|
|
print "Recursive Tabstops: TODO: this will still take some time"
|
2009-07-05 16:25:01 -04:00
|
|
|
# class RecTabStops_SimpleCase_ExceptCorrectResult(_VimTest):
|
|
|
|
# snippets = ("m", "[ ${1:first} ${2:sec} ]")
|
2009-07-09 09:30:23 -04:00
|
|
|
# keys = "m" + EX + "m" + JF + "hello\tworld\tend"
|
2009-07-05 16:25:01 -04:00
|
|
|
# wanted = "[ [ hello world ] end ]"
|
|
|
|
# class RecTabStops_SimpleCaseLeaveSecond_ExceptCorrectResult(_VimTest):
|
|
|
|
# snippets = ("m", "[ ${1:first} ${2:sec} ]")
|
2009-07-09 09:30:23 -04:00
|
|
|
# keys = "m" + EX + "m" + JF + "hello\tworld\t"
|
2009-07-05 16:25:01 -04:00
|
|
|
# wanted = "[ [ hello world ] sec ]"
|
|
|
|
|
|
|
|
# # TODO: pasting with <C-R> while mirroring, also multiline
|
2009-07-03 04:59:55 -04:00
|
|
|
# ###########
|
|
|
|
# # MIRRORS #
|
|
|
|
# ###########
|
2009-07-03 05:39:46 -04:00
|
|
|
class TextTabStopTextAfterTab_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1 Hinten\n$1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo"
|
2009-07-03 05:39:46 -04:00
|
|
|
wanted = "hallo Hinten\nhallo"
|
|
|
|
class TextTabStopTextBeforeTab_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "Vorne $1\n$1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo"
|
2009-07-03 05:39:46 -04:00
|
|
|
wanted = "Vorne hallo\nhallo"
|
|
|
|
class TextTabStopTextSurroundedTab_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "Vorne $1 Hinten\n$1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo test"
|
2009-07-03 05:39:46 -04:00
|
|
|
wanted = "Vorne hallo test Hinten\nhallo test"
|
|
|
|
|
|
|
|
class TextTabStopTextBeforeMirror_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1\nVorne $1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo"
|
2009-07-03 05:39:46 -04:00
|
|
|
wanted = "hallo\nVorne hallo"
|
|
|
|
class TextTabStopAfterMirror_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1\n$1 Hinten")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo"
|
2009-07-03 05:39:46 -04:00
|
|
|
wanted = "hallo\nhallo Hinten"
|
|
|
|
class TextTabStopSurroundMirror_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1\nVorne $1 Hinten")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo welt"
|
2009-07-03 05:39:46 -04:00
|
|
|
wanted = "hallo welt\nVorne hallo welt Hinten"
|
|
|
|
class TextTabStopAllSurrounded_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "ObenVorne $1 ObenHinten\nVorne $1 Hinten")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo welt"
|
2009-07-03 05:39:46 -04:00
|
|
|
wanted = "ObenVorne hallo welt ObenHinten\nVorne hallo welt Hinten"
|
|
|
|
|
2009-07-03 07:54:35 -04:00
|
|
|
class MirrorBeforeTabstopLeave_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1 ${1:this is it} $1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX
|
2009-07-03 07:54:35 -04:00
|
|
|
wanted = "this is it this is it this is it"
|
|
|
|
class MirrorBeforeTabstopOverwrite_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1 ${1:this is it} $1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "a"
|
2009-07-03 07:54:35 -04:00
|
|
|
wanted = "a a a"
|
|
|
|
|
2009-07-03 05:39:46 -04:00
|
|
|
class TextTabStopSimpleMirrorMultiline_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1\n$1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo"
|
2009-07-03 05:39:46 -04:00
|
|
|
wanted = "hallo\nhallo"
|
|
|
|
class SimpleMirrorMultilineMany_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", " $1\n$1\na$1b\n$1\ntest $1 mich")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo"
|
2009-07-03 05:39:46 -04:00
|
|
|
wanted = " hallo\nhallo\nahallob\nhallo\ntest hallo mich"
|
|
|
|
class MultilineTabStopSimpleMirrorMultiline_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1\n\n$1\n\n$1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo Du\nHi"
|
2009-07-03 05:39:46 -04:00
|
|
|
wanted = "hallo Du\nHi\n\nhallo Du\nHi\n\nhallo Du\nHi"
|
|
|
|
class MultilineTabStopSimpleMirrorMultiline1_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1\n$1\n$1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo Du\nHi"
|
2009-07-03 05:39:46 -04:00
|
|
|
wanted = "hallo Du\nHi\nhallo Du\nHi\nhallo Du\nHi"
|
|
|
|
# TODO: Multiline delete over line endings
|
|
|
|
class MultilineTabStopSimpleMirrorDeleteInLine_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1\n$1\n$1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo Du\nHi\b\bAch Blah"
|
2009-07-03 05:39:46 -04:00
|
|
|
wanted = "hallo Du\nAch Blah\nhallo Du\nAch Blah\nhallo Du\nAch Blah"
|
2009-07-04 09:01:19 -04:00
|
|
|
class TextTabStopSimpleMirrorMultilineMirrorInFront_ECR(_VimTest):
|
|
|
|
snippets = ("test", "$1\n${1:sometext}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo\nagain"
|
2009-07-04 09:01:19 -04:00
|
|
|
wanted = "hallo\nagain\nhallo\nagain"
|
2009-07-03 05:39:46 -04:00
|
|
|
|
|
|
|
class SimpleMirrorDelete_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1\n$1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo\b\b"
|
2009-07-03 05:39:46 -04:00
|
|
|
wanted = "hal\nhal"
|
|
|
|
|
|
|
|
class SimpleMirrorSameLine_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1 $1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo"
|
2009-07-03 05:39:46 -04:00
|
|
|
wanted = "hallo hallo"
|
2009-07-04 06:14:13 -04:00
|
|
|
class Transformation_SimpleMirrorSameLineBeforeTabDefVal_ECR(_VimTest):
|
|
|
|
snippets = ("test", "$1 ${1:replace me}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo foo"
|
2009-07-04 06:14:13 -04:00
|
|
|
wanted = "hallo foo hallo foo"
|
2009-07-03 05:39:46 -04:00
|
|
|
class SimpleMirrorSameLineMany_ExceptCorrectResult(_VimTest):
|
2009-07-04 17:04:12 -04:00
|
|
|
snippets = ("test", "$1 $1 $1 $1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo du"
|
2009-07-03 05:39:46 -04:00
|
|
|
wanted = "hallo du hallo du hallo du hallo du"
|
|
|
|
class SimpleMirrorSameLineManyMultiline_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1 $1 $1 $1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo du\nwie gehts"
|
|
|
|
wanted = "hallo du\nwie gehts hallo du\nwie gehts hallo du\nwie gehts" \
|
|
|
|
" hallo du\nwie gehts"
|
2009-07-03 05:39:46 -04:00
|
|
|
class SimpleMirrorDeleteSomeEnterSome_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1\n$1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo\b\bhups"
|
2009-07-03 05:39:46 -04:00
|
|
|
wanted = "halhups\nhalhups"
|
|
|
|
|
|
|
|
|
|
|
|
class SimpleTabstopWithDefaultSimpelType_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "ha ${1:defa}\n$1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "world"
|
2009-07-03 05:39:46 -04:00
|
|
|
wanted = "ha world\nworld"
|
|
|
|
class SimpleTabstopWithDefaultComplexType_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "ha ${1:default value} $1\nanother: $1 mirror")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "world"
|
2009-07-03 05:39:46 -04:00
|
|
|
wanted = "ha world world\nanother: world mirror"
|
|
|
|
class SimpleTabstopWithDefaultSimpelKeep_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "ha ${1:defa}\n$1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX
|
2009-07-03 05:39:46 -04:00
|
|
|
wanted = "ha defa\ndefa"
|
|
|
|
class SimpleTabstopWithDefaultComplexKeep_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "ha ${1:default value} $1\nanother: $1 mirror")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX
|
2009-07-03 05:39:46 -04:00
|
|
|
wanted = "ha default value default value\nanother: default value mirror"
|
|
|
|
|
2009-07-06 17:26:01 -04:00
|
|
|
class TabstopWithMirrorManyFromAll_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "ha $5 ${1:blub} $4 $0 ${2:$1.h} $1 $3 ${4:More}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hi" + JF + "hu" + JF + "hub" + JF + "hulla" + \
|
|
|
|
JF + "blah" + JF + "end"
|
2009-07-06 17:26:01 -04:00
|
|
|
wanted = "ha blah hi hulla end hu hi hub hulla"
|
2009-07-03 06:05:34 -04:00
|
|
|
class TabstopWithMirrorInDefaultNoType_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "ha ${1:blub} ${2:$1.h}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX
|
2009-07-03 06:05:34 -04:00
|
|
|
wanted = "ha blub blub.h"
|
|
|
|
class TabstopWithMirrorInDefaultTwiceAndExtra_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "ha $1 ${2:$1.h $1.c}\ntest $1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "stdin"
|
2009-07-03 06:05:34 -04:00
|
|
|
wanted = "ha stdin stdin.h stdin.c\ntest stdin"
|
2009-07-03 06:11:09 -04:00
|
|
|
class TabstopWithMirrorInDefaultMultipleLeave_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "ha $1 ${2:snip} ${3:$1.h $2}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "stdin"
|
2009-07-03 06:11:09 -04:00
|
|
|
wanted = "ha stdin snip stdin.h snip"
|
|
|
|
class TabstopWithMirrorInDefaultMultipleOverwrite_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "ha $1 ${2:snip} ${3:$1.h $2}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "stdin" + JF + "do snap"
|
2009-07-03 06:11:09 -04:00
|
|
|
wanted = "ha stdin do snap stdin.h do snap"
|
2009-07-03 06:05:34 -04:00
|
|
|
class TabstopWithMirrorInDefaultOverwrite_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "ha $1 ${2:$1.h}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "stdin" + JF + "overwritten"
|
2009-07-03 06:05:34 -04:00
|
|
|
wanted = "ha stdin overwritten"
|
2009-07-03 05:39:46 -04:00
|
|
|
|
2009-07-03 07:54:35 -04:00
|
|
|
class MirrorRealLifeExample_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = (
|
|
|
|
("for", "for(size_t ${2:i} = 0; $2 < ${1:count}; ${3:++$2})" \
|
2009-07-09 09:30:23 -04:00
|
|
|
"\n{\n" + EX + "${0:/* code */}\n}"),
|
2009-07-03 07:54:35 -04:00
|
|
|
)
|
2009-07-09 09:30:23 -04:00
|
|
|
keys ="for" + EX + "100" + JF + "avar\b\b\b\ba_variable" + JF + \
|
|
|
|
"a_variable *= 2" + JF + "// do nothing"
|
2009-07-03 07:54:35 -04:00
|
|
|
wanted = """for(size_t a_variable = 0; a_variable < 100; a_variable *= 2)
|
|
|
|
{
|
|
|
|
\t// do nothing
|
|
|
|
}"""
|
2009-07-01 14:03:29 -04:00
|
|
|
|
|
|
|
|
2009-07-03 07:54:35 -04:00
|
|
|
###################
|
|
|
|
# TRANSFORMATIONS #
|
|
|
|
###################
|
|
|
|
class Transformation_SimpleCase_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1 ${1/foo/batzl/}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo foo boy"
|
2009-07-03 07:54:35 -04:00
|
|
|
wanted = "hallo foo boy hallo batzl boy"
|
|
|
|
class Transformation_SimpleCaseNoTransform_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1 ${1/foo/batzl/}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo"
|
2009-07-03 07:54:35 -04:00
|
|
|
wanted = "hallo hallo"
|
2009-07-04 06:14:13 -04:00
|
|
|
class Transformation_SimpleCaseTransformInFront_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "${1/foo/batzl/} $1")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo foo"
|
2009-07-04 06:14:13 -04:00
|
|
|
wanted = "hallo batzl hallo foo"
|
|
|
|
class Transformation_SimpleCaseTransformInFrontDefVal_ECR(_VimTest):
|
|
|
|
snippets = ("test", "${1/foo/batzl/} ${1:replace me}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo foo"
|
2009-07-04 06:14:13 -04:00
|
|
|
wanted = "hallo batzl hallo foo"
|
2009-07-03 11:50:52 -04:00
|
|
|
class Transformation_MultipleTransformations_ECR(_VimTest):
|
|
|
|
snippets = ("test", "${1:Some Text}${1/.+/\U$0\E/}\n${1/.+/\L$0\E/}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "SomE tExt "
|
2009-07-03 11:50:52 -04:00
|
|
|
wanted = "SomE tExt SOME TEXT \nsome text "
|
2009-07-04 17:01:23 -04:00
|
|
|
class Transformation_TabIsAtEndAndDeleted_ECR(_VimTest):
|
|
|
|
snippets = ("test", "${1/.+/is something/}${1:some}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "hallo test" + EX + "some\b\b\b\b\b"
|
2009-07-04 17:01:23 -04:00
|
|
|
wanted = "hallo "
|
|
|
|
class Transformation_TabIsAtEndAndDeleted1_ECR(_VimTest):
|
|
|
|
snippets = ("test", "${1/.+/is something/}${1:some}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "hallo test" + EX + "some\b\b\b\bmore"
|
2009-07-04 17:01:23 -04:00
|
|
|
wanted = "hallo is somethingmore"
|
|
|
|
class Transformation_TabIsAtEndNoTextLeave_ECR(_VimTest):
|
|
|
|
snippets = ("test", "${1/.+/is something/}${1}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "hallo test" + EX
|
2009-07-04 17:01:23 -04:00
|
|
|
wanted = "hallo "
|
|
|
|
class Transformation_TabIsAtEndNoTextType_ECR(_VimTest):
|
|
|
|
snippets = ("test", "${1/.+/is something/}${1}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "hallo test" + EX + "b"
|
2009-07-04 17:01:23 -04:00
|
|
|
wanted = "hallo is somethingb"
|
2009-07-06 15:16:02 -04:00
|
|
|
class Transformation_InsideTabLeaveAtDefault_ECR(_VimTest):
|
2009-07-06 15:45:30 -04:00
|
|
|
snippets = ("test", r"$1 ${2:${1/.+/(?0:defined $0)/}}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "sometext" + JF
|
2009-07-06 15:16:02 -04:00
|
|
|
wanted = "sometext defined sometext"
|
|
|
|
class Transformation_InsideTabOvertype_ECR(_VimTest):
|
2009-07-06 15:45:30 -04:00
|
|
|
snippets = ("test", r"$1 ${2:${1/.+/(?0:defined $0)/}}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "sometext" + JF + "overwrite"
|
2009-07-06 15:16:02 -04:00
|
|
|
wanted = "sometext overwrite"
|
2009-07-04 17:01:23 -04:00
|
|
|
|
2009-07-03 11:50:52 -04:00
|
|
|
|
2009-07-03 10:13:39 -04:00
|
|
|
class Transformation_Backreference_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1 ${1/([ab])oo/$1ull/}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "foo boo aoo"
|
2009-07-03 10:13:39 -04:00
|
|
|
wanted = "foo boo aoo foo bull aoo"
|
|
|
|
class Transformation_BackreferenceTwice_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", r"$1 ${1/(dead) (par[^ ]*)/this $2 is a bit $1/}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "dead parrot"
|
2009-07-03 10:13:39 -04:00
|
|
|
wanted = "dead parrot this parrot is a bit dead"
|
|
|
|
|
|
|
|
class Transformation_CleverTransformUpercaseChar_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1 ${1/(.)/\u$1/}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo"
|
2009-07-03 10:13:39 -04:00
|
|
|
wanted = "hallo Hallo"
|
|
|
|
class Transformation_CleverTransformLowercaseChar_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1 ${1/(.*)/\l$1/}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "Hallo"
|
2009-07-03 10:13:39 -04:00
|
|
|
wanted = "Hallo hallo"
|
|
|
|
class Transformation_CleverTransformLongUpper_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1 ${1/(.*)/\U$1\E/}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "hallo"
|
2009-07-03 10:13:39 -04:00
|
|
|
wanted = "hallo HALLO"
|
|
|
|
class Transformation_CleverTransformLongLower_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1 ${1/(.*)/\L$1\E/}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "HALLO"
|
2009-07-03 10:13:39 -04:00
|
|
|
wanted = "HALLO hallo"
|
|
|
|
|
2009-07-03 11:50:52 -04:00
|
|
|
class Transformation_ConditionalInsertionSimple_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1 ${1/(^a).*/(?0:began with an a)/}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "a some more text"
|
2009-07-03 11:50:52 -04:00
|
|
|
wanted = "a some more text began with an a"
|
|
|
|
class Transformation_CIBothDefinedNegative_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1 ${1/(?:(^a)|(^b)).*/(?1:yes:no)/}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "b some"
|
2009-07-03 11:50:52 -04:00
|
|
|
wanted = "b some no"
|
|
|
|
class Transformation_CIBothDefinedPositive_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = ("test", "$1 ${1/(?:(^a)|(^b)).*/(?1:yes:no)/}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "a some"
|
2009-07-03 11:50:52 -04:00
|
|
|
wanted = "a some yes"
|
|
|
|
class Transformation_ConditionalInsertRWEllipsis_ECR(_VimTest):
|
|
|
|
snippets = ("test", r"$1 ${1/(\w+(?:\W+\w+){,7})\W*(.+)?/$1(?2:...)/}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "a b c d e f ghhh h oha"
|
2009-07-03 11:50:52 -04:00
|
|
|
wanted = "a b c d e f ghhh h oha a b c d e f ghhh h..."
|
|
|
|
|
|
|
|
class Transformation_CINewlines_ECR(_VimTest):
|
|
|
|
snippets = ("test", r"$1 ${1/, */\n/}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "test, hallo"
|
2009-07-03 11:50:52 -04:00
|
|
|
wanted = "test, hallo test\nhallo"
|
2009-07-04 18:26:19 -04:00
|
|
|
class Transformation_CIEscapedParensinReplace_ECR(_VimTest):
|
|
|
|
snippets = ("test", r"$1 ${1/hal((?:lo)|(?:ul))/(?1:ha\($1\))/}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "test, halul"
|
2009-07-04 18:26:19 -04:00
|
|
|
wanted = "test, halul test, ha(ul)"
|
2009-07-03 11:50:52 -04:00
|
|
|
|
|
|
|
class Transformation_OptionIgnoreCase_ECR(_VimTest):
|
|
|
|
snippets = ("test", r"$1 ${1/test/blah/i}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "TEST"
|
2009-07-03 11:50:52 -04:00
|
|
|
wanted = "TEST blah"
|
|
|
|
class Transformation_OptionReplaceGlobal_ECR(_VimTest):
|
|
|
|
snippets = ("test", r"$1 ${1/, */-/g}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "a, nice, building"
|
2009-07-03 11:50:52 -04:00
|
|
|
wanted = "a, nice, building a-nice-building"
|
|
|
|
class Transformation_OptionReplaceGlobalMatchInReplace_ECR(_VimTest):
|
|
|
|
snippets = ("test", r"$1 ${1/, */, /g}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "a, nice, building"
|
2009-07-03 11:50:52 -04:00
|
|
|
wanted = "a, nice, building a, nice, building"
|
|
|
|
|
|
|
|
# TODO: conditional in conditional, case folding recursive
|
2009-07-01 09:20:40 -04:00
|
|
|
|
2009-07-04 06:14:13 -04:00
|
|
|
###################
|
|
|
|
# CURSOR MOVEMENT #
|
|
|
|
###################
|
2009-07-04 09:01:19 -04:00
|
|
|
class CursorMovement_Multiline_ECR(_VimTest):
|
|
|
|
snippets = ("test", r"$1 ${1:a tab}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "this is something\nvery nice\nnot" + JF + "more text"
|
|
|
|
wanted = "this is something\nvery nice\nnot " \
|
|
|
|
"this is something\nvery nice\nnotmore text"
|
2009-07-04 06:14:13 -04:00
|
|
|
|
2009-07-05 16:25:01 -04:00
|
|
|
|
2009-07-04 11:36:06 -04:00
|
|
|
# TODO: expandtab and therelikes
|
|
|
|
|
2009-07-05 16:25:01 -04:00
|
|
|
######################
|
|
|
|
# INSERT MODE MOVING #
|
|
|
|
######################
|
|
|
|
class IMMoving_CursorsKeys_ECR(_VimTest):
|
|
|
|
snippets = ("test", "${1:Some}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "text" + 3*ARR_U + 6*ARR_D
|
2009-07-05 16:25:01 -04:00
|
|
|
wanted = "text"
|
2009-07-06 04:31:12 -04:00
|
|
|
class IMMoving_DoNotAcceptInputWhenMoved_ECR(_VimTest):
|
2009-07-05 16:25:01 -04:00
|
|
|
snippets = ("test", r"$1 ${1:a tab}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "this" + ARR_L + "hallo"
|
2009-07-05 16:25:01 -04:00
|
|
|
wanted = "this thihallos"
|
2009-07-06 04:31:12 -04:00
|
|
|
class IMMoving_NoExiting_ECR(_VimTest):
|
|
|
|
snippets = ("test", r"$1 ${2:a tab} ${1:Tab}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "hello test this" + ESC + "02f i" + EX + "tab" + 7*ARR_L + \
|
|
|
|
JF + "hallo"
|
2009-07-06 04:31:12 -04:00
|
|
|
wanted = "hello tab hallo tab this"
|
|
|
|
class IMMoving_NoExitingEventAtEnd_ECR(_VimTest):
|
|
|
|
snippets = ("test", r"$1 ${2:a tab} ${1:Tab}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "hello test this" + ESC + "02f i" + EX + "tab" + JF + "hallo"
|
2009-07-06 04:31:12 -04:00
|
|
|
wanted = "hello tab hallo tab this"
|
|
|
|
class IMMoving_ExitWhenOutsideRight_ECR(_VimTest):
|
|
|
|
snippets = ("test", r"$1 ${2:blub} ${1:Tab}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "hello test this" + ESC + "02f i" + EX + "tab" + ARR_R + JF + "hallo"
|
2009-07-06 04:31:12 -04:00
|
|
|
wanted = "hello tab blub tab hallothis"
|
|
|
|
class IMMoving_NotExitingWhenBarelyOutsideLeft_ECR(_VimTest):
|
|
|
|
snippets = ("test", r"${1:Hi} ${2:blub}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "hello test this" + ESC + "02f i" + EX + "tab" + 3*ARR_L + \
|
|
|
|
JF + "hallo"
|
2009-07-06 04:31:12 -04:00
|
|
|
wanted = "hello tab hallo this"
|
|
|
|
class IMMoving_ExitWhenOutsideLeft_ECR(_VimTest):
|
|
|
|
snippets = ("test", r"${1:Hi} ${2:blub}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "hello test this" + ESC + "02f i" + EX + "tab" + 4*ARR_L + \
|
|
|
|
JF + "hallo"
|
2009-07-06 04:31:12 -04:00
|
|
|
wanted = "hellohallo tab blub this"
|
2009-07-06 10:43:24 -04:00
|
|
|
class IMMoving_ExitWhenOutsideAbove_ECR(_VimTest):
|
|
|
|
snippets = ("test", "${1:Hi}\n${2:blub}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "hello test this" + ESC + "02f i" + EX + "tab" + 1*ARR_U + JF + \
|
|
|
|
"\nhallo"
|
2009-07-06 10:43:24 -04:00
|
|
|
wanted = "hallo\nhello tab\nblub this"
|
|
|
|
class IMMoving_ExitWhenOutsideBelow_ECR(_VimTest):
|
|
|
|
snippets = ("test", "${1:Hi}\n${2:blub}")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "hello test this" + ESC + "02f i" + EX + "tab" + 2*ARR_D + JF + \
|
|
|
|
"testhallo\n"
|
2009-07-06 10:43:24 -04:00
|
|
|
wanted = "hello tab\nblub this\ntesthallo"
|
2009-07-05 16:25:01 -04:00
|
|
|
|
2009-07-04 11:59:50 -04:00
|
|
|
####################
|
|
|
|
# PROPER INDENTING #
|
|
|
|
####################
|
|
|
|
class ProperIndenting_SimpleCase_ECR(_VimTest):
|
|
|
|
snippets = ("test", "for\n blah")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = " test" + EX + "Hui"
|
2009-07-04 11:59:50 -04:00
|
|
|
wanted = " for\n blahHui"
|
2009-07-06 04:40:07 -04:00
|
|
|
class ProperIndenting_SingleLineNoReindenting_ECR(_VimTest):
|
|
|
|
snippets = ("test", "hui")
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = " test" + EX + "blah"
|
2009-07-06 04:40:07 -04:00
|
|
|
wanted = " huiblah"
|
2009-07-04 15:58:13 -04:00
|
|
|
|
|
|
|
######################
|
|
|
|
# SELECTING MULTIPLE #
|
|
|
|
######################
|
|
|
|
class Multiple_SimpleCaseSelectFirst_ECR(_VimTest):
|
|
|
|
snippets = ( ("test", "Case1", "This is Case 1"),
|
|
|
|
("test", "Case2", "This is Case 2") )
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "1\n"
|
2009-07-04 15:58:13 -04:00
|
|
|
wanted = "Case1"
|
|
|
|
class Multiple_SimpleCaseSelectSecond_ECR(_VimTest):
|
|
|
|
snippets = ( ("test", "Case1", "This is Case 1"),
|
|
|
|
("test", "Case2", "This is Case 2") )
|
2009-07-09 09:30:23 -04:00
|
|
|
keys = "test" + EX + "2\n"
|
2009-07-04 15:58:13 -04:00
|
|
|
wanted = "Case2"
|
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
# END OF TEST #
|
|
|
|
###########################################################################
|
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>")
|
|
|
|
|
2009-07-04 09:01:19 -04:00
|
|
|
p.set_defaults(session="vim", interrupt=False, verbose=False)
|
2009-07-01 09:20:40 -04:00
|
|
|
|
2009-07-04 09:01:19 -04:00
|
|
|
p.add_option("-v", "--verbose", dest="verbose", action="store_true",
|
|
|
|
help="print name of tests as they are executed")
|
2009-07-01 09:20:40 -04:00
|
|
|
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
|
|
|
|
2009-07-04 10:08:14 -04:00
|
|
|
# Send some mappings to vim
|
2009-07-09 09:30:23 -04:00
|
|
|
send(":imapclear\n", options.session)
|
|
|
|
send(":smapclear\n", options.session)
|
|
|
|
|
|
|
|
send(":inoremap <Tab> <C-R>=PyVimSnips_ExpandSnippet()<cr>\n",
|
|
|
|
options.session)
|
|
|
|
send(":snoremap <Tab> <Esc>:call PyVimSnips_ExpandSnippet()<cr>\n",
|
|
|
|
options.session)
|
2009-07-04 10:08:14 -04:00
|
|
|
send(":inoremap + <C-R>=PyVimSnips_JumpBackwards()<cr>\n", options.session)
|
|
|
|
send(":snoremap + <Esc>:call PyVimSnips_JumpBackwards()<cr>\n",
|
|
|
|
options.session)
|
2009-07-09 09:30:23 -04:00
|
|
|
send(":inoremap ? <C-R>=PyVimSnips_JumpForwards()<cr>\n", options.session)
|
|
|
|
send(":snoremap ? <Esc>:call PyVimSnips_JumpForwards()<cr>\n",
|
|
|
|
options.session)
|
2009-07-04 10:08:14 -04:00
|
|
|
|
2009-07-09 09:30:23 -04:00
|
|
|
# Mandatory remapping
|
|
|
|
send(":snoremap <BS> <Esc>:py PySnipSnippets." \
|
|
|
|
"backspace_while_selected()<cr>\n", options.session)
|
2009-07-04 10:08:14 -04:00
|
|
|
|
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]
|
2009-07-03 11:50:52 -04:00
|
|
|
if not any([ id.startswith(t) for t in selected_tests ]):
|
2009-07-01 09:20:40 -04:00
|
|
|
continue
|
|
|
|
suite.addTest(test)
|
|
|
|
|
|
|
|
|
2009-07-04 09:01:19 -04:00
|
|
|
if options.verbose:
|
|
|
|
v = 2
|
|
|
|
else:
|
|
|
|
v = 1
|
|
|
|
res = unittest.TextTestRunner(verbosity=v).run(suite)
|
2009-07-01 09:20:40 -04:00
|
|
|
|