Mor fixes and refactorings
This commit is contained in:
parent
544af97bff
commit
b49d5482fa
@ -163,6 +163,7 @@ class _TOParser(object):
|
||||
|
||||
def _replace_initital_texts(self):
|
||||
def _do_it(obj):
|
||||
debug("In _do_it: obj: %r" % (obj))
|
||||
obj.initial_replace()
|
||||
|
||||
for c in obj._childs: # TODO: private parts!
|
||||
@ -181,7 +182,7 @@ class _TOParser(object):
|
||||
seen_ts[token.no] = ts
|
||||
self._parent_to._add_tabstop(ts)
|
||||
|
||||
k = _TOParser(ts, ts.current_text, self._indent)
|
||||
k = _TOParser(ts, token.initial_text, self._indent)
|
||||
k._do_parse(all_tokens, seen_ts)
|
||||
elif isinstance(token, EscapeCharToken):
|
||||
EscapedChar(self._parent_to, token)
|
||||
@ -232,7 +233,7 @@ class TextObject(CheapTotalOrdering):
|
||||
self._end = ct.calc_end(self._start)
|
||||
if self.abs_end != old_end:
|
||||
if self._parent is not None:
|
||||
self._parent.child_end_moved(self, old_end, self.abs_end)
|
||||
self._parent.child_end_moved(old_end, self.abs_end - old_end, set((self,)))
|
||||
|
||||
def __cmp__(self, other):
|
||||
return self._start.__cmp__(other._start)
|
||||
@ -249,9 +250,9 @@ class TextObject(CheapTotalOrdering):
|
||||
return as_unicode(buf[abs_span.start.line][abs_span.start.col:abs_span.end.col])
|
||||
else:
|
||||
lines = []
|
||||
lines.append(buf[abs_span.start.line][abs_span.col:])
|
||||
lines.append(buf[abs_span.start.line][abs_span.start.col:])
|
||||
lines.extend(buf[abs_span.start.line+1:abs_span.end.line])
|
||||
line.append(buf[aps_span.end.line][:abs_span.end.col])
|
||||
lines.append(buf[abs_span.end.line][:abs_span.end.col])
|
||||
return as_unicode('\n'.join(lines))
|
||||
|
||||
@property
|
||||
@ -300,43 +301,34 @@ class TextObject(CheapTotalOrdering):
|
||||
####################
|
||||
# Public functions #
|
||||
####################
|
||||
def child_end_moved(self, child, old_end, new_end): # TODO: pretty wasteful, give index
|
||||
debug("self: %r, child: %r, old_end: %r, new_end: %r" % (self, child, old_end, new_end))
|
||||
delta = new_end - old_end
|
||||
def child_end_moved(self, sp, diff, skip): # TODO: pretty wasteful, give index
|
||||
debug("self: %r, skip: %r, diff: %r" % (self, skip, diff))
|
||||
|
||||
def _move_col_start(obj):
|
||||
if obj.abs_start.line == old_end.line and obj.abs_start.col >= old_end.col:
|
||||
obj._start.col += delta.col
|
||||
def _move_col_end(obj):
|
||||
if obj.abs_end.line == old_end.line and obj.abs_end.col >= old_end.col:
|
||||
obj._end.col += delta.col
|
||||
def _move_start(obj):
|
||||
if obj.abs_start.line == sp.line and obj.abs_start.col >= sp.col:
|
||||
obj._start.line += diff.line
|
||||
obj._start.col += diff.col
|
||||
elif obj.abs_start.line > sp.line:
|
||||
obj._start.line += diff.line
|
||||
|
||||
def _move_line_col_start(obj):
|
||||
if obj.abs_start.line == old_end.line and obj.abs_start.col >= old_end.col:
|
||||
obj._start.line += delta.line
|
||||
obj._start.col += delta.col
|
||||
elif obj.abs_start.line > old_end.line:
|
||||
obj._start.line += delta.line
|
||||
def _move_end(obj):
|
||||
if obj.abs_end.line == sp.line and obj.abs_end.col >= sp.col:
|
||||
obj._end.line += diff.line
|
||||
obj._end.col += diff.col
|
||||
elif obj.abs_end.line > sp.line:
|
||||
obj._end.line += diff.line
|
||||
|
||||
def _move_line_col_end(obj):
|
||||
if obj.abs_end.line == old_end.line and obj.abs_end.col >= old_end.col:
|
||||
obj._end.line += delta.line
|
||||
obj._end.col += delta.col
|
||||
elif obj.abs_end.line > old_end.line:
|
||||
obj._end.line += delta.line
|
||||
|
||||
if delta.line == 0:
|
||||
_move_col_end(self)
|
||||
if self not in skip:
|
||||
_move_end(self)
|
||||
for c in self._childs:
|
||||
if c == child: continue
|
||||
_move_col_start(c)
|
||||
_move_col_end(c)
|
||||
else:
|
||||
_move_line_col_end(self)
|
||||
for c in self._childs:
|
||||
if c == child: continue
|
||||
_move_line_col_start(c)
|
||||
_move_line_col_end(c)
|
||||
if c in skip: continue
|
||||
_move_start(c)
|
||||
_move_end(c)
|
||||
|
||||
for c in self._childs: # TODO: is this needed?
|
||||
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?
|
||||
|
||||
def _do_edit(self, cmd):
|
||||
debug("self: %r, cmd: %r" % (self, cmd))
|
||||
@ -364,11 +356,16 @@ class TextObject(CheapTotalOrdering):
|
||||
pos = Position(line, col)
|
||||
|
||||
for c in self._childs:
|
||||
if pos in c.abs_span:
|
||||
c._do_edit(cmd)
|
||||
return
|
||||
abs_span = c.abs_span
|
||||
if pos in abs_span:
|
||||
if c._do_edit(cmd):
|
||||
return True
|
||||
|
||||
# We have to handle this ourselves
|
||||
if ctype == "D":
|
||||
if self._start == self._end:
|
||||
self._parent._del_child(self)
|
||||
return False
|
||||
oe = self.abs_end
|
||||
__del_move_col_end(self)
|
||||
|
||||
@ -380,7 +377,7 @@ class TextObject(CheapTotalOrdering):
|
||||
ne = self.abs_end
|
||||
|
||||
if self._parent and oe != ne:
|
||||
self._parent.child_end_moved(self, oe, ne)
|
||||
self._parent.child_end_moved(oe, ne - oe, set((self,)))
|
||||
else:
|
||||
oe = self.abs_end
|
||||
__ins_move_col_end(self)
|
||||
@ -393,7 +390,14 @@ class TextObject(CheapTotalOrdering):
|
||||
|
||||
ne = self.abs_end
|
||||
if self._parent and oe != ne:
|
||||
self._parent.child_end_moved(self, 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
|
||||
|
||||
|
||||
def edited(self, cmds):
|
||||
@ -407,19 +411,20 @@ class TextObject(CheapTotalOrdering):
|
||||
|
||||
|
||||
def update(self):
|
||||
def _update_childs(childs):
|
||||
for idx,c in childs:
|
||||
oldend = Position(c.end.line, c.end.col)
|
||||
pass # TODO: remove this function
|
||||
# def _update_childs(childs):
|
||||
# for idx,c in childs:
|
||||
# oldend = Position(c.end.line, c.end.col)
|
||||
|
||||
new_end = c.update()
|
||||
# new_end = c.update()
|
||||
|
||||
moved_lines = new_end.line - oldend.line
|
||||
moved_cols = new_end.col - oldend.col
|
||||
# moved_lines = new_end.line - oldend.line
|
||||
# moved_cols = new_end.col - oldend.col
|
||||
|
||||
self._current_text.replace_text(c.start, oldend, c._current_text)
|
||||
# self._current_text.replace_text(c.start, oldend, c._current_text)
|
||||
|
||||
self._move_textobjects_behind(c.start, oldend, moved_lines,
|
||||
moved_cols, idx)
|
||||
# self._move_textobjects_behind(c.start, oldend, moved_lines,
|
||||
# moved_cols, idx)
|
||||
|
||||
# _update_childs((idx, c) for idx, c in enumerate(self._childs) if isinstance(c, TabStop))
|
||||
# _update_childs((idx, c) for idx, c in enumerate(self._childs) if not isinstance(c, TabStop))
|
||||
@ -485,28 +490,28 @@ class TextObject(CheapTotalOrdering):
|
||||
def _do_update(self):
|
||||
pass
|
||||
|
||||
def _move_textobjects_behind(self, start, end, lines, cols, obj_idx):
|
||||
if lines == 0 and cols == 0:
|
||||
return
|
||||
# def _move_textobjects_behind(self, start, end, lines, cols, obj_idx):
|
||||
# if lines == 0 and cols == 0:
|
||||
# return
|
||||
|
||||
for idx,m in enumerate(self._childs[obj_idx+1:]):
|
||||
delta_lines = 0
|
||||
delta_cols_begin = 0
|
||||
delta_cols_end = 0
|
||||
# for idx,m in enumerate(self._childs[obj_idx+1:]):
|
||||
# delta_lines = 0
|
||||
# delta_cols_begin = 0
|
||||
# delta_cols_end = 0
|
||||
|
||||
if m.start.line > end.line:
|
||||
delta_lines = lines
|
||||
elif m.start.line == end.line:
|
||||
if m.start.col >= end.col:
|
||||
if lines:
|
||||
delta_lines = lines
|
||||
delta_cols_begin = cols
|
||||
if m.start.line == m.end.line:
|
||||
delta_cols_end = cols
|
||||
m.start.line += delta_lines
|
||||
m.end.line += delta_lines
|
||||
m.start.col += delta_cols_begin
|
||||
m.end.col += delta_cols_end
|
||||
# if m.start.line > end.line:
|
||||
# delta_lines = lines
|
||||
# elif m.start.line == end.line:
|
||||
# if m.start.col >= end.col:
|
||||
# if lines:
|
||||
# delta_lines = lines
|
||||
# delta_cols_begin = cols
|
||||
# if m.start.line == m.end.line:
|
||||
# delta_cols_end = cols
|
||||
# m.start.line += delta_lines
|
||||
# m.end.line += delta_lines
|
||||
# m.start.col += delta_cols_begin
|
||||
# m.end.col += delta_cols_end
|
||||
|
||||
def _get_tabstop(self, requester, no):
|
||||
if no in self._tabstops:
|
||||
@ -525,6 +530,12 @@ class TextObject(CheapTotalOrdering):
|
||||
self._childs.append(c)
|
||||
self._childs.sort()
|
||||
|
||||
def _del_child(self,c):
|
||||
self._childs.remove(c)
|
||||
|
||||
if isinstance(c, TabStop):
|
||||
del self._tabstops[c.no]
|
||||
|
||||
def _add_tabstop(self, ts):
|
||||
self._tabstops[ts.no] = ts
|
||||
|
||||
|
@ -788,6 +788,9 @@ class SnippetManager(object):
|
||||
if len(self._csnippets):
|
||||
debug("self._lvb: %r, cb: %r" % (self._lvb, cb))
|
||||
rv = edit_distance.edit_script(self._lvb, cb)
|
||||
debug("rv: %r" % (rv,))
|
||||
cv = edit_distance.compactify(rv)
|
||||
debug("cv: %r" % (cv))
|
||||
self._csnippets[0].edited(rv)
|
||||
|
||||
# debug("rv: %r" % (rv,))
|
||||
|
@ -4,6 +4,7 @@
|
||||
import heapq # TODO: overkill. Bucketing is better
|
||||
from collections import defaultdict
|
||||
import sys
|
||||
from debug import debug
|
||||
|
||||
class GridPoint(object):
|
||||
"""Docstring for GridPoint """
|
||||
@ -58,6 +59,18 @@ def edit_script(a, b):
|
||||
d[cost + 1].append((x,y+1, nline, ncol, what + (("I", oline, ocol,b[y]),)))
|
||||
cost += 1
|
||||
|
||||
def compactify(es):
|
||||
cmds = []
|
||||
for cmd in es:
|
||||
ctype, line, col, char = cmd
|
||||
if (cmds and ctype == "D" and cmds[-1][1] == cmd[1] and cmds[-1][2] == cmd[2] and char != '\n'):
|
||||
cmds[-1][-1] += char
|
||||
elif (cmds and ctype == "I" and cmds[-1][1] == cmd[1] and cmds[-1][2]+1 == cmd[2] and char != '\n'):
|
||||
cmds[-1][-1] += char
|
||||
else:
|
||||
cmds.append(list(cmd))
|
||||
return cmds
|
||||
|
||||
def transform(a, cmds):
|
||||
buf = a.split("\n")
|
||||
|
||||
|
360
test.py
360
test.py
@ -551,183 +551,175 @@ class MultilineExpandTestTyping_ExceptCorrectResult(_VimTest):
|
||||
snippets = ("hallo", "Hallo Welt!\nUnd Wie gehts")
|
||||
wanted = "Wie Hallo Welt!\nUnd Wie gehtsHuiui! gehts"
|
||||
keys = "Wie hallo gehts" + ESC + "bhi" + EX + "Huiui!"
|
||||
class SimpleExpandEndingWithNewline_ExceptCorrectResult(_VimTest):
|
||||
snippets = ("hallo", "Hallo Welt\n")
|
||||
keys = "hallo" + EX + "\nAnd more"
|
||||
wanted = "Hallo Welt\n\nAnd more"
|
||||
|
||||
|
||||
# End: Simple Expands #}}}
|
||||
### TabStop Tests {{{#
|
||||
##class TabStopSimpleReplace_ExceptCorrectResult(_VimTest):
|
||||
## snippets = ("hallo", "hallo ${0:End} ${1:Beginning}")
|
||||
## keys = "hallo" + EX + "na" + JF + "Du Nase"
|
||||
## wanted = "hallo Du Nase na"
|
||||
##class TabStopSimpleReplaceSurrounded_ExceptCorrectResult(_VimTest):
|
||||
## snippets = ("hallo", "hallo ${0:End} a small feed")
|
||||
## keys = "hallo" + EX + "Nase"
|
||||
## wanted = "hallo Nase a small feed"
|
||||
##class TabStopSimpleReplaceSurrounded1_ExceptCorrectResult(_VimTest):
|
||||
## snippets = ("hallo", "hallo $0 a small feed")
|
||||
## keys = "hallo" + EX + "Nase"
|
||||
## wanted = "hallo Nase a small feed"
|
||||
##class TabStopSimpleReplaceEndingWithNewline_ExceptCorrectResult(_VimTest):
|
||||
## snippets = ("hallo", "Hallo Welt\n")
|
||||
## keys = "hallo" + EX + "\nAnd more"
|
||||
## wanted = "Hallo Welt\n\nAnd more"
|
||||
##
|
||||
##class ExitTabStop_ExceptCorrectResult(_VimTest):
|
||||
## snippets = ("echo", "$0 run")
|
||||
## keys = "echo" + EX + "test"
|
||||
## wanted = "test run"
|
||||
##
|
||||
##class TabStopNoReplace_ExceptCorrectResult(_VimTest):
|
||||
## snippets = ("echo", "echo ${1:Hallo}")
|
||||
## keys = "echo" + EX
|
||||
## wanted = "echo Hallo"
|
||||
##
|
||||
##class TabStop_EscapingCharsBackticks(_VimTest):
|
||||
## snippets = ("test", r"snip \` literal")
|
||||
## keys = "test" + EX
|
||||
## wanted = "snip ` literal"
|
||||
##class TabStop_EscapingCharsDollars(_VimTest):
|
||||
## snippets = ("test", r"snip \$0 $$0 end")
|
||||
## keys = "test" + EX + "hi"
|
||||
## wanted = "snip $0 $hi end"
|
||||
##class TabStop_EscapingCharsDollars1(_VimTest):
|
||||
## snippets = ("test", r"a\${1:literal}")
|
||||
## keys = "test" + EX
|
||||
## wanted = "a${1:literal}"
|
||||
##class TabStop_EscapingCharsDollars_BeginningOfLine(_VimTest):
|
||||
## snippets = ("test", "\n\\${1:literal}")
|
||||
## keys = "test" + EX
|
||||
## wanted = "\n${1:literal}"
|
||||
##class TabStop_EscapingCharsDollars_BeginningOfDefinitionText(_VimTest):
|
||||
## snippets = ("test", "\\${1:literal}")
|
||||
## keys = "test" + EX
|
||||
## wanted = "${1:literal}"
|
||||
##class TabStop_EscapingChars_Backslash(_VimTest):
|
||||
## snippets = ("test", r"This \ is a backslash!")
|
||||
## keys = "test" + EX
|
||||
## wanted = "This \\ is a backslash!"
|
||||
##class TabStop_EscapingChars_Backslash2(_VimTest):
|
||||
## snippets = ("test", r"This is a backslash \\ done")
|
||||
## keys = "test" + EX
|
||||
## wanted = r"This is a backslash \ done"
|
||||
##class TabStop_EscapingChars_Backslash3(_VimTest):
|
||||
## snippets = ("test", r"These are two backslashes \\\\ done")
|
||||
## keys = "test" + EX
|
||||
## wanted = r"These are two backslashes \\ done"
|
||||
##class TabStop_EscapingChars_Backslash4(_VimTest):
|
||||
## # Test for bug 746446
|
||||
## snippets = ("test", r"\\$1{$2}")
|
||||
## keys = "test" + EX + "hello" + JF + "world"
|
||||
## wanted = r"\hello{world}"
|
||||
##class TabStop_EscapingChars_RealLife(_VimTest):
|
||||
## snippets = ("test", r"usage: \`basename \$0\` ${1:args}")
|
||||
## keys = "test" + EX + "[ -u -v -d ]"
|
||||
## wanted = "usage: `basename $0` [ -u -v -d ]"
|
||||
##
|
||||
##class TabStopEscapingWhenSelected_ECR(_VimTest):
|
||||
## snippets = ("test", "snip ${1:default}")
|
||||
## keys = "test" + EX + ESC + "0ihi"
|
||||
## wanted = "hisnip default"
|
||||
##class TabStopEscapingWhenSelectedSingleCharTS_ECR(_VimTest):
|
||||
## snippets = ("test", "snip ${1:i}")
|
||||
## keys = "test" + EX + ESC + "0ihi"
|
||||
## wanted = "hisnip i"
|
||||
##class TabStopEscapingWhenSelectedNoCharTS_ECR(_VimTest):
|
||||
## snippets = ("test", "snip $1")
|
||||
## keys = "test" + EX + ESC + "0ihi"
|
||||
## wanted = "hisnip "
|
||||
##
|
||||
##class TabStopUsingBackspaceToDeleteDefaultValue_ECR(_VimTest):
|
||||
## snippets = ("test", "snip ${1/.+/(?0:matched)/} ${1:default}")
|
||||
## keys = "test" + EX + BS
|
||||
## wanted = "snip "
|
||||
##class TabStopUsingBackspaceToDeleteDefaultValueInFirstTab_ECR(_VimTest):
|
||||
## sleeptime = 0.09 # Do this very slowly
|
||||
## snippets = ("test", "snip ${1/.+/(?0:m1)/} ${2/.+/(?0:m2)/} "
|
||||
## "${1:default} ${2:def}")
|
||||
## keys = "test" + EX + BS + JF + "hi"
|
||||
## wanted = "snip m2 hi"
|
||||
##class TabStopUsingBackspaceToDeleteDefaultValueInSecondTab_ECR(_VimTest):
|
||||
## snippets = ("test", "snip ${1/.+/(?0:m1)/} ${2/.+/(?0:m2)/} "
|
||||
## "${1:default} ${2:def}")
|
||||
## keys = "test" + EX + "hi" + JF + BS
|
||||
## wanted = "snip m1 hi "
|
||||
##class TabStopUsingBackspaceToDeleteDefaultValueTypeSomethingThen_ECR(_VimTest):
|
||||
## snippets = ("test", "snip ${1/.+/(?0:matched)/} ${1:default}")
|
||||
## keys = "test" + EX + BS + "hallo"
|
||||
## wanted = "snip matched hallo"
|
||||
##
|
||||
##class TabStopWithOneChar_ExceptCorrectResult(_VimTest):
|
||||
## snippets = ("hallo", "nothing ${1:i} hups")
|
||||
## keys = "hallo" + EX + "ship"
|
||||
## wanted = "nothing ship hups"
|
||||
##
|
||||
##class TabStopTestJumping_ExceptCorrectResult(_VimTest):
|
||||
## snippets = ("hallo", "hallo ${2:End} mitte ${1:Beginning}")
|
||||
## keys = "hallo" + EX + JF + "Test" + JF + "Hi"
|
||||
## wanted = "hallo Test mitte BeginningHi"
|
||||
##class TabStopTestJumping2_ExceptCorrectResult(_VimTest):
|
||||
## snippets = ("hallo", "hallo $2 $1")
|
||||
## keys = "hallo" + EX + JF + "Test" + JF + "Hi"
|
||||
## wanted = "hallo Test Hi"
|
||||
##class TabStopTestJumpingRLExampleWithZeroTab_ExceptCorrectResult(_VimTest):
|
||||
## snippets = ("test", "each_byte { |${1:byte}| $0 }")
|
||||
## keys = "test" + EX + JF + "Blah"
|
||||
## wanted = "each_byte { |byte| Blah }"
|
||||
##
|
||||
##class TabStopTestJumpingDontJumpToEndIfThereIsTabZero_ExceptCorrectResult(_VimTest):
|
||||
## snippets = ("hallo", "hallo $0 $1")
|
||||
## keys = "hallo" + EX + "Test" + JF + "Hi" + JF + JF + "du"
|
||||
## wanted = "hallo Hidu Test"
|
||||
##
|
||||
##class TabStopTestBackwardJumping_ExceptCorrectResult(_VimTest):
|
||||
## snippets = ("hallo", "hallo ${2:End} mitte${1:Beginning}")
|
||||
## keys = "hallo" + EX + "Somelengthy Text" + JF + "Hi" + JB + \
|
||||
## "Lets replace it again" + JF + "Blah" + JF + JB*2 + JF
|
||||
## wanted = "hallo Blah mitteLets replace it again"
|
||||
##class TabStopTestBackwardJumping2_ExceptCorrectResult(_VimTest):
|
||||
## snippets = ("hallo", "hallo $2 $1")
|
||||
## keys = "hallo" + EX + "Somelengthy Text" + JF + "Hi" + JB + \
|
||||
## "Lets replace it again" + JF + "Blah" + JF + JB*2 + JF
|
||||
## wanted = "hallo Blah Lets replace it again"
|
||||
##
|
||||
##class TabStopTestMultilineExpand_ExceptCorrectResult(_VimTest):
|
||||
## snippets = ("hallo", "hallo $0\nnice $1 work\n$3 $2\nSeem to work")
|
||||
## keys ="test hallo World" + ESC + "02f i" + EX + "world" + JF + "try" + \
|
||||
## JF + "test" + JF + "one more" + JF + JF
|
||||
## wanted = "test hallo one more\nnice world work\n" \
|
||||
## "test try\nSeem to work World"
|
||||
##
|
||||
##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>"""
|
||||
##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>"""
|
||||
##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>"""
|
||||
##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>"""
|
||||
##
|
||||
# TabStop Tests {{{#
|
||||
class TabStopSimpleReplace_ExceptCorrectResult(_VimTest):
|
||||
snippets = ("hallo", "hallo ${0:End} ${1:Beginning}")
|
||||
keys = "hallo" + EX + "na" + JF + "Du Nase"
|
||||
wanted = "hallo Du Nase na"
|
||||
class TabStopSimpleReplaceSurrounded_ExceptCorrectResult(_VimTest):
|
||||
snippets = ("hallo", "hallo ${0:End} a small feed")
|
||||
keys = "hallo" + EX + "Nase"
|
||||
wanted = "hallo Nase a small feed"
|
||||
class TabStopSimpleReplaceSurrounded1_ExceptCorrectResult(_VimTest):
|
||||
snippets = ("hallo", "hallo $0 a small feed")
|
||||
keys = "hallo" + EX + "Nase"
|
||||
wanted = "hallo Nase a small feed"
|
||||
class TabStop_Exit_ExceptCorrectResult(_VimTest):
|
||||
snippets = ("echo", "$0 run")
|
||||
keys = "echo" + EX + "test"
|
||||
wanted = "test run"
|
||||
|
||||
class TabStopNoReplace_ExceptCorrectResult(_VimTest):
|
||||
snippets = ("echo", "echo ${1:Hallo}")
|
||||
keys = "echo" + EX
|
||||
wanted = "echo Hallo"
|
||||
|
||||
class TabStop_EscapingCharsBackticks(_VimTest):
|
||||
snippets = ("test", r"snip \` literal")
|
||||
keys = "test" + EX
|
||||
wanted = "snip ` literal"
|
||||
class TabStop_EscapingCharsDollars(_VimTest):
|
||||
snippets = ("test", r"snip \$0 $$0 end")
|
||||
keys = "test" + EX + "hi"
|
||||
wanted = "snip $0 $hi end"
|
||||
class TabStop_EscapingCharsDollars1(_VimTest):
|
||||
snippets = ("test", r"a\${1:literal}")
|
||||
keys = "test" + EX
|
||||
wanted = "a${1:literal}"
|
||||
class TabStop_EscapingCharsDollars_BeginningOfLine(_VimTest):
|
||||
snippets = ("test", "\n\\${1:literal}")
|
||||
keys = "test" + EX
|
||||
wanted = "\n${1:literal}"
|
||||
class TabStop_EscapingCharsDollars_BeginningOfDefinitionText(_VimTest):
|
||||
snippets = ("test", "\\${1:literal}")
|
||||
keys = "test" + EX
|
||||
wanted = "${1:literal}"
|
||||
class TabStop_EscapingChars_Backslash(_VimTest):
|
||||
snippets = ("test", r"This \ is a backslash!")
|
||||
keys = "test" + EX
|
||||
wanted = "This \\ is a backslash!"
|
||||
class TabStop_EscapingChars_Backslash2(_VimTest):
|
||||
snippets = ("test", r"This is a backslash \\ done")
|
||||
keys = "test" + EX
|
||||
wanted = r"This is a backslash \ done"
|
||||
class TabStop_EscapingChars_Backslash3(_VimTest):
|
||||
snippets = ("test", r"These are two backslashes \\\\ done")
|
||||
keys = "test" + EX
|
||||
wanted = r"These are two backslashes \\ done"
|
||||
class TabStop_EscapingChars_Backslash4(_VimTest):
|
||||
# Test for bug 746446
|
||||
snippets = ("test", r"\\$1{$2}")
|
||||
keys = "test" + EX + "hello" + JF + "world"
|
||||
wanted = r"\hello{world}"
|
||||
class TabStop_EscapingChars_RealLife(_VimTest):
|
||||
snippets = ("test", r"usage: \`basename \$0\` ${1:args}")
|
||||
keys = "test" + EX + "[ -u -v -d ]"
|
||||
wanted = "usage: `basename $0` [ -u -v -d ]"
|
||||
|
||||
class TabStopEscapingWhenSelected_ECR(_VimTest):
|
||||
snippets = ("test", "snip ${1:default}")
|
||||
keys = "test" + EX + ESC + "0ihi"
|
||||
wanted = "hisnip default"
|
||||
class TabStopEscapingWhenSelectedSingleCharTS_ECR(_VimTest):
|
||||
snippets = ("test", "snip ${1:i}")
|
||||
keys = "test" + EX + ESC + "0ihi"
|
||||
wanted = "hisnip i"
|
||||
class TabStopEscapingWhenSelectedNoCharTS_ECR(_VimTest):
|
||||
snippets = ("test", "snip $1")
|
||||
keys = "test" + EX + ESC + "0ihi"
|
||||
wanted = "hisnip "
|
||||
|
||||
class TabStopUsingBackspaceToDeleteDefaultValue_ECR(_VimTest):
|
||||
snippets = ("test", "snip ${1/.+/(?0:matched)/} ${1:default}")
|
||||
keys = "test" + EX + BS
|
||||
wanted = "snip "
|
||||
|
||||
class TabStopWithOneChar_ExceptCorrectResult(_VimTest):
|
||||
snippets = ("hallo", "nothing ${1:i} hups")
|
||||
keys = "hallo" + EX + "ship"
|
||||
wanted = "nothing ship hups"
|
||||
|
||||
class TabStopTestJumping_ExceptCorrectResult(_VimTest):
|
||||
snippets = ("hallo", "hallo ${2:End} mitte ${1:Beginning}")
|
||||
keys = "hallo" + EX + JF + "Test" + JF + "Hi"
|
||||
wanted = "hallo Test mitte BeginningHi"
|
||||
class TabStopTestJumping2_ExceptCorrectResult(_VimTest):
|
||||
snippets = ("hallo", "hallo $2 $1")
|
||||
keys = "hallo" + EX + JF + "Test" + JF + "Hi"
|
||||
wanted = "hallo Test Hi"
|
||||
class TabStopTestJumpingRLExampleWithZeroTab_ExceptCorrectResult(_VimTest):
|
||||
snippets = ("test", "each_byte { |${1:byte}| $0 }")
|
||||
keys = "test" + EX + JF + "Blah"
|
||||
wanted = "each_byte { |byte| Blah }"
|
||||
|
||||
class TabStopTestJumpingDontJumpToEndIfThereIsTabZero_ExceptCorrectResult(_VimTest):
|
||||
snippets = ("hallo", "hallo $0 $1")
|
||||
keys = "hallo" + EX + "Test" + JF + "Hi" + JF + JF + "du"
|
||||
wanted = "hallo Hidu Test"
|
||||
|
||||
class TabStopTestBackwardJumping_ExceptCorrectResult(_VimTest):
|
||||
snippets = ("hallo", "hallo ${2:End} mitte${1:Beginning}")
|
||||
keys = "hallo" + EX + "Somelengthy Text" + JF + "Hi" + JB + \
|
||||
"Lets replace it again" + JF + "Blah" + JF + JB*2 + JF
|
||||
wanted = "hallo Blah mitteLets replace it again"
|
||||
class TabStopTestBackwardJumping2_ExceptCorrectResult(_VimTest):
|
||||
snippets = ("hallo", "hallo $2 $1")
|
||||
keys = "hallo" + EX + "Somelengthy Text" + JF + "Hi" + JB + \
|
||||
"Lets replace it again" + JF + "Blah" + JF + JB*2 + JF
|
||||
wanted = "hallo Blah Lets replace it again"
|
||||
|
||||
class TabStopTestMultilineExpand_ExceptCorrectResult(_VimTest):
|
||||
snippets = ("hallo", "hallo $0\nnice $1 work\n$3 $2\nSeem to work")
|
||||
keys ="test hallo World" + ESC + "02f i" + EX + "world" + JF + "try" + \
|
||||
JF + "test" + JF + "one more" + JF + JF
|
||||
wanted = "test hallo one more\nnice world work\n" \
|
||||
"test try\nSeem to work World"
|
||||
|
||||
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_NoJumpBack(_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>"""
|
||||
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>"""
|
||||
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>"""
|
||||
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_TSInDefaultText_ZeroLengthNested_Overwrite(_VimTest):
|
||||
snippets = ("test", """h${1:a$2b}l""")
|
||||
keys = "test" + EX + JF + "ups" + JF + "End"
|
||||
wanted = """haupsblEnd"""
|
||||
|
||||
|
||||
##class TabStop_TSInDefaultNested_OverwriteOneJumpBackToOther(_VimTest):
|
||||
## snippets = ("test", "hi ${1:this ${2:second ${3:third}}} $4")
|
||||
## keys = "test" + EX + JF + "Hallo" + JF + "Ende"
|
||||
@ -1415,6 +1407,22 @@ class MultilineExpandTestTyping_ExceptCorrectResult(_VimTest):
|
||||
## snippets = ("test", r"$1 ${1/, */, /g}")
|
||||
## keys = "test" + EX + "a, nice, building"
|
||||
## wanted = "a, nice, building a, nice, building"
|
||||
## class TransformationUsingBackspaceToDeleteDefaultValueInFirstTab_ECR(_VimTest):
|
||||
## sleeptime = 0.09 # Do this very slowly
|
||||
## snippets = ("test", "snip ${1/.+/(?0:m1)/} ${2/.+/(?0:m2)/} "
|
||||
## "${1:default} ${2:def}")
|
||||
## keys = "test" + EX + BS + JF + "hi"
|
||||
## wanted = "snip m2 hi"
|
||||
## class TransformationUsingBackspaceToDeleteDefaultValueInSecondTab_ECR(_VimTest):
|
||||
## snippets = ("test", "snip ${1/.+/(?0:m1)/} ${2/.+/(?0:m2)/} "
|
||||
## "${1:default} ${2:def}")
|
||||
## keys = "test" + EX + "hi" + JF + BS
|
||||
## wanted = "snip m1 hi "
|
||||
## class TransformationUsingBackspaceToDeleteDefaultValueTypeSomethingThen_ECR(_VimTest):
|
||||
## snippets = ("test", "snip ${1/.+/(?0:matched)/} ${1:default}")
|
||||
## keys = "test" + EX + BS + "hallo"
|
||||
## wanted = "snip matched hallo"
|
||||
|
||||
### End: Transformations #}}}
|
||||
### ${VISUAL} {{{#
|
||||
##class Visual_NoVisualSelection_Ignore(_VimTest):
|
||||
|
Loading…
x
Reference in New Issue
Block a user