All enabled tests pass for the moment

This commit is contained in:
Holger Rapp 2012-01-16 18:57:37 +01:00
parent b49d5482fa
commit 5c476983d7
4 changed files with 66 additions and 59 deletions

View File

@ -227,13 +227,17 @@ class TextObject(CheapTotalOrdering):
def initial_replace(self): def initial_replace(self):
ct = self._initial_text # TODO: Initial Text is nearly unused. ct = self._initial_text # TODO: Initial Text is nearly unused.
debug("self._start: %r, self._end: %r" % (self._start, self._end)) debug("self._start: %r, self._end: %r" % (self._start, self._end))
debug("self.abs_start: %r, self.abs_end: %r" % (self.abs_start, self.abs_end))
debug("ct: %r" % (ct)) debug("ct: %r" % (ct))
old_end = self.abs_end old_end = self.abs_end
ct.to_vim(self.abs_start, self.abs_end) # TODO: to vim returns something unused ct.to_vim(self.abs_start, self.abs_end) # TODO: to vim returns something unused
debug("self.abs_end: %r" % (self.abs_end))
self._end = ct.calc_end(self._start) self._end = ct.calc_end(self._start)
debug("self.abs_start: %r, self.abs_end: %r" % (self.abs_start, self.abs_end))
if self.abs_end != old_end: if self.abs_end != old_end:
if self._parent is not None: exclude = set(c for c in self._childs)
self._parent.child_end_moved(old_end, self.abs_end - old_end, set((self,))) exclude.add(self)
self.child_end_moved(old_end, self.abs_end - old_end, exclude)
def __cmp__(self, other): def __cmp__(self, other):
return self._start.__cmp__(other._start) return self._start.__cmp__(other._start)
@ -320,18 +324,19 @@ class TextObject(CheapTotalOrdering):
if self not in skip: if self not in skip:
_move_end(self) _move_end(self)
for c in self._childs: for c in self._childs:
if c in skip: continue if c in skip: continue
_move_start(c) _move_start(c)
_move_end(c) _move_end(c)
for c in self._childs: # TODO: is this needed? if self._parent and self._parent not in skip:
if c.abs_start == self.abs_start and (c._start == c._end): self._parent.child_end_moved(sp, diff, set((self,)))
debug("Deleting Child: c: %r" % (c))
self._del_child(c) # TODO: What about mirrors?
def _do_edit(self, cmd): def _do_edit(self, cmd):
debug("self: %r, cmd: %r" % (self, cmd)) debug("self: %r, cmd: %r" % (self, cmd))
debug("self._childs: %r" % (self._childs))
def __del_move_col_end(obj): def __del_move_col_end(obj):
end = obj.abs_end end = obj.abs_end
if end.line == line and end.col > col: if end.line == line and end.col > col:
@ -352,50 +357,46 @@ class TextObject(CheapTotalOrdering):
obj._start.col += 1 obj._start.col += 1
ctype, line, col, char = cmd ctype, line, col, char = cmd
assert(char != '\n') assert('\n' not in char)
pos = Position(line, col) pos = Position(line, col)
to_kill = set()
for c in self._childs: for c in self._childs:
abs_span = c.abs_span abs_start = c.abs_start
if pos in abs_span: abs_end = c.abs_end
if c._do_edit(cmd):
return True if ctype == "D":
end_pos = pos + Position(0, len(char))
# TODO: char is no longer true -> Text
# Case: this deletion removes the child
if (pos <= abs_start and end_pos > abs_end):
to_kill.add(c)
# Case: this edit command is completely for the child
elif (abs_start <= pos <= abs_end) and (abs_start <= end_pos <= abs_end):
c._do_edit(cmd)
return
if ctype == "I":
if (abs_start <= pos <= abs_end):
c._do_edit(cmd)
return
for c in to_kill:
debug("Kill c: %r" % (c))
self._del_child(c)
# We have to handle this ourselves # We have to handle this ourselves
if ctype == "D": if ctype == "D": # TODO: code duplication
if self._start == self._end: assert(self.abs_start != self.abs_end) # Makes no sense to delete in empty textobject
self._parent._del_child(self)
return False
oe = self.abs_end
__del_move_col_end(self)
for c in self._childs: delta = Position(0, -len(char))
debug("b4c: %r" % (c)) self._end += delta
__del_move_col_start(c)
__del_move_col_end(c)
debug("afc: %r" % (c))
ne = self.abs_end
if self._parent and oe != ne: self.child_end_moved(self.abs_end, delta, set((self,)))
self._parent.child_end_moved(oe, ne - oe, set((self,)))
else: else:
oe = self.abs_end old_end = self.abs_end
__ins_move_col_end(self) delta = Position(0, len(char))
self._end += delta
for c in self._childs: self.child_end_moved(old_end, delta, set((self,)))
debug("b4c: %r" % (c))
__ins_move_col_start(c)
__ins_move_col_end(c)
debug("afc: %r" % (c))
ne = self.abs_end
if self._parent and oe != ne:
self._parent.child_end_moved(oe, ne - oe, set((self,)))
for c in self._childs: # TODO: Code duplicate
if c.abs_start == self.abs_start and (c._start == c._end):
debug("Deleting Child: c: %r" % (c))
self._del_child(c) # TODO: What about mirrors?
return True return True

View File

@ -791,7 +791,7 @@ class SnippetManager(object):
debug("rv: %r" % (rv,)) debug("rv: %r" % (rv,))
cv = edit_distance.compactify(rv) cv = edit_distance.compactify(rv)
debug("cv: %r" % (cv)) debug("cv: %r" % (cv))
self._csnippets[0].edited(rv) self._csnippets[0].edited(cv)
# debug("rv: %r" % (rv,)) # debug("rv: %r" % (rv,))
self._lvb = cb self._lvb = cb

View File

@ -4,7 +4,6 @@
import heapq # TODO: overkill. Bucketing is better import heapq # TODO: overkill. Bucketing is better
from collections import defaultdict from collections import defaultdict
import sys import sys
from debug import debug
class GridPoint(object): class GridPoint(object):
"""Docstring for GridPoint """ """Docstring for GridPoint """
@ -29,34 +28,33 @@ def edit_script(a, b):
cost = 0 cost = 0
while True: while True:
while len(d[cost]): while len(d[cost]):
x, y, nline, ncol, what = d[cost].pop() x, y, line, col, what = d[cost].pop()
if x == len(a) and y == len(b): if x == len(a) and y == len(b):
return what return what
while x < len(a) and y < len(b) and a[x] == b[y]: if x < len(a) and y < len(b) and a[x] == b[y]:
ncol += 1 ncol = col + 1
nline = line
if a[x] == '\n': if a[x] == '\n':
ncol = 0 ncol = 0
nline += 1 nline +=1
if seen[x,y] > cost: if seen[x+1,y+1] > cost:
d[cost].append((x+1,y+1, nline, ncol, what)) d[cost].append((x+1,y+1, nline, ncol, what))
seen[x,y] = cost seen[x+1,y+1] = cost
x += 1
y += 1
if x < len(a):
if seen[x+1,y] > cost + 1:
seen[x+1,y] = cost + 1
d[cost + 1].append((x+1,y, nline, ncol, what + (("D",nline, ncol, a[x]),) ))
if y < len(b): if y < len(b):
oline, ocol = nline, ncol ncol = col + 1
ncol += 1 nline = line
if b[y] == '\n': if b[y] == '\n':
ncol = 0 ncol = 0
nline += 1 nline += 1
if seen[x,y+1] > cost + 1: if seen[x,y+1] > cost + 1:
seen[x,y+1] = cost + 1 seen[x,y+1] = cost + 1
d[cost + 1].append((x,y+1, nline, ncol, what + (("I", oline, ocol,b[y]),))) d[cost + 1].append((x,y+1, nline, ncol, what + (("I", line, col,b[y]),)))
if x < len(a):
if seen[x+1,y] > cost + 1:
seen[x+1,y] = cost + 1
d[cost + 1].append((x+1,y, line, col, what + (("D",line, col, a[x]),) ))
cost += 1 cost += 1
def compactify(es): def compactify(es):
@ -104,6 +102,10 @@ class TestLotsaNewlines(_Base, unittest.TestCase):
class TestCrash(_Base, unittest.TestCase): class TestCrash(_Base, unittest.TestCase):
a = 'hallo Blah mitte=sdfdsfsd\nhallo kjsdhfjksdhfkjhsdfkh mittekjshdkfhkhsdfdsf' a = 'hallo Blah mitte=sdfdsfsd\nhallo kjsdhfjksdhfkjhsdfkh mittekjshdkfhkhsdfdsf'
b = 'hallo Blah mitte=sdfdsfsd\nhallo b mittekjshdkfhkhsdfdsf' b = 'hallo Blah mitte=sdfdsfsd\nhallo b mittekjshdkfhkhsdfdsf'
class TestRealLife(_Base, unittest.TestCase):
a = 'hallo End Beginning'
b = 'hallo End t'
# def test_all_match(self): # def test_all_match(self):
# rv = edit_script("abcdef", "abcdef") # rv = edit_script("abcdef", "abcdef")
# self.assertEqual("MMMMMM", rv) # self.assertEqual("MMMMMM", rv)

View File

@ -563,6 +563,10 @@ class TabStopSimpleReplace_ExceptCorrectResult(_VimTest):
snippets = ("hallo", "hallo ${0:End} ${1:Beginning}") snippets = ("hallo", "hallo ${0:End} ${1:Beginning}")
keys = "hallo" + EX + "na" + JF + "Du Nase" keys = "hallo" + EX + "na" + JF + "Du Nase"
wanted = "hallo Du Nase na" wanted = "hallo Du Nase na"
class TabStopSimpleReplaceReversed_ExceptCorrectResult(_VimTest):
snippets = ("hallo", "hallo ${1:End} ${0:Beginning}")
keys = "hallo" + EX + "na" + JF + "Du Nase"
wanted = "hallo na Du Nase"
class TabStopSimpleReplaceSurrounded_ExceptCorrectResult(_VimTest): class TabStopSimpleReplaceSurrounded_ExceptCorrectResult(_VimTest):
snippets = ("hallo", "hallo ${0:End} a small feed") snippets = ("hallo", "hallo ${0:End} a small feed")
keys = "hallo" + EX + "Nase" keys = "hallo" + EX + "Nase"
@ -719,7 +723,7 @@ class TabStop_TSInDefaultText_ZeroLengthNested_Overwrite(_VimTest):
keys = "test" + EX + JF + "ups" + JF + "End" keys = "test" + EX + JF + "ups" + JF + "End"
wanted = """haupsblEnd""" wanted = """haupsblEnd"""
# TODO: Test for Python where initial text is longer than python code. Might lead to problems
##class TabStop_TSInDefaultNested_OverwriteOneJumpBackToOther(_VimTest): ##class TabStop_TSInDefaultNested_OverwriteOneJumpBackToOther(_VimTest):
## snippets = ("test", "hi ${1:this ${2:second ${3:third}}} $4") ## snippets = ("test", "hi ${1:this ${2:second ${3:third}}} $4")
## keys = "test" + EX + JF + "Hallo" + JF + "Ende" ## keys = "test" + EX + JF + "Hallo" + JF + "Ende"