UltiSnips/test/test_SnippetPriorities.py

159 lines
4.1 KiB
Python
Raw Normal View History

from test.vim_test_case import VimTestCase as _VimTest
2015-02-08 14:34:38 -05:00
from test.constant import EX, ESC
# Snippet Priority {{{#
2015-01-20 15:26:03 -05:00
class SnippetPriorities_MultiWordTriggerOverwriteExisting(_VimTest):
snippets = (
2015-01-20 15:26:03 -05:00
('test me', '${1:Hallo}', 'Types Hallo'),
('test me', '${1:World}', 'Types World'),
('test me', 'We overwrite', 'Overwrite the two', '', 1),
)
2015-01-20 15:26:03 -05:00
keys = 'test me' + EX
wanted = 'We overwrite'
class SnippetPriorities_DoNotCareAboutNonMatchings(_VimTest):
snippets = (
2015-01-20 15:26:03 -05:00
('test1', 'Hallo', 'Types Hallo'),
('test2', 'We overwrite', 'Overwrite the two', '', 1),
)
2015-01-20 15:26:03 -05:00
keys = 'test1' + EX
wanted = 'Hallo'
class SnippetPriorities_OverwriteExisting(_VimTest):
snippets = (
2015-01-20 15:26:03 -05:00
('test', '${1:Hallo}', 'Types Hallo'),
('test', '${1:World}', 'Types World'),
('test', 'We overwrite', 'Overwrite the two', '', 1),
)
2015-01-20 15:26:03 -05:00
keys = 'test' + EX
wanted = 'We overwrite'
class SnippetPriorities_OverwriteTwice_ECR(_VimTest):
snippets = (
2015-01-20 15:26:03 -05:00
('test', '${1:Hallo}', 'Types Hallo'),
('test', '${1:World}', 'Types World'),
('test', 'We overwrite', 'Overwrite the two', '', 1),
('test', 'again', 'Overwrite again', '', 2),
)
2015-01-20 15:26:03 -05:00
keys = 'test' + EX
wanted = 'again'
class SnippetPriorities_OverwriteThenChoose_ECR(_VimTest):
snippets = (
2015-01-20 15:26:03 -05:00
('test', '${1:Hallo}', 'Types Hallo'),
('test', '${1:World}', 'Types World'),
('test', 'We overwrite', 'Overwrite the two', '', 1),
('test', 'No overwrite', 'Not overwritten', '', 1),
)
2015-01-20 15:26:03 -05:00
keys = 'test' + EX + '1\n\n' + 'test' + EX + '2\n'
wanted = 'We overwrite\nNo overwrite'
class SnippetPriorities_AddedHasHigherThanFile(_VimTest):
2015-01-20 15:26:03 -05:00
files = { 'us/all.snippets': r"""
snippet test "Test Snippet" b
This is a test snippet
endsnippet
"""}
snippets = (
2015-01-20 15:26:03 -05:00
('test', 'We overwrite', 'Overwrite the two', '', 1),
)
2015-01-20 15:26:03 -05:00
keys = 'test' + EX
wanted = 'We overwrite'
class SnippetPriorities_FileHasHigherThanAdded(_VimTest):
2015-01-20 15:26:03 -05:00
files = { 'us/all.snippets': r"""
snippet test "Test Snippet" b
This is a test snippet
endsnippet
"""}
snippets = (
2015-01-20 15:26:03 -05:00
('test', 'We do not overwrite', 'Overwrite the two', '', -1),
)
2015-01-20 15:26:03 -05:00
keys = 'test' + EX
wanted = 'This is a test snippet'
class SnippetPriorities_FileHasHigherThanAdded_neg_prio(_VimTest):
2015-01-20 15:26:03 -05:00
files = { 'us/all.snippets': r"""
priority -3
snippet test "Test Snippet" b
This is a test snippet
endsnippet
"""}
snippets = (
2015-01-20 15:26:03 -05:00
('test', 'We overwrite', 'Overwrite the two', '', -5),
)
2015-01-20 15:26:03 -05:00
keys = 'test' + EX
wanted = 'This is a test snippet'
class SnippetPriorities_SimpleClear(_VimTest):
files = {
2015-01-20 15:26:03 -05:00
'us/all.snippets': r"""
priority 1
clearsnippets
priority -1
snippet test "Test Snippet"
Should not expand to this.
endsnippet
"""
}
2015-01-20 15:26:03 -05:00
keys = 'test' + EX
wanted = 'test' + EX
class SnippetPriorities_SimpleClear2(_VimTest):
files = {
2015-01-20 15:26:03 -05:00
'us/all.snippets': r"""
clearsnippets
snippet test "Test snippet"
Should not expand to this.
endsnippet
"""
}
2015-01-20 15:26:03 -05:00
keys = 'test' + EX
wanted = 'test' + EX
class SnippetPriorities_ClearedByParent(_VimTest):
files = {
2015-01-20 15:26:03 -05:00
'us/p.snippets': r"""
clearsnippets
""",
2015-01-20 15:26:03 -05:00
'us/c.snippets': r"""
extends p
snippet test "Test snippets"
Should not expand to this.
endsnippet
"""
}
2015-01-20 15:26:03 -05:00
keys = ESC + ':set ft=c\n' + 'itest' + EX
wanted = 'test' + EX
class SnippetPriorities_ClearedByChild(_VimTest):
files = {
2015-01-20 15:26:03 -05:00
'us/p.snippets': r"""
snippet test "Test snippets"
Should only expand in p.
endsnippet
""",
2015-01-20 15:26:03 -05:00
'us/c.snippets': r"""
extends p
clearsnippets
"""
}
2015-01-20 15:26:03 -05:00
keys = (ESC + ':set ft=p\n' + 'itest' + EX + '\n' +
ESC + ':set ft=c\n' + 'itest' + EX + ESC + ':set ft=p')
wanted = 'Should only expand in p.\ntest' + EX
# End: Snippet Priority #}}}