diff --git a/scribble-doc/scriblib/scribblings/autobib.scrbl b/scribble-doc/scriblib/scribblings/autobib.scrbl index 787c6169..50baa4cd 100644 --- a/scribble-doc/scriblib/scribblings/autobib.scrbl +++ b/scribble-doc/scriblib/scribblings/autobib.scrbl @@ -212,9 +212,10 @@ describing a paper's location within a journal.} element?]{ Combines elements to generate an element that is suitable for -describing a book's location.} +describing a book's location. +Both arguments are optional, but at least one must be supplied.} -@defproc[(techrpt-location [#:institution institution edition any/c] +@defproc[(techrpt-location [#:institution institution any/c] [#:number number any/c]) element?]{ diff --git a/scribble-lib/scriblib/autobib.rkt b/scribble-lib/scriblib/autobib.rkt index ffe11d1e..4d102b71 100644 --- a/scribble-lib/scriblib/autobib.rkt +++ b/scribble-lib/scriblib/autobib.rkt @@ -16,11 +16,19 @@ (provide define-cite author+date-style number-style make-bib in-bib (rename-out [auto-bib? bib?]) - proceedings-location journal-location book-location - techrpt-location dissertation-location author-name org-author-name (contract-out - [authors (->* (content?) #:rest (listof content?) element?)]) + [authors (->* (content?) #:rest (listof content?) element?)] + [proceedings-location + (->* [any/c] [#:pages (or/c (list/c any/c any/c) #f) #:series any/c #:volume any/c] element?)] + [journal-location + (->* [any/c] [#:pages (or/c (list/c any/c any/c) #f) #:number any/c #:volume any/c] element?)] + [book-location + (->* [] [#:edition any/c #:publisher any/c] element?)] + [techrpt-location + (-> #:institution any/c #:number any/c element?)] + [dissertation-location + (->* [#:institution any/c] [#:degree any/c] element?)]) other-authors editor abbreviate-given-names) @@ -485,12 +493,12 @@ #:pages [pages #f] #:series [series #f] #:volume [volume #f]) - (let* ([s @elem{In @italic{@elem{Proc. @|location|}}}] + (let* ([s @elem{In @italic{@elem{Proc. @to-string[location]}}}] [s (if series - @elem{@|s|, @(format "~a" series)} + @elem{@|s|, @to-string[series]} s)] [s (if volume - @elem{@|s| volume @(format "~a" volume)} + @elem{@|s| volume @to-string[volume]} s)] [s (if pages @elem{@|s|, pp. @(to-string (car pages))--@(to-string (cadr pages))} @@ -502,7 +510,7 @@ #:pages [pages #f] #:number [number #f] #:volume [volume #f]) - (let* ([s @italic{@|location|}] + (let* ([s @italic{@to-string[location]}] [s (if volume @elem{@|s| @(to-string volume)} s)] @@ -518,12 +526,12 @@ #:edition [edition #f] #:publisher [publisher #f]) (let* ([s (if edition - @elem{@(string-titlecase edition) edition} + @elem{@(string-titlecase (to-string edition)) edition} #f)] [s (if publisher (if s - @elem{@|s|. @|publisher|} - publisher) + @elem{@|s|. @to-string[publisher]} + @elem{@to-string[publisher]}) s)]) (unless s (error 'book-location "no arguments")) @@ -532,12 +540,12 @@ (define (techrpt-location #:institution org #:number num) - @elem{@|org|, @|num|}) + @elem{@to-string[org], @to-string[num]}) (define (dissertation-location #:institution org #:degree [degree "PhD"]) - @elem{@|degree| dissertation, @|org|}) + @elem{@to-string[degree] dissertation, @to-string[org]}) ;; ---------------------------------------- diff --git a/scribble-test/tests/scriblib/autobib.rkt b/scribble-test/tests/scriblib/autobib.rkt index 22e65f02..2db86253 100644 --- a/scribble-test/tests/scriblib/autobib.rkt +++ b/scribble-test/tests/scriblib/autobib.rkt @@ -1,15 +1,56 @@ -#lang racket +#lang racket/base -(require scriblib/autobib) +(require rackunit scriblib/autobib) -(let () - (define-cite cite citet gen-bib) - cite citet gen-bib - (void)) +(test-case "define-cite" + ;; Check that `define-cite` binds the expected identifiers -(let () - (define-cite cite citet gen-bib - #:cite-author cite-author - #:cite-year cite-year) - cite citet gen-bib cite-author cite-year - (void)) + (let () + (define-cite cite citet gen-bib) + (check-pred values (void cite citet gen-bib))) + + (let () + (define-cite cite citet gen-bib + #:cite-author cite-author + #:cite-year cite-year) + (check-pred values (void cite citet gen-bib cite-author cite-year)))) + +(test-case "proceedings-location" + (check-not-exn + (λ () (proceedings-location "RacketCon" #:pages '(1 2) #:series 3 #:volume 4))) + (check-not-exn + (λ () (proceedings-location 'PLDI))) + (check-exn exn:fail:contract? + (λ () (proceedings-location "USENIX" #:pages "4--5")))) + +(test-case "journal-location" + (check-not-exn + (λ () (journal-location "CACM" #:pages '(1 2) #:number 3 #:volume 4))) + (check-not-exn + (λ () (journal-location 'JFP))) + (check-exn exn:fail:contract? + (λ () (journal-location "Journal of Chromatography" #:pages 30)))) + +(test-case "book-location" + (check-not-exn + (λ () (book-location #:edition 1 #:publisher "A.C. Clayton"))) + (check-not-exn + (λ () (book-location #:edition 'B #:publisher 'Elsiver))) + (check-exn exn:fail? + (λ () (book-location)))) + +(test-case "techrpt-location" + (check-not-exn + (λ () (techrpt-location #:institution "MIT" #:number 'AIM-353))) + (check-exn exn:fail:contract? + (λ () (techrpt-location #:institution 'UCB)))) + +(test-case "dissertation-location" + (check-not-exn + (λ () (dissertation-location #:institution "New College"))) + (check-not-exn + (λ () (dissertation-location #:institution 'Oberlin))) + (check-not-exn + (λ () (dissertation-location #:institution "Georgetown University" #:degree "BS"))) + (check-exn exn:fail:contract? + (λ () (dissertation-location #:degree "PhD"))))