| 1 |
;; Tests for operations on list items -*- lexical-binding: t -*- |
| 2 |
|
| 3 |
(add-to-list 'load-path ".") |
| 4 |
(load "init" nil t) |
| 5 |
(init-rst-ert t) |
| 6 |
|
| 7 |
(ert-deftest items-asserts () |
| 8 |
"Check some assertions." |
| 9 |
(should (equal ert-Buf-point-char "\^@")) |
| 10 |
(should (equal ert-Buf-mark-char "\^?")) |
| 11 |
) |
| 12 |
|
| 13 |
(defun find-begs (beg-re) |
| 14 |
(rst-find-begs (region-beginning) (region-end) beg-re)) |
| 15 |
|
| 16 |
(ert-deftest rst-find-begs () |
| 17 |
"Tests `rst-find-begs'." |
| 18 |
(should (ert-equal-buffer-return |
| 19 |
'(find-begs 'itmany-beg-1) |
| 20 |
"\^@1 Normal paragraph. |
| 21 |
|
| 22 |
* 22 A bullet |
| 23 |
|
| 24 |
* 37 Another bullet |
| 25 |
|
| 26 |
58 Another normal paragraph. |
| 27 |
|
| 28 |
\^?" |
| 29 |
t '((22 . 0) |
| 30 |
(37 . 0)))) |
| 31 |
(should (ert-equal-buffer-return |
| 32 |
'(find-begs 'itmany-beg-1) |
| 33 |
"1 Normal paragraph. |
| 34 |
|
| 35 |
\^?* 22 A bullet |
| 36 |
|
| 37 |
* 37 Another bullet |
| 38 |
|
| 39 |
\^@58 Another normal paragraph. |
| 40 |
|
| 41 |
" |
| 42 |
t '((22 . 0) |
| 43 |
(37 . 0)))) |
| 44 |
(should (ert-equal-buffer-return |
| 45 |
'(find-begs 'itmany-beg-1) |
| 46 |
"1 Normal paragraph. |
| 47 |
|
| 48 |
\^?* 22 A bullet |
| 49 |
|
| 50 |
* 37 Another bullet |
| 51 |
|
| 52 |
1. 58 An enum. |
| 53 |
|
| 54 |
2. 74 Another enum. |
| 55 |
|
| 56 |
\^@95 Another normal paragraph. |
| 57 |
|
| 58 |
" |
| 59 |
t '((22 . 0) |
| 60 |
(37 . 0) |
| 61 |
(58 . 0) |
| 62 |
(74 . 0)))) |
| 63 |
(should (ert-equal-buffer-return |
| 64 |
'(find-begs 'bul-beg) |
| 65 |
"\^@ |
| 66 |
- 2 one |
| 67 |
+ 10 two |
| 68 |
* 19 three |
| 69 |
\^?" |
| 70 |
t '((2 . 0) |
| 71 |
(10 . 0) |
| 72 |
(19 . 0)))) |
| 73 |
(should (ert-equal-buffer-return |
| 74 |
'(find-begs 'bul-beg) |
| 75 |
" |
| 76 |
- 2 one\^@ |
| 77 |
+ 10 two |
| 78 |
* 19 three |
| 79 |
\^?" |
| 80 |
t '((2 . 0) |
| 81 |
(10 . 0) |
| 82 |
(19 . 0)))) |
| 83 |
(should (ert-equal-buffer-return |
| 84 |
'(find-begs 'bul-beg) |
| 85 |
"+ 1 zero |
| 86 |
\^@- 10 one |
| 87 |
+ 19 two |
| 88 |
* 28 three\^? |
| 89 |
" |
| 90 |
t '((10 . 0) |
| 91 |
(19 . 0) |
| 92 |
(28 . 0)))) |
| 93 |
(should (ert-equal-buffer-return |
| 94 |
'(find-begs 'bul-beg) |
| 95 |
"\^@ |
| 96 |
- 2 one |
| 97 |
|
| 98 |
+ 11 two |
| 99 |
|
| 100 |
* 23 three |
| 101 |
\^?" |
| 102 |
t '((2 . 0) |
| 103 |
(13 . 2) |
| 104 |
(23 . 0)))) |
| 105 |
(should (ert-equal-buffer-return |
| 106 |
'(find-begs 'bul-beg) |
| 107 |
"\^@Normal paragraph |
| 108 |
|
| 109 |
* 19 bullet |
| 110 |
|
| 111 |
* 32 three |
| 112 |
|
| 113 |
Another normal paragraph |
| 114 |
\^?" |
| 115 |
t '((19 . 0) |
| 116 |
(34 . 2)))) |
| 117 |
) |
| 118 |
|
| 119 |
(ert-deftest rst-find-begs-BUGS () |
| 120 |
"Exposes bugs in `rst-find-begs'." |
| 121 |
:expected-result :failed ;; These are bugs |
| 122 |
(should (ert-equal-buffer-return |
| 123 |
'(find-begs 'bul-beg) |
| 124 |
"\^@Normal paragraph |
| 125 |
* 18 bullet |
| 126 |
* 30 three |
| 127 |
Another normal paragraph |
| 128 |
\^?" |
| 129 |
t '((18 . 0) |
| 130 |
(32 . 2)))) |
| 131 |
(should (ert-equal-buffer-return |
| 132 |
'(find-begs 'bul-beg) |
| 133 |
"\^@ |
| 134 |
- 2 one |
| 135 |
+ 10 two |
| 136 |
* 21 three |
| 137 |
\^?" |
| 138 |
t '((2 . 0) |
| 139 |
(12 . 2) |
| 140 |
(19 . 0)))) |
| 141 |
) |
| 142 |
|
| 143 |
(ert-deftest rst-convert-bullets-to-enumeration () |
| 144 |
"Tests `rst-convert-bullets-to-enumeration'." |
| 145 |
(should (ert-equal-buffer |
| 146 |
'(rst-convert-bullets-to-enumeration) |
| 147 |
"\^@Normal paragraph. |
| 148 |
|
| 149 |
* A bullet |
| 150 |
|
| 151 |
* Another bullet |
| 152 |
|
| 153 |
Another normal paragraph. |
| 154 |
|
| 155 |
\^?" |
| 156 |
"\^@Normal paragraph. |
| 157 |
|
| 158 |
1. A bullet |
| 159 |
|
| 160 |
2. Another bullet |
| 161 |
|
| 162 |
Another normal paragraph. |
| 163 |
|
| 164 |
\^?" t)) |
| 165 |
(should (ert-equal-buffer |
| 166 |
'(rst-convert-bullets-to-enumeration) |
| 167 |
"Normal paragraph. |
| 168 |
|
| 169 |
\^?* A bullet |
| 170 |
|
| 171 |
* Another bullet |
| 172 |
|
| 173 |
\^@Another normal paragraph. |
| 174 |
|
| 175 |
" |
| 176 |
"Normal paragraph. |
| 177 |
|
| 178 |
\^?1. A bullet |
| 179 |
|
| 180 |
2. Another bullet |
| 181 |
|
| 182 |
\^@Another normal paragraph. |
| 183 |
|
| 184 |
" t)) |
| 185 |
(should (ert-equal-buffer |
| 186 |
'(rst-convert-bullets-to-enumeration) |
| 187 |
"Normal paragraph. |
| 188 |
|
| 189 |
\^?* A bullet |
| 190 |
|
| 191 |
* Another bullet |
| 192 |
|
| 193 |
1. A bullet |
| 194 |
|
| 195 |
2. Another bullet |
| 196 |
|
| 197 |
\^@Another normal paragraph. |
| 198 |
|
| 199 |
" |
| 200 |
|
| 201 |
"Normal paragraph. |
| 202 |
|
| 203 |
\^?1. A bullet |
| 204 |
|
| 205 |
2. Another bullet |
| 206 |
|
| 207 |
3. A bullet |
| 208 |
|
| 209 |
4. Another bullet |
| 210 |
|
| 211 |
\^@Another normal paragraph. |
| 212 |
|
| 213 |
" t)) |
| 214 |
) |
| 215 |
|
| 216 |
(ert-deftest rst-convert-bullets-to-enumeration-BUGS () |
| 217 |
"Exposes bugs in `rst-convert-bullets-to-enumeration'." |
| 218 |
:expected-result :failed ;; These are bugs |
| 219 |
(should (ert-equal-buffer |
| 220 |
'(rst-convert-bullets-to-enumeration) |
| 221 |
"\^@Normal paragraph. |
| 222 |
|
| 223 |
* A bullet |
| 224 |
|
| 225 |
* Another bullet |
| 226 |
|
| 227 |
* A bullet |
| 228 |
|
| 229 |
* Another bullet |
| 230 |
|
| 231 |
Another normal paragraph. |
| 232 |
|
| 233 |
\^?" |
| 234 |
"\^@Normal paragraph. |
| 235 |
|
| 236 |
1. A bullet |
| 237 |
|
| 238 |
2. Another bullet |
| 239 |
|
| 240 |
* A bullet |
| 241 |
|
| 242 |
* Another bullet |
| 243 |
|
| 244 |
Another normal paragraph. |
| 245 |
|
| 246 |
\^?" t)) |
| 247 |
) |
| 248 |
|
| 249 |
(ert-deftest rst-insert-list-continue () |
| 250 |
"Tests `rst-insert-list' when continuing a list." |
| 251 |
(should (ert-equal-buffer |
| 252 |
'(rst-insert-list) |
| 253 |
"* Some text\^@\n" |
| 254 |
"* Some text |
| 255 |
* \^@\n")) |
| 256 |
(should (ert-equal-buffer |
| 257 |
'(rst-insert-list) |
| 258 |
"* Some \^@text\n" |
| 259 |
"* Some text |
| 260 |
* \^@\n")) |
| 261 |
(should (ert-equal-buffer |
| 262 |
'(rst-insert-list) |
| 263 |
"* \^@Some text\n" |
| 264 |
"* Some text |
| 265 |
* \^@\n")) |
| 266 |
(should (ert-equal-buffer |
| 267 |
'(rst-insert-list) |
| 268 |
"* Some text |
| 269 |
- A deeper hyphen bullet\^@\n" |
| 270 |
"* Some text |
| 271 |
- A deeper hyphen bullet |
| 272 |
- \^@\n")) |
| 273 |
(should (ert-equal-buffer |
| 274 |
'(rst-insert-list) |
| 275 |
"* Some text |
| 276 |
- \^@Some text\n" |
| 277 |
"* Some text |
| 278 |
- Some text |
| 279 |
- \^@\n")) |
| 280 |
(should (ert-equal-buffer |
| 281 |
'(rst-insert-list) |
| 282 |
"1. Some text\^@\n" |
| 283 |
"1. Some text |
| 284 |
2. \^@\n")) |
| 285 |
(should (ert-equal-buffer |
| 286 |
'(rst-insert-list) |
| 287 |
"2. Some text\^@\n" |
| 288 |
"2. Some text |
| 289 |
3. \^@\n")) |
| 290 |
(should (ert-equal-buffer |
| 291 |
'(rst-insert-list) |
| 292 |
"a) Some text\^@\n" |
| 293 |
"a) Some text |
| 294 |
b) \^@\n")) |
| 295 |
(should (ert-equal-buffer |
| 296 |
'(rst-insert-list) |
| 297 |
"(A) Some text\^@\n" |
| 298 |
"(A) Some text |
| 299 |
\(B) \^@\n")) |
| 300 |
(should (ert-equal-buffer |
| 301 |
'(rst-insert-list) |
| 302 |
"(I) Some text\^@\n" |
| 303 |
"(I) Some text |
| 304 |
\(J) \^@\n")) |
| 305 |
(should (ert-equal-buffer |
| 306 |
'(rst-insert-list) |
| 307 |
"(I) Some text\^@\n" |
| 308 |
"(I) Some text |
| 309 |
\(J) \^@\n")) |
| 310 |
(should (ert-equal-buffer |
| 311 |
'(rst-insert-list) |
| 312 |
"(h) Some text |
| 313 |
\(i) Some text\^@\n" |
| 314 |
"(h) Some text |
| 315 |
\(i) Some text |
| 316 |
\(j) \^@\n")) |
| 317 |
(should (ert-equal-buffer |
| 318 |
'(rst-insert-list t) |
| 319 |
"(i) Some text\^@\n" |
| 320 |
"(i) Some text |
| 321 |
\(ii) \^@\n")) |
| 322 |
(should (ert-equal-buffer |
| 323 |
'(rst-insert-list) |
| 324 |
"(IV) Some text |
| 325 |
\(V) Some text\^@\n" |
| 326 |
"(IV) Some text |
| 327 |
\(V) Some text |
| 328 |
\(VI) \^@\n")) |
| 329 |
) |
| 330 |
|
| 331 |
(ert-deftest rst-insert-list-continue-BUGS () |
| 332 |
"Exposes bugs in `rst-insert-list-continue'." |
| 333 |
:expected-result :failed ;; These are bugs |
| 334 |
(should (ert-equal-buffer |
| 335 |
'(rst-insert-list) |
| 336 |
"(iv) Some text |
| 337 |
|
| 338 |
\(v) Some text\^@\n" |
| 339 |
"(iv) Some text |
| 340 |
|
| 341 |
\(v) Some text |
| 342 |
\(vi) \^@\n"))) |
| 343 |
|
| 344 |
(ert-deftest rst-insert-list-new () |
| 345 |
"Tests `rst-insert-list' when inserting a new list." |
| 346 |
(should (ert-equal-buffer |
| 347 |
'(rst-insert-list) |
| 348 |
"\^@ |
| 349 |
" |
| 350 |
"* \^@ |
| 351 |
" '("*"))) |
| 352 |
(should (ert-equal-buffer |
| 353 |
'(rst-insert-list) |
| 354 |
" |
| 355 |
\^@ |
| 356 |
" |
| 357 |
" |
| 358 |
- \^@ |
| 359 |
" '("-"))) |
| 360 |
(should (ert-equal-buffer |
| 361 |
'(rst-insert-list) |
| 362 |
" |
| 363 |
\^@ |
| 364 |
|
| 365 |
" |
| 366 |
" |
| 367 |
#. \^@ |
| 368 |
|
| 369 |
" '("#."))) |
| 370 |
(should (ert-equal-buffer |
| 371 |
'(rst-insert-list) |
| 372 |
"\^@ |
| 373 |
" |
| 374 |
"5) \^@ |
| 375 |
" '("1)" 5))) |
| 376 |
(should (ert-equal-buffer |
| 377 |
'(rst-insert-list) |
| 378 |
"\^@ |
| 379 |
" |
| 380 |
"(i) \^@ |
| 381 |
" '("(i)" ""))) |
| 382 |
(should (ert-equal-buffer |
| 383 |
'(rst-insert-list) |
| 384 |
"\^@ |
| 385 |
" |
| 386 |
"IV. \^@ |
| 387 |
" '("I." 4))) |
| 388 |
(should (ert-equal-buffer |
| 389 |
'(rst-insert-list) |
| 390 |
"Some line\^@ |
| 391 |
" |
| 392 |
"Some line |
| 393 |
|
| 394 |
c. \^@ |
| 395 |
" '("a." "c"))) |
| 396 |
(should (ert-equal-buffer |
| 397 |
'(rst-insert-list) |
| 398 |
"Some line |
| 399 |
\^@ |
| 400 |
" |
| 401 |
"Some line |
| 402 |
|
| 403 |
B) \^@ |
| 404 |
" '("A)" "B"))) |
| 405 |
(should (ert-equal-buffer |
| 406 |
'(rst-insert-list) |
| 407 |
"Some line |
| 408 |
|
| 409 |
\^@ |
| 410 |
" |
| 411 |
"Some line |
| 412 |
|
| 413 |
IV. \^@ |
| 414 |
" '("I." 4))) |
| 415 |
(should (ert-equal-buffer |
| 416 |
'(rst-insert-list) |
| 417 |
"Some line |
| 418 |
\^@Another line |
| 419 |
" |
| 420 |
"Some line |
| 421 |
Another line |
| 422 |
|
| 423 |
* \^@ |
| 424 |
" '("*"))) |
| 425 |
) |
| 426 |
|
| 427 |
(ert-deftest rst-insert-list-new-BUGS () |
| 428 |
"Exposes bugs in `rst-insert-list' when inserting a new list." |
| 429 |
:expected-result :failed ;; These are bugs |
| 430 |
(should (ert-equal-buffer |
| 431 |
'(rst-insert-list) |
| 432 |
"\^@ \n" |
| 433 |
"* \^@ |
| 434 |
" '("*"))) |
| 435 |
(should (ert-equal-buffer |
| 436 |
'(rst-insert-list) |
| 437 |
"Some line |
| 438 |
\^@ |
| 439 |
Another line |
| 440 |
" |
| 441 |
"Some line |
| 442 |
|
| 443 |
* \^@ |
| 444 |
|
| 445 |
Another line |
| 446 |
" '("*"))) |
| 447 |
) |
| 448 |
|
| 449 |
(ert-deftest rst-straighten-bullets-region () |
| 450 |
"Tests `rst-straighten-bullets-region'." |
| 451 |
(let ((rst-preferred-bullets '(?* ?-))) |
| 452 |
(should (ert-equal-buffer |
| 453 |
'(rst-straighten-bullets-region) |
| 454 |
"\^@\^?" |
| 455 |
"\^@\^?" |
| 456 |
t)) |
| 457 |
(should (ert-equal-buffer |
| 458 |
'(rst-straighten-bullets-region) |
| 459 |
"\^@ |
| 460 |
- one |
| 461 |
+ two |
| 462 |
* three |
| 463 |
\^?" |
| 464 |
"\^@ |
| 465 |
* one |
| 466 |
* two |
| 467 |
* three |
| 468 |
\^?" |
| 469 |
t)) |
| 470 |
(should (ert-equal-buffer |
| 471 |
'(rst-straighten-bullets-region) |
| 472 |
"- one\^@ |
| 473 |
+ two\^?" |
| 474 |
"* one\^@ |
| 475 |
* two\^?" |
| 476 |
t)) |
| 477 |
(should (ert-equal-buffer |
| 478 |
'(rst-straighten-bullets-region) |
| 479 |
"+ zero |
| 480 |
\^@- one |
| 481 |
+ two |
| 482 |
* three\^? |
| 483 |
- four" |
| 484 |
"+ zero |
| 485 |
\^@* one |
| 486 |
* two |
| 487 |
* three\^? |
| 488 |
- four" |
| 489 |
t)) |
| 490 |
(should (ert-equal-buffer |
| 491 |
'(rst-straighten-bullets-region) |
| 492 |
"\^@ |
| 493 |
- one |
| 494 |
|
| 495 |
+ two |
| 496 |
|
| 497 |
* three |
| 498 |
\^?" |
| 499 |
"\^@ |
| 500 |
* one |
| 501 |
|
| 502 |
- two |
| 503 |
|
| 504 |
* three |
| 505 |
\^?" |
| 506 |
t)) |
| 507 |
(should (ert-equal-buffer |
| 508 |
'(rst-straighten-bullets-region) |
| 509 |
"\^@ |
| 510 |
- one |
| 511 |
|
| 512 |
- two |
| 513 |
|
| 514 |
* three |
| 515 |
\^?" |
| 516 |
"\^@ |
| 517 |
* one |
| 518 |
|
| 519 |
- two |
| 520 |
|
| 521 |
* three |
| 522 |
\^?" |
| 523 |
t)) |
| 524 |
(should (ert-equal-buffer |
| 525 |
'(rst-straighten-bullets-region) |
| 526 |
"\^@ |
| 527 |
+ one |
| 528 |
|
| 529 |
* two |
| 530 |
|
| 531 |
+ three |
| 532 |
\^?" |
| 533 |
"\^@ |
| 534 |
* one |
| 535 |
|
| 536 |
- two |
| 537 |
|
| 538 |
* three |
| 539 |
\^?" |
| 540 |
t)) |
| 541 |
) |
| 542 |
(let ((rst-preferred-bullets nil)) |
| 543 |
(should (ert-equal-buffer |
| 544 |
'(rst-straighten-bullets-region) |
| 545 |
"\^@ |
| 546 |
- one |
| 547 |
+ two |
| 548 |
* three |
| 549 |
\^?" |
| 550 |
"\^@ |
| 551 |
- one |
| 552 |
+ two |
| 553 |
* three |
| 554 |
\^?" |
| 555 |
t)) |
| 556 |
)) |
| 557 |
|
| 558 |
(ert-deftest rst-straighten-bullets-region-BUGS () |
| 559 |
"Tests `rst-straighten-bullets-region'." |
| 560 |
:expected-result :failed ;; These are bugs |
| 561 |
(let ((rst-preferred-bullets '(?* ?-))) |
| 562 |
(should (ert-equal-buffer |
| 563 |
'(rst-straighten-bullets-region) |
| 564 |
"\^@ |
| 565 |
- one |
| 566 |
+ two |
| 567 |
* three |
| 568 |
\^?" |
| 569 |
"\^@ |
| 570 |
* one |
| 571 |
- two |
| 572 |
* three |
| 573 |
\^?" |
| 574 |
t)) |
| 575 |
(should (ert-equal-buffer |
| 576 |
'(rst-straighten-bullets-region) |
| 577 |
"\^@ |
| 578 |
- one |
| 579 |
+ two |
| 580 |
* three |
| 581 |
\^?" |
| 582 |
"\^@ |
| 583 |
* one |
| 584 |
- two |
| 585 |
* three |
| 586 |
\^?" |
| 587 |
t)) |
| 588 |
(should (ert-equal-buffer |
| 589 |
'(rst-straighten-bullets-region) |
| 590 |
"\^@ |
| 591 |
+ one |
| 592 |
* two |
| 593 |
+ three |
| 594 |
\^?" |
| 595 |
"\^@ |
| 596 |
* one |
| 597 |
- two |
| 598 |
* three |
| 599 |
\^?" |
| 600 |
t)) |
| 601 |
)) |
| 602 |
|
| 603 |
(defun arabic-roman-roundtrip (arabic roman) |
| 604 |
"Convert ARABIC to roman, compare it to ROMAN and convert this back. |
| 605 |
Return t if roundtrip is correct." |
| 606 |
(let ((cvt-roman (rst-arabic-to-roman arabic)) |
| 607 |
(cvt-arabic (rst-roman-to-arabic roman))) |
| 608 |
(and (equal roman cvt-roman) (equal arabic cvt-arabic)))) |
| 609 |
|
| 610 |
(ert-deftest arabic-roman-roundtrip () |
| 611 |
"Test `rst-arabic-to-roman' and `rst-roman-to-arabic'." |
| 612 |
|
| 613 |
;; Test invalid arabic numbers. |
| 614 |
(should-error (arabic-roman-roundtrip -1 "I") |
| 615 |
:type 'wrong-type-argument) |
| 616 |
(should-error (arabic-roman-roundtrip 0 "I") |
| 617 |
:type 'wrong-type-argument) |
| 618 |
(should-error (arabic-roman-roundtrip nil "I") |
| 619 |
:type 'wrong-type-argument) |
| 620 |
|
| 621 |
;; Test invalid roman numbers. |
| 622 |
(should-error (arabic-roman-roundtrip 1 nil) |
| 623 |
:type 'wrong-type-argument) |
| 624 |
(should-error (arabic-roman-roundtrip 1 "NoRoman") |
| 625 |
:type 'wrong-type-argument) |
| 626 |
(should-error (arabic-roman-roundtrip 1 "") |
| 627 |
:type 'wrong-type-argument) |
| 628 |
|
| 629 |
;; Test values. |
| 630 |
(should (arabic-roman-roundtrip 1 "I")) |
| 631 |
(should (arabic-roman-roundtrip 4 "IV")) |
| 632 |
(should (arabic-roman-roundtrip 5 "V")) |
| 633 |
(should (arabic-roman-roundtrip 10 "X")) |
| 634 |
(should (arabic-roman-roundtrip 20 "XX")) |
| 635 |
(should (arabic-roman-roundtrip 1999 "MCMXCIX")) |
| 636 |
(should (arabic-roman-roundtrip 2000 "MM")) |
| 637 |
(should (arabic-roman-roundtrip 3333 "MMMCCCXXXIII")) |
| 638 |
(should (arabic-roman-roundtrip 444 "CDXLIV")) |
| 639 |
) |