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 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737
|
;;; parsebib-test.el --- Tests for parsebib
(require 'parsebib)
;; Note: tests are named with the prefix `parsebib-test-' followed by the name
;; of the function being tested, without the `parsebib-' or `parsebib--' prefix.
(ert-deftest parsebib-test-json-stringify-date-part ()
(should (string= (parsebib--json-stringify-date-part [2021 22 4]) "2021-22-4"))
(should (string= (parsebib--json-stringify-date-part [2021 22]) "2021-22"))
(should (string= (parsebib--json-stringify-date-part [2021]) "2021")))
(ert-deftest parsebib-test-json-stringify-date-field ()
(should (string= (parsebib--json-stringify-date-field '(issued
(date-parts . [[2004]])))
"2004"))
(should (string= (parsebib--json-stringify-date-field '(issued
(date-parts . [[2004 4 22]])))
"2004-4-22"))
(should (string= (parsebib--json-stringify-date-field '(issued
(date-parts . [[2004 4 22] [2021 4 22]])))
"2004-4-22/2021-4-22"))
(should (string= (parsebib--json-stringify-date-field '(issued
(date-parts . [[2004] [2021]])))
"2004/2021"))
(should (string= (parsebib--json-stringify-date-field '(issued
(date-parts . [[2004 4]])
(circa . t)))
"ca. 2004-4"))
(should (string= (parsebib--json-stringify-date-field '(issued
(date-parts . [[2004]])
(season . 1)))
"Spring 2004"))
(should (string= (parsebib--json-stringify-date-field '(issued
(literal . "April 2004")))
"April 2004")))
(ert-deftest parsebib-test-json-stringify-name-field ()
(should (string= (parsebib--json-stringify-name-field [((family . "Anderson")
(given . "John R."))
((family . "Bothell")
(given . "Daniel"))])
"Anderson, John R. and Bothell, Daniel"))
(should (string= (parsebib--json-stringify-name-field [((family . "Koning")
(given . "Willem")
(non-dropping-particle . "de"))
((family . "Beethoven")
(dropping-particle . "van")
(given . "Ludwig"))])
"de Koning, Willem and Beethoven, Ludwig van"))
(should (string= (parsebib--json-stringify-name-field [((family . "Gates")
(given . "Bill")
(suffix . "III"))])
"Gates, Bill, III"))
(should (string= (parsebib--json-stringify-name-field [((literal . "Michigan Institute of Technology"))])
"Michigan Institute of Technology")))
;; Test `parsebib-stringify-json-field' with name fields.
(ert-deftest parsebib-test-stringify-json-field--name-fields ()
(should (string= (parsebib-stringify-json-field '(author . [((family . "Anderson")
(given . "John R."))
((family . "Bothell")
(given . "Daniel"))]))
"Anderson, John R. and Bothell, Daniel"))
(should (string= (parsebib-stringify-json-field '(editor . [((family . "Koning")
(given . "Willem")
(non-dropping-particle . "de"))
((family . "Beethoven")
(dropping-particle . "van")
(given . "Ludwig"))]))
"de Koning, Willem and Beethoven, Ludwig van"))
(should (string= (parsebib-stringify-json-field '(translator . [((family . "Gates")
(given . "Bill")
(suffix . "III"))]))
"Gates, Bill, III"))
(should (string= (parsebib-stringify-json-field '(recipient . [((literal . "Michigan Institute of Technology"))]))
"Michigan Institute of Technology")))
;; Test `parsebib-stringify-json-field' with date fields.
(ert-deftest parsebib-test-stringify-json-field--date-fields ()
(should (string= (parsebib-stringify-json-field '(container
(date-parts . [[2004 4 22] [2021 4 22]])))
"2004-4-22/2021-4-22"))
(should (string= (parsebib-stringify-json-field '(submitted
(date-parts . [[2004]])))
"2004"))
(should (string= (parsebib-stringify-json-field '(issued
(date-parts . [[2004 4]])
(circa . t)))
"ca. 2004-4"))
(should (string= (parsebib-stringify-json-field '(event-date
(date-parts . [[2004]])
(season . 1)))
"Spring 2004"))
(should (string= (parsebib-stringify-json-field '(accessed
(literal . "April 2004")))
"April 2004")))
;; Test `parsebib-stringify-json-field' with string fields.
(ert-deftest parsebib-test-stringify-json-field--string-fields ()
(should (string= (parsebib-stringify-json-field '(title . "The Minimalist Program"))
"The Minimalist Program"))
(should (string= (parsebib-stringify-json-field '(ISBN . "1-01-XXXXXX-X"))
"1-01-XXXXXX-X")))
;; Test `parsebib-stringify-json-field' with number fields.
(ert-deftest parsebib-test-stringify-json-field--number-fields ()
(should (string= (parsebib-stringify-json-field '(volume . 3))
"3"))
(should (string= (parsebib-stringify-json-field '(page . 155))
"155")))
;; Test `parsebib-stringify-json-field' with array fields.
(ert-deftest parsebib-test-stringify-json-field--array-fields ()
(should (string= (parsebib-stringify-json-field '(categories . ["fiction" "horror"]))
"fiction, horror")))
;;; Tests for `parsebib-clean-TeX-markup'
(ert-deftest parsebib-clean-TeX-markup-dashes ()
(should (equal (parsebib-clean-TeX-markup "---") "—"))
(should (equal (parsebib-clean-TeX-markup "\\textemdash") "—"))
(should (equal (parsebib-clean-TeX-markup "\\textemdash and") "—and"))
(should (equal (parsebib-clean-TeX-markup "\\textemdash and") "—and"))
(should (equal (parsebib-clean-TeX-markup "\\textemdash{}") "—"))
(should (equal (parsebib-clean-TeX-markup "\\textemdash{}and") "—and"))
(should (equal (parsebib-clean-TeX-markup "\\textemdash{} and") "— and"))
(should (equal (parsebib-clean-TeX-markup "\\textemdash{} and") "— and"))
(should (equal (parsebib-clean-TeX-markup "--") "–"))
(should (equal (parsebib-clean-TeX-markup "\\textendash") "–"))
(should (equal (parsebib-clean-TeX-markup "\\textendash{}") "–")))
(ert-deftest parsebib-clean-TeX-markup-math-and-text-mode-commands ()
(should (equal (parsebib-clean-TeX-markup "\\ddag{} \\textdaggerdbl") "‡ ‡"))
(should (equal (parsebib-clean-TeX-markup "10\\textpertenthousand") "10‱"))
(should (equal (parsebib-clean-TeX-markup "200\\textperthousand.") "200‰."))
(should (equal (parsebib-clean-TeX-markup "\\textquestiondown") "¿"))
(should (equal (parsebib-clean-TeX-markup "\\P 3.2") "¶3.2"))
(should (equal (parsebib-clean-TeX-markup "\\textdollar") "$"))
(should (equal (parsebib-clean-TeX-markup "\\S 5.2") "§5.2"))
(should (equal (parsebib-clean-TeX-markup "\\ldots{} [\\dots] \\textellipsis and")
"… […] …and")))
(ert-deftest parsebib-clean-TeX-markup-nonletter-diacritics-without-braces ()
;; No space is needed after a nonletter diacritic commands.
(should (equal (parsebib-clean-TeX-markup "\\\"a") "a\N{COMBINING DIAERESIS}"))
(should (equal (parsebib-clean-TeX-markup "\\'a") "a\N{COMBINING ACUTE ACCENT}"))
(should (equal (parsebib-clean-TeX-markup "\\.a") "a\N{COMBINING DOT ABOVE}"))
(should (equal (parsebib-clean-TeX-markup "\\=a") "a\N{COMBINING MACRON}"))
(should (equal (parsebib-clean-TeX-markup "\\^a") "a\N{COMBINING CIRCUMFLEX ACCENT}"))
(should (equal (parsebib-clean-TeX-markup "\\`a") "a\N{COMBINING GRAVE ACCENT}"))
(should (equal (parsebib-clean-TeX-markup "\\~a") "a\N{COMBINING TILDE}"))
(should (equal (parsebib-clean-TeX-markup "\\|a") "a\N{COMBINING COMMA ABOVE}"))
;; Spaces are possible, though:
(should (equal (parsebib-clean-TeX-markup "\\' a") "a\N{COMBINING ACUTE ACCENT}"))
(should (equal (parsebib-clean-TeX-markup "\\' a") "a\N{COMBINING ACUTE ACCENT}")))
(ert-deftest parsebib-clean-TeX-markup-letter-diacritics-without-braces ()
;; Diacritic commands that consist of a single letter require a space.
(should (equal (parsebib-clean-TeX-markup "\\b a") "a\N{COMBINING MACRON BELOW}"))
(should (equal (parsebib-clean-TeX-markup "\\c c") "c\N{COMBINING CEDILLA}"))
(should (equal (parsebib-clean-TeX-markup "\\d a") "a\N{COMBINING DOT BELOW}"))
(should (equal (parsebib-clean-TeX-markup "\\H a") "a\N{COMBINING DOUBLE ACUTE ACCENT}"))
(should (equal (parsebib-clean-TeX-markup "\\k a") "a\N{COMBINING OGONEK}"))
(should (equal (parsebib-clean-TeX-markup "\\U a") "a\N{COMBINING DOUBLE VERTICAL LINE ABOVE}"))
(should (equal (parsebib-clean-TeX-markup "\\u a") "a\N{COMBINING BREVE}"))
(should (equal (parsebib-clean-TeX-markup "\\v a") "a\N{COMBINING CARON}"))
(should (equal (parsebib-clean-TeX-markup "\\f a") "a\N{COMBINING INVERTED BREVE}"))
(should (equal (parsebib-clean-TeX-markup "\\G a") "a\N{COMBINING DOUBLE GRAVE ACCENT}"))
(should (equal (parsebib-clean-TeX-markup "\\h a") "a\N{COMBINING HOOK ABOVE}"))
(should (equal (parsebib-clean-TeX-markup "\\C a") "a\N{COMBINING DOUBLE GRAVE ACCENT}"))
(should (equal (parsebib-clean-TeX-markup "\\r a") "a\N{COMBINING RING ABOVE}"))
;; More than one space should also work:
(should (equal (parsebib-clean-TeX-markup "\\b a") "a\N{COMBINING MACRON BELOW}"))
(should (equal (parsebib-clean-TeX-markup "\\b a") "a\N{COMBINING MACRON BELOW}"))
;; It shouldn't work without space. Since something like "\ba after" is
;; essentially a command without an (explicit) argument, it should remain
;; unchanged.
(should (equal (parsebib-clean-TeX-markup "before \\ba after") "before \\ba after")))
(ert-deftest parsebib-clean-TeX-markup-diacritics-with-braces ()
;; Diacritic commands may use braces to mark the argument.
(should (equal (parsebib-clean-TeX-markup "\\\"{a}") "a\N{COMBINING DIAERESIS}"))
(should (equal (parsebib-clean-TeX-markup "\\'{a}") "a\N{COMBINING ACUTE ACCENT}"))
(should (equal (parsebib-clean-TeX-markup "\\.{a}") "a\N{COMBINING DOT ABOVE}"))
(should (equal (parsebib-clean-TeX-markup "\\={a}") "a\N{COMBINING MACRON}"))
(should (equal (parsebib-clean-TeX-markup "\\^{a}") "a\N{COMBINING CIRCUMFLEX ACCENT}"))
(should (equal (parsebib-clean-TeX-markup "\\`{a}") "a\N{COMBINING GRAVE ACCENT}"))
(should (equal (parsebib-clean-TeX-markup "\\b{a}") "a\N{COMBINING MACRON BELOW}"))
(should (equal (parsebib-clean-TeX-markup "\\c{c}") "c\N{COMBINING CEDILLA}"))
(should (equal (parsebib-clean-TeX-markup "\\d{a}") "a\N{COMBINING DOT BELOW}"))
(should (equal (parsebib-clean-TeX-markup "\\H{a}") "a\N{COMBINING DOUBLE ACUTE ACCENT}"))
(should (equal (parsebib-clean-TeX-markup "\\k{a}") "a\N{COMBINING OGONEK}"))
(should (equal (parsebib-clean-TeX-markup "\\U{a}") "a\N{COMBINING DOUBLE VERTICAL LINE ABOVE}"))
(should (equal (parsebib-clean-TeX-markup "\\u{a}") "a\N{COMBINING BREVE}"))
(should (equal (parsebib-clean-TeX-markup "\\v{a}") "a\N{COMBINING CARON}"))
(should (equal (parsebib-clean-TeX-markup "\\~{a}") "a\N{COMBINING TILDE}"))
(should (equal (parsebib-clean-TeX-markup "\\|{a}") "a\N{COMBINING COMMA ABOVE}"))
(should (equal (parsebib-clean-TeX-markup "\\f{a}") "a\N{COMBINING INVERTED BREVE}"))
(should (equal (parsebib-clean-TeX-markup "\\G{a}") "a\N{COMBINING DOUBLE GRAVE ACCENT}"))
(should (equal (parsebib-clean-TeX-markup "\\h{a}") "a\N{COMBINING HOOK ABOVE}"))
(should (equal (parsebib-clean-TeX-markup "\\C{a}") "a\N{COMBINING DOUBLE GRAVE ACCENT}"))
(should (equal (parsebib-clean-TeX-markup "\\r{a}") "a\N{COMBINING RING ABOVE}"))
;; There may be spaces between the command and the argument.
(should (equal (parsebib-clean-TeX-markup "\\' {a}") "a\N{COMBINING ACUTE ACCENT}"))
(should (equal (parsebib-clean-TeX-markup "\\' {a}") "a\N{COMBINING ACUTE ACCENT}")))
(ert-deftest parsebib-clean-TeX-markup-escapable-characters ()
(should (equal (parsebib-clean-TeX-markup "percent: \\%")
"percent: %"))
(should (equal (parsebib-clean-TeX-markup "ampersand: \\&")
"ampersand: &"))
(should (equal (parsebib-clean-TeX-markup "hash: \\#")
"hash: #"))
(should (equal (parsebib-clean-TeX-markup "dollar: \\$")
"dollar: $")))
(ert-deftest parsebib-clean-TeX-markup-quotes ()
(should (equal (parsebib-clean-TeX-markup "``double'' quotes") "\N{LEFT DOUBLE QUOTATION MARK}double\N{RIGHT DOUBLE QUOTATION MARK} quotes"))
(should (equal (parsebib-clean-TeX-markup "`single' quotes") "\N{LEFT SINGLE QUOTATION MARK}single\N{RIGHT SINGLE QUOTATION MARK} quotes")))
(ert-deftest parsebib-clean-TeX-markup-textit ()
(should (equal-including-properties
(parsebib-clean-TeX-markup "The verb \\textit{krijgen} as an undative verb.")
#("The verb krijgen as an undative verb." 9 16
(face italic))))
(should (equal
(let ((parsebib-TeX-cleanup-target 'markdown))
(parsebib-clean-TeX-markup "The verb \\textit{krijgen} as an undative verb."))
"The verb *krijgen* as an undative verb."))
(should (equal
(let ((parsebib-TeX-cleanup-target 'org))
(parsebib-clean-TeX-markup "The verb \\textit{krijgen} as an undative verb."))
"The verb /krijgen/ as an undative verb."))
(should (equal
(let ((parsebib-TeX-cleanup-target 'plain))
(parsebib-clean-TeX-markup "The verb \\textit{krijgen} as an undative verb."))
"The verb krijgen as an undative verb.")))
(ert-deftest parsebib-clean-TeX-markup-emph ()
(should (equal-including-properties
(parsebib-clean-TeX-markup "The verb \\emph{krijgen} as an undative verb.")
#("The verb krijgen as an undative verb." 9 16
(face italic))))
(should (equal
(let ((parsebib-TeX-cleanup-target 'markdown))
(parsebib-clean-TeX-markup "The verb \\emph{krijgen} as an undative verb."))
"The verb *krijgen* as an undative verb."))
(should (equal
(let ((parsebib-TeX-cleanup-target 'org))
(parsebib-clean-TeX-markup "The verb \\emph{krijgen} as an undative verb."))
"The verb /krijgen/ as an undative verb.")))
(ert-deftest parsebib-clean-TeX-markup-textbf ()
(should (equal-including-properties
(parsebib-clean-TeX-markup "The verb \\textbf{krijgen} as an undative verb.")
#("The verb krijgen as an undative verb." 9 16
(face bold))))
(should (equal
(let ((parsebib-TeX-cleanup-target 'markdown))
(parsebib-clean-TeX-markup "The verb \\textbf{krijgen} as an undative verb."))
"The verb **krijgen** as an undative verb."))
(should (equal
(let ((parsebib-TeX-cleanup-target 'org))
(parsebib-clean-TeX-markup "The verb \\textbf{krijgen} as an undative verb."))
"The verb *krijgen* as an undative verb.")))
(ert-deftest parsebib-clean-TeX-markup-textsc ()
(should (equal
(parsebib-clean-TeX-markup "The verb \\textsc{krijgen} as an undative verb.")
"The verb KRIJGEN as an undative verb.")))
(ert-deftest parsebib-clean-TeX-markup-nested-macros ()
(should (equal (parsebib-clean-TeX-markup "\\textit{\\foo{bar}}")
#("bar" 0 3 (face italic))))
(should (equal (parsebib-clean-TeX-markup "\\textit{\\foo}}")
#("\\foo" 0 4 (face italic)))))
(ert-deftest parsebib-clean-TeX-markup-nonascii-letters-with-braces ()
;; The braces should be removed and the space after it retained.
(should (equal (parsebib-clean-TeX-markup "\\AA{} and") "\N{LATIN CAPITAL LETTER A WITH RING ABOVE} and"))
(should (equal (parsebib-clean-TeX-markup "\\AE{} and") "\N{LATIN CAPITAL LETTER AE} and"))
(should (equal (parsebib-clean-TeX-markup "\\DH{} and") "\N{LATIN CAPITAL LETTER ETH} and"))
(should (equal (parsebib-clean-TeX-markup "\\DJ{} and") "\N{LATIN CAPITAL LETTER ETH} and"))
(should (equal (parsebib-clean-TeX-markup "\\L{} and") "\N{LATIN CAPITAL LETTER L WITH STROKE} and"))
(should (equal (parsebib-clean-TeX-markup "\\SS{} and") "\N{LATIN CAPITAL LETTER SHARP S} and"))
(should (equal (parsebib-clean-TeX-markup "\\NG{} and") "\N{LATIN CAPITAL LETTER ENG} and"))
(should (equal (parsebib-clean-TeX-markup "\\OE{} and") "\N{LATIN CAPITAL LIGATURE OE} and"))
(should (equal (parsebib-clean-TeX-markup "\\O{} and") "\N{LATIN CAPITAL LETTER O WITH STROKE} and"))
(should (equal (parsebib-clean-TeX-markup "\\TH{} and") "\N{LATIN CAPITAL LETTER THORN} and"))
(should (equal (parsebib-clean-TeX-markup "\\aa{} and") "\N{LATIN SMALL LETTER A WITH RING ABOVE} and"))
(should (equal (parsebib-clean-TeX-markup "\\ae{} and") "\N{LATIN SMALL LETTER AE} and"))
(should (equal (parsebib-clean-TeX-markup "\\dh{} and") "\N{LATIN SMALL LETTER ETH} and"))
(should (equal (parsebib-clean-TeX-markup "\\dj{} and") "\N{LATIN SMALL LETTER ETH} and"))
(should (equal (parsebib-clean-TeX-markup "\\l{} and") "\N{LATIN SMALL LETTER L WITH STROKE} and"))
(should (equal (parsebib-clean-TeX-markup "\\ss{} and") "\N{LATIN SMALL LETTER SHARP S} and"))
(should (equal (parsebib-clean-TeX-markup "\\ng{} and") "\N{LATIN SMALL LETTER ENG} and"))
(should (equal (parsebib-clean-TeX-markup "\\oe{} and") "\N{LATIN SMALL LIGATURE OE} and"))
(should (equal (parsebib-clean-TeX-markup "\\o{} and") "\N{LATIN SMALL LETTER O WITH STROKE} and"))
(should (equal (parsebib-clean-TeX-markup "\\th{} and") "\N{LATIN SMALL LETTER THORN} and"))
(should (equal (parsebib-clean-TeX-markup "\\ij{} and") "ij and"))
(should (equal (parsebib-clean-TeX-markup "\\i{} and") "\N{LATIN SMALL LETTER DOTLESS I} and"))
(should (equal (parsebib-clean-TeX-markup "\\j{} and") "\N{LATIN SMALL LETTER DOTLESS J} and"))
;; More than one space should work as well.
(should (equal (parsebib-clean-TeX-markup "\\AA{} and") "\N{LATIN CAPITAL LETTER A WITH RING ABOVE} and"))
(should (equal (parsebib-clean-TeX-markup "\\AA{} and") "\N{LATIN CAPITAL LETTER A WITH RING ABOVE} and")))
(ert-deftest parsebib-clean-TeX-markup-nonascii-letters-without-braces ()
;; The space should be removed.
(should (equal (parsebib-clean-TeX-markup "\\AA n") "\N{LATIN CAPITAL LETTER A WITH RING ABOVE}n"))
(should (equal (parsebib-clean-TeX-markup "\\AE n") "\N{LATIN CAPITAL LETTER AE}n"))
(should (equal (parsebib-clean-TeX-markup "\\DH n") "\N{LATIN CAPITAL LETTER ETH}n"))
(should (equal (parsebib-clean-TeX-markup "\\DJ n") "\N{LATIN CAPITAL LETTER ETH}n"))
(should (equal (parsebib-clean-TeX-markup "\\L n") "\N{LATIN CAPITAL LETTER L WITH STROKE}n"))
(should (equal (parsebib-clean-TeX-markup "\\SS n") "\N{LATIN CAPITAL LETTER SHARP S}n"))
(should (equal (parsebib-clean-TeX-markup "\\NG n") "\N{LATIN CAPITAL LETTER ENG}n"))
(should (equal (parsebib-clean-TeX-markup "\\OE n") "\N{LATIN CAPITAL LIGATURE OE}n"))
(should (equal (parsebib-clean-TeX-markup "\\O n") "\N{LATIN CAPITAL LETTER O WITH STROKE}n"))
(should (equal (parsebib-clean-TeX-markup "\\TH n") "\N{LATIN CAPITAL LETTER THORN}n"))
(should (equal (parsebib-clean-TeX-markup "\\aa n") "\N{LATIN SMALL LETTER A WITH RING ABOVE}n"))
(should (equal (parsebib-clean-TeX-markup "\\ae n") "\N{LATIN SMALL LETTER AE}n"))
(should (equal (parsebib-clean-TeX-markup "\\dh n") "\N{LATIN SMALL LETTER ETH}n"))
(should (equal (parsebib-clean-TeX-markup "\\dj n") "\N{LATIN SMALL LETTER ETH}n"))
(should (equal (parsebib-clean-TeX-markup "\\l n") "\N{LATIN SMALL LETTER L WITH STROKE}n"))
(should (equal (parsebib-clean-TeX-markup "\\ss n") "\N{LATIN SMALL LETTER SHARP S}n"))
(should (equal (parsebib-clean-TeX-markup "\\ng n") "\N{LATIN SMALL LETTER ENG}n"))
(should (equal (parsebib-clean-TeX-markup "\\oe n") "\N{LATIN SMALL LIGATURE OE}n"))
(should (equal (parsebib-clean-TeX-markup "\\o n") "\N{LATIN SMALL LETTER O WITH STROKE}n"))
(should (equal (parsebib-clean-TeX-markup "\\th n") "\N{LATIN SMALL LETTER THORN}n"))
(should (equal (parsebib-clean-TeX-markup "\\ij n") "ijn"))
(should (equal (parsebib-clean-TeX-markup "\\i n") "\N{LATIN SMALL LETTER DOTLESS I}n"))
(should (equal (parsebib-clean-TeX-markup "\\j n") "\N{LATIN SMALL LETTER DOTLESS J}n"))
;; More than one space should work as well.
(should (equal (parsebib-clean-TeX-markup "\\AA n") "\N{LATIN CAPITAL LETTER A WITH RING ABOVE}n"))
(should (equal (parsebib-clean-TeX-markup "\\AA n") "\N{LATIN CAPITAL LETTER A WITH RING ABOVE}n"))
;; If there is no space, treat it as an unknown command.
(should (equal (parsebib-clean-TeX-markup "\\AAn") "\\AAn")))
(ert-deftest parsebib-clean-TeX-markup-other-commands ()
;; Do not change commands with no arguments.
(should (equal (parsebib-clean-TeX-markup "\\LaTeX and") "\\LaTeX and"))
;; Commands with an empty set of braces should remain, the braces should be removed.
(should (equal (parsebib-clean-TeX-markup "\\LaTeX{} and") "\\LaTeX and"))
;; Obligatory arguments should replace the command.
(should (equal (parsebib-clean-TeX-markup "\\foo{bar} and") "bar and"))
;; Optional arguments should be removed, even empty ones.
(should (equal (parsebib-clean-TeX-markup "\\foo[]{bar} and") "bar and"))
(should (equal (parsebib-clean-TeX-markup "\\foo[bar]{baz} and") "baz and"))
(should (equal (parsebib-clean-TeX-markup "\\foo[bar][baz]{boo} and") "boo and"))
(should (equal (parsebib-clean-TeX-markup "\\foo[bar][baz]{} and") "\\foo and")))
(ert-deftest parsebib-clean-TeX-markup-braces ()
;; Braces not part of a command should be removed.
(should (equal (parsebib-clean-TeX-markup "The {UN} should be all-caps.") "The UN should be all-caps.")))
;;; Test for reading the .bib file for display.
;; Test if @String abbreviations are expanded.
(ert-deftest parsebib-test-parse-bib-buffer-@Strings ()
(should (equal
(with-temp-buffer
(insert "@String{MGrt = {Berlin: Mouton de Gruyter}}\n"
"\n"
"@book{Alexiadou:Haegeman:Stavrou2007,\n"
" year = {2007},\n"
" publisher = MGrt,\n"
" title = {Noun Phrase in the Generative Perspective},\n"
" author = {Alexiadou, Artemis and Haegeman, Liliane and Stavrou, Melita},\n"
" timestamp = {2013-09-25 12:00:00 (CET)},\n"
" file = {a/Alexiadou_Haegeman_Stavrou2007.pdf}}\n")
(let ((results (parsebib-parse-bib-buffer :expand-strings t)))
(alist-get "publisher" (gethash "Alexiadou:Haegeman:Stavrou2007" (car results))
nil nil #'equal)))
"Berlin: Mouton de Gruyter")))
;; Test if braces around the `file' field are removed.
(ert-deftest parsebib-test-parse-bib-buffer-braces-in-file-field ()
(should (equal
(with-temp-buffer
(insert "@String{MGrt = {Berlin: Mouton de Gruyter}}\n"
"\n"
"@book{Alexiadou:Haegeman:Stavrou2007,\n"
" year = {2007},\n"
" publisher = MGrt,\n"
" title = {Noun Phrase in the Generative Perspective},\n"
" author = {Alexiadou, Artemis and Haegeman, Liliane and Stavrou, Melita},\n"
" timestamp = {2013-09-25 12:00:00 (CET)},\n"
" file = {a/Alexiadou_Haegeman_Stavrou2007.pdf}}\n")
(let ((results (parsebib-parse-bib-buffer :expand-strings t)))
(alist-get "file" (gethash "Alexiadou:Haegeman:Stavrou2007" (car results))
nil nil #'equal)))
"a/Alexiadou_Haegeman_Stavrou2007.pdf")))
;; Test if TeX markup is handled.
(ert-deftest parsebib-test-parse-bib-buffer-TeX-markup ()
(should (equal
(with-temp-buffer
(insert "@Article{Broekhuis:Cornips2012,\n"
" doi = {10.1515/ling-2012-0039},\n"
" file = {b/Broekhuis_Cornips2012.pdf},\n"
" pages = {1205-1249},\n"
" volume = {50},\n"
" number = {6},\n"
" date = {2012},\n"
" journaltitle = {Linguistics},\n"
" title = {The Verb \\textit{krijgen} `to get' as an Undative Verb},\n"
" author = {Broekhuis, Hans and Cornips, Leonie},\n"
" timestamp = {2019-01-16 23:38:31 (CET)}}\n")
(let ((results (parsebib-parse-bib-buffer :replace-TeX t)))
(alist-get "title" (gethash "Broekhuis:Cornips2012" (car results))
nil nil #'equal)))
#("The Verb krijgen ‘to get’ as an Undative Verb" 9 16 (face italic)))))
;; Test if white space is collapsed.
(ert-deftest parsebib-test-parse-bib-buffer-collapse-whitespace ()
(should (equal
(with-temp-buffer
(insert "@String{MGrt = {Berlin: Mouton de Gruyter}}\n"
"\n"
"@book{Alexiadou:Haegeman:Stavrou2007,\n"
" year = {2007},\n"
" publisher = MGrt,\n"
" title = {Noun Phrase in the \n Generative Perspective},\n"
" author = {Alexiadou, Artemis and Haegeman, Liliane and Stavrou, Melita},\n"
" timestamp = {2013-09-25 12:00:00 (CET)},\n"
" file = {a/Alexiadou_Haegeman_Stavrou2007.pdf}}\n")
(let ((results (parsebib-parse-bib-buffer :expand-strings t)))
(alist-get "title" (gethash "Alexiadou:Haegeman:Stavrou2007" (car results))
nil nil #'equal)))
"Noun Phrase in the Generative Perspective")))
;; Test if sequences of spaces in file names are retained, even if @strings are expanded.
(ert-deftest parsebib-test-parse-bib-buffer-dont-collapse-whitespace-in-file-field ()
(should (equal
(with-temp-buffer
(insert
"@inproceedings{ahnIdentifyingCPUBottlenecks,\n"
" title = {Identifying {{On-}}/{{Off-CPU Bottlenecks Together}} with {{Blocked Samples}} {\textbar} {{USENIX}}},\n"
" shorttitle = {{{BCOZ}}},\n"
" author = {Ahn, Minwoo and Han, Jeongmin and Kwon, Youngjin and Jeong, Jinkyu},\n"
" urldate = {2024-10-09},\n"
" langid = {english},\n"
" file = {/Users/xxxx/Zotero/storage/ZJVUZD8F/Ahn et al. - Identifying On-Off-CPU Bottlenecks Together with Blocked Samples USENIX.pdf}}\n")
(let ((results (parsebib-parse-bib-buffer :expand-strings t)))
(alist-get "file" (gethash "ahnIdentifyingCPUBottlenecks" (car results))
nil nil #'equal)))
"/Users/xxxx/Zotero/storage/ZJVUZD8F/Ahn et al. - Identifying On-Off-CPU Bottlenecks Together with Blocked Samples USENIX.pdf")))
;;; Test inheritance
(ert-deftest parsebib-test-parse-bib-buffer-biblatex-inheritance ()
(should (equal
(with-temp-buffer
(insert
"@InCollection{Ackema:Neeleman2002,\n"
"pages = {219-256},\n"
"title = {Effects of Short-Term Storage in Processing Rightward Movement},\n"
"crossref = {Nooteboom:Weerman:Wijnen},\n"
"author = {Ackema, Peter and Neeleman, Ad}}\n"
"\n"
"@Collection{Nooteboom:Weerman:Wijnen,\n"
" year = {2002},\n"
" publisher = Klw,\n"
" title = {Storage and Computation in the Language Faculty},\n"
" editor = {Nooteboom, Sieb and Weerman, Fred and Wijnen, Frank}}\n")
(let* ((results (parsebib-parse-bib-buffer :inheritance 'biblatex)))
(alist-get "booktitle" (gethash "Ackema:Neeleman2002" (car results))
nil nil #'equal)))
"{Storage and Computation in the Language Faculty}")))
;;; Test the RDP
(ert-deftest parsebib-test-@comment ()
(should (equal
(with-temp-buffer
(insert "@Comment{ -*-coding: utf-8 -*- }\n")
(goto-char (point-min))
(parsebib--@comment))
"{ -*-coding: utf-8 -*- }"))
(should (equal
(with-temp-buffer
(insert "@Comment -*-coding: utf-8 -*-\n")
(goto-char (point-min))
(parsebib--@comment))
"-*-coding: utf-8 -*-"))
(should (equal
(with-temp-buffer
(insert "@Comment{\n"
" Local Variables:\n"
" bibtex-dialect: biblatex\n"
" End:\n"
"}\n")
(goto-char (point-min))
(parsebib--@comment))
(concat "{\n"
" Local Variables:\n"
" bibtex-dialect: biblatex\n"
" End:\n"
"}"))))
(ert-deftest parsebib-test-@string ()
;; @String definition with curly braces.
(should (equal
(with-temp-buffer
(insert "@String{MGrt = {Berlin: Mouton de Gruyter}}")
(goto-char (point-min))
(parsebib--@string))
(list "MGrt" "{Berlin: Mouton de Gruyter}")))
;; @String definition with double quotes.
(should (equal
(with-temp-buffer
(insert "@String{LI = \"Linguistic Inquiry\"}")
(goto-char (point-min))
(parsebib--@string))
(list "LI" "\"Linguistic Inquiry\"")))
;; @String definition with @String abbrev.
(should (equal
(with-temp-buffer
(insert "@String{CUP = {Cambridge: Cambridge } # UP}")
(goto-char (point-min))
(parsebib--@string))
(list "CUP" "{Cambridge: Cambridge }" "UP")))
;; @String definition missing closing curly brace.
(should-error (with-temp-buffer
(insert "@String{CUP = {Cambridge: Cambridge } # UP\n")
(goto-char (point-min))
(parsebib--@string))
:type 'parsebib-error)
;; @String definition with mismatched brace/parenthesis.
(should-error (with-temp-buffer
(insert "@String{CUP = {Cambridge: Cambridge } # UP)\n")
(goto-char (point-min))
(parsebib--@string))
:type 'parsebib-error)
;; @String abbreviation without expansion.
(should (equal (with-temp-buffer
(insert "@Article{Potapov_2016aa,\n"
" author = {Potapov, Denis and Sukochev, Fedor and Zanin, Dmitriy},\n"
" month = dec,\n"
" title = {{Krein's trace theorem revisited}},\n"
" url = {http://arxiv.org/abs/1701.00697v1},\n"
" year = {2016}\n"
"}\n")
(goto-char (point-min))
(let ((results (parsebib-read-entry nil #s(hash-table size 10 data nil test equal))))
(alist-get "month" results nil nil #'equal)))
"dec")))
(ert-deftest parsebib-test-read-entry-nested-braces ()
(should (equal
(with-temp-buffer
(insert "@article{10.1162/coli_a_00528,\n"
" title = {Usage-based {Grammar Induction} from {Minimal Cognitive Principles}}\n"
"}\n")
(goto-char (point-min))
(let ((results (parsebib-read-entry)))
(alist-get "title" results nil nil #'equal)))
"{Usage-based {Grammar Induction} from {Minimal Cognitive Principles}}")))
(ert-deftest parsebib-test-read-entry-after-last-field ()
;; The last field in an entry does not have to have a comma after it:
(should (equal
(with-temp-buffer
(insert "@article{10.1162/coli_a_00528,\n"
" title = {Usage-based Grammar Induction from Minimal Cognitive Principles}\n"
"}\n")
(goto-char (point-min))
(let ((results (parsebib-read-entry)))
(cons (alist-get "=key=" results nil nil #'equal)
(alist-get "title" results nil nil #'equal))))
(cons "10.1162/coli_a_00528"
"{Usage-based Grammar Induction from Minimal Cognitive Principles}")))
;; But there *may* be a comma after the last field:
(should (equal
(with-temp-buffer
(insert "@article{10.1162/coli_a_00528,\n"
" title = {Usage-based Grammar Induction from Minimal Cognitive Principles},\n"
"}\n")
(goto-char (point-min))
(let ((results (parsebib-read-entry)))
(cons (alist-get "=key=" results nil nil #'equal)
(alist-get "title" results nil nil #'equal))))
(cons "10.1162/coli_a_00528"
"{Usage-based Grammar Induction from Minimal Cognitive Principles}"))))
;; Test braces and parentheses around an entry:
(ert-deftest parsebib-test-read-entry-parentheses ()
;; Braces.
(should (equal
(with-temp-buffer
(insert "@book{Alexiadou:Haegeman:Stavrou2007,\n"
" year = {2007},\n"
" publisher = MGrt,\n"
" title = {Noun Phrase in the Generative Perspective},\n"
" author = {Alexiadou, Artemis and Haegeman, Liliane and Stavrou, Melita},\n"
" timestamp = {2013-09-25 12:00:00 (CET)},\n"
" file = {a/Alexiadou_Haegeman_Stavrou2007.pdf}}\n")
(goto-char (point-min))
(let ((results (parsebib-read-entry)))
(alist-get "=key=" results nil nil #'equal)))
"Alexiadou:Haegeman:Stavrou2007"))
;; Parentheses.
(should (equal
(with-temp-buffer
(insert "@book(Alexiadou:Haegeman:Stavrou2007,\n"
" year = {2007},\n"
" publisher = MGrt,\n"
" title = {Noun Phrase in the Generative Perspective},\n"
" author = {Alexiadou, Artemis and Haegeman, Liliane and Stavrou, Melita},\n"
" timestamp = {2013-09-25 12:00:00 (CET)},\n"
" file = {a/Alexiadou_Haegeman_Stavrou2007.pdf})\n")
(goto-char (point-min))
(let ((results (parsebib-read-entry)))
(alist-get "=key=" results nil nil #'equal)))
"Alexiadou:Haegeman:Stavrou2007"))
;; Mismatched should error.
(should-error (with-temp-buffer
(insert "@book(Alexiadou:Haegeman:Stavrou2007,\n"
" year = {2007},\n"
" publisher = MGrt,\n"
" title = {Noun Phrase in the Generative Perspective},\n"
" author = {Alexiadou, Artemis and Haegeman, Liliane and Stavrou, Melita},\n"
" timestamp = {2013-09-25 12:00:00 (CET)},\n"
" file = {a/Alexiadou_Haegeman_Stavrou2007.pdf}}\n")
(goto-char (point-min))
(let ((results (parsebib-read-entry)))
(alist-get "=key=" results nil nil #'equal)))
:type 'parsebib-error))
;; Test unbalanced parentheses in field values.
(ert-deftest parsebib-test-unbalanced-parentheses-in-fields ()
;; (ASCII) LEFT PARENTHESIS
(should (equal (with-temp-buffer
(insert
"@article{Title,\n"
" title = {{Title}},\n"
" author = {Author},\n"
" year = {1970},\n"
" journal = {Journal},\n"
" abstract = {(}\n"
"}\n")
(goto-char (point-min))
(let ((results (parsebib-read-entry)))
(alist-get "abstract" results nil nil #'equal)))
"{(}"))
;; (ASCII) RIGHT PARENTHESIS
(should (equal (with-temp-buffer
(insert
"@article{Title,\n"
" title = {{Title}},\n"
" author = {Author},\n"
" year = {1970},\n"
" journal = {Journal},\n"
" abstract = {)}\n"
"}\n")
(goto-char (point-min))
(let ((results (parsebib-read-entry)))
(alist-get "abstract" results nil nil #'equal)))
"{)}"))
;; (ASCII) LEFT and RIGHT CURLY BRACKET with double quotes as delimiters.
(should (equal (with-temp-buffer
(insert
"@article{Title,\n"
" title = {{Title}},\n"
" author = {Author},\n"
" year = {1970},\n"
" journal = \"Journal{\",\n"
" abstract = \"Abstract}\"\n"
"}\n")
(goto-char (point-min))
(let ((results (parsebib-read-entry)))
(cons (alist-get "journal" results nil nil #'equal)
(alist-get "abstract" results nil nil #'equal))))
(cons "\"Journal{\"" "\"Abstract}\"")))
;; (CJK) FULLWIDTH LEFT PARENTHESIS
(should (equal (with-temp-buffer
(insert
"@article{Title,\n"
" title = {{Title}},\n"
" author = {Author},\n"
" year = {1970},\n"
" journal = {Journal},\n"
" abstract = {(}\n"
"}\n")
(goto-char (point-min))
(let ((results (parsebib-read-entry)))
(alist-get "abstract" results nil nil #'equal)))
"{(}"))
;; (CJK) FULLWIDTH LEFT PARENTHESIS
(should (equal (with-temp-buffer
(insert
"@article{Title,\n"
" title = {{Title}},\n"
" author = {Author},\n"
" year = {1970},\n"
" journal = {Journal},\n"
" abstract = {)}\n"
"}\n")
(goto-char (point-min))
(let ((results (parsebib-read-entry)))
(alist-get "abstract" results nil nil #'equal)))
"{)}"))
;; (CJK) FULLWIDTH LEFT and RIGHT PARENTHESIS with double quotes as delimiters.
(should (equal (with-temp-buffer
(insert
"@article{Title,\n"
" title = {{Title}},\n"
" author = {Author},\n"
" year = {1970},\n"
" journal = \"Journal(\",\n"
" abstract = \"Abstract)\"\n"
"}\n")
(goto-char (point-min))
(let ((results (parsebib-read-entry)))
(cons (alist-get "journal" results nil nil #'equal)
(alist-get "abstract" results nil nil #'equal))))
(cons "\"Journal(\"" "\"Abstract)\""))))
(ert-deftest parsebib-test-@-in-key ()
(should (equal (with-temp-buffer
(insert
"@misc{[@mjnanakar]_2024,\n"
" type = {{Tweet}},\n"
" year = {2024},\n"
" month = dec,\n"
" journal = {Twitter},\n"
" urldate = {2024-12-25},\n"
" langid = {persian},\n"
" keywords = {/unread}\n"
"}\n")
(goto-char (point-min))
(let ((results (parsebib-read-entry)))
(alist-get "=key=" results nil nil #'equal)))
"[@mjnanakar]_2024")))
;;; parsebib-test.el ends here
|