bkyk8rc3zvpnsf5inmcqq4n3k98cv6hj-my-site-hyper-literate-git.test.suzanne.soy-0.0.1

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

bibtex.rkt (3083B)


      1 #lang racket
      2 (require racket/runtime-path
      3          tests/eli-tester
      4          scriblib/bibtex
      5          scriblib/autobib
      6          scribble/render
      7          (prefix-in text: scribble/text-render))
      8 
      9 (define-runtime-path example.bib "example.bib")
     10 
     11 (define-runtime-path normal-expected-path "bibtex.normal.txt")
     12 (define-runtime-path number-expected-path "bibtex.number.txt")
     13 (define-runtime-path latex-escapes-path "bibtex.latex-escapes.txt")
     14 
     15 (define-syntax-rule (test-render* definer expected-path body generate-bibliography-id)
     16   (let ()
     17     definer
     18 
     19     body
     20 
     21     (define actual-path
     22       (make-temporary-file "~a-bibtex.txt"))
     23 
     24     (render (list (generate-bibliography-id))
     25             (list actual-path)
     26             #:dest-dir (path-only actual-path)
     27             #:render-mixin text:render-mixin)
     28 
     29     (test
     30      (file->string actual-path) => (file->string expected-path))))
     31 
     32 (define-syntax-rule (test-render expected-path options body)
     33   (begin
     34     (test-render* (define-bibtex-cite example.bib
     35                     ~cite-id citet-id generate-bibliography-id . options)
     36                   expected-path
     37                   (body ~cite-id citet-id)
     38                   generate-bibliography-id)
     39     (test-render* (begin
     40                     (define-cite autobib-cite autobib-citet
     41                       generate-bibliography-id . options)
     42                     (define-bibtex-cite* example.bib
     43                       autobib-cite autobib-citet
     44                       ~cite-id citet-id))
     45                   expected-path
     46                   (body ~cite-id citet-id)
     47                   generate-bibliography-id)))
     48 
     49 (test
     50  (let ()
     51    (define example (path->bibdb example.bib))
     52    (define raw (bibdb-raw example))
     53 
     54    (test
     55     (hash-ref (hash-ref raw "sweig42") "month") => "march"
     56     (hash-ref (hash-ref raw "sweig42a") "month") => "1~mar"
     57     (hash-ref (hash-ref raw "sweig42b") "month") => "1~march"
     58     (hash-ref (hash-ref raw "sweig42c") "month") => "1~marcha"))
     59 
     60  (test-render normal-expected-path ()
     61               (λ (~cite-id citet-id)
     62                 (~cite-id "salib:starkiller")
     63                 (~cite-id "cryptoeprint:2000:067")
     64                 (~cite-id "Tobin-Hochstadt:2011fk")
     65                 (~cite-id "cryptoeprint:2000:067" "Tobin-Hochstadt:2011fk")
     66                 (~cite-id "cryptoeprint:2000:067 Tobin-Hochstadt:2011fk")
     67 
     68                 (citet-id "salib:starkiller")
     69                 (citet-id "cryptoeprint:2000:067")
     70                 (citet-id "Tobin-Hochstadt:2011fk")
     71                 (citet-id "Tobin-Hochstadt:2011fk" "Tobin-Hochstadt:2011fk")
     72                 (citet-id "Tobin-Hochstadt:2011fk Tobin-Hochstadt:2011fk")))
     73  (test-render number-expected-path (#:style number-style)
     74               (λ (~cite-id citet-id)
     75                 (citet-id "salib:starkiller")
     76                 (citet-id "cryptoeprint:2000:067")
     77                 (citet-id "Tobin-Hochstadt:2011fk")
     78                 (citet-id "anannoyingkey")))
     79  (test-render latex-escapes-path (#:style number-style)
     80               (λ (~cite-id citet-id)
     81                 (citet-id "Braberman:2008:PPH:1375634.1375655"))))