| 1 |
;; Tests for font-locking code -*- lexical-binding: t -*- |
| 2 |
|
| 3 |
(add-to-list 'load-path ".") |
| 4 |
(load "init" nil t) |
| 5 |
(init-rst-ert t) |
| 6 |
|
| 7 |
(ert-deftest font-lock--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-forward-indented-block () |
| 14 |
"Tests `rst-forward-indented-block'." |
| 15 |
(should (ert-equal-buffer-return |
| 16 |
'(rst-forward-indented-block) |
| 17 |
"\^@abc" |
| 18 |
t |
| 19 |
nil)) |
| 20 |
(should (ert-equal-buffer-return |
| 21 |
'(rst-forward-indented-block) |
| 22 |
(concat " \^@abc |
| 23 |
|
| 24 |
def") |
| 25 |
(concat " abc |
| 26 |
\^@ |
| 27 |
def") |
| 28 |
7)) |
| 29 |
(should (ert-equal-buffer-return |
| 30 |
'(rst-forward-indented-block) |
| 31 |
(concat " \^@abc |
| 32 |
def") |
| 33 |
(concat " abc |
| 34 |
\^@def") |
| 35 |
7)) |
| 36 |
(should (ert-equal-buffer-return |
| 37 |
'(rst-forward-indented-block) |
| 38 |
(concat " \^@abc |
| 39 |
def |
| 40 |
ghi") |
| 41 |
(concat " abc |
| 42 |
def |
| 43 |
\^@ghi") |
| 44 |
13)) |
| 45 |
(should (ert-equal-buffer-return |
| 46 |
'(rst-forward-indented-block) |
| 47 |
(concat " \^@abc |
| 48 |
def |
| 49 |
|
| 50 |
ghi") |
| 51 |
(concat " abc |
| 52 |
def |
| 53 |
\^@ |
| 54 |
ghi") |
| 55 |
13)) |
| 56 |
(should (ert-equal-buffer-return |
| 57 |
'(rst-forward-indented-block) |
| 58 |
(concat " \^@abc |
| 59 |
|
| 60 |
def |
| 61 |
|
| 62 |
ghi") |
| 63 |
(concat " abc |
| 64 |
|
| 65 |
def |
| 66 |
\^@ |
| 67 |
ghi") |
| 68 |
14)) |
| 69 |
(should (ert-equal-buffer-return |
| 70 |
'(rst-forward-indented-block) |
| 71 |
(concat " \^@abc |
| 72 |
|
| 73 |
|
| 74 |
def |
| 75 |
|
| 76 |
|
| 77 |
ghi") |
| 78 |
(concat " abc |
| 79 |
|
| 80 |
|
| 81 |
def |
| 82 |
\^@ |
| 83 |
|
| 84 |
ghi") |
| 85 |
17)) |
| 86 |
(should (ert-equal-buffer-return |
| 87 |
'(rst-forward-indented-block) |
| 88 |
(concat " \^@abc |
| 89 |
def |
| 90 |
ghi") |
| 91 |
(concat " abc |
| 92 |
def |
| 93 |
\^@ghi") |
| 94 |
15)) |
| 95 |
(should (ert-equal-buffer-return |
| 96 |
'(rst-forward-indented-block) |
| 97 |
(concat " \^@abc |
| 98 |
|
| 99 |
def") |
| 100 |
t |
| 101 |
nil)) |
| 102 |
(should (ert-equal-buffer-return |
| 103 |
'(rst-forward-indented-block) |
| 104 |
(concat "\^@abc |
| 105 |
def |
| 106 |
ghi |
| 107 |
") |
| 108 |
t |
| 109 |
nil)) |
| 110 |
(should (ert-equal-buffer-return |
| 111 |
'(rst-forward-indented-block) |
| 112 |
(concat "abc\^@ def |
| 113 |
ghi |
| 114 |
") |
| 115 |
(concat "abc def |
| 116 |
\^@ghi |
| 117 |
") |
| 118 |
9)) |
| 119 |
(should (ert-equal-buffer-return |
| 120 |
'(rst-forward-indented-block) |
| 121 |
(concat "abc\^@ def |
| 122 |
ghi") |
| 123 |
(concat "abc def |
| 124 |
\^@ghi") |
| 125 |
9)) |
| 126 |
(should (ert-equal-buffer-return |
| 127 |
'(rst-forward-indented-block) |
| 128 |
(concat ".. \^@abc |
| 129 |
def |
| 130 |
|
| 131 |
ghi |
| 132 |
|
| 133 |
jkl |
| 134 |
") |
| 135 |
(concat ".. abc |
| 136 |
def |
| 137 |
|
| 138 |
ghi |
| 139 |
\^@ |
| 140 |
jkl |
| 141 |
") |
| 142 |
23)) |
| 143 |
) |
| 144 |
|
| 145 |
(defun extend-region (beg end) |
| 146 |
"Wrapper for `rst-font-lock-extend-region-internal'. |
| 147 |
Uses and sets region and returns t if region has been changed." |
| 148 |
(interactive "r") |
| 149 |
(let ((r (rst-font-lock-extend-region-internal beg end))) |
| 150 |
(when r |
| 151 |
(goto-char (car r)) |
| 152 |
(set-mark (cdr r)) |
| 153 |
t))) |
| 154 |
|
| 155 |
(ert-deftest rst-font-lock-extend-region-internal-indent () |
| 156 |
"Tests `rst-font-lock-extend-region-internal'." |
| 157 |
(should (ert-equal-buffer-return |
| 158 |
'(extend-region) |
| 159 |
"\^@abc\^?" |
| 160 |
t |
| 161 |
nil |
| 162 |
t)) |
| 163 |
(should (ert-equal-buffer-return |
| 164 |
'(extend-region) |
| 165 |
"\^@ abc\^?" |
| 166 |
t |
| 167 |
nil |
| 168 |
t)) |
| 169 |
(should (ert-equal-buffer-return |
| 170 |
'(extend-region) |
| 171 |
" abc |
| 172 |
\^@ def\^?" |
| 173 |
"\^@ abc |
| 174 |
def\^?" |
| 175 |
t |
| 176 |
t)) |
| 177 |
(should (ert-equal-buffer-return |
| 178 |
'(extend-region) |
| 179 |
" abc |
| 180 |
\^@ def |
| 181 |
\^? ghi |
| 182 |
uvw" |
| 183 |
"\^@ abc |
| 184 |
def |
| 185 |
ghi |
| 186 |
\^?uvw" |
| 187 |
t |
| 188 |
t)) |
| 189 |
(should (ert-equal-buffer-return |
| 190 |
'(extend-region) |
| 191 |
"xyz |
| 192 |
abc |
| 193 |
\^@ def |
| 194 |
\^? ghi" |
| 195 |
"xyz |
| 196 |
\^@abc |
| 197 |
def |
| 198 |
ghi\^?" |
| 199 |
t |
| 200 |
t)) |
| 201 |
(should (ert-equal-buffer-return |
| 202 |
'(extend-region) |
| 203 |
"xyz |
| 204 |
abc:: |
| 205 |
\^@ def |
| 206 |
\^? ghi |
| 207 |
uvw" |
| 208 |
"xyz |
| 209 |
\^@ abc:: |
| 210 |
def |
| 211 |
ghi |
| 212 |
\^?uvw" |
| 213 |
t |
| 214 |
t)) |
| 215 |
(should (ert-equal-buffer-return |
| 216 |
'(extend-region) |
| 217 |
"xyz |
| 218 |
.. abc |
| 219 |
\^@ def |
| 220 |
\^?uvw" |
| 221 |
"xyz |
| 222 |
\^@ .. abc |
| 223 |
def |
| 224 |
\^?uvw" |
| 225 |
t |
| 226 |
t)) |
| 227 |
(should (ert-equal-buffer-return |
| 228 |
'(extend-region) |
| 229 |
"xyz |
| 230 |
.. abc |
| 231 |
123 |
| 232 |
\^@ def |
| 233 |
\^? |
| 234 |
uvw" |
| 235 |
"xyz |
| 236 |
\^@ .. abc |
| 237 |
123 |
| 238 |
def |
| 239 |
\^? |
| 240 |
uvw" |
| 241 |
t |
| 242 |
t)) |
| 243 |
(should (ert-equal-buffer-return |
| 244 |
'(extend-region) |
| 245 |
"xyz |
| 246 |
|
| 247 |
.. abc |
| 248 |
|
| 249 |
123 |
| 250 |
|
| 251 |
\^@ def |
| 252 |
\^? |
| 253 |
uvw" |
| 254 |
"xyz |
| 255 |
|
| 256 |
\^@ .. abc |
| 257 |
|
| 258 |
123 |
| 259 |
|
| 260 |
def |
| 261 |
\^? |
| 262 |
uvw" |
| 263 |
t |
| 264 |
t)) |
| 265 |
) |
| 266 |
|
| 267 |
(ert-deftest rst-font-lock-extend-region-internal-adornment () |
| 268 |
"Tests `rst-font-lock-extend-region-internal'." |
| 269 |
(should (ert-equal-buffer-return |
| 270 |
'(extend-region) |
| 271 |
"\^@===\^?" |
| 272 |
t |
| 273 |
nil |
| 274 |
t)) |
| 275 |
(should (ert-equal-buffer-return |
| 276 |
'(extend-region) |
| 277 |
"abc |
| 278 |
\^@===\^?" |
| 279 |
"\^@abc |
| 280 |
===\^?" |
| 281 |
t |
| 282 |
t)) |
| 283 |
(should (ert-equal-buffer-return ; Quite complicated without the trailing newline |
| 284 |
'(extend-region) |
| 285 |
"\^@abc |
| 286 |
\^?===" |
| 287 |
t |
| 288 |
nil |
| 289 |
t)) |
| 290 |
(should (ert-equal-buffer-return |
| 291 |
'(extend-region) |
| 292 |
"\^@abc |
| 293 |
\^?=== |
| 294 |
" |
| 295 |
"\^@abc |
| 296 |
=== |
| 297 |
\^?" |
| 298 |
t |
| 299 |
t)) |
| 300 |
(should (ert-equal-buffer-return |
| 301 |
'(extend-region) |
| 302 |
"=== |
| 303 |
abc |
| 304 |
\^@=== |
| 305 |
\^?" |
| 306 |
"\^@=== |
| 307 |
abc |
| 308 |
=== |
| 309 |
\^?" |
| 310 |
t |
| 311 |
t)) |
| 312 |
(should (ert-equal-buffer-return |
| 313 |
'(extend-region) |
| 314 |
"\^@=== |
| 315 |
\^?abc |
| 316 |
=== |
| 317 |
" |
| 318 |
"\^@=== |
| 319 |
abc |
| 320 |
=== |
| 321 |
\^?" |
| 322 |
t |
| 323 |
t)) |
| 324 |
(should (ert-equal-buffer-return |
| 325 |
'(extend-region) |
| 326 |
"def |
| 327 |
|
| 328 |
=== |
| 329 |
\^@abc |
| 330 |
=== |
| 331 |
\^?" |
| 332 |
"def |
| 333 |
|
| 334 |
\^@=== |
| 335 |
abc |
| 336 |
=== |
| 337 |
\^?" |
| 338 |
t |
| 339 |
t)) |
| 340 |
(should (ert-equal-buffer-return |
| 341 |
'(extend-region) |
| 342 |
"def |
| 343 |
|
| 344 |
\^@=== |
| 345 |
abc |
| 346 |
\^?=== |
| 347 |
|
| 348 |
xyz" |
| 349 |
"def |
| 350 |
|
| 351 |
\^@=== |
| 352 |
abc |
| 353 |
=== |
| 354 |
\^? |
| 355 |
xyz" |
| 356 |
t |
| 357 |
t)) |
| 358 |
) |