22/339 tests are failing

This commit is contained in:
Holger Rapp 2012-01-10 18:11:02 +01:00
parent 1653eb89ea
commit d72eb587f6
5 changed files with 35 additions and 15 deletions

View File

@ -1,10 +1,11 @@
#!/usr/bin/env python
# encoding: utf-8
from UltiSnips.Util import CheapTotalOrdering
__all__ = [ "Position", "Span" ]
class Position(object):
class Position(CheapTotalOrdering):
def __init__(self, line, col):
self.line = line
self.col = col
@ -43,7 +44,9 @@ class Position(object):
def __cmp__(self, other):
s = self._line, self._col
o = other._line, other._col
return cmp(s,o)
if s < o: return -1
if s > o: return 1
return 0
def __repr__(self):
return "(%i,%i)" % (self._line, self._col)

View File

@ -9,7 +9,7 @@ into Logical Units called Tokens.
import string
import re
from .Geometry import Position
from UltiSnips.Geometry import Position
__all__ = [
"tokenize", "EscapeCharToken", "TransformationToken", "TabStopToken",
@ -122,7 +122,7 @@ class TabStopToken(Token):
self.no = _parse_number(stream)
if stream.peek() is ":":
if stream.peek() == ":":
stream.next()
self.initial_text = _parse_till_closing_brace(stream)

View File

@ -7,7 +7,7 @@ import stat
import tempfile
import vim
from UltiSnips.Util import IndentUtil
from UltiSnips.Util import IndentUtil, CheapTotalOrdering
from UltiSnips.Buffer import TextBuffer
from UltiSnips.Geometry import Span, Position
from UltiSnips.Lexer import tokenize, EscapeCharToken, TransformationToken, \
@ -95,6 +95,7 @@ class _CleverReplace(object):
def _unescape(self, v):
return self._UNESCAPE.subn(lambda m: m.group(0)[-1], v)[0]
def replace(self, match):
start, end = match.span()
@ -108,7 +109,9 @@ class _CleverReplace(object):
tv = self._LONG_CASEFOLDINGS.subn(self._lcase_folding, tv)[0]
tv = self._replace_conditional(match, tv)
return self._unescape(tv.decode("string-escape"))
tv = tv.replace(r'\"', '"')
tv = tv.replace(r"\'", "'")
return self._unescape(tv)
class _TOParser(object):
def __init__(self, parent_to, text, indent):
@ -167,12 +170,10 @@ class _TOParser(object):
elif isinstance(token, VimLCodeToken):
VimLCode(self._parent_to, token)
###########################################################################
# Public classes #
###########################################################################
class TextObject(object):
class TextObject(CheapTotalOrdering):
"""
This base class represents any object in the text
that has a span in any ways
@ -198,7 +199,7 @@ class TextObject(object):
self._cts = 0
def __cmp__(self, other):
return cmp(self._start, other._start)
return self._start.__cmp__(other._start)
##############
# PROPERTIES #
@ -446,7 +447,7 @@ class ShellCode(TextObject):
# Write the code to a temporary file
handle, path = tempfile.mkstemp(text=True)
os.write(handle, code)
os.write(handle, code.encode("utf-8"))
os.close(handle)
os.chmod(path, stat.S_IRWXU)
@ -644,7 +645,7 @@ class PythonCode(TextObject):
self._globals = {}
globals = snippet.globals.get("!p", [])
exec("\n".join(globals).replace("\r\n", "\n") in self._globals)
exec("\n".join(globals).replace("\r\n", "\n"), self._globals)
# Add Some convenience to the code
self._code = "import re, os, vim, string, random\n" + code
@ -672,7 +673,7 @@ class PythonCode(TextObject):
})
self._code = self._code.replace("\r\n", "\n")
exec(self._code in self._globals, local_d)
exec(self._code, self._globals, local_d)
if self._snip._rv_changed:
self.current_text = self._snip.rv

View File

@ -6,6 +6,22 @@ import types
import vim
import sys
class CheapTotalOrdering:
"""Total ordering only appears in python 2.7. We try to stay compatible with
python 2.5 for now, so we define our own"""
def __lt__(self, other):
return self.__cmp__(other) < 0
def __le__(self, other):
return self.__cmp__(other) <= 0
def __gt__(self, other):
return self.__cmp__(other) > 0
def __ge__(self, other):
return self.__cmp__(other) >= 0
if sys.version_info > (2,8):
def as_utf8(s):
return s.encode("utf-8")

View File

@ -295,7 +295,7 @@ class Snippet(object):
return before.strip()
else:
before_words = before
for i in xrange(-1, -(num_words + 1), -1):
for i in range(-1, -(num_words + 1), -1):
left = before_words.rfind(word_list[i])
before_words = before_words[:left]
return before[len(before_words):].strip()