-
-
Notifications
You must be signed in to change notification settings - Fork 195
/
smartparens-commands-test.el
1119 lines (963 loc) · 41.4 KB
/
smartparens-commands-test.el
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
(require 'smartparens)
(defun sp-test-command-setup ()
(cond
((not (boundp 'mode)) (emacs-lisp-mode))
((eq mode 'elisp) (emacs-lisp-mode))
((eq mode 'md) (markdown-mode))
((eq mode 'racket) (racket-mode))
((eq mode 'clojure) (clojure-mode))
((eq mode 'c) (c-mode))
((eq mode 'js) (js2-mode))
((eq mode 'python) (shut-up (python-mode))))
(smartparens-mode 1))
;; TODO: don't use this, simply define the tests manually. Gives more
;; control and less magic
(defmacro sp-test-command (command examples)
"Define a series of tests for COMMAND using EXAMPLES.
EXAMPLES is a list of (LETBINDINGS TESTCASES...)
LETBINDINGS takes the same form as bindings to `let', but
additionally the symbol mode can be used to set the major mode.
TESTCASES is a list of strings:
\(initial-state state-after-1-call state-after-2-calls...)
that are used to test the resulting state after running the
command. Each string must contain | to specify where point should
be."
(declare (indent 1))
(let* ((group-index 0)
(forms
(-mapcat
(lambda (example-group)
(setq group-index (1+ group-index))
(let ((example-index 0))
(mapcar
(lambda (test-sequence)
(setq example-index (1+ example-index))
`(ert-deftest
,(intern (concat "sp-test-command-"
(symbol-name command)
"-"
(number-to-string group-index)
"-"
(number-to-string example-index)
)) ()
(let ,(car example-group)
(sp--test-command ',command ',(list test-sequence)))))
(cdr example-group))))
examples)))
`(progn ,@forms)))
(defun sp--test-command (command examples)
"Run the test for COMMAND."
;; TODO: get rid of this
(unless (and (boundp 'mode)
(eq mode 'racket))
(shut-up
(cl-dolist (example examples)
(let ((before (car example)))
(cl-dolist (expected (cdr example))
(with-temp-buffer
(sp-test-command-setup)
(insert before)
(goto-char (point-min))
(search-forward "|")
(delete-char -1)
(call-interactively command)
(insert "|")
(cond
((eq expected 'error)
(should (equal before (buffer-string))))
((stringp expected)
(should (equal expected (buffer-string)))))
(setq before expected))))))))
(sp-test-command sp-forward-sexp
((nil
("|foo" "foo|")
("|foo bar" "foo| bar" "foo bar|")
;; test movement over comments
("|(foo)\nbar ;; baz (foo) baz\n(quux)"
"(foo)|\nbar ;; baz (foo) baz\n(quux)"
"(foo)\nbar| ;; baz (foo) baz\n(quux)"
"(foo)\nbar ;; baz (foo) baz\n(quux)|")
("(foo)\nbar ;; |baz (foo) baz\n(quux)"
"(foo)\nbar ;; baz| (foo) baz\n(quux)"
"(foo)\nbar ;; baz (foo)| baz\n(quux)"
"(foo)\nbar ;; baz (foo) baz|\n(quux)")
;; @{ paredit tests
("|" "|")
("|()" "()|" "()|")
("(|)" "()|" "()|")
("()|" "()|")
("|( )" "( )|" "( )|")
("(| )" "( )|" "( )|")
("( |)" "( )|" "( )|")
("( )|" "( )|")
("|\"\"" "\"\"|" "\"\"|")
("\"|\"" "\"\"|" "\"\"|")
("\"\"|" "\"\"|")
("|\")\"" "\")\"|" "\")\"|")
;; ("\"|)\"" "\")|\"" "\")\"|" "\")\"|")
("\")|\"" "\")\"|" "\")\"|")
("\")\"|" "\")\"|")
("|\"()\"" "\"()\"|" "\"()\"|")
("\"|()\"" "\"()|\"" "\"()\"|" "\"()\"|")
("\"(|)\"" "\"()|\"" "\"()\"|" "\"()\"|")
("\"()\"|" "\"()\"|")
("|(\"x\" \"y\")" "(\"x\" \"y\")|" "(\"x\" \"y\")|")
("(|\"x\" \"y\")" "(\"x\"| \"y\")" "(\"x\" \"y\"|)"
"(\"x\" \"y\")|" "(\"x\" \"y\")|")
("(\"|x\" \"y\")" "(\"x|\" \"y\")" "(\"x\"| \"y\")" "(\"x\" \"y\"|)"
"(\"x\" \"y\")|" "(\"x\" \"y\")|")
("(\"x|\" \"y\")" "(\"x\"| \"y\")" "(\"x\" \"y\"|)"
"(\"x\" \"y\")|" "(\"x\" \"y\")|")
("(\"x\"| \"y\")" "(\"x\" \"y\"|)" "(\"x\" \"y\")|" "(\"x\" \"y\")|")
("(\"x\" |\"y\")" "(\"x\" \"y\"|)" "(\"x\" \"y\")|" "(\"x\" \"y\")|")
("(\"x\" \"|y\")" "(\"x\" \"y|\")" "(\"x\" \"y\"|)"
"(\"x\" \"y\")|" "(\"x\" \"y\")|")
("(\"x\" \"y|\")" "(\"x\" \"y\"|)" "(\"x\" \"y\")|" "(\"x\" \"y\")|")
("(\"x\" \"y\"|)" "(\"x\" \"y\")|" "(\"x\" \"y\")|")
("(\"x\" \"y\")|" "(\"x\" \"y\")|")
;; @}
)
(((current-prefix-arg 2))
("|foo bar" "foo bar|")
("|(foo bar) baz" "(foo bar) baz|"))))
(sp-test-command sp-backward-sexp
((nil
("foo|" "|foo")
("foo bar|" "foo |bar" "|foo bar")
;; test movement over comments
("(foo)\nbar ;; baz (foo) baz\n(quux)|"
"(foo)\nbar ;; baz (foo) baz\n|(quux)"
"(foo)\n|bar ;; baz (foo) baz\n(quux)"
"|(foo)\nbar ;; baz (foo) baz\n(quux)")
("(foo)\nbar ;; baz (foo) baz|\n(quux)"
"(foo)\nbar ;; baz (foo) |baz\n(quux)"
"(foo)\nbar ;; baz |(foo) baz\n(quux)"
"(foo)\nbar ;; |baz (foo) baz\n(quux)")
;; @{paredit tests
("|" "|")
("|()" "|()")
("(|)" "|()" "|()")
("()|" "|()" "|()")
("|( )" "|( )")
("(| )" "|( )" "|( )")
("( |)" "|( )" "|( )")
("( )|" "|( )" "|( )")
("|\"\"" "|\"\"")
("\"|\"" "|\"\"" "|\"\"")
("\"\"|" "|\"\"" "|\"\"")
("|\")\"" "|\")\"")
("\"|)\"" "|\")\"" "|\")\"")
;; ("\")|\"" "|\")\"" "|\")\"")
("\")\"|" "|\")\"" "|\")\"")
("|\"()\"" "|\"()\"")
("\"|()\"" "|\"()\"" "|\"()\"")
("\"(|)\"" "\"|()\"" "|\"()\"" "|\"()\"")
("\"()\"|" "|\"()\"" "|\"()\"")
("|(\"x\" \"y\")" "|(\"x\" \"y\")")
("(|\"x\" \"y\")" "|(\"x\" \"y\")" "|(\"x\" \"y\")")
("(\"|x\" \"y\")" "(|\"x\" \"y\")" "|(\"x\" \"y\")" "|(\"x\" \"y\")")
("(\"x|\" \"y\")" "(\"|x\" \"y\")" "(|\"x\" \"y\")"
"|(\"x\" \"y\")" "|(\"x\" \"y\")")
("(\"x\"| \"y\")" "(|\"x\" \"y\")" "|(\"x\" \"y\")" "|(\"x\" \"y\")")
("(\"x\" |\"y\")" "(|\"x\" \"y\")" "|(\"x\" \"y\")" "|(\"x\" \"y\")")
("(\"x\" \"|y\")" "(\"x\" |\"y\")" "(|\"x\" \"y\")"
"|(\"x\" \"y\")" "|(\"x\" \"y\")")
("(\"x\" \"y|\")" "(\"x\" \"|y\")" "(\"x\" |\"y\")" "(|\"x\" \"y\")"
"|(\"x\" \"y\")" "|(\"x\" \"y\")")
("(\"x\" \"y\"|)" "(\"x\" |\"y\")" "(|\"x\" \"y\")"
"|(\"x\" \"y\")" "|(\"x\" \"y\")")
("(\"x\" \"y\")|" "|(\"x\" \"y\")" "|(\"x\" \"y\")")
;; @}
)))
(sp-test-command sp-forward-symbol
((nil
("|foo bar" "foo| bar" "foo bar|"))
(((mode 'clojure))
("|(map #(identity) {:a 1})"
"(map| #(identity) {:a 1})"
"(map #(identity|) {:a 1})"
"(map #(identity) {:a| 1})"
"(map #(identity) {:a 1|})"))))
(sp-test-command sp-forward-parallel-sexp
((nil
("|foo" "foo|")
("foo|" "foo|")
("|foo bar" "foo| bar" "foo bar|")
("(|foo bar)" "(foo| bar)" "(foo bar|)" "(foo| bar)")
("(foo| bar baz)" "(foo bar| baz)" "(foo bar baz|)" "(foo| bar baz)" )
("(|foo)" "(foo|)" "(foo|)")
)
(((current-prefix-arg 2))
("|foo bar" "foo bar|")
("|(foo bar) baz" "(foo bar) baz|")
("(foo| bar) baz" "(foo| bar) baz")
)
))
(sp-test-command sp-backward-parallel-sexp
((nil
("foo|" "|foo")
("|foo" "|foo")
("foo bar|" "foo |bar" "|foo bar")
("(foo bar|)" "(foo |bar)" "(|foo bar)" "(foo |bar)")
("(foo| bar baz)" "(|foo bar baz)" "(foo bar |baz)" "(foo |bar baz)" )
("(foo|)" "(|foo)" "(|foo)")
)
(((current-prefix-arg 2))
("foo bar|" "|foo bar")
("(foo bar) baz|" "|(foo bar) baz")
("(foo |bar) baz" "(foo |bar) baz")
)
))
(sp-test-command sp-forward-slurp-sexp
((nil
;; beware, this also tests the reindenting/cleanup!!!
("(f|oo)\nbar ;; baz (foo) baz\n(quux)"
"(f|oo\n bar) ;; baz (foo) baz\n(quux)"
"(f|oo\n bar ;; baz (foo) baz\n (quux))")
("(foo)\nbar ;; baz (f|oo) baz\n(quux)"
"(foo)\nbar ;; baz (f|oo baz)\n(quux)")
;; #1010
("(foo (baz|) ;; bar\n moo\n mee)"
"(foo (baz| ;; bar\n moo)\n mee)"
"(foo (baz| ;; bar\n moo\n mee))")
("(foo (gah|) ?\\; bar baz)"
"(foo (gah| ?\\;) bar baz)"
"(foo (gah| ?\\; bar) baz)")
;; do not slurp outside of comment
("(foo)\nbar ;; (|foo) baz\n(asd)\n\n"
"(foo)\nbar ;; (|foo baz)\n(asd)\n\n"
"(foo)\nbar ;; (|foo baz)\n(asd)\n\n"))
(((current-prefix-arg '(4)))
("[(fo|o) bar baz]" "[(fo|o bar baz)]")
("((progn| bar (baz) (baz)))" "((progn| bar (baz) (baz)))"))
(((mode 'c))
("int funct() { int |foo =} bar;" "int funct() { int |foo = bar;}")
("int funct() { int |foo =}; bar" "int funct() { int |foo = bar};")
("int funct() { int |foo =}; bar;" "int funct() { int |foo = bar;};"))
(((mode 'racket)
(sp-sexp-prefix '((racket-mode regexp "#?['`,]@?"))))
("(f|oo) #'(bar)" "(f|oo #'(bar))"))
(((sp-sexp-prefix '((emacs-lisp-mode regexp "\\(?:['`]*,@?\\|[',`]\\)"))))
("(fo|o) `',(bar)" "(fo|o `',(bar))")
("(fo|o) ,@(bar)" "(fo|o ,@(bar))"))
(((mode 'clojure))
;; was sp-test-clojure-slurp-with-prefix
("(foo|) #{...}" "(foo| #{...})")
("(foo|) ^{:a 1}" "(foo| ^{:a 1})")
("(foo|) #(xyzzy 1 2 %)" "(foo| #(xyzzy 1 2 %))")
("(foo|) #_(comment reader macro)" "(foo| #_(comment reader macro))")
("(foo|) ~unquote-me" "(foo| ~unquote-me)")
("(foo|) `~'unquote-me" "(foo| `~'unquote-me)")
("(foo|) ~@(splice-me)" "(foo| ~@(splice-me))")
("(foo|) `(quote-me)" "(foo| `(quote-me))")
("(foo|) @(deref-me)" "(foo| @(deref-me))")
("(foo|) @deref-me" "(foo| @deref-me)")
("(foo|) #?@(:clj [3 4] :cljs [5 6])" "(foo| #?@(:clj [3 4] :cljs [5 6]))")
("(foo|) #?(:clj Double/NaN\n :cljs js/NaN\n :default nil)"
;; longer because slurp causes "autoformat"
"(foo| #?(:clj Double/NaN\n :cljs js/NaN\n :default nil))"))))
(sp-test-command sp-backward-slurp-sexp
((nil
;; beware, this also tests the reindenting/cleanup!!!
("(foo)\nbar ;; baz (foo) baz\n(qu|ux)"
"(foo)\n(bar ;; baz (foo) baz\n qu|ux)"
"((foo)\n bar ;; baz (foo) baz\n qu|ux)")
("(foo)\nbar ;; baz (f|oo) baz\n(quux)"
"(foo)\nbar ;; (baz f|oo) baz\n(quux)")
;; do not slurp outside of comment
("(foo)\nbar ;; baz (foo|)\n(asd)\n\n"
"(foo)\nbar ;; (baz foo|)\n(asd)\n\n"
"(foo)\nbar ;; (baz foo|)\n(asd)\n\n"))
(((sp-sexp-prefix '((emacs-lisp-mode regexp "\\(?:['`]*,@?\\|[',`]\\)"))))
("(foo `',(b|ar))" "(`',(foo b|ar))")
("(foo ,@(b|ar))" "(,@(foo b|ar))"))))
(sp-test-command sp-forward-barf-sexp
((nil
;; beware, this also tests the reindenting/cleanup!!!
("(f|oo\n bar ;; baz (foo) baz\n (quux))"
"(f|oo\n bar) ;; baz (foo) baz\n(quux)"
"(f|oo)\nbar ;; baz (foo) baz\n(quux)")
("(foo)\nbar ;; baz (f|oo baz)\n(quux)"
"(foo)\nbar ;; baz (f|oo) baz\n(quux)"))
(((mode 'clojure))
("(|#{...})" "(|)#{...}")
("(|#(xyzzy 1 2 %))" "(|)#(xyzzy 1 2 %)")
("(|#_(comment reader macro))" "(|)#_(comment reader macro)")
("(|#?@(:clj [3 4] :cljs [5 6]))" "(|)#?@(:clj [3 4] :cljs [5 6])")
("(|#?(:clj Double/NaN
:cljs js/NaN
:default nil))"
"(|)#?(:clj Double/NaN\n :cljs js/NaN\n :default nil)"))
(((mode 'racket)
(sp-sexp-prefix '((racket-mode regexp "#?['`,]@?"))))
("(f|oo #'(bar))" "(f|oo) #'(bar)"))))
(sp-test-command sp-backward-barf-sexp
((nil
;; beware, this also tests the reindenting/cleanup!!!
("((foo)\n bar ;; baz (foo) baz\n qu|ux)"
"(foo)\n(bar ;; baz (foo) baz\n qu|ux)"
"(foo)\nbar ;; baz (foo) baz\n(qu|ux)")
("(foo)\nbar ;; (baz f|oo) baz\n(quux)"
"(foo)\nbar ;; baz (f|oo) baz\n(quux)"))))
(sp-test-command sp-splice-sexp
((nil
("|(f (g\n h))" error)
("(|f (g\n h))" "|f (g\n h)")
("(f| (g\n h))" "f| (g\n h)")
("(f |(g\n h))" "f |(g\n h)")
("(f (|g\n h))" "(f |g\n h)")
("(f (g|\n h))" "(f g|\n h)")
("(f (g\n| h))" "(f g\n| h)")
("(f (g\n | h))" "(f g\n | h)")
("(f (g\n | h))" "(f g\n | h)")
("(f (g\n | h))" "(f g\n |h)")
("(f (g\n |h))" "(f g\n |h)")
("(f (g\n h|))" "(f g\n h|)")
("(f (g\n h)|)" "f (g\n h)|")
("(f (g\n h))|" error)
;; Omit whitespace if appropriate.
("|(f (\n h))" error)
("(|f (\n h))" "|f (\n h)")
("(f| (\n h))" "f| (\n h)")
("(f |(\n h))" "f |(\n h)")
("(f (|\n h))" "(f |\n h)")
("(f (\n| h))" "(f \n| h)")
("(f (\n | h))" "(f \n |h)")
("(f (\n | h))" "(f \n |h)")
("(f (\n | h))" "(f \n |h)")
("(f (\n |h))" "(f \n |h)")
("(f (\n h|))" "(f \n h|)")
("(f (\n h)|)" "f (\n h)|")
("(f (\n h))|" error)
;; But leave comments intact.
("(f (| ;xy\n h))" "(f | ;xy\n h)")
("(f ( | ;xy\n h))" "(f | ;xy\n h)")
("(f ( | ;xy\n h))" "(f | ;xy\n h)")
("(f ( |;xy\n h))" "(f |;xy\n h)")
("(f ( ;|xy\n h))" "(f ;|xy\n h)")
("(f ( ;x|y\n h))" "(f ;x|y\n h)")
("(f ( ;xy|\n h))" "(f ;xy|\n h)")
("(f ( ;xy\n| h))" "(f ;xy\n| h)")
("(f ( ;xy\n | h))" "(f ;xy\n |h)")
("(f ( ;xy\n | h))" "(f ;xy\n |h)")
("(f ( ;xy\n | h))" "(f ;xy\n |h)")
("(f ( ;xy\n |h))" "(f ;xy\n |h)")
("(f ( ;xy\n h|))" "(f ;xy\n h|)")
;; Don't touch indentation outside a limited scope.
("(foo (|bar)\n baz)" "(foo |bar\n baz)")
("(foo (b|ar)\n baz)" "(foo b|ar\n baz)")
("(foo (ba|r)\n baz)" "(foo ba|r\n baz)")
("(foo (bar|)\n baz)" "(foo bar|\n baz)")
(" (foo\n (|bar baz))" " (foo\n |bar baz)")
(" (foo\n (b|ar baz))" " (foo\n b|ar baz)")
(" (foo\n (ba|r baz))" " (foo\n ba|r baz)")
(" (foo\n (bar| baz))" " (foo\n bar| baz)")
(" (foo\n (bar |baz))" " (foo\n bar |baz)")
(" (foo\n (bar b|az))" " (foo\n bar b|az)")
(" (foo\n (bar ba|z))" " (foo\n bar ba|z)")
(" (foo\n (bar baz|))" " (foo\n bar baz|)")
(" (foo (|(bar\n baz)\n quux)\n zot)"
"(foo |(bar\n baz)\n quux\n zot)")
(" (foo ((bar\n b|az)\n quux)\n zot)"
"(foo (bar\n b|az\n quux)\n zot)"))))
(sp-test-command sp-splice-sexp-killing-backward
((nil
("(\n ;; foo bar\n asd\n as\n ;; asds (asdasd asd hgujirjf) asd\n a|sd\n )" "|asd")
;; if we are in front of a comment which is on a separate line,
;; keep it as it most likely pertains to the line after
("(\n ;; foo bar\n asd\n as\n |;; asds (asdasd asd hgujirjf) asd\n asd\n )" "|;; asds (asdasd asd hgujirjf) asd\nasd")
("(\n ;; foo bar\n asd\n as\n ;; as|ds (asdasd asd hgujirjf) asd\n asd\n )" "|;; asds (asdasd asd hgujirjf) asd\nasd")
;; valid sexps inside comments should be treated as such
("(\n ;; foo bar\n asd\n as\n ;; asds (asdasd asd |hgujirjf) asd\n asd\n )" "(\n ;; foo bar\n asd\n as\n ;; asds |hgujirjf asd\n asd\n )")
;; if first "form" is a comment, keep it
("(\n | ;; foo bar\n asd\n as\n ;; asds (asdasd asd hgujirjf) asd\n asd\n )" "|;; foo bar\nasd\nas\n;; asds (asdasd asd hgujirjf) asd\nasd")
;; keep comment before the form from which we are splicing if it is on a separate line
("(\n ;; foo bar\n |asd\n as\n ;; asds (asdasd asd hgujirjf) asd\n asd\n )" "|;; foo bar\nasd\nas\n;; asds (asdasd asd hgujirjf) asd\nasd")
("(\n ;; foo bar\n asd\n as\n ;; asds (asdasd asd hgujirjf) asd\n |asd\n )" "|;; asds (asdasd asd hgujirjf) asd\nasd")
;; when at the end of the expression, kill entire expression
("(asdad asd (some-func) asdasd|)" "|")
("(asdad asd (some-func) asdasd| )" "|")
("(asdad asd (some-func) asdasd |)" "|")
("(asdad asd (some-func) asdasd | )" "|")
("foo (asdad asd (some-func) asdasd|)" "foo |")
("foo (asdad asd (some-func) asdasd|) bar" "foo | bar")
;; when there is a comment before the parent sexp and we are at
;; the beginning, the comment shouldn't play any role
(";; foo bar\n\n(|foo bar baz)" ";; foo bar\n\n|foo bar baz")
)))
(sp-test-command sp-splice-sexp-killing-around
((nil
("(\n ;; foo bar\n asd\n as\n ;; asds (asdasd asd hgujirjf) asd\n a|sd\n )" "|asd")
;; if we are in front of a comment which is on a separate line,
;; keep it as it most likely pertains to the line after
("(\n ;; foo bar\n asd\n as\n |;; asds (asdasd asd hgujirjf) asd\n asd\n )" "|;; asds (asdasd asd hgujirjf) asd\nasd")
("(\n ;; foo bar\n asd\n as\n ;; as|ds (asdasd asd hgujirjf) asd\n asd\n )" "|;; asds (asdasd asd hgujirjf) asd\nasd")
;; valid sexps inside comments should be treated as such
("(\n ;; foo bar\n asd\n as\n ;; asds (asdasd asd |hgujirjf) asd\n asd\n )" "(\n ;; foo bar\n asd\n as\n ;; asds |hgujirjf asd\n asd\n )")
;; if first "form" is a comment, keep it
("(\n | ;; foo bar\n asd\n as\n ;; asds (asdasd asd hgujirjf) asd\n asd\n )" "|;; foo bar\nasd")
;; keep comment before the form from which we are splicing if it is on a separate line
("(\n ;; foo bar\n |asd\n as\n ;; asds (asdasd asd hgujirjf) asd\n asd\n )" "|;; foo bar\nasd")
("(\n ;; foo bar\n asd\n as\n ;; asds (asdasd asd hgujirjf) asd\n |asd\n )" "|;; asds (asdasd asd hgujirjf) asd\nasd")
;; from #243
(";; \"quote\" here\nand \"|here\"" ";; \"quote\" here\nand |here")
(";; \"|quote\" here\nand here" ";; |quote here\nand here")
;; from #580
("(foo \"|bar\")" "(foo |bar)")
;; from #569
("(\" \" f|oo)" "|foo")
("(\" \" |foo)" "|foo")
("(\"x\" |foo)" "|foo")
)))
(sp-test-command sp-split-sexp
((nil
("(foo |bar baz)" "(foo) |(bar baz)")
("(foo bar|)" "(foo bar)|()")
("\"foo |bar baz\"" "\"foo \"|\"bar baz\"")
("\"foo bar|\"" "\"foo bar\"|\"\"")
("\"(foo |bar) baz\"" "\"(foo \"|\"bar) baz\"")
)
(((mode 'python))
("\"foo |bar baz\"" "\"foo \"|\"bar baz\"")
("'foo |bar baz'" "'foo '|'bar baz'")
("'foo bar|'" "'foo bar'|''")
("\"\"\"foo|bar\"\"\"" "\"\"\"foo\"\"\"|\"\"\"bar\"\"\"")
)
(((sp-split-sexp-always-split-as-string nil))
("\"foo |bar baz\"" "\"foo\" |\"bar baz\"")
("\"foo bar|\"" "\"foo bar\"|\"\"")
("\"(foo |bar) baz\"" "\"(foo) |(bar) baz\"")
)
(((current-prefix-arg '(4)))
("(foo |bar baz)" "(foo) |(bar) (baz)")
("\"foo |bar baz\"" "\"foo\" |\"bar\" \"baz\""))))
(sp-test-command sp-extract-before-sexp
((nil
("(foo\n |bar\n baz\n )" "|bar\n(foo\n baz\n )")
("(foo\n |bar\n baz)" "|bar\n(foo\n baz)")
("(foo\n bar\n |baz\n )" "|baz\n(foo\n bar\n )")
("(foo\n bar\n |baz)" "|baz\n(foo\n bar)"))))
(sp-test-command sp-extract-after-sexp
((nil
("(foo\n |bar\n baz\n )" "(foo\n baz\n )\nbar|")
("(foo\n |bar\n baz)" "(foo\n baz)\nbar|")
("(foo\n bar\n |baz\n )" "(foo\n bar\n )\nbaz|")
("(foo\n bar\n |baz)" "(foo\n bar)\nbaz|"))))
(sp-test-command sp-join-sexp
((nil
("(foo bar) |(baz)" "(foo bar |baz)")
("[foo bar] |[baz]" "[foo bar |baz]")
("(foo bar) |[baz]" error))
(((current-prefix-arg 2))
("(foo) |(bar) (baz)" "(foo |bar baz)")
("[foo] |[bar] [baz]" "[foo |bar baz]")
("(foo) |[bar] [baz]" error))
(((current-prefix-arg '(4)))
("(foo bar (baz)| (quux) (blob bluq))" "(foo bar (baz| quux blob bluq))"))))
(sp-test-command sp-kill-word
((nil
("| 'foo-bar-baz" "|-bar-baz")
("|'foo-bar-baz" "|-bar-baz")
("'|foo-bar-baz" "'|-bar-baz")
("'f|oo-bar-baz" "'f|-bar-baz")
("'foo-|bar-baz" "'foo-|-baz")
("|(foo-bar-baz)" "(|-bar-baz)")
("foo|: (foo-bar-baz)" "foo| (foo-bar-baz)" "foo (|-bar-baz)")
("foo|: bar (foo-bar-baz)" "foo| (foo-bar-baz)" "foo (|-bar-baz)")
("(foo-bar-baz|) foo" "(foo-bar-baz) |")
)
(((mode 'clojure))
("|(-> (first (secord)))" "(| (first (secord)))" "( (| (secord)))" "( ( (|)))")
("(|-> (first (secord)))" "(| (first (secord)))"))))
(sp-test-command sp-backward-kill-word
((nil
("'foo-bar-baz |" "'foo-bar-|" "'foo-|" "'|")
("'foo-|bar-baz" "'|bar-baz")
("'foo|-bar-baz" "'|-bar-baz")
("'f|oo-bar-baz" "'|oo-bar-baz")
("'foo-b|ar-baz" "'foo-|ar-baz")
("(foo-bar-baz)|" "(foo-bar-|)")
("(foo-bar-baz) :|foo" "(foo-bar-baz) |foo")
("(foo-bar-baz) asd :|foo" "(foo-bar-baz) |foo")
("foo (|foo-bar-baz)" "|(foo-bar-baz)")
)
(((mode 'md))
("foo bar;|" "foo |")
("foo bar; |" "foo |")
("foo ;ba|r" "foo ;|r" "|r")
("(foo) ;|bar" "(|) ;bar" )
)
(((mode 'js))
("foo bar;|" "foo |")
("foo bar; |" "foo |")
("foo ;ba|r" "foo ;|r" "|r")
("(foo) ;|bar" "(|) ;bar" )
)
(((mode 'clojure))
("(-> (first (secord)))|" "(-> (first (|)))" "(-> (| ()))" "(| ( ()))")
("(-> |(first (secord)))" "(|(first (secord)))"))))
(sp-test-command sp-backward-kill-symbol
((nil
("'foo-bar-baz |" "|")
("'foo-|bar-baz" "|")
("'foo|-bar-baz" "|")
("'f|oo-bar-baz" "|")
("'foo-b|ar-baz" "|")
("(foo-bar-baz)|" "(|)")
("(foo-bar-baz) :|foo" "(foo-bar-baz) |")
("foo (|foo-bar-baz)" "|(foo-bar-baz)")
)
))
;; #936
(ert-deftest sp-test-command-sp-backward-delete-kill-word-obeys-indent-line-function ()
(sp-test-with-temp-buffer "foo\nbar baz|"
(progn
(smartparens-strict-mode 1)
(setq indent-line-function 'insert-tab))
(sp-backward-kill-word 1)
(sp-buffer-equals "foo\nbar |")))
(sp-test-command sp-kill-symbol
((nil
("| 'foo-bar-baz" "|")
("|'foo-bar-baz" "|")
("'|foo-bar-baz" "'|")
("'f|oo-bar-baz" "'|")
("'foo-|bar-baz" "'|"))))
(sp-test-command sp-up-sexp
((nil
("(;; foo\n b|ar\n baz\n )" "(;; foo\n bar\n baz)|")
("(;; foo\n b|ar\n baz\n ;; foo\n )" "(;; foo\n bar\n baz\n ;; foo\n )|")
;; #446
("(define-key smartparens-mode-map (kbd | \"C-(\") 'sp-down-sexp)" "(define-key smartparens-mode-map (kbd \"C-(\")| 'sp-down-sexp)" )
("(define-key smartparens-mode-map (kbd | \"C-[\") 'sp-up-sexp)" "(define-key smartparens-mode-map (kbd \"C-[\")| 'sp-up-sexp)" )
("(define-key smartparens-mode-map (kbd | \"C-{\") 'sp-beginning-of-next-sexp)" "(define-key smartparens-mode-map (kbd \"C-{\")| 'sp-beginning-of-next-sexp)")
;; #616
("\"[\t| ]\"" "\"[\t ]|\"")
("\"[\t ]| \"" "\"[\t ]\"|"))
(((current-prefix-arg -1))
("(\n b|ar\n baz)" "|(bar\n baz)")
("(;; foo\n b|ar\n baz)" "|(;; foo\n bar\n baz)")
("(`|(depends-on ,pkg))" "|(`(depends-on ,pkg))")
("(,@|(depends-on ,pkg))" "|(,@(depends-on ,pkg))"))))
(sp-test-command sp-down-sexp
((((mode 'python))
("\"foo bar| 'baz qux' fux\"" "\"foo bar '|baz qux' fux\"")
("\"foo |bar 'baz qux' fux\"" "\"foo bar '|baz qux' fux\"")
("\"foo |bar [baz qux] fux\"" "\"foo bar [|baz qux] fux\""))))
(sp-test-command sp-backward-down-sexp
((((mode 'python))
("\"foo bar 'baz qux' |fux\"" "\"foo bar 'baz qux|' fux\"")
("\"foo bar 'baz qux' fux| bla\"" "\"foo bar 'baz qux|' fux bla\"")
("\"foo bar [baz qux] fux| bla\"" "\"foo bar [baz qux|] fux bla\""))))
(sp-test-command sp-end-of-sexp
((nil
;; #446
("(define-key smartparens-mode-map (kbd | \"C-(\") 'sp-down-sexp)" "(define-key smartparens-mode-map (kbd \"C-(\"|) 'sp-down-sexp)" )
("(define-key smartparens-mode-map (kbd | \"C-[\") 'sp-up-sexp)" "(define-key smartparens-mode-map (kbd \"C-[\"|) 'sp-up-sexp)" )
("(define-key smartparens-mode-map (kbd | \"C-{\") 'sp-beginning-of-next-sexp)" "(define-key smartparens-mode-map (kbd \"C-{\"|) 'sp-beginning-of-next-sexp)" ))))
(sp-test-command sp-beginning-of-sexp
((nil
;; #446
("(define-key smartparens-mode-map (kbd | \"C-(\") 'sp-down-sexp)" "(define-key smartparens-mode-map (|kbd \"C-(\") 'sp-down-sexp)" )
("(define-key smartparens-mode-map (kbd | \"C-[\") 'sp-up-sexp)" "(define-key smartparens-mode-map (|kbd \"C-[\") 'sp-up-sexp)" )
("(define-key smartparens-mode-map (kbd | \"C-{\") 'sp-beginning-of-next-sexp)" "(define-key smartparens-mode-map (|kbd \"C-{\") 'sp-beginning-of-next-sexp)" ))))
(sp-test-command backward-delete-char
((nil
(";;asdas'|\n'asdasd'" ";;asdas|\n'asdasd'")
("foo \"|\" bar" "foo | bar")
("foo [|] bar" "foo | bar")
("foo \\{|\\} bar" "foo | bar")
(";;foo \\{|\\}\nbar" ";;foo |\nbar"))))
(sp-test-command sp-comment
((((sp-comment-string '(((emacs-lisp-mode) . ";; "))))
;; don't do magic inside strings or commends
(";; | asd" ";; ;| asd")
(";; (asd|\nbar)" ";; (asd;|\nbar)")
("\"| asd\"" "\";| asd\"")
("\"(asd|\nbar)\"" "\"(asd;|\nbar)\"")
("|asd" ";; |asd")
("|(asd asd)" ";; |(asd asd)")
("(asd| asd)" "(asd ;; | asd\n )")
("(asd |asd)" "(asd ;; |asd\n )")
("|(foo\n bar)" ";; |\n(foo\n bar)")
("(foo|\n bar)" "(foo ;; |\n bar)")
("(foo\n bar|)" "(foo\n bar ;; |\n )")
("(foo\n bar| )" "(foo\n bar ;; |\n )")
("(foo\n bar | )" "(foo\n bar ;; |\n )")
("(foo\n |(bar ) )" "(foo\n ;; |(bar )\n )")
("(foo\n (bar| ) )" "(foo\n (bar ;; |\n ) )")
("(foo\n (bar |) )" "(foo\n (bar ;; |\n ) )")
("(foo\n (bar )| )" "(foo\n (bar ) ;; |\n )")
("(foo\n (bar ) |)" "(foo\n (bar ) ;; |\n )")
;; clean up hanging whitespace
("(foo\n |bar (baz\n qux))" "(foo\n ;; |bar\n (baz\n qux))")
("(foo\n bar| (baz\n qux))" "(foo\n bar ;; |\n (baz\n qux))")
("(foo\n bar |(baz\n qux))" "(foo\n bar ;; |\n (baz\n qux))")
("(foo\n bar (baz\n |qux))" "(foo\n bar (baz\n ;; |qux\n ))"))))
(sp-test-command sp-kill-sexp
((nil
("(foo |(abc) bar)" "(foo | bar)"))
(((current-prefix-arg 2))
("(foo (bar) | baz)" "|"))
(((current-prefix-arg '(16)))
("(foo |(bar) baz)" "|"))
(((current-prefix-arg '(4)))
("(1 |2 3 4 5 6)" "(1|)"))
(((current-prefix-arg 3))
("(1 |2 3 4 5 6)" "(1 | 5 6)"))
(((current-prefix-arg -2))
("(1 2 3 4 5| 6)" "(1 2 3 | 6)"))
(((current-prefix-arg '(-4)))
("(1 2 3 4| 5 6)" "(|5 6)"))
(((current-prefix-arg '(4)))
("(1 2 | )" "(1 2|)"))
(((current-prefix-arg 0))
("(1 2 3 |4 5 6)" "(|)"))
(((mode 'python)
(current-prefix-arg -1))
("x - |" "|"))))
(sp-test-command sp-backward-delete-char
((nil
("[foo]|" "[foo|]")
("\\{foo\\}|" "\\{foo|\\}")
("\"foo\\\\\"|" "\"foo\\\\|\"")
("(|)" "|"))
(((sp-delete-blank-sexps t))
("[| ]" "|"))))
(ert-deftest sp-test-command-sp-backward-delete-char-hungry-delete-mode ()
"In `hungry-delete-mode' we should kill all whitespace."
(sp-test-with-temp-elisp-buffer "(foo ) |"
(require 'hungry-delete)
(hungry-delete-mode 1)
(sp-backward-delete-char)
(sp-buffer-equals "(foo )|")
(sp-backward-delete-char)
(sp-buffer-equals "(foo |)")
(sp-backward-delete-char)
(sp-buffer-equals "(foo|)")))
(defun sp-test--sp-backward-delete-char-textmode (initial expected &optional n)
(setq n (or n 1))
(let ((sp-pairs '((t . ((:open "\"" :close "\"" :actions (insert wrap autoskip navigate))
(:open "'" :close "'" :actions (insert wrap autoskip navigate)))))))
(sp-test-with-temp-buffer initial
(text-mode)
(sp-backward-delete-char n)
(sp-buffer-equals expected))))
(sp-ert-deftest sp-test-command-sp-backward-delete-char-textmode
(sp-test--sp-backward-delete-char-textmode "foo \"it'| OK\" baz" "foo \"it| OK\" baz")
(sp-test--sp-backward-delete-char-textmode "foo \"|OK\" baz" "foo \"|OK\" baz")
(sp-test--sp-backward-delete-char-textmode "foo \"it's OK\"| baz" "foo \"it's OK|\" baz")
(sp-test--sp-backward-delete-char-textmode "\"this\" doesn'|" "\"this\" doesn|")
(sp-test--sp-backward-delete-char-textmode "\"don't\"|" "|" 7))
(ert-deftest sp-test-command-sp-backward-delete-pair-with-skip-match ()
(let ((sp-pairs '((t . ((:open "`" :close "'" :actions (insert wrap autoskip navigate)
:skip-match (lambda (ms mb me)
(when (equal ms "'")
(save-excursion
(goto-char me)
(looking-at-p "\\sw"))))))))))
(sp-test-with-temp-buffer "`foo'|bar'"
(latex-mode)
(smartparens-strict-mode 1)
(sp-backward-delete-char 1)
(sp-buffer-equals "`foo|bar'"))))
(sp-test-command sp-delete-char
((nil
("|[foo]" "[|foo]")
("|\\{foo\\}" "\\{|foo\\}")
("|\"foo\\\\\"" "\"|foo\\\\\""))))
(ert-deftest sp-test-command-sp-delete-char-hungry-delete-mode ()
"In `hungry-delete-mode' we should kill all whitespace."
(sp-test-with-temp-elisp-buffer "| ( foo)"
(require 'hungry-delete)
(hungry-delete-mode 1)
(sp-delete-char)
(sp-buffer-equals "|( foo)")
(sp-delete-char)
(sp-buffer-equals "(| foo)")
(sp-delete-char)
(sp-buffer-equals "(|foo)")))
(defun sp-test--sp-delete-char-textmode (initial expected)
(sp-test-with-temp-buffer initial
(text-mode)
(sp-delete-char)
(sp-buffer-equals expected)))
(ert-deftest sp-test-command-sp-delete-char-textmode ()
(let ((sp-pairs '((t . ((:open "\"" :close "\"" :actions (insert wrap autoskip navigate))
(:open "'" :close "'" :actions (insert wrap autoskip navigate)))))))
(sp-test--sp-delete-char-textmode "foo \"it|' OK\" baz" "foo \"it| OK\" baz")
(sp-test--sp-delete-char-textmode "foo \"OK|\" baz" "foo \"OK|\" baz")
(sp-test--sp-delete-char-textmode "foo |\"it's OK\" baz" "foo \"|it's OK\" baz")
(sp-test--sp-delete-char-textmode "foo|'s \"baz bar\" aaa" "foo|s \"baz bar\" aaa")
))
(sp-test-command sp-kill-whole-line
((nil
("(progn (some |long sexp))" "|")
("(progn (some |long sexp))\n" "|")
("(progn\n (some |long sexp))" "(progn\n |)")
("(progn\n | (some\nlong\nsexp))" "(progn\n |)")
("(progn\n (so|me\nlong\nsexp))" "(progn\n |)")
("(progn\n (line|1)\n (line2))" "(progn\n| (line2))")
(" (indented |line)" "|"))))
(sp-test-command sp-transpose-sexp
((nil
;; Preserve whitespace
("foo | bar" "bar foo|")
("(foo bar)|:symbol" ":symbol(foo bar)|")
;; Preserve prefix
("'foo | bar" "bar 'foo|")
(",@(foo bar)| :symbol" ":symbol ,@(foo bar)|")
)
(((mode 'python))
;; Do not drag suffix
("def foo(first, |second):" "def foo(second, first|):"))))
(sp-test-command sp-transpose-hybrid-sexp
((nil
;; Preserve whitespace
("foo bar|\nbaz" "baz\nfoo bar|")
("foo (bas\n bar)|\n(next list)" "(next list)\nfoo (bas\n bar)|"))
;; Do not drag suffix
(((mode 'c))
("void f() {\n int a[] = {\n foo(1,2),|\n bar(3,4)\n }; \n}"
"void f() {\n int a[] = {\n bar(3,4),\n foo(1,2)\n |}; \n}"))))
(sp-test-command sp-change-inner
((nil
("(f|oo [bar] baz)" "(foo [|] baz)"))
(((mode 'js))
("{|'foo': 'bar'}" "{'|': 'bar'}"))))
(sp-test-command sp-clone-sexp
((nil
;; from #938 later in the thread
("|(foo (bar) baz)" "(foo (bar) baz)\n|(foo (bar) baz)")
("(foo |(bar) baz)" "(foo (bar)\n |(bar) baz)")
("(foo (bar) |baz)" "(foo (bar) baz)\n(foo (bar) |baz)")
("(foo (bar) baz)|" "(foo (bar) baz)|")
("(foo (bar)| 'baz 'qux)" "(foo (bar) 'baz 'qux)\n(foo (bar)| 'baz 'qux)")
("(foo (bar) 'baz '|qux)" "(foo (bar) 'baz 'qux)\n(foo (bar) 'baz '|qux)")
;; from #938 OP
("(defun my-smartparens-hook ()
(setq sp-base-key-bindings 'paredit)
(define-key smartparens-|mode-map (kbd \"C-, C-y\") #'sp-clone-sexp)
(define-key smartparens-mode-map (kbd \"C-k\") #'kill-sexp)
(define-key smartparens-mode-map (kbd \"C-M-t\") #'sp-transpose-sexp)
)" "(defun my-smartparens-hook ()
(setq sp-base-key-bindings 'paredit)
(define-key smartparens-mode-map (kbd \"C-, C-y\") #'sp-clone-sexp)
(define-key smartparens-|mode-map (kbd \"C-, C-y\") #'sp-clone-sexp)
(define-key smartparens-mode-map (kbd \"C-k\") #'kill-sexp)
(define-key smartparens-mode-map (kbd \"C-M-t\") #'sp-transpose-sexp)
)"))))
(defun sp--test-sp-rewrap-sexp (initial pair expected &optional keep)
(sp-test-with-temp-elisp-buffer initial
(sp-rewrap-sexp pair keep)
(insert "|")
(should (equal (buffer-string) expected))))
(defun sp--test-sp-rewrap-sexp-python (initial pair expected &optional keep)
(sp-test-with-temp-buffer initial
(python-mode)
(sp-rewrap-sexp pair keep)
(insert "|")
(should (equal (buffer-string) expected))))
(ert-deftest sp-test-command-sp-rewrap-sexp ()
(sp--test-sp-rewrap-sexp "[f|oo]" '("(" . ")") "(f|oo)")
(sp--test-sp-rewrap-sexp "{f|oo}" '("(" . ")") "(f|oo)")
(sp--test-sp-rewrap-sexp "\"f|oo\"" '("(" . ")") "(f|oo)")
(sp--test-sp-rewrap-sexp "(f|oo)" '("[" . "]") "[f|oo]")
(sp--test-sp-rewrap-sexp "(f|oo)" '("\\{" . "\\}") "\\{f|oo\\}")
(sp--test-sp-rewrap-sexp "(f|oo)" '("\"" . "\"") "\"f|oo\"")
(sp--test-sp-rewrap-sexp "[f|oo]" '("(" . ")") "([f|oo])" :keep)
(sp--test-sp-rewrap-sexp "(f|oo)" '("[" . "]") "[(f|oo)]" :keep)
(sp--test-sp-rewrap-sexp "\\{f|oo\\}" '("[" . "]") "[\\{f|oo\\}]" :keep)
(sp--test-sp-rewrap-sexp "[f|oo]" '("\\{" . "\\}") "\\{[f|oo]\\}" :keep))
(ert-deftest sp-test-command-sp-rewrap-sexp-escape-after-rewrap ()
;; #667
(sp--test-sp-rewrap-sexp "\"foo (b|ar) baz\"" '("\"" . "\"") "\"foo \\\"b|ar\\\" baz\"")
(sp--test-sp-rewrap-sexp "\"foo \\\"b|ar\\\" baz\"" '("(" . ")") "\"foo (b|ar) baz\"")
(sp--test-sp-rewrap-sexp-python "\"foo 'b|ar' baz\"" '("\"" . "\"") "\"foo \\\"b|ar\\\" baz\"")
(sp--test-sp-rewrap-sexp-python "\"foo 'bar' b|az\"" '("'" . "'") "'foo \\'bar\\' b|az'")
(sp--test-sp-rewrap-sexp-python "'foo \\'b|ar\\' baz'" '("\"" . "\"") "'foo \"b|ar\" baz'"))
;; #841
(ert-deftest sp-test-command-sp-rewrap-empty-pair-should-unwrap ()
(sp--test-sp-rewrap-sexp "[fo|o]" nil "fo|o"))
;; #841
(ert-deftest sp-test-command-sp-rewrap-empty-pair-should-unwrap-interactive-spec ()
(sp-test-with-temp-elisp-buffer "[fo|o]"
(let ((unread-command-events (list 'return)))
(call-interactively 'sp-rewrap-sexp)
(sp-buffer-equals "fo|o"))))
(ert-deftest sp-test-command-sp-rewrap-sexp-invalid-pair ()
(should-error
(sp-test-with-temp-elisp-buffer "(fo|o)"
(let ((unread-command-events (list ?\a)))
(call-interactively 'sp-rewrap-sexp)))
:type 'user-error))
(ert-deftest sp-test-command-sp-select-next-thing-empty-buffer ()
"Ensure we call user-error at buffer end."
(should-error
(sp-test-with-temp-elisp-buffer ""
(call-interactively 'sp-select-next-thing))
:type 'user-error))
(ert-deftest sp-test-command-sp-select-previous-thing-empty-buffer ()
"Ensure we call user-error at buffer end."
(should-error
(sp-test-with-temp-elisp-buffer ""
(call-interactively 'sp-select-previous-thing))
:type 'user-error))
(ert-deftest sp-test-command-sp-mark-sexp ()
(sp-test-with-temp-elisp-buffer "|(foo) (bar) (baz)"
(call-interactively 'sp-mark-sexp)
(sp-buffer-equals "|(foo)M (bar) (baz)")))
(ert-deftest sp-test-command-sp-mark-sexp-extend-existing-region ()
(sp-test-with-temp-elisp-buffer "|(foo)M (bar) (baz)"
(call-interactively 'sp-mark-sexp)
(sp-buffer-equals "|(foo) (bar)M (baz)")))
(ert-deftest sp-test-command-sp-mark-sexp-multiple-invocations ()
(let ((smartparens-mode-map smartparens-mode-map))
(sp-test-with-temp-elisp-buffer "|(foo) (bar) (baz)"
(execute-kbd-macro "mm")
(sp-buffer-equals "|(foo) (bar)M (baz)"))))
(ert-deftest sp-test-command-sp-mark-sexp-invalid ()
(let ((smartparens-mode-map smartparens-mode-map))
(should-error
(sp-test-with-temp-elisp-buffer "(progn (foo) |(bar)) (baz)"
(define-key smartparens-mode-map "m" 'sp-mark-sexp)
(execute-kbd-macro "mm"))
:type 'user-error)))
(ert-deftest sp-test-command-sp-convolute-sexp-inside-symbol ()
"Calling `sp-convolute-sexp' with point inside of symbol moves
point to end of symbol before convolving."
(sp-test-with-temp-elisp-buffer "(foo (bar b|az))"
(call-interactively #'sp-convolute-sexp)
(sp-buffer-equals "(bar baz (foo|))")))
(ert-deftest sp-test-command-sp-convolute-sexp-whitespace ()
"Calling `sp-convolute-sexp' eliminates extra whitespace.
This is the behavior of `paredit-convolute-sexp'."
(sp-test-with-temp-elisp-buffer "(foo (bar | baz))"
(call-interactively #'sp-convolute-sexp)
(sp-buffer-equals "(bar (foo |baz))")))
(ert-deftest sp-test-yank-after-multiple-word-kill ()
"When we `sp-kill-word' multiple times in a row, we should
`yank' the entire killed sequence."
(sp-test-with-temp-elisp-buffer "|some-long-symbol"
(let ((smartparens-mode-map smartparens-mode-map))
(define-key smartparens-mode-map "d" 'sp-kill-word)
(execute-kbd-macro "ddd")
(shut-up (call-interactively 'yank))
(sp-buffer-equals "some-long-symbol|"))))
(ert-deftest sp-test-yank-after-multiple-backward-word-kill ()
"When we `sp-backward-kill-word' multiple times in a row, we
should `yank' the entire killed sequence."
(sp-test-with-temp-elisp-buffer "some-long-symbol|"
(let ((smartparens-mode-map smartparens-mode-map))
(define-key smartparens-mode-map "d" 'sp-backward-kill-word)
(execute-kbd-macro "ddd")
(shut-up (call-interactively 'yank))
(sp-buffer-equals "some-long-symbol|"))))
(ert-deftest sp-test-kill-region ()