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
|
;; Tests for class `rst-Ttl' -*- lexical-binding: t -*-
(add-to-list 'load-path ".")
(load "init" nil t)
(init-rst-ert t)
(setq buf-lines
"Simple
======
----------
Double
----------
Candidate
\^@
~~~~~~~~~~
Half
**********
"
ado-spl (rst-Ado-new-simple ?=)
txt-spl-beg 1
txt-spl-end 7
und-spl-beg 8
und-spl-end 14
mtc-spl (list txt-spl-beg und-spl-end
nil nil
txt-spl-beg txt-spl-end
und-spl-beg und-spl-end)
ind-spl 0
hdr-spl (rst-Hdr-new ado-spl 0)
txt-spl "Simple"
ado-dbl (rst-Ado-new-over-and-under ?-)
ovr-dbl-beg 16
ovr-dbl-end 26
txt-dbl-beg 27
txt-dbl-end 35
und-dbl-beg 36
und-dbl-end 46
mtc-dbl (list ovr-dbl-beg und-dbl-end
ovr-dbl-beg ovr-dbl-end
txt-dbl-beg txt-dbl-end
und-dbl-beg und-dbl-end)
ind-dbl 2
hdr-dbl (rst-Hdr-new ado-dbl 2)
txt-dbl "Double"
ado-cnd nil
txt-cnd-beg 48
txt-cnd-end 58
mtc-cnd (list txt-cnd-beg txt-cnd-end
nil nil
txt-cnd-beg txt-cnd-end
nil nil)
ind-cnd 1
txt-cnd "Candidate"
ado-hlf (rst-Ado-new-over-and-under ?~)
ovr-hlf-beg 60
ovr-hlf-end 70
txt-hlf-beg 71
txt-hlf-end 78
mtc-hlf (list ovr-hlf-beg txt-hlf-end
ovr-hlf-beg ovr-hlf-end
txt-hlf-beg txt-hlf-end
nil nil)
mtc-hlf (list ovr-hlf-beg txt-hlf-end
ovr-hlf-beg ovr-hlf-end
txt-hlf-beg txt-hlf-end
nil nil)
ind-hlf 3
txt-hlf "Half"
ado-trn (rst-Ado-new-transition)
txt-trn-beg 80
txt-trn-end 90
mtc-trn (list txt-trn-beg txt-trn-end
nil nil
txt-trn-beg txt-trn-end
nil nil)
ind-trn nil
txt-trn nil
)
(ert-deftest rst-Ttl-asserts ()
"Check some assertions."
(should (equal ert-Buf-point-char "\^@"))
(should (equal ert-Buf-mark-char "\^?"))
)
(ert-deftest rst-Ttl--new ()
"Test `rst-Ttl--new'."
;; Check type checking of ado argument.
(should-error (rst-Ttl--new hdr-spl mtc-spl ind-spl txt-spl)
:type 'wrong-type-argument)
;; Check type and value checking of match argument.
(should-error (rst-Ttl--new ado-spl 1 ind-spl txt-spl)
:type 'wrong-type-argument)
(should-error (rst-Ttl--new ado-spl nil ind-spl txt-spl)
:type 'wrong-type-argument)
(should-error (rst-Ttl--new ado-spl '(1 2 3) ind-spl txt-spl)
:type 'wrong-type-argument)
(should-error (rst-Ttl--new ado-spl '(1 2 "3" 4 5 6 7 8) ind-spl txt-spl)
:type 'wrong-type-argument)
(should-error (rst-Ttl--new nil '(1 2 3 4 5 6 7 8) ind-spl txt-spl)
:type 'args-out-of-range)
;; Check value checking of match argument for tranisitions.
(should-error (rst-Ttl--new ado-trn (list nil nil
nil nil
txt-spl-beg txt-spl-end
und-spl-beg und-spl-end)
ind-spl txt-trn)
:type 'args-out-of-range)
(should-error (rst-Ttl--new ado-trn (list txt-spl-beg und-spl-end
txt-spl-beg txt-spl-end
und-spl-beg und-spl-end
nil nil)
ind-spl txt-trn)
:type 'args-out-of-range)
(should-error (rst-Ttl--new ado-trn (list txt-spl-beg und-spl-end
nil nil
txt-spl-beg txt-spl-end
und-spl-beg und-spl-end)
ind-spl txt-trn)
:type 'args-out-of-range)
(should-error (rst-Ttl--new ado-trn (list txt-spl-beg und-spl-end
nil nil
nil nil
und-spl-beg und-spl-end)
ind-spl txt-trn)
:type 'args-out-of-range)
;; Check value checking of match argument for simple section header.
(should-error (rst-Ttl--new ado-spl (list nil nil
nil nil
txt-spl-beg txt-spl-end
und-spl-beg und-spl-end)
ind-spl txt-spl)
:type 'args-out-of-range)
(should-error (rst-Ttl--new ado-spl (list txt-spl-beg und-spl-end
txt-spl-beg txt-spl-end
und-spl-beg und-spl-end
und-spl-beg und-spl-end)
ind-spl txt-spl)
:type 'args-out-of-range)
(should-error (rst-Ttl--new ado-spl (list txt-spl-beg und-spl-end
nil nil
txt-spl-beg txt-spl-end
nil nil)
ind-spl txt-spl)
:type 'args-out-of-range)
;; Check value checking of match argument for double section header.
(should-error (rst-Ttl--new ado-dbl (list nil nil
ovr-dbl-beg ovr-dbl-end
txt-dbl-beg txt-dbl-end
und-dbl-beg und-dbl-end)
ind-dbl txt-dbl)
:type 'args-out-of-range)
(should-error (rst-Ttl--new ado-dbl (list ovr-dbl-beg und-dbl-end
nil nil
txt-dbl-beg txt-dbl-end
und-dbl-beg und-dbl-end)
ind-dbl txt-dbl)
:type 'args-out-of-range)
(should-error (rst-Ttl--new ado-dbl (list ovr-dbl-beg und-dbl-end
ovr-dbl-beg ovr-dbl-end
nil nil
und-dbl-beg und-dbl-end)
ind-dbl txt-dbl)
:type 'args-out-of-range)
;; Check type and value checking of indent argument.
(should-error (rst-Ttl--new ado-trn mtc-trn 1 txt-trn)
:type 'wrong-type-argument)
(should-error (rst-Ttl--new ado-spl mtc-spl nil txt-spl)
:type 'wrong-type-argument)
(should-error (rst-Ttl--new ado-spl mtc-spl -1 txt-spl)
:type 'wrong-type-argument)
;; Check type and value checking of text argument.
(should-error (rst-Ttl--new ado-trn mtc-trn ind-trn "Text")
:type 'wrong-type-argument)
(should-error (rst-Ttl--new ado-spl mtc-spl ind-spl nil)
:type 'wrong-type-argument)
(should-error (rst-Ttl--new ado-spl mtc-spl ind-spl 3)
:type 'wrong-type-argument)
(should-error (rst-Ttl--new ado-trn mtc-spl ind-spl txt-spl)
:type 'args-out-of-range)
(should (rst-Ttl-p (rst-Ttl--new ado-spl mtc-spl ind-spl txt-spl)))
(should (rst-Ttl-p (rst-Ttl--new ado-dbl mtc-dbl ind-dbl txt-dbl)))
(should (rst-Ttl-p (rst-Ttl--new ado-cnd mtc-cnd ind-cnd txt-cnd)))
(should (rst-Ttl-p (rst-Ttl--new ado-hlf mtc-hlf ind-hlf txt-hlf)))
(should (rst-Ttl-p (rst-Ttl--new ado-trn mtc-trn ind-trn txt-trn)))
;; Check setting of header.
(should (equal (rst-Ttl-hdr (rst-Ttl--new ado-spl mtc-spl ind-spl txt-spl))
(rst-Hdr-new ado-spl ind-spl)))
(should (equal (rst-Ttl-hdr (rst-Ttl--new ado-dbl mtc-dbl ind-dbl txt-dbl))
(rst-Hdr-new ado-dbl ind-dbl)))
(should (equal (rst-Ttl-hdr (rst-Ttl--new ado-hlf mtc-hlf ind-hlf txt-hlf))
(rst-Hdr-new ado-hlf ind-hlf)))
(should-not (rst-Ttl-hdr (rst-Ttl--new ado-cnd mtc-cnd ind-cnd txt-cnd)))
(should-not (rst-Ttl-hdr (rst-Ttl--new ado-trn mtc-cnd nil txt-trn)))
)
(ert-deftest rst-Ttl-get-title-beginning ()
"Test `rst-Ttl-get-title-beginning'."
(should (equal (rst-Ttl-get-title-beginning
(rst-Ttl--new ado-spl mtc-spl ind-spl txt-spl)) txt-spl-beg))
(should (equal (rst-Ttl-get-title-beginning
(rst-Ttl--new ado-dbl mtc-dbl ind-dbl txt-dbl)) txt-dbl-beg))
(should (equal (rst-Ttl-get-title-beginning
(rst-Ttl--new ado-hlf mtc-hlf ind-hlf txt-hlf)) txt-hlf-beg))
(should (equal (rst-Ttl-get-title-beginning
(rst-Ttl--new ado-cnd mtc-cnd ind-cnd txt-cnd)) txt-cnd-beg))
)
(ert-deftest rst-Ttl-get-beginning_end ()
"Test `rst-Ttl-get-beginning' and `rst-Ttl-get-end'."
(should (equal (rst-Ttl-get-beginning
(rst-Ttl--new ado-spl mtc-spl ind-spl txt-spl)) txt-spl-beg))
(should (equal (rst-Ttl-get-end
(rst-Ttl--new ado-spl mtc-spl ind-spl txt-spl)) und-spl-end))
(should (equal (rst-Ttl-get-beginning
(rst-Ttl--new ado-dbl mtc-dbl ind-dbl txt-dbl)) ovr-dbl-beg))
(should (equal (rst-Ttl-get-end
(rst-Ttl--new ado-dbl mtc-dbl ind-dbl txt-dbl)) und-dbl-end))
(should (equal (rst-Ttl-get-beginning
(rst-Ttl--new ado-hlf mtc-hlf ind-hlf txt-hlf)) ovr-hlf-beg))
(should (equal (rst-Ttl-get-end
(rst-Ttl--new ado-hlf mtc-hlf ind-hlf txt-hlf)) txt-hlf-end))
(should (equal (rst-Ttl-get-beginning
(rst-Ttl--new ado-cnd mtc-cnd ind-cnd txt-cnd)) txt-cnd-beg))
(should (equal (rst-Ttl-get-end
(rst-Ttl--new ado-cnd mtc-cnd ind-cnd txt-cnd)) txt-cnd-end))
)
(ert-deftest rst-Ttl-from-buffer ()
"Test `rst-Ttl-from-buffer'."
(let ((ttl-spl (rst-Ttl--new ado-spl mtc-spl ind-spl txt-spl))
(ttl-dbl (rst-Ttl--new ado-dbl mtc-dbl ind-dbl txt-dbl))
(ttl-cnd (rst-Ttl--new nil mtc-cnd ind-cnd txt-cnd))
(ttl-hlf (rst-Ttl--new ado-hlf mtc-hlf ind-hlf txt-hlf))
(ttl-trn (rst-Ttl--new ado-trn mtc-trn ind-trn txt-trn)))
;; Check type checking of beg-txt argument.
(should-error (rst-Ttl-from-buffer nil nil nil nil nil)
:type 'wrong-type-argument)
(should (ert-equal-buffer-return
'(rst-Ttl-from-buffer
ado-spl nil txt-spl-beg und-spl-beg txt-spl)
buf-lines
t
ttl-spl))
(should (ert-equal-buffer-return
'(rst-Ttl-from-buffer
ado-dbl ovr-dbl-beg txt-dbl-beg und-dbl-beg txt-dbl)
buf-lines
t
ttl-dbl))
(should (ert-equal-buffer-return
'(rst-Ttl-from-buffer
nil nil txt-cnd-beg nil txt-cnd)
buf-lines
t
ttl-cnd))
(should (ert-equal-buffer-return
'(rst-Ttl-from-buffer
ado-hlf ovr-hlf-beg txt-hlf-beg nil txt-hlf)
buf-lines
t
ttl-hlf))
(should (ert-equal-buffer-return
'(rst-Ttl-from-buffer
ado-trn nil txt-trn-beg nil txt-trn)
buf-lines
t
ttl-trn))
))
(defun ttl-contains (pnt)
"Run `rst-Ttl-contains' on current buffer comparing first title with point."
(interactive "d")
(rst-Ttl-contains (car (rst-all-ttls-compute)) pnt))
(ert-deftest rst-Ttl-contains ()
"Test `rst-Ttl-contains'."
(should-error (rst-Ttl-contains nil nil)
:type 'wrong-type-argument)
(should (ert-equal-buffer-return
'(ttl-contains nil)
"
===
\^@One
===
"
nil
0
t))
(should (ert-equal-buffer-return
'(ttl-contains nil)
"
\^@===
One
===
"
nil
0
t))
(should (ert-equal-buffer-return
'(ttl-contains nil)
"
===
One
===\^@
"
nil
0
t))
(should (ert-equal-buffer-return
'(ttl-contains nil)
"
\^@One
===
"
nil
0
t))
(should (ert-equal-buffer-return
'(ttl-contains nil)
"
One
===\^@
"
nil
0
t))
(should (ert-equal-buffer-return
'(ttl-contains nil)
"\^@
One
===
"
nil
1
t))
(should (ert-equal-buffer-return
'(ttl-contains nil)
"
One
===
\^@"
nil
-1
t))
)
|