forked from SirVer/ultisnips
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·3144 lines (2861 loc) · 112 KB
/
test.py
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# encoding: utf-8
#
# To execute this test requires two terminals, one for running Vim and one
# for executing the test script. Both terminals should have their current
# working directories set to this directory (the one containing this test.py
# script).
#
# In one terminal, launch a GNU ``screen`` session named ``vim``:
# $ screen -S vim
#
# Within this new session, launch Vim with the absolute bare minimum settings
# to ensure a consistent test environment:
# $ vim -u NONE
#
# The '-u NONE' disables normal .vimrc and .gvimrc processing (note
# that '-u NONE' implies '-U NONE').
#
# All other settings are configured by the test script.
#
# Now, from another terminal, launch the testsuite:
# $ ./test.py
#
# The testsuite will use ``screen`` to inject commands into the Vim under test,
# and will compare the resulting output to expected results.
#
# Under windows, COM's SendKeys is used to send keystrokes to the gvim window.
# Note that Gvim must use english keyboard input (choose in windows registry)
# for this to work properly as SendKeys is a piece of chunk. (i.e. it sends
# <F13> when you send a | symbol while using german key mappings)
import os
import tempfile
import unittest
import time
import re
import platform
import sys
import subprocess
from textwrap import dedent
# Some constants for better reading
BS = '\x7f'
ESC = '\x1b'
ARR_L = '\x1bOD'
ARR_R = '\x1bOC'
ARR_U = '\x1bOA'
ARR_D = '\x1bOB'
# multi-key sequences generating a single key press
SEQUENCES = [ARR_L, ARR_R, ARR_U, ARR_D]
# Defined Constants
JF = "?" # Jump forwards
JB = "+" # Jump backwards
LS = "@" # List snippets
EX = "\t" # EXPAND
EA = "#" # Expand anonymous
# Some VIM functions
COMPL_KW = chr(24)+chr(14)
COMPL_ACCEPT = chr(25)
NUMBER_OF_RETRIES_FOR_EACH_TEST = 4
class VimInterface:
def focus(title=None):
pass
def send_keystrokes(self, str, sleeptime):
"""
Send the keystrokes to vim via screen. Pause after each char, so
vim can handle this
"""
for c in str:
self.send(c)
time.sleep(sleeptime)
def get_buffer_data(self):
handle, fn = tempfile.mkstemp(prefix="UltiSnips_Test",suffix=".txt")
os.close(handle)
os.unlink(fn)
self.send(ESC + ":w! %s\n" % fn)
# Read the output, chop the trailing newline
tries = 50
while tries:
if os.path.exists(fn):
return open(fn,"r").read()[:-1]
time.sleep(.05)
tries -= 1
class VimInterfaceScreen(VimInterface):
def __init__(self, session):
self.session = session
self.need_screen_escapes = 0
self.detect_parsing()
def send(self, s):
if self.need_screen_escapes:
# escape characters that are special to some versions of screen
repl = lambda m: '\\' + m.group(0)
s = re.sub( r"[$^#\\']", repl, s )
if sys.version_info >= (3,0):
s = s.encode("utf-8")
silent_call = lambda cmd: subprocess.call(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
while True:
rv = 0
if len(s) > 30:
rv |= silent_call(["screen", "-x", self.session, "-X", "register", "S", s])
rv |= silent_call(["screen", "-x", self.session, "-X", "paste", "S"])
else:
rv |= silent_call(["screen", "-x", self.session, "-X", "stuff", s])
if not rv: break
time.sleep(.2)
def detect_parsing(self):
# Clear the buffer
self.send("bggVGd")
# Send a string where the interpretation will depend on version of screen
string = "$TERM"
self.send("i" + string + ESC)
output = self.get_buffer_data()
# If the output doesn't match the input, need to do additional escaping
if output != string:
self.need_screen_escapes = 1
class VimInterfaceWindows(VimInterface):
BRACES = re.compile("([}{])")
WIN_ESCAPES = ["+", "^", "%", "~", "[", "]", "<", ">", "(", ")"]
WIN_REPLACES = [
(BS, "{BS}"),
(ARR_L, "{LEFT}"),
(ARR_R, "{RIGHT}"),
(ARR_U, "{UP}"),
(ARR_D, "{DOWN}"),
("\t", "{TAB}"),
("\n", "~"),
(ESC, "{ESC}"),
# On my system ` waits for a second keystroke, so `+SPACE = "`". On
# most systems, `+Space = "` ". I work around this, by sending the host
# ` as `+_+BS. Awkward, but the only way I found to get this working.
("`", "`_{BS}"),
("´", "´_{BS}"),
("{^}", "{^}_{BS}"),
]
def __init__(self):
self.seq_buf = []
# import windows specific modules
import win32com.client, win32gui
self.win32gui = win32gui
self.shell = win32com.client.Dispatch("WScript.Shell")
def is_focused(self, title=None):
cur_title = self.win32gui.GetWindowText(self.win32gui.GetForegroundWindow())
if (title or "- GVIM") in cur_title:
return True
return False
def focus(self, title=None):
if not self.shell.AppActivate(title or "- GVIM"):
raise Exception("Failed to switch to GVim window")
time.sleep(1)
def convert_keys(self, keys):
keys = self.BRACES.sub(r"{\1}", keys)
for k in self.WIN_ESCAPES:
keys = keys.replace(k, "{%s}" % k)
for f, r in self.WIN_REPLACES:
keys = keys.replace(f, r)
return keys
def send(self, keys):
self.seq_buf.append(keys)
seq = "".join(self.seq_buf)
for f in SEQUENCES:
if f.startswith(seq) and f != seq:
return
self.seq_buf = []
seq = self.convert_keys(seq)
if not self.is_focused():
time.sleep(2)
self.focus()
if not self.is_focused():
# This is the only way I can find to stop test execution
raise KeyboardInterrupt("Failed to focus GVIM")
self.shell.SendKeys(seq)
class _VimTest(unittest.TestCase):
snippets = ("dummy", "donotdefine")
snippets_test_file = ("", "", "") # file type, file name, file content
text_before = " --- some text before --- \n\n"
text_after = "\n\n --- some text after --- "
expected_error = ""
wanted = ""
keys = ""
sleeptime = 0.00
output = None
skip_on_windows = False
skip_on_linux = False
skip_on_mac = False
def send(self,s):
self.vim.send(s)
def send_py(self,s):
# Do not delete the file so that Vim can safely read it.
with tempfile.NamedTemporaryFile(
prefix="UltiSnips_Python",suffix=".py", delete=False
) as temporary_file:
temporary_file.write(s)
temporary_file.close()
if sys.version_info < (3,0):
self.send(":pyfile %s\n" % temporary_file.name)
else:
self.send(":py3file %s\n" % temporary_file.name)
def send_keystrokes(self,s):
self.vim.send_keystrokes(s, self.sleeptime)
def check_output(self):
wanted = self.text_before + self.wanted + self.text_after
if self.expected_error:
wanted = wanted + "\n" + self.expected_error
for i in range(NUMBER_OF_RETRIES_FOR_EACH_TEST):
if self.output != wanted:
# Redo this, but slower
self.sleeptime += 0.02
self.send(ESC)
self.setUp()
self.assertEqual(self.output, wanted)
def runTest(self): self.check_output()
def _options_on(self):
pass
def _options_off(self):
pass
def _skip(self, reason):
if hasattr(self, "skipTest"):
self.skipTest(reason)
def setUp(self):
system = platform.system()
if self.skip_on_windows and system == "Windows":
return self._skip("Running on windows")
if self.skip_on_linux and system == "Linux":
return self._skip("Running on Linux")
if self.skip_on_mac and system == "Darwin":
return self._skip("Running on Darwin/Mac")
# Escape for good measure
self.send(ESC + ESC + ESC)
# Close all scratch buffers
self.send(":silent! close\n")
# Reset UltiSnips
self.send_py("UltiSnips_Manager.reset(test_error=True)")
# Make it unlikely that we do not parse any shipped snippets
self.send(":let g:UltiSnipsSnippetDirectories=['<un_def_ined>']\n")
# Clear the buffer
self.send("bggVGd")
if len(self.snippets) and not isinstance(self.snippets[0],tuple):
self.snippets = ( self.snippets, )
for s in self.snippets:
sv,content = s[:2]
descr = ""
options = ""
if len(s) > 2:
descr = s[2]
if len(s) > 3:
options = s[3]
self.send_py("UltiSnips_Manager.add_snippet(%r, %r, %r, %r)" %
(sv, content, descr, options))
ft, fn, file_data = self.snippets_test_file
if ft:
self.send_py("UltiSnips_Manager._parse_snippets(%r, %r, %r)" %
(ft, fn, dedent(file_data + '\n')))
if not self.interrupt:
# Enter insert mode
self.send("i")
self.send(self.text_before)
self.send(self.text_after)
# Go to the middle of the buffer
self.send(ESC + "ggjj")
self._options_on()
self.send("i")
# Execute the command
self.send_keystrokes(self.keys)
self.send(ESC)
self._options_off()
self.output = self.vim.get_buffer_data()
###########################################################################
# BEGINNING OF TEST #
###########################################################################
# Snippet Definition Parsing {{{#
class _PS_Base(_VimTest):
def _options_on(self):
self.send(":let UltiSnipsDoHash=0\n")
def _options_off(self):
self.send(":unlet UltiSnipsDoHash\n")
class ParseSnippets_SimpleSnippet(_PS_Base):
snippets_test_file = ("all", "test_file", r"""
snippet testsnip "Test Snippet" b!
This is a test snippet!
endsnippet
""")
keys = "testsnip" + EX
wanted = "This is a test snippet!"
class ParseSnippets_MissingEndSnippet(_PS_Base):
snippets_test_file = ("all", "test_file", r"""
snippet testsnip "Test Snippet" b!
This is a test snippet!
""")
keys = "testsnip" + EX
wanted = "testsnip" + EX
expected_error = dedent("""
UltiSnips: Missing 'endsnippet' for 'testsnip' in test_file(5)
""").strip()
class ParseSnippets_UnknownDirective(_PS_Base):
snippets_test_file = ("all", "test_file", r"""
unknown directive
""")
keys = "testsnip" + EX
wanted = "testsnip" + EX
expected_error = dedent("""
UltiSnips: Invalid line 'unknown directive' in test_file(2)
""").strip()
class ParseSnippets_ExtendsWithoutFiletype(_PS_Base):
snippets_test_file = ("all", "test_file", r"""
extends
""")
keys = "testsnip" + EX
wanted = "testsnip" + EX
expected_error = dedent("""
UltiSnips: 'extends' without file types in test_file(2)
""").strip()
class ParseSnippets_ClearAll(_PS_Base):
snippets_test_file = ("all", "test_file", r"""
snippet testsnip "Test snippet"
This is a test.
endsnippet
clearsnippets
""")
keys = "testsnip" + EX
wanted = "testsnip" + EX
class ParseSnippets_ClearOne(_PS_Base):
snippets_test_file = ("all", "test_file", r"""
snippet testsnip "Test snippet"
This is a test.
endsnippet
snippet toclear "Snippet to clear"
Do not expand.
endsnippet
clearsnippets toclear
""")
keys = "toclear" + EX + "\n" + "testsnip" + EX
wanted = "toclear" + EX + "\n" + "This is a test."
class ParseSnippets_ClearTwo(_PS_Base):
snippets_test_file = ("all", "test_file", r"""
snippet testsnip "Test snippet"
This is a test.
endsnippet
snippet toclear "Snippet to clear"
Do not expand.
endsnippet
clearsnippets testsnip toclear
""")
keys = "toclear" + EX + "\n" + "testsnip" + EX
wanted = "toclear" + EX + "\n" + "testsnip" + EX
class _ParseSnippets_MultiWord(_PS_Base):
snippets_test_file = ("all", "test_file", r"""
snippet /test snip/
This is a test.
endsnippet
snippet !snip test! "Another snippet"
This is another test.
endsnippet
snippet "snippet test" "Another snippet" b
This is yet another test.
endsnippet
""")
class ParseSnippets_MultiWord_Simple(_ParseSnippets_MultiWord):
keys = "test snip" + EX
wanted = "This is a test."
class ParseSnippets_MultiWord_Description(_ParseSnippets_MultiWord):
keys = "snip test" + EX
wanted = "This is another test."
class ParseSnippets_MultiWord_Description_Option(_ParseSnippets_MultiWord):
keys = "snippet test" + EX
wanted = "This is yet another test."
class _ParseSnippets_MultiWord_RE(_PS_Base):
snippets_test_file = ("all", "test_file", r"""
snippet /[d-f]+/ "" r
az test
endsnippet
snippet !^(foo|bar)$! "" r
foo-bar test
endsnippet
snippet "(test ?)+" "" r
re-test
endsnippet
""")
class ParseSnippets_MultiWord_RE1(_ParseSnippets_MultiWord_RE):
keys = "abc def" + EX
wanted = "abc az test"
class ParseSnippets_MultiWord_RE2(_ParseSnippets_MultiWord_RE):
keys = "foo" + EX + " bar" + EX + "\nbar" + EX
wanted = "foo-bar test bar\t\nfoo-bar test"
class ParseSnippets_MultiWord_RE3(_ParseSnippets_MultiWord_RE):
keys = "test test test" + EX
wanted = "re-test"
class ParseSnippets_MultiWord_Quotes(_PS_Base):
snippets_test_file = ("all", "test_file", r"""
snippet "test snip"
This is a test.
endsnippet
""")
keys = "test snip" + EX
wanted = "This is a test."
class ParseSnippets_MultiWord_WithQuotes(_PS_Base):
snippets_test_file = ("all", "test_file", r"""
snippet !"test snip"!
This is a test.
endsnippet
""")
keys = '"test snip"' + EX
wanted = "This is a test."
class ParseSnippets_MultiWord_NoContainer(_PS_Base):
snippets_test_file = ("all", "test_file", r"""
snippet test snip
This is a test.
endsnippet
""")
keys = "test snip" + EX
wanted = keys
expected_error = dedent("""
UltiSnips: Invalid multiword trigger: 'test snip' in test_file(2)
""").strip()
class ParseSnippets_MultiWord_UnmatchedContainer(_PS_Base):
snippets_test_file = ("all", "test_file", r"""
snippet !inv snip/
This is a test.
endsnippet
""")
keys = "inv snip" + EX
wanted = keys
expected_error = dedent("""
UltiSnips: Invalid multiword trigger: '!inv snip/' in test_file(2)
""").strip()
class ParseSnippets_Global_Python(_PS_Base):
snippets_test_file = ("all", "test_file", r"""
global !p
def tex(ins):
return "a " + ins + " b"
endglobal
snippet ab
x `!p snip.rv = tex("bob")` y
endsnippet
snippet ac
x `!p snip.rv = tex("jon")` y
endsnippet
""")
keys = "ab" + EX + "\nac" + EX
wanted = "x a bob b y\nx a jon b y"
class ParseSnippets_Global_Local_Python(_PS_Base):
snippets_test_file = ("all", "test_file", r"""
global !p
def tex(ins):
return "a " + ins + " b"
endglobal
snippet ab
x `!p first = tex("bob")
snip.rv = "first"` `!p snip.rv = first` y
endsnippet
""")
keys = "ab" + EX
wanted = "x first a bob b y"
# End: Snippet Definition Parsing #}}}
# Simple Expands {{{#
class _SimpleExpands(_VimTest):
snippets = ("hallo", "Hallo Welt!")
class SimpleExpand_ExceptCorrectResult(_SimpleExpands):
keys = "hallo" + EX
wanted = "Hallo Welt!"
class SimpleExpandTwice_ExceptCorrectResult(_SimpleExpands):
keys = "hallo" + EX + '\nhallo' + EX
wanted = "Hallo Welt!\nHallo Welt!"
class SimpleExpandNewLineAndBackspae_ExceptCorrectResult(_SimpleExpands):
keys = "hallo" + EX + "\nHallo Welt!\n\n\b\b\b\b\b"
wanted = "Hallo Welt!\nHallo We"
def _options_on(self):
self.send(":set backspace=eol,start\n")
def _options_off(self):
self.send(":set backspace=\n")
class SimpleExpandTypeAfterExpand_ExceptCorrectResult(_SimpleExpands):
keys = "hallo" + EX + "and again"
wanted = "Hallo Welt!and again"
class SimpleExpandTypeAndDelete_ExceptCorrectResult(_SimpleExpands):
keys = "na du hallo" + EX + "and again\b\b\b\b\bblub"
wanted = "na du Hallo Welt!and blub"
class DoNotExpandAfterSpace_ExceptCorrectResult(_SimpleExpands):
keys = "hallo " + EX
wanted = "hallo " + EX
class ExitSnippetModeAfterTabstopZero(_VimTest):
snippets = ("test", "SimpleText")
keys = "test" + EX + EX
wanted = "SimpleText" + EX
class ExpandInTheMiddleOfLine_ExceptCorrectResult(_SimpleExpands):
keys = "Wie hallo gehts" + ESC + "bhi" + EX
wanted = "Wie Hallo Welt! gehts"
class MultilineExpand_ExceptCorrectResult(_VimTest):
snippets = ("hallo", "Hallo Welt!\nUnd Wie gehts")
keys = "Wie hallo gehts" + ESC + "bhi" + EX
wanted = "Wie Hallo Welt!\nUnd Wie gehts gehts"
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 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):
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 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_OverwriteSecond(_VimTest):
snippets = ("test", """h${1:a$2b}l""")
keys = "test" + EX + JF + "ups" + JF + "End"
wanted = """haupsblEnd"""
class TabStop_TSInDefaultText_ZeroLengthNested_OverwriteFirst(_VimTest):
snippets = ("test", """h${1:a$2b}l""")
keys = "test" + EX + "ups" + JF + "End"
wanted = """hupslEnd"""
class TabStop_TSInDefaultText_ZeroLengthNested_OverwriteSecondJumpBackOverwrite(_VimTest):
snippets = ("test", """h${1:a$2b}l""")
keys = "test" + EX + JF + "longertext" + JB + "overwrite" + JF + "End"
wanted = """hoverwritelEnd"""
class TabStop_TSInDefaultText_ZeroLengthNested_OverwriteSecondJumpBackAndForward0(_VimTest):
snippets = ("test", """h${1:a$2b}l""")
keys = "test" + EX + JF + "longertext" + JB + JF + "overwrite" + JF + "End"
wanted = """haoverwriteblEnd"""
class TabStop_TSInDefaultText_ZeroLengthNested_OverwriteSecondJumpBackAndForward1(_VimTest):
snippets = ("test", """h${1:a$2b}l""")
keys = "test" + EX + JF + "longertext" + JB + JF + JF + "End"
wanted = """halongertextblEnd"""
class TabStop_TSInDefaultNested_OverwriteOneJumpBackToOther(_VimTest):
snippets = ("test", "hi ${1:this ${2:second ${3:third}}} $4")
keys = "test" + EX + JF + "Hallo" + JF + "Ende"
wanted = "hi this Hallo Ende"
class TabStop_TSInDefaultNested_OverwriteOneJumpToThird(_VimTest):
snippets = ("test", "hi ${1:this ${2:second ${3:third}}} $4")
keys = "test" + EX + JF + JF + "Hallo" + JF + "Ende"
wanted = "hi this second Hallo Ende"
class TabStop_TSInDefaultNested_OverwriteOneJumpAround(_VimTest):
snippets = ("test", "hi ${1:this ${2:second ${3:third}}} $4")
keys = "test" + EX + JF + JF + "Hallo" + JB+JB + "Blah" + JF + "Ende"
wanted = "hi Blah Ende"
class TabStop_TSInDefault_MirrorsOutside_DoNothing(_VimTest):
snippets = ("test", "hi ${1:this ${2:second}} $2")
keys = "test" + EX
wanted = "hi this second second"
class TabStop_TSInDefault_MirrorsOutside_OverwriteSecond(_VimTest):
snippets = ("test", "hi ${1:this ${2:second}} $2")
keys = "test" + EX + JF + "Hallo"
wanted = "hi this Hallo Hallo"
class TabStop_TSInDefault_MirrorsOutside_Overwrite0(_VimTest):
snippets = ("test", "hi ${1:this ${2:second}} $2")
keys = "test" + EX + "Hallo"
wanted = "hi Hallo "
class TabStop_TSInDefault_MirrorsOutside_Overwrite1(_VimTest):
snippets = ("test", "$1: ${1:'${2:second}'} $2")
keys = "test" + EX + "Hallo"
wanted = "Hallo: Hallo "
class TabStop_TSInDefault_MirrorsOutside_OverwriteSecond1(_VimTest):
snippets = ("test", "$1: ${1:'${2:second}'} $2")
keys = "test" + EX + JF + "Hallo"
wanted = "'Hallo': 'Hallo' Hallo"
class TabStop_TSInDefault_MirrorsOutside_OverwriteFirstSwitchNumbers(_VimTest):
snippets = ("test", "$2: ${2:'${1:second}'} $1")
keys = "test" + EX + "Hallo"
wanted = "'Hallo': 'Hallo' Hallo"
class TabStop_TSInDefault_MirrorsOutside_OverwriteFirst_RLExample(_VimTest):
snippets = ("test", """`!p snip.rv = t[1].split('/')[-1].lower().strip("'")` = require(${1:'${2:sys}'})""")
keys = "test" + EX + "WORLD" + JF + "End"
wanted = "world = require(WORLD)End"
class TabStop_TSInDefault_MirrorsOutside_OverwriteSecond_RLExample(_VimTest):
snippets = ("test", """`!p snip.rv = t[1].split('/')[-1].lower().strip("'")` = require(${1:'${2:sys}'})""")
keys = "test" + EX + JF + "WORLD" + JF + "End"
wanted = "world = require('WORLD')End"
class TabStop_Multiline_Leave(_VimTest):
snippets = ("test", "hi ${1:first line\nsecond line} world" )
keys = "test" + EX
wanted = "hi first line\nsecond line world"
class TabStop_Multiline_Overwrite(_VimTest):
snippets = ("test", "hi ${1:first line\nsecond line} world" )
keys = "test" + EX + "Nothing"
wanted = "hi Nothing world"
class TabStop_Multiline_MirrorInFront_Leave(_VimTest):
snippets = ("test", "hi $1 ${1:first line\nsecond line} world" )
keys = "test" + EX
wanted = "hi first line\nsecond line first line\nsecond line world"
class TabStop_Multiline_MirrorInFront_Overwrite(_VimTest):
snippets = ("test", "hi $1 ${1:first line\nsecond line} world" )
keys = "test" + EX + "Nothing"
wanted = "hi Nothing Nothing world"
class TabStop_Multiline_DelFirstOverwriteSecond_Overwrite(_VimTest):
snippets = ("test", "hi $1 $2 ${1:first line\nsecond line} ${2:Hi} world" )
keys = "test" + EX + BS + JF + "Nothing"
wanted = "hi Nothing Nothing world"
class TabStopNavigatingInInsertModeSimple_ExceptCorrectResult(_VimTest):
snippets = ("hallo", "Hallo ${1:WELT} ups")
keys = "hallo" + EX + "haselnut" + 2*ARR_L + "hips" + JF + "end"
wanted = "Hallo haselnhipsut upsend"
# End: TabStop Tests #}}}
# ShellCode Interpolation {{{#
class TabStop_Shell_SimpleExample(_VimTest):
skip_on_windows = True
snippets = ("test", "hi `echo hallo` you!")
keys = "test" + EX + "and more"
wanted = "hi hallo you!and more"
class TabStop_Shell_TextInNextLine(_VimTest):
skip_on_windows = True
snippets = ("test", "hi `echo hallo`\nWeiter")
keys = "test" + EX + "and more"
wanted = "hi hallo\nWeiterand more"
class TabStop_Shell_InDefValue_Leave(_VimTest):
skip_on_windows = True
snippets = ("test", "Hallo ${1:now `echo fromecho`} end")
keys = "test" + EX + JF + "and more"
wanted = "Hallo now fromecho endand more"
class TabStop_Shell_InDefValue_Overwrite(_VimTest):
skip_on_windows = True
snippets = ("test", "Hallo ${1:now `echo fromecho`} end")
keys = "test" + EX + "overwrite" + JF + "and more"
wanted = "Hallo overwrite endand more"
class TabStop_Shell_TestEscapedChars_Overwrite(_VimTest):
skip_on_windows = True
snippets = ("test", r"""`echo \`echo "\\$hi"\``""")
keys = "test" + EX
wanted = "$hi"
class TabStop_Shell_TestEscapedCharsAndShellVars_Overwrite(_VimTest):
skip_on_windows = True
snippets = ("test", r"""`hi="blah"; echo \`echo "$hi"\``""")
keys = "test" + EX
wanted = "blah"
class TabStop_Shell_ShebangPython(_VimTest):
skip_on_windows = True
snippets = ("test", """Hallo ${1:now `#!/usr/bin/env python
print "Hallo Welt"
`} end""")
keys = "test" + EX + JF + "and more"
wanted = "Hallo now Hallo Welt endand more"
# End: ShellCode Interpolation #}}}
# VimScript Interpolation {{{#
class TabStop_VimScriptInterpolation_SimpleExample(_VimTest):
snippets = ("test", """hi `!v indent(".")` End""")
keys = " test" + EX
wanted = " hi 4 End"
# End: VimScript Interpolation #}}}
# PythonCode Interpolation {{{#
# Deprecated Implementation {{{#
class PythonCodeOld_SimpleExample(_VimTest):
snippets = ("test", """hi `!p res = "Hallo"` End""")
keys = "test" + EX
wanted = "hi Hallo End"
class PythonCodeOld_ReferencePlaceholderAfter(_VimTest):
snippets = ("test", """${1:hi} `!p res = t[1]+".blah"` End""")
keys = "test" + EX + "ho"
wanted = "ho ho.blah End"
class PythonCodeOld_ReferencePlaceholderBefore(_VimTest):
snippets = ("test", """`!p res = len(t[1])*"#"`\n${1:some text}""")
keys = "test" + EX + "Hallo Welt"
wanted = "##########\nHallo Welt"
class PythonCodeOld_TransformedBeforeMultiLine(_VimTest):
snippets = ("test", """${1/.+/egal/m} ${1:`!p
res = "Hallo"`} End""")
keys = "test" + EX
wanted = "egal Hallo End"
class PythonCodeOld_IndentedMultiline(_VimTest):
snippets = ("test", """start `!p a = 1
b = 2
if b > a:
res = "b isbigger a"
else:
res = "a isbigger b"` end""")
keys = " test" + EX
wanted = " start b isbigger a end"
# End: Deprecated Implementation #}}}
# New Implementation {{{#
class PythonCode_UseNewOverOld(_VimTest):
snippets = ("test", """hi `!p res = "Old"
snip.rv = "New"` End""")
keys = "test" + EX
wanted = "hi New End"
class PythonCode_SimpleExample(_VimTest):
snippets = ("test", """hi `!p snip.rv = "Hallo"` End""")
keys = "test" + EX
wanted = "hi Hallo End"
class PythonCode_SimpleExample_ReturnValueIsEmptyString(_VimTest):
snippets = ("test", """hi`!p snip.rv = ""`End""")
keys = "test" + EX
wanted = "hiEnd"
class PythonCode_ReferencePlaceholder(_VimTest):
snippets = ("test", """${1:hi} `!p snip.rv = t[1]+".blah"` End""")
keys = "test" + EX + "ho"
wanted = "ho ho.blah End"
class PythonCode_ReferencePlaceholderBefore(_VimTest):
snippets = ("test", """`!p snip.rv = len(t[1])*"#"`\n${1:some text}""")
keys = "test" + EX + "Hallo Welt"
wanted = "##########\nHallo Welt"
class PythonCode_TransformedBeforeMultiLine(_VimTest):
snippets = ("test", """${1/.+/egal/m} ${1:`!p
snip.rv = "Hallo"`} End""")
keys = "test" + EX
wanted = "egal Hallo End"
class PythonCode_MultilineIndented(_VimTest):
snippets = ("test", """start `!p a = 1
b = 2
if b > a:
snip.rv = "b isbigger a"
else:
snip.rv = "a isbigger b"` end""")
keys = " test" + EX
wanted = " start b isbigger a end"
class PythonCode_SimpleAppend(_VimTest):
snippets = ("test", """hi `!p snip.rv = "Hallo1"
snip += "Hallo2"` End""")
keys = "test" + EX
wanted = "hi Hallo1\nHallo2 End"
class PythonCode_MultiAppend(_VimTest):
snippets = ("test", """hi `!p snip.rv = "Hallo1"
snip += "Hallo2"
snip += "Hallo3"` End""")
keys = "test" + EX
wanted = "hi Hallo1\nHallo2\nHallo3 End"
class PythonCode_MultiAppendSimpleIndent(_VimTest):
snippets = ("test", """hi
`!p snip.rv="Hallo1"
snip += "Hallo2"
snip += "Hallo3"`
End""")
keys = """
test""" + EX
wanted = """
hi
Hallo1
Hallo2
Hallo3
End"""
class PythonCode_SimpleMkline(_VimTest):
snippets = ("test", r"""hi
`!p snip.rv="Hallo1\n"
snip.rv += snip.mkline("Hallo2") + "\n"
snip.rv += snip.mkline("Hallo3")`
End""")
keys = """
test""" + EX
wanted = """
hi
Hallo1
Hallo2
Hallo3
End"""