All tests pass except for my Favorite :(

This commit is contained in:
Holger Rapp 2009-07-03 11:39:46 +02:00
parent 4392de37bb
commit 6f25b53761
2 changed files with 180 additions and 185 deletions

View File

@ -139,23 +139,27 @@ class TextObject(object):
self._current_text = TextBuffer(self._parse(initial_text))
def _do_update(self, buffer):
return buffer.replace_text(self.start, self.end, self._current_text)
def _do_update(self):
pass
def update(self, change_buffer, indend = ""):
debug("%sUpdating %s" % (indend, self))
for c in self._children:
debug("%s Updating Child%s" % (indend, self))
oldend = c.end
oldend = Position(c.end.line, c.end.col)
moved_lines, moved_cols = c.update( self._current_text, indend + ' '*8 )
self._move_textobjects_behind(oldend, moved_lines, moved_cols, c)
debug("%s Moved%i, %i" % (indend, moved_lines, moved_cols))
debug("%s Our text is now: %s" % (indend, repr(self._current_text)))
debug("%s self._current_text: %s" % (indend, repr(self._current_text)))
new_end = self._do_update(change_buffer)
self._do_update()
new_end = change_buffer.replace_text(self.start, self.end, self._current_text)
moved_lines = new_end.line - self._end.line
moved_cols = new_end.col - self._end.col
@ -171,15 +175,18 @@ class TextObject(object):
if lines == 0 and cols == 0:
return
debug("_move_textobjects_behind: %s" % end)
for m in self._children:
if m == obj:
continue
debug("Considering %s for moving!" % m)
delta_lines = 0
delta_cols_begin = 0
delta_cols_end = 0
if m.start.line > end:
if m.start.line > end.line:
delta_lines = lines
elif m.start.line == end.line:
if m.start.col >= end.col:
@ -189,6 +196,8 @@ class TextObject(object):
if m.start.line == m.end.line:
delta_cols_end = cols
debug("delta_lines: %i, delta_cols_begin: %i, delta_cols_end: %i" %
(delta_lines, delta_cols_begin, delta_cols_end))
m.start.line += delta_lines
m.end.line += delta_lines
m.start.col += delta_cols_begin
@ -221,11 +230,10 @@ class TextObject(object):
line_start = val[:start].rfind('\n') + 1
start_in_line = start - line_start
# TODO: recomment int
# if no in self._tabstops:
# m = Mirror(self, self._tabstops[no], line_idx, start_in_line)
# val = val[:start] + self._tabstops[no].current_text + val[end:]
# if:
if no in self._tabstops:
m = Mirror(self, self._tabstops[no], line_idx, start_in_line)
val = val[:start] + self._tabstops[no].current_text + val[end:]
else:
ts = TabStop(self, line_idx, (start_in_line,start_in_line))
val = val[:start] + val[end:]
self.add_tabstop(no,ts)
@ -286,28 +294,23 @@ class ChangeableText(TextObject):
current_text = property(**current_text())
# class Mirror(ChangeableText):
# """
# A Mirror object mirrors a TabStop that is, text is repeated here
# """
# def __init__(self, parent, ts, idx, start_col):
# start = Position(idx,start_col)
# end = start + (ts.end - ts.start)
# ChangeableText.__init__(self, parent, start, end)
#
# ts.add_mirror(self)
#
# def __repr__(self):
# return "Mirror(%s -> %s)" % (self._start, self._end)
#
# def _set_text(self,text):
# _replace_text_in_buffer(
# self._parent.start + self._start,
# self._parent.start + self._end,
# text,
# )
# ChangeableText._set_text(self, text)
class Mirror(ChangeableText):
"""
A Mirror object mirrors a TabStop that is, text is repeated here
"""
def __init__(self, parent, ts, idx, start_col):
start = Position(idx,start_col)
end = start + (ts.end - ts.start)
ChangeableText.__init__(self, parent, start, end)
self._ts = ts
def _do_update(self):
debug("In Mirror: %s %s" % (repr(self.current_text),repr(self._ts.current_text)))
self.current_text = self._ts.current_text
def __repr__(self):
return "Mirror(%s -> %s)" % (self._start, self._end)
class TabStop(ChangeableText):
@ -320,21 +323,10 @@ class TabStop(ChangeableText):
end = Position(idx,span[1])
ChangeableText.__init__(self, parent, start, end, default_text)
self._mirrors = []
def __repr__(self):
return "TabStop(%s -> %s, %s)" % (self._start, self._end,
repr(self._current_text))
def _set_text(self,text):
ChangeableText._set_text(self,text)
for m in self._mirrors:
m.current_text = text
def add_mirror(self, m):
self._mirrors.append(m)
def select(self):
lineno, col = self._parent.start.line, self._parent.start.col
@ -513,6 +505,9 @@ class SnippetManager(object):
# Detect a carriage return
if col == 0 and lineno == self._last_cursor_pos[0] + 1:
# Hack, remove this line in vim, because we are going
# to overwrite the old range with the new snippet value.
del vim.current.buffer[lineno]
cs.chars_entered('\n')
elif lcol > col: # Some deleting was going on
cs.backspace(lcol-col)

280
test.py
View File

@ -210,152 +210,152 @@ class TabStopTestMultilineExpand_ExceptCorrectResult(_VimTest):
# ###########
# # MIRRORS #
# ###########
# class TextTabStopTextAfterTab_ExceptCorrectResult(_VimTest):
# snippets = ("test", "$1 Hinten\n$1")
# wanted = "hallo Hinten\nhallo"
# def cmd(self):
# self.type("test\thallo")
# def runTest(self): self.check_output()
# class TextTabStopTextBeforeTab_ExceptCorrectResult(_VimTest):
# snippets = ("test", "Vorne $1\n$1")
# wanted = "Vorne hallo\nhallo"
# def cmd(self):
# self.type("test\thallo")
# def runTest(self): self.check_output()
# class TextTabStopTextSurroundedTab_ExceptCorrectResult(_VimTest):
# snippets = ("test", "Vorne $1 Hinten\n$1")
# wanted = "Vorne hallo test Hinten\nhallo test"
# def cmd(self):
# self.type("test\thallo test")
# def runTest(self): self.check_output()
#
# class TextTabStopTextBeforeMirror_ExceptCorrectResult(_VimTest):
# snippets = ("test", "$1\nVorne $1")
# wanted = "hallo\nVorne hallo"
# def cmd(self):
# self.type("test\thallo")
# def runTest(self): self.check_output()
# class TextTabStopAfterMirror_ExceptCorrectResult(_VimTest):
# snippets = ("test", "$1\n$1 Hinten")
# wanted = "hallo\nhallo Hinten"
# def cmd(self):
# self.type("test\thallo")
# def runTest(self): self.check_output()
# class TextTabStopSurroundMirror_ExceptCorrectResult(_VimTest):
# snippets = ("test", "$1\nVorne $1 Hinten")
# wanted = "hallo welt\nVorne hallo welt Hinten"
# def cmd(self):
# self.type("test\thallo welt")
# def runTest(self): self.check_output()
# class TextTabStopAllSurrounded_ExceptCorrectResult(_VimTest):
# snippets = ("test", "ObenVorne $1 ObenHinten\nVorne $1 Hinten")
# wanted = "ObenVorne hallo welt ObenHinten\nVorne hallo welt Hinten"
# def cmd(self):
# self.type("test\thallo welt")
# def runTest(self): self.check_output()
#
#
# class TextTabStopSimpleMirrorMultiline_ExceptCorrectResult(_VimTest):
# snippets = ("test", "$1\n$1")
# wanted = "hallo\nhallo"
# def cmd(self):
# self.type("test\thallo")
# def runTest(self): self.check_output()
# class SimpleMirrorMultilineMany_ExceptCorrectResult(_VimTest):
# snippets = ("test", " $1\n$1\na$1b\n$1\ntest $1 mich")
# wanted = " hallo\nhallo\nahallob\nhallo\ntest hallo mich"
# def cmd(self):
# self.type("test\thallo")
# def runTest(self): self.check_output()
# class MultilineTabStopSimpleMirrorMultiline_ExceptCorrectResult(_VimTest):
# snippets = ("test", "$1\n\n$1\n\n$1")
# wanted = "hallo Du\nHi\n\nhallo Du\nHi\n\nhallo Du\nHi"
# def cmd(self):
# 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")
# def runTest(self): self.check_output()
#
#
# class SimpleMirrorDelete_ExceptCorrectResult(_VimTest):
# snippets = ("test", "$1\n$1")
# wanted = "hal\nhal"
# def cmd(self):
# self.type("test\thallo")
# self.type("\b\b")
#
# def runTest(self): self.check_output()
#
# class SimpleMirrorSameLine_ExceptCorrectResult(_VimTest):
# snippets = ("test", "$1 $1")
# wanted = "hallo hallo"
# def cmd(self):
# self.type("test\thallo")
# def runTest(self): self.check_output()
# class SimpleMirrorSameLineMany_ExceptCorrectResult(_VimTest):
# snippets = ("test", "$1 $1 $1")
# wanted = "hallo du hallo du hallo du hallo du"
# def cmd(self):
# self.type("test\thallo du")
# class SimpleMirrorSameLineManyMultiline_ExceptCorrectResult(_VimTest):
# snippets = ("test", "$1 $1 $1 $1")
# wanted = "hallo du\nwie gehts? hallo du\nwie gehts? hallo du\nwie gehts?" \
# " hallo du\nwie gehts?"
# def cmd(self):
# self.type("test\thallo du\nwie gehts?")
# def runTest(self): self.check_output()
# class SimpleMirrorDeleteSomeEnterSome_ExceptCorrectResult(_VimTest):
# snippets = ("test", "$1\n$1")
# wanted = "halhups\nhalhups"
# def cmd(self):
# self.type("test\thallo\b\bhups")
# def runTest(self): self.check_output()
#
#
# class SimpleTabstopWithDefaultSimpelType_ExceptCorrectResult(_VimTest):
# snippets = ("test", "ha ${1:defa}\n$1")
# wanted = "ha world\nworld"
# def cmd(self):
# self.type("test\tworld")
# def runTest(self): self.check_output()
# class SimpleTabstopWithDefaultComplexType_ExceptCorrectResult(_VimTest):
# snippets = ("test", "ha ${1:default value} $1\nanother: $1 mirror")
# wanted = "ha world world\nanother: world mirror"
# def cmd(self):
# self.type("test\tworld")
# def runTest(self): self.check_output()
# class SimpleTabstopWithDefaultSimpelKeep_ExceptCorrectResult(_VimTest):
# snippets = ("test", "ha ${1:defa}\n$1")
# wanted = "ha defa\ndefa"
# def cmd(self):
# self.type("test\t")
# def runTest(self): self.check_output()
# class SimpleTabstopWithDefaultComplexKeep_ExceptCorrectResult(_VimTest):
# snippets = ("test", "ha ${1:default value} $1\nanother: $1 mirror")
# wanted = "ha default value default value\nanother: default value mirror"
# def cmd(self):
# self.type("test\t")
# def runTest(self): self.check_output()
#
class TextTabStopTextAfterTab_ExceptCorrectResult(_VimTest):
snippets = ("test", "$1 Hinten\n$1")
wanted = "hallo Hinten\nhallo"
def cmd(self):
self.type("test\thallo")
def runTest(self): self.check_output()
class TextTabStopTextBeforeTab_ExceptCorrectResult(_VimTest):
snippets = ("test", "Vorne $1\n$1")
wanted = "Vorne hallo\nhallo"
def cmd(self):
self.type("test\thallo")
def runTest(self): self.check_output()
class TextTabStopTextSurroundedTab_ExceptCorrectResult(_VimTest):
snippets = ("test", "Vorne $1 Hinten\n$1")
wanted = "Vorne hallo test Hinten\nhallo test"
def cmd(self):
self.type("test\thallo test")
def runTest(self): self.check_output()
class TextTabStopTextBeforeMirror_ExceptCorrectResult(_VimTest):
snippets = ("test", "$1\nVorne $1")
wanted = "hallo\nVorne hallo"
def cmd(self):
self.type("test\thallo")
def runTest(self): self.check_output()
class TextTabStopAfterMirror_ExceptCorrectResult(_VimTest):
snippets = ("test", "$1\n$1 Hinten")
wanted = "hallo\nhallo Hinten"
def cmd(self):
self.type("test\thallo")
def runTest(self): self.check_output()
class TextTabStopSurroundMirror_ExceptCorrectResult(_VimTest):
snippets = ("test", "$1\nVorne $1 Hinten")
wanted = "hallo welt\nVorne hallo welt Hinten"
def cmd(self):
self.type("test\thallo welt")
def runTest(self): self.check_output()
class TextTabStopAllSurrounded_ExceptCorrectResult(_VimTest):
snippets = ("test", "ObenVorne $1 ObenHinten\nVorne $1 Hinten")
wanted = "ObenVorne hallo welt ObenHinten\nVorne hallo welt Hinten"
def cmd(self):
self.type("test\thallo welt")
def runTest(self): self.check_output()
class TextTabStopSimpleMirrorMultiline_ExceptCorrectResult(_VimTest):
snippets = ("test", "$1\n$1")
wanted = "hallo\nhallo"
def cmd(self):
self.type("test\thallo")
def runTest(self): self.check_output()
class SimpleMirrorMultilineMany_ExceptCorrectResult(_VimTest):
snippets = ("test", " $1\n$1\na$1b\n$1\ntest $1 mich")
wanted = " hallo\nhallo\nahallob\nhallo\ntest hallo mich"
def cmd(self):
self.type("test\thallo")
def runTest(self): self.check_output()
class MultilineTabStopSimpleMirrorMultiline_ExceptCorrectResult(_VimTest):
snippets = ("test", "$1\n\n$1\n\n$1")
wanted = "hallo Du\nHi\n\nhallo Du\nHi\n\nhallo Du\nHi"
def cmd(self):
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")
def runTest(self): self.check_output()
class SimpleMirrorDelete_ExceptCorrectResult(_VimTest):
snippets = ("test", "$1\n$1")
wanted = "hal\nhal"
def cmd(self):
self.type("test\thallo")
self.type("\b\b")
def runTest(self): self.check_output()
class SimpleMirrorSameLine_ExceptCorrectResult(_VimTest):
snippets = ("test", "$1 $1")
wanted = "hallo hallo"
def cmd(self):
self.type("test\thallo")
def runTest(self): self.check_output()
class SimpleMirrorSameLineMany_ExceptCorrectResult(_VimTest):
snippets = ("test", "$1 $1 $1")
wanted = "hallo du hallo du hallo du hallo du"
def cmd(self):
self.type("test\thallo du")
class SimpleMirrorSameLineManyMultiline_ExceptCorrectResult(_VimTest):
snippets = ("test", "$1 $1 $1 $1")
wanted = "hallo du\nwie gehts? hallo du\nwie gehts? hallo du\nwie gehts?" \
" hallo du\nwie gehts?"
def cmd(self):
self.type("test\thallo du\nwie gehts?")
def runTest(self): self.check_output()
class SimpleMirrorDeleteSomeEnterSome_ExceptCorrectResult(_VimTest):
snippets = ("test", "$1\n$1")
wanted = "halhups\nhalhups"
def cmd(self):
self.type("test\thallo\b\bhups")
def runTest(self): self.check_output()
class SimpleTabstopWithDefaultSimpelType_ExceptCorrectResult(_VimTest):
snippets = ("test", "ha ${1:defa}\n$1")
wanted = "ha world\nworld"
def cmd(self):
self.type("test\tworld")
def runTest(self): self.check_output()
class SimpleTabstopWithDefaultComplexType_ExceptCorrectResult(_VimTest):
snippets = ("test", "ha ${1:default value} $1\nanother: $1 mirror")
wanted = "ha world world\nanother: world mirror"
def cmd(self):
self.type("test\tworld")
def runTest(self): self.check_output()
class SimpleTabstopWithDefaultSimpelKeep_ExceptCorrectResult(_VimTest):
snippets = ("test", "ha ${1:defa}\n$1")
wanted = "ha defa\ndefa"
def cmd(self):
self.type("test\t")
def runTest(self): self.check_output()
class SimpleTabstopWithDefaultComplexKeep_ExceptCorrectResult(_VimTest):
snippets = ("test", "ha ${1:default value} $1\nanother: $1 mirror")
wanted = "ha default value default value\nanother: default value mirror"
def cmd(self):
self.type("test\t")
def runTest(self): self.check_output()
# TODO: Mehrer tabs und mehrere mirrors
# class TabstopWithMirrorInDefaultNoType_ExceptCorrectResult(_VimTest):
# snippets = ("test", "ha ${2:$1.h} ${1:blub}")
# wanted = "ha blub.h blub"
# def cmd(self):
# self.type("test\t")
# def runTest(self): self.check_output()
# TODO: Mehrer tabs und mehrere mirrors
#
# class MirrorMoreInvolved_ExceptCorrectResult(_VimTest):