2009-06-23 08:45:04 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# encoding: utf-8
|
|
|
|
#
|
|
|
|
|
|
|
|
import vim
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
from PySnipEmu import PySnipSnippets
|
|
|
|
|
|
|
|
|
|
|
|
class _VimTest(unittest.TestCase):
|
|
|
|
def setUp(self):
|
2009-06-28 16:22:19 -04:00
|
|
|
PySnipSnippets.reset()
|
|
|
|
|
|
|
|
for sv,content in self.snippets:
|
|
|
|
PySnipSnippets.add_snippet(sv,content)
|
|
|
|
|
2009-06-23 08:45:04 -04:00
|
|
|
vim.command(":new")
|
|
|
|
try:
|
|
|
|
self.cmd()
|
|
|
|
self.output = '\n'.join(vim.current.buffer[:])
|
|
|
|
finally:
|
|
|
|
vim.command(":q!")
|
2009-06-28 16:22:19 -04:00
|
|
|
|
2009-06-23 08:45:04 -04:00
|
|
|
def insert(self,string):
|
|
|
|
"""A helper function to type some text"""
|
|
|
|
vim.command('normal i%s' % string)
|
2009-06-28 16:22:19 -04:00
|
|
|
def change(self,string):
|
|
|
|
"""A helper function to type some text"""
|
|
|
|
vim.command('normal c%s' % string)
|
2009-06-23 08:45:04 -04:00
|
|
|
|
|
|
|
def expand(self):
|
|
|
|
vim.command("call PyVimSnips_ExpandSnippet()")
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
PySnipSnippets.clear_snippets()
|
|
|
|
|
|
|
|
def cmd(self):
|
|
|
|
"""Overwrite these in the children"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
##################
|
|
|
|
# Simple Expands #
|
|
|
|
##################
|
|
|
|
class _SimpleExpands(_VimTest):
|
2009-06-28 16:22:19 -04:00
|
|
|
snippets = (
|
|
|
|
("hallo", "Hallo Welt!"),
|
|
|
|
)
|
2009-06-23 08:45:04 -04:00
|
|
|
|
|
|
|
class SimpleExpand_ExceptCorrectResult(_SimpleExpands):
|
|
|
|
def cmd(self):
|
|
|
|
self.insert("hallo ")
|
|
|
|
self.expand()
|
|
|
|
|
|
|
|
def runTest(self):
|
|
|
|
self.assertEqual(self.output,"Hallo Welt! ")
|
|
|
|
|
|
|
|
class SimpleExpandTypeAfterExpand_ExceptCorrectResult(_SimpleExpands):
|
|
|
|
def cmd(self):
|
|
|
|
self.insert("hallo ")
|
|
|
|
self.expand()
|
|
|
|
self.insert("and again")
|
|
|
|
|
|
|
|
def runTest(self):
|
|
|
|
self.assertEqual(self.output,"Hallo Welt!and again ")
|
|
|
|
|
|
|
|
class SimpleExpandTypeAfterExpand1_ExceptCorrectResult(_SimpleExpands):
|
|
|
|
def cmd(self):
|
|
|
|
self.insert("na du hallo ")
|
|
|
|
self.expand()
|
|
|
|
self.insert("and again")
|
|
|
|
|
|
|
|
def runTest(self):
|
|
|
|
self.assertEqual(self.output,"na du Hallo Welt!and again ")
|
|
|
|
|
|
|
|
class DoNotExpandAfterSpace_ExceptCorrectResult(_SimpleExpands):
|
|
|
|
def cmd(self):
|
|
|
|
self.insert("hallo ")
|
|
|
|
self.expand()
|
|
|
|
|
|
|
|
def runTest(self):
|
|
|
|
self.assertEqual(self.output,"hallo ")
|
|
|
|
|
|
|
|
class ExpandInTheMiddleOfLine_ExceptCorrectResult(_SimpleExpands):
|
|
|
|
def cmd(self):
|
|
|
|
self.insert("Wie hallo gehts?")
|
|
|
|
vim.command("normal 02f ")
|
|
|
|
self.expand()
|
|
|
|
|
|
|
|
def runTest(self):
|
|
|
|
self.assertEqual(self.output,"Wie Hallo Welt! gehts?")
|
|
|
|
|
|
|
|
class MultilineExpand_ExceptCorrectResult(_VimTest):
|
2009-06-28 16:22:19 -04:00
|
|
|
snippets = (
|
|
|
|
("hallo", "Hallo Welt!\nUnd Wie gehts?"),
|
|
|
|
)
|
|
|
|
|
2009-06-23 08:45:04 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.insert("Wie hallo gehts?")
|
|
|
|
vim.command("normal 02f ")
|
|
|
|
self.expand()
|
|
|
|
|
|
|
|
def runTest(self):
|
|
|
|
self.assertEqual(self.output, "Wie Hallo Welt!\nUnd Wie gehts? gehts?")
|
2009-06-28 08:51:27 -04:00
|
|
|
class MultilineExpandTestTyping_ExceptCorrectResult(_VimTest):
|
2009-06-28 16:22:19 -04:00
|
|
|
snippets = (
|
|
|
|
("hallo", "Hallo Welt!\nUnd Wie gehts?"),
|
|
|
|
)
|
|
|
|
|
2009-06-28 08:51:27 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.insert("Wie hallo gehts?")
|
|
|
|
vim.command("normal 02f ")
|
|
|
|
self.expand()
|
|
|
|
self.insert("Huiui!")
|
|
|
|
|
|
|
|
def runTest(self):
|
|
|
|
self.assertEqual(self.output,
|
|
|
|
"Wie Hallo Welt!\nUnd Wie gehts?Huiui! gehts?")
|
2009-06-23 08:45:04 -04:00
|
|
|
|
|
|
|
############
|
|
|
|
# TabStops #
|
|
|
|
############
|
2009-06-28 08:51:27 -04:00
|
|
|
class ExitTabStop_ExceptCorrectResult(_VimTest):
|
2009-06-28 16:22:19 -04:00
|
|
|
snippets = (
|
|
|
|
("echo", "$0 run"),
|
|
|
|
)
|
|
|
|
|
2009-06-23 08:45:04 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.insert("echo ")
|
|
|
|
self.expand()
|
|
|
|
self.insert("test")
|
|
|
|
|
|
|
|
def runTest(self):
|
|
|
|
self.assertEqual(self.output,"test run ")
|
2009-06-28 08:51:27 -04:00
|
|
|
|
|
|
|
class TextTabStopNoReplace_ExceptCorrectResult(_VimTest):
|
2009-06-28 16:22:19 -04:00
|
|
|
snippets = (
|
|
|
|
("echo", "echo ${1:Hallo}"),
|
|
|
|
)
|
|
|
|
|
2009-06-28 08:51:27 -04:00
|
|
|
def cmd(self):
|
|
|
|
self.insert("echo ")
|
|
|
|
self.expand()
|
|
|
|
|
|
|
|
def runTest(self):
|
|
|
|
self.assertEqual(self.output,"echo Hallo ")
|
2009-06-28 16:22:19 -04:00
|
|
|
|
|
|
|
class TextTabStopSimpleReplace_ExceptCorrectResult(_VimTest):
|
|
|
|
snippets = (
|
|
|
|
("hallo", "hallo ${0:End} ${1:Beginning}"),
|
|
|
|
)
|
|
|
|
|
|
|
|
def cmd(self):
|
|
|
|
self.insert("hallo ")
|
|
|
|
self.expand()
|
|
|
|
vim.command(r'call feedkeys("na")')
|
2009-06-23 08:45:04 -04:00
|
|
|
|
2009-06-28 16:22:19 -04:00
|
|
|
def runTest(self):
|
|
|
|
self.assertEqual(self.output,"hallo End na ")
|
|
|
|
|
2009-06-23 08:45:04 -04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
from cStringIO import StringIO
|
|
|
|
|
|
|
|
s = StringIO()
|
2009-06-28 08:51:27 -04:00
|
|
|
|
|
|
|
tests = [
|
|
|
|
SimpleExpand_ExceptCorrectResult(),
|
|
|
|
SimpleExpandTypeAfterExpand_ExceptCorrectResult(),
|
|
|
|
SimpleExpandTypeAfterExpand1_ExceptCorrectResult(),
|
|
|
|
DoNotExpandAfterSpace_ExceptCorrectResult(),
|
|
|
|
ExpandInTheMiddleOfLine_ExceptCorrectResult(),
|
|
|
|
MultilineExpand_ExceptCorrectResult(),
|
|
|
|
MultilineExpandTestTyping_ExceptCorrectResult(),
|
|
|
|
ExitTabStop_ExceptCorrectResult(),
|
|
|
|
TextTabStopNoReplace_ExceptCorrectResult(),
|
2009-06-28 16:22:19 -04:00
|
|
|
TextTabStopSimpleReplace_ExceptCorrectResult(),
|
2009-06-28 08:51:27 -04:00
|
|
|
]
|
|
|
|
# suite = unittest.TestLoader(.loadTestsFromModule(__import__("test"))
|
|
|
|
suite = unittest.TestSuite()
|
|
|
|
suite.addTests(tests)
|
2009-06-23 08:45:04 -04:00
|
|
|
res = unittest.TextTestRunner(stream=s).run(suite)
|
2009-06-28 16:22:19 -04:00
|
|
|
|
2009-06-28 08:51:27 -04:00
|
|
|
# if res.wasSuccessful():
|
|
|
|
# vim.command("qa!")
|
2009-06-23 08:45:04 -04:00
|
|
|
|
|
|
|
vim.current.buffer[:] = s.getvalue().split('\n')
|
|
|
|
|