7 failures. Now weeding out abs_start and abs_end

This commit is contained in:
Holger Rapp 2012-01-17 14:36:15 +01:00
parent b057d6332e
commit f1f6e9abff
3 changed files with 58 additions and 31 deletions

View File

@ -411,14 +411,27 @@ class TextObject(object):
self._del_child(c) self._del_child(c)
# We have to handle this ourselves # We have to handle this ourselves
sp = self.abs_start # TODO
def _move_end(obj, diff): # TODO: this is code duplication, the other one is buggy!
if obj.abs_end < sp: return
if delta.line >= 0:
if obj.abs_end.line == sp.line:
obj._end.col += diff.col
obj._end.line += diff.line
else:
obj._end.line += diff.line
if obj.abs_end.line == sp.line:
obj._end.col += diff.col
if ctype == "D": # TODO: code duplication if ctype == "D": # TODO: code duplication
assert(self.abs_start != self.abs_end) # Makes no sense to delete in empty textobject assert(self.abs_start != self.abs_end) # Makes no sense to delete in empty textobject
if char == "\n": if char == "\n":
delta = Position(-1, 0) # TODO: this feels somehow incorrect: delta = Position(-1, col) # TODO: this feels somehow incorrect:
else: else:
delta = Position(0, -len(char)) delta = Position(0, -len(char))
self._end += delta _move_end(self, delta)
self.child_end_moved(self.abs_end, delta, set((self,))) self.child_end_moved(self.abs_end, delta, set((self,)))
else: else:
@ -427,8 +440,7 @@ class TextObject(object):
delta = Position(1, -col) # TODO: this feels somehow incorrect delta = Position(1, -col) # TODO: this feels somehow incorrect
else: else:
delta = Position(0, len(char)) delta = Position(0, len(char))
_move_end(self, delta)
self._end += delta
self.child_end_moved(old_end, delta, set((self,))) self.child_end_moved(old_end, delta, set((self,)))

View File

@ -60,7 +60,7 @@ def edit_script(a, b, sline = 0, scol = 0):
if x < len(a): # DELETE if x < len(a): # DELETE
if (what and what[-1][0] == "D" and what[-1][1] == line and if (what and what[-1][0] == "D" and what[-1][1] == line and
what[-1][2] == col and a[x] != '\n' and what[-1][2] == col and a[x] != '\n' and what[-1][-1] != '\n' and
seen[x+1,y] > cost + D_COST // 2 seen[x+1,y] > cost + D_COST // 2
): ):
seen[x+1,y] = cost + D_COST // 2 seen[x+1,y] = cost + D_COST // 2
@ -76,7 +76,11 @@ def transform(a, cmds):
for cmd in cmds: for cmd in cmds:
ctype, line, col, char = cmd ctype, line, col, char = cmd
if ctype == "D": if ctype == "D":
buf[line] = buf[line][:col] + buf[line][col+len(char):] if char != '\n':
buf[line] = buf[line][:col] + buf[line][col+len(char):]
else:
buf[line] = buf[line] + buf[line+1]
del buf[line+1]
elif ctype == "I": elif ctype == "I":
buf[line] = buf[line][:col] + char + buf[line][col:] buf[line] = buf[line][:col] + char + buf[line][col:]
buf = '\n'.join(buf).split('\n') buf = '\n'.join(buf).split('\n')
@ -134,6 +138,17 @@ class TestRealLife1(_Base, unittest.TestCase):
("I", 0, 11, " "), ("I", 0, 11, " "),
) )
class TestWithNewline(_Base, unittest.TestCase):
a = 'First Line\nSecond Line'
b = 'n'
wanted = (
("D", 0, 0, "First Line"),
("D", 0, 0, "\n"),
("D", 0, 0, "Second Line"),
("I", 0, 0, "n"),
)
class TestCheapDelete(_Base, unittest.TestCase): class TestCheapDelete(_Base, unittest.TestCase):
a = 'Vorne hallo Hinten' a = 'Vorne hallo Hinten'
b = 'Vorne Hinten' b = 'Vorne Hinten'

50
test.py
View File

@ -782,31 +782,31 @@ class TabStop_TSInDefault_MirrorsOutside_OverwriteFirstSwitchNumbers(_VimTest):
# keys = "test" + EX + JF + "WORLD" + JF + "End" # keys = "test" + EX + JF + "WORLD" + JF + "End"
# wanted = "world = require('WORLD')End" # wanted = "world = require('WORLD')End"
##class TabStop_Multiline_Leave(_VimTest): class TabStop_Multiline_Leave(_VimTest):
## snippets = ("test", "hi ${1:first line\nsecond line} world" ) snippets = ("test", "hi ${1:first line\nsecond line} world" )
## keys = "test" + EX keys = "test" + EX
## wanted = "hi first line\nsecond line world" wanted = "hi first line\nsecond line world"
##class TabStop_Multiline_Overwrite(_VimTest): class TabStop_Multiline_Overwrite(_VimTest):
## snippets = ("test", "hi ${1:first line\nsecond line} world" ) snippets = ("test", "hi ${1:first line\nsecond line} world" )
## keys = "test" + EX + "Nothing" keys = "test" + EX + "Nothing"
## wanted = "hi Nothing world" wanted = "hi Nothing world"
##class TabStop_Multiline_MirrorInFront_Leave(_VimTest): class TabStop_Multiline_MirrorInFront_Leave(_VimTest):
## snippets = ("test", "hi $1 ${1:first line\nsecond line} world" ) snippets = ("test", "hi $1 ${1:first line\nsecond line} world" )
## keys = "test" + EX keys = "test" + EX
## wanted = "hi first line\nsecond line first line\nsecond line world" wanted = "hi first line\nsecond line first line\nsecond line world"
##class TabStop_Multiline_MirrorInFront_Overwrite(_VimTest): class TabStop_Multiline_MirrorInFront_Overwrite(_VimTest):
## snippets = ("test", "hi $1 ${1:first line\nsecond line} world" ) snippets = ("test", "hi $1 ${1:first line\nsecond line} world" )
## keys = "test" + EX + "Nothing" keys = "test" + EX + "Nothing"
## wanted = "hi Nothing Nothing world" wanted = "hi Nothing Nothing world"
##class TabStop_Multiline_DelFirstOverwriteSecond_Overwrite(_VimTest): class TabStop_Multiline_DelFirstOverwriteSecond_Overwrite(_VimTest):
## snippets = ("test", "hi $1 $2 ${1:first line\nsecond line} ${2:Hi} world" ) snippets = ("test", "hi $1 $2 ${1:first line\nsecond line} ${2:Hi} world" )
## keys = "test" + EX + BS + JF + "Nothing" keys = "test" + EX + BS + JF + "Nothing"
## wanted = "hi Nothing Nothing world" wanted = "hi Nothing Nothing world"
##
##class TabStopNavigatingInInsertModeSimple_ExceptCorrectResult(_VimTest): class TabStopNavigatingInInsertModeSimple_ExceptCorrectResult(_VimTest):
## snippets = ("hallo", "Hallo ${1:WELT} ups") snippets = ("hallo", "Hallo ${1:WELT} ups")
## keys = "hallo" + EX + "welt" + 2*ARR_L + "hips" + JF + "end" keys = "hallo" + EX + "haselnut" + 2*ARR_L + "hips" + JF + "end"
## wanted = "hallo wehipslt upsend" wanted = "Hallo haselnhipsut upsend"
### End: TabStop Tests #}}} ### End: TabStop Tests #}}}
### ShellCode Interpolation {{{# ### ShellCode Interpolation {{{#
##class TabStop_Shell_SimpleExample(_VimTest): ##class TabStop_Shell_SimpleExample(_VimTest):