This repository has been archived by the owner on Mar 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
evil-latex-textobjects-tests.el
165 lines (136 loc) · 5.41 KB
/
evil-latex-textobjects-tests.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
;;; evil-latex-textobjects-tests.el --- tests for evil-latex-textobjects -*- lexical-binding: t -*-
;; Copyright (C) 2015 Hans-Peter Deifel
;; Author: Hans-Peter Deifel <hpd@hpdeifel.de>
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or (at
;; your option) any later version.
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Code:
(require 'ert)
(require 'evil-latex-textobjects)
(defun evil-latex-textobjects-on-str (string keys)
"Insert string in tmp buffer, execute keys and return the result"
(let ((win (selected-window)))
(unwind-protect
(with-temp-buffer
(set-window-buffer win (current-buffer) t)
(turn-on-evil-mode)
(turn-on-evil-latex-textobjects-mode)
(insert string)
(goto-char (point-min))
(execute-kbd-macro keys)
(buffer-string))
(set-window-buffer win (current-buffer) t))))
;;; dollar
(ert-deftest evil-latex-textobjects-di$ ()
(should (equal (evil-latex-textobjects-on-str "$foo$" "di$")
"$$"))
(should (equal (evil-latex-textobjects-on-str " $ foo $" "f$lci$bar")
" $bar$")))
(ert-deftest evil-latex-textobjects-da$ ()
(should (equal (evil-latex-textobjects-on-str "$foo$" "da$")
""))
(should (equal (evil-latex-textobjects-on-str " $ foo $" "f$lda$")
"")))
;;; display math
(ert-deftest evil-latex-textobjects-dimath ()
(should (equal (evil-latex-textobjects-on-str " \\[foo\\] " "llldi\\")
" \\[\\] ")))
(ert-deftest evil-latex-textobjects-damath ()
(should (equal (evil-latex-textobjects-on-str " \\[foo\\] " "lllda\\")
" ")))
(ert-deftest evil-latex-textobjects-visual-inner-math ()
(should (equal (evil-latex-textobjects-on-str
" \\[\\[foo\\]\\] " "ffvi\\i\\d")
" \\[\\] ")))
(ert-deftest evil-latex-textobjects-visual-a-math ()
(should (equal (evil-latex-textobjects-on-str
" \\[\\[foo\\]\\] " "ffva\\a\\d")
" ")))
(ert-deftest evil-latex-textobjects-inner-math-count ()
(should (equal (evil-latex-textobjects-on-str
" \\[\\[foo\\]\\] " "ffd2i\\")
" \\[\\] ")))
(ert-deftest evil-latex-textobjects-a-math-count ()
(should (equal (evil-latex-textobjects-on-str
" \\[\\[foo\\]\\] " "ffd2a\\")
" ")))
;;; macro
(ert-deftest evil-latex-textobjects-dimacro ()
(should (equal (evil-latex-textobjects-on-str " \\foo{bar} " "llldim")
" \\foo{} ")))
(ert-deftest evil-latex-textobjects-damacro ()
(should (equal (evil-latex-textobjects-on-str " \\foo{bar} " "llldam")
" ")))
(ert-deftest evil-latex-textobjects-visual-inner-macro ()
:expected-result :failed
(should (equal (evil-latex-textobjects-on-str " \\bar{\\foo{baz}} " "2f{lvimimd")
" \\bar{} ")))
(ert-deftest evil-latex-textobjects-visual-a-macro ()
:expected-result :failed
(should (equal (evil-latex-textobjects-on-str " \\bar{\\foo{baz}} " "2f{lvamamd")
" ")))
(ert-deftest evil-latex-textobjects-inner-macro-count ()
:expected-result :failed
(should (equal (evil-latex-textobjects-on-str
" \\bar{\\foo{baz}} " "2f{ld2im")
" \\bar{} ")))
(ert-deftest evil-latex-textobjects-a-macro-count ()
:expected-result :failed
(should (equal (evil-latex-textobjects-on-str
" \\bar{\\foo{baz}} " "2f{ld2am")
" ")))
;;; environment
(ert-deftest evil-latex-textobjects-dienv ()
(should (equal (evil-latex-textobjects-on-str
" \\begin{foo}\n bar\n\\end{foo} " "jdie")
" \\begin{foo}\\end{foo} ")))
(ert-deftest evil-latex-textobjects-daenv ()
(should (equal (evil-latex-textobjects-on-str
" \\begin{foo}\n bar\n\\end{foo} " "jdae")
" ")))
(ert-deftest evil-latex-textobjects-visual-inner-env ()
:expected-result :failed
(should (equal (evil-latex-textobjects-on-str
" \\begin{bar}
\\begin{foo}
bar
\\end{foo}
\\end{bar} " "jjvieied")
" \\begin{bar}\\end{bar} ")))
(ert-deftest evil-latex-textobjects-visual-a-env ()
:expected-result :failed
(should (equal (evil-latex-textobjects-on-str
" \\begin{bar}
\\begin{foo}
bar
\\end{foo}
\\end{bar} " "jjvaeaed")
" ")))
(ert-deftest evil-latex-textobjects-inner-env-count ()
:expected-result :failed
(should (equal (evil-latex-textobjects-on-str
" \\begin{bar}
\\begin{foo}
bar
\\end{foo}
\\end{bar} " "jjd2ie")
" \\begin{bar}\\end{bar} ")))
(ert-deftest evil-latex-textobjects-a-env-count ()
:expected-result :failed
(should (equal (evil-latex-textobjects-on-str
" \\begin{bar}
\\begin{foo}
bar
\\end{foo}
\\end{bar} " "jjd2ae")
" ")))
;;; end