1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
from test.vim_test_case import VimTestCase as _VimTest
from test.constant import *
from test.util import running_on_windows
class _ExpandTabs(_VimTest):
def _extra_vim_config(self, vim_config):
vim_config.append("set sw=3")
vim_config.append("set expandtab")
class RecTabStopsWithExpandtab_SimpleExample_ECR(_ExpandTabs):
snippets = ("m", "\tBlaahblah \t\t ")
keys = "m" + EX
wanted = " Blaahblah \t\t "
class RecTabStopsWithExpandtab_SpecialIndentProblem_ECR(_ExpandTabs):
# Windows indents the Something line after pressing return, though it
# shouldn't because it contains a manual indent. All other vim versions do
# not do this. Windows vim does not interpret the changes made by :py as
# changes made 'manually', while the other vim version seem to do so. Since
# the fault is not with UltiSnips, we simply skip this test on windows
# completely.
skip_if = lambda self: running_on_windows()
snippets = (("m1", "Something"), ("m", "\t$0"))
keys = "m" + EX + "m1" + EX + "\nHallo"
wanted = " Something\n Hallo"
def _extra_vim_config(self, vim_config):
_ExpandTabs._extra_vim_config(self, vim_config)
vim_config.append("set indentkeys=o,O,*<Return>,<>>,{,}")
vim_config.append("set indentexpr=8")
class ProperIndenting_SimpleCase_ECR(_VimTest):
snippets = ("test", "for\n blah")
keys = " test" + EX + "Hui"
wanted = " for\n blahHui"
class ProperIndenting_SingleLineNoReindenting_ECR(_VimTest):
snippets = ("test", "hui")
keys = " test" + EX + "blah"
wanted = " huiblah"
class ProperIndenting_AutoIndentAndNewline_ECR(_VimTest):
snippets = ("test", "hui")
keys = " test" + EX + "\n" + "blah"
wanted = " hui\n blah"
def _extra_vim_config(self, vim_config):
vim_config.append("set autoindent")
# Test for bug 1073816
class ProperIndenting_FirstLineInFile_ECR(_VimTest):
text_before = ""
text_after = ""
files = {
"us/all.snippets": r"""
global !p
def complete(t, opts):
if t:
opts = [ m[len(t):] for m in opts if m.startswith(t) ]
if len(opts) == 1:
return opts[0]
elif len(opts) > 1:
return "(" + "|".join(opts) + ")"
else:
return ""
endglobal
snippet '^#?inc' "#include <>" !r
#include <$1`!p snip.rv = complete(t[1], ['cassert', 'cstdio', 'cstdlib', 'cstring', 'fstream', 'iostream', 'sstream'])`>
endsnippet
"""
}
keys = "inc" + EX + "foo"
wanted = "#include <foo>"
class ProperIndenting_FirstLineInFileComplete_ECR(ProperIndenting_FirstLineInFile_ECR):
keys = "inc" + EX + "cstdl"
wanted = "#include <cstdlib>"
class _FormatoptionsBase(_VimTest):
def _extra_vim_config(self, vim_config):
vim_config.append("set tw=20")
vim_config.append("set fo=lrqntc")
class FOSimple_Break_ExpectCorrectResult(_FormatoptionsBase):
snippets = ("test", "${1:longer expand}\n$1\n$0", "", "f")
keys = (
"test"
+ EX
+ "This is a longer text that should wrap as formatoptions are enabled"
+ JF
+ "end"
)
wanted = (
"This is a longer\ntext that should\nwrap as\nformatoptions are\nenabled\n"
+ "This is a longer\ntext that should\nwrap as\nformatoptions are\nenabled\n"
+ "end"
)
class FOTextBeforeAndAfter_ExpectCorrectResult(_FormatoptionsBase):
snippets = ("test", "Before${1:longer expand}After\nstart$1end")
keys = "test" + EX + "This is a longer text that should wrap"
wanted = """BeforeThis is a
longer text that
should wrapAfter
startThis is a
longer text that
should wrapend"""
# Tests for https://bugs.launchpad.net/bugs/719998
class FOTextAfter_ExpectCorrectResult(_FormatoptionsBase):
snippets = ("test", "${1:longer expand}after\nstart$1end")
keys = (
"test" + EX + "This is a longer snippet that should wrap properly "
"and the mirror below should work as well"
)
wanted = """This is a longer
snippet that should
wrap properly and
the mirror below
should work as wellafter
startThis is a longer
snippet that should
wrap properly and
the mirror below
should work as wellend"""
class FOWrapOnLongWord_ExpectCorrectResult(_FormatoptionsBase):
snippets = ("test", "${1:longer expand}after\nstart$1end")
keys = "test" + EX + "This is a longersnippet that should wrap properly"
wanted = """This is a
longersnippet that
should wrap properlyafter
startThis is a
longersnippet that
should wrap properlyend"""
|