| 1 |
;; Tests for helper functions and macros. -*- lexical-binding: t -*- |
| 2 |
|
| 3 |
(add-to-list 'load-path ".") |
| 4 |
(load "init" nil t) |
| 5 |
(init-rst-ert t) |
| 6 |
|
| 7 |
(ert-deftest helpers-asserts () |
| 8 |
"Check some assertions." |
| 9 |
(should (equal ert-Buf-point-char "\^@")) |
| 10 |
(should (equal ert-Buf-mark-char "\^?")) |
| 11 |
) |
| 12 |
|
| 13 |
(ert-deftest rst-destructuring-dolist () |
| 14 |
"Test `rst-destructuring-dolist'." |
| 15 |
(should (equal nil (rst-destructuring-dolist (i nil) |
| 16 |
(signal 'error nil)))) |
| 17 |
(should (equal t (rst-destructuring-dolist (i nil t) |
| 18 |
(signal 'error nil)))) |
| 19 |
(should (let (res) |
| 20 |
(rst-destructuring-dolist (e '(1) res) |
| 21 |
(setq res (not (boundp '--rst-destructuring-dolist-var--)))))) |
| 22 |
(should (equal |
| 23 |
'((4 . 3) (2 . 1)) |
| 24 |
(let (res) |
| 25 |
(rst-destructuring-dolist ((l &rest r) '((1 . 2) (3 . 4)) res) |
| 26 |
(push (cons r l) res))))) |
| 27 |
(should (equal |
| 28 |
'((6 5 4) (3 2 1)) |
| 29 |
(let (res) |
| 30 |
(rst-destructuring-dolist ((l m r) '((1 2 3) (4 5 6)) res) |
| 31 |
(push (list r m l) res))))) |
| 32 |
(should (equal |
| 33 |
'(3 2 1) |
| 34 |
(let (res) |
| 35 |
(rst-destructuring-dolist (e '(1 2 3) res) |
| 36 |
(push e res))))) |
| 37 |
(should (equal |
| 38 |
'(30 20 10) |
| 39 |
(let (res) |
| 40 |
(rst-destructuring-dolist ((e &aux (a 10)) '((1) (2) (3)) res) |
| 41 |
(push (* e a) res) |
| 42 |
(setq a (+ a a)))))) |
| 43 |
(should (equal |
| 44 |
'(30 20 10) |
| 45 |
(let (res) |
| 46 |
(rst-destructuring-dolist ((&rest e &aux (a 10)) '(1 2 3) res) |
| 47 |
(push (* e a) res) |
| 48 |
(setq a (+ a a)))))) |
| 49 |
) |
| 50 |
|
| 51 |
(ert-deftest rst-forward-line-strict () |
| 52 |
"Test `rst-forward-line-strict'." |
| 53 |
(should (ert-equal-buffer-return |
| 54 |
'(rst-forward-line-strict 1) |
| 55 |
"\^@" |
| 56 |
t |
| 57 |
nil)) |
| 58 |
(should (ert-equal-buffer-return |
| 59 |
'(rst-forward-line-strict 0) |
| 60 |
"\^@" |
| 61 |
t |
| 62 |
t)) |
| 63 |
(should (ert-equal-buffer-return |
| 64 |
'(rst-forward-line-strict -1) |
| 65 |
"\^@" |
| 66 |
t |
| 67 |
nil)) |
| 68 |
(should (ert-equal-buffer-return |
| 69 |
'(rst-forward-line-strict 1) |
| 70 |
"abc\^@" |
| 71 |
t |
| 72 |
nil)) |
| 73 |
(should (ert-equal-buffer-return |
| 74 |
'(rst-forward-line-strict 0) |
| 75 |
"abc\^@" |
| 76 |
"\^@abc" |
| 77 |
t)) |
| 78 |
(should (ert-equal-buffer-return |
| 79 |
'(rst-forward-line-strict -1) |
| 80 |
"abc\^@" |
| 81 |
t |
| 82 |
nil)) |
| 83 |
(should (ert-equal-buffer-return |
| 84 |
'(rst-forward-line-strict 1) |
| 85 |
"abc\^@ |
| 86 |
" |
| 87 |
"abc |
| 88 |
\^@" |
| 89 |
t)) |
| 90 |
(should (ert-equal-buffer-return |
| 91 |
'(rst-forward-line-strict 2) |
| 92 |
"abc\^@ |
| 93 |
" |
| 94 |
t |
| 95 |
nil)) |
| 96 |
(should (ert-equal-buffer-return |
| 97 |
'(rst-forward-line-strict 0) |
| 98 |
"abc\^@ |
| 99 |
" |
| 100 |
"\^@abc |
| 101 |
" |
| 102 |
t)) |
| 103 |
(should (ert-equal-buffer-return |
| 104 |
'(rst-forward-line-strict -1) |
| 105 |
"abc |
| 106 |
\^@" |
| 107 |
"\^@abc |
| 108 |
" |
| 109 |
t)) |
| 110 |
(should (ert-equal-buffer-return |
| 111 |
'(rst-forward-line-strict -2) |
| 112 |
"abc |
| 113 |
\^@" |
| 114 |
t |
| 115 |
nil)) |
| 116 |
(should (ert-equal-buffer-return |
| 117 |
'(rst-forward-line-strict 1 1) |
| 118 |
"\^@" |
| 119 |
t |
| 120 |
nil)) |
| 121 |
(should (ert-equal-buffer-return |
| 122 |
'(rst-forward-line-strict 1 2) |
| 123 |
"\^@" |
| 124 |
t |
| 125 |
nil)) |
| 126 |
(should (ert-equal-buffer-return |
| 127 |
'(rst-forward-line-strict 1 4) |
| 128 |
"\^@abc" |
| 129 |
"abc\^@" |
| 130 |
t)) |
| 131 |
(should (ert-equal-buffer-return |
| 132 |
'(rst-forward-line-strict 1 4) |
| 133 |
"abc\^@" |
| 134 |
t |
| 135 |
nil)) |
| 136 |
(should (ert-equal-buffer-return |
| 137 |
'(rst-forward-line-strict 1 3) |
| 138 |
"\^@abc" |
| 139 |
"abc\^@" |
| 140 |
t)) |
| 141 |
(should (ert-equal-buffer-return |
| 142 |
'(rst-forward-line-strict 1 5) |
| 143 |
"abc\^@ |
| 144 |
" |
| 145 |
"abc |
| 146 |
\^@" |
| 147 |
t)) |
| 148 |
(should (ert-equal-buffer-return |
| 149 |
'(rst-forward-line-strict 2 5) |
| 150 |
"abc\^@ |
| 151 |
" |
| 152 |
t |
| 153 |
nil)) |
| 154 |
) |
| 155 |
|
| 156 |
(defun forward-line-looking-at (n &rest rst-res) |
| 157 |
"Call `rst-forward-line-looking-at'. If match is returned |
| 158 |
return t if `(match-beginning 0)' satisfies `(bolp)' |
| 159 |
and `(match-end 0)' matches mark." |
| 160 |
(rst-forward-line-looking-at |
| 161 |
n rst-res |
| 162 |
#'(lambda (mtcd) |
| 163 |
(when mtcd |
| 164 |
(and (bolp) |
| 165 |
(= (match-end 0) (mark))))))) |
| 166 |
|
| 167 |
(ert-deftest rst-forward-line-looking-at () |
| 168 |
"Test `rst-forward-line-looking-at'." |
| 169 |
(should (ert-equal-buffer-return |
| 170 |
'(forward-line-looking-at 0) |
| 171 |
"\^@\^?" |
| 172 |
t |
| 173 |
t)) |
| 174 |
(should (ert-equal-buffer-return |
| 175 |
'(forward-line-looking-at 1) |
| 176 |
"\^@\^?" |
| 177 |
t |
| 178 |
nil)) |
| 179 |
(should (ert-equal-buffer-return |
| 180 |
'(forward-line-looking-at 1) |
| 181 |
"\^@ |
| 182 |
\^?" |
| 183 |
t |
| 184 |
t)) |
| 185 |
(should (ert-equal-buffer-return |
| 186 |
'(forward-line-looking-at 1) |
| 187 |
"\^@ |
| 188 |
.. \^?" |
| 189 |
t |
| 190 |
nil)) |
| 191 |
(should (ert-equal-buffer-return |
| 192 |
'(forward-line-looking-at 1 'exm-sta) |
| 193 |
"\^@ |
| 194 |
.. \^? |
| 195 |
" |
| 196 |
t |
| 197 |
nil)) |
| 198 |
(should (ert-equal-buffer-return |
| 199 |
'(forward-line-looking-at 1 'exm-beg) |
| 200 |
"\^@ |
| 201 |
.. \^? |
| 202 |
" |
| 203 |
t |
| 204 |
t)) |
| 205 |
) |
| 206 |
|
| 207 |
(ert-deftest rst-delete-entire-line () |
| 208 |
"Test `rst-delete-entire-line'." |
| 209 |
(should (ert-equal-buffer |
| 210 |
'(rst-delete-entire-line 0) |
| 211 |
"\^@" |
| 212 |
t)) |
| 213 |
(should (ert-equal-buffer |
| 214 |
'(rst-delete-entire-line 0) |
| 215 |
" \^@" |
| 216 |
"\^@")) |
| 217 |
(should (ert-equal-buffer |
| 218 |
'(rst-delete-entire-line 1) |
| 219 |
"\^@ |
| 220 |
abc |
| 221 |
" |
| 222 |
"\^@ |
| 223 |
")) |
| 224 |
(should (ert-equal-buffer |
| 225 |
'(rst-delete-entire-line 2) |
| 226 |
"\^@ |
| 227 |
abc |
| 228 |
" |
| 229 |
t)) |
| 230 |
(should (ert-equal-buffer |
| 231 |
'(rst-delete-entire-line 3) |
| 232 |
"\^@ |
| 233 |
abc |
| 234 |
" |
| 235 |
t)) |
| 236 |
(should (ert-equal-buffer |
| 237 |
'(rst-delete-entire-line 0) |
| 238 |
" |
| 239 |
\^@abc |
| 240 |
" |
| 241 |
" |
| 242 |
\^@")) |
| 243 |
(should (ert-equal-buffer |
| 244 |
'(rst-delete-entire-line -1) |
| 245 |
" |
| 246 |
abc |
| 247 |
\^@" |
| 248 |
" |
| 249 |
\^@")) |
| 250 |
) |