autobib: add contracts to *-location
functions
add contracts to location-formatting functions, and make sure those functions convert their inputs to strings, and fix a documentation bug in `techrpt-location`
This commit is contained in:
parent
4c8ac8e021
commit
b289b76536
|
@ -212,9 +212,10 @@ describing a paper's location within a journal.}
|
||||||
element?]{
|
element?]{
|
||||||
|
|
||||||
Combines elements to generate an element that is suitable for
|
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])
|
[#:number number any/c])
|
||||||
element?]{
|
element?]{
|
||||||
|
|
||||||
|
|
|
@ -16,11 +16,19 @@
|
||||||
(provide define-cite
|
(provide define-cite
|
||||||
author+date-style number-style
|
author+date-style number-style
|
||||||
make-bib in-bib (rename-out [auto-bib? bib?])
|
make-bib in-bib (rename-out [auto-bib? bib?])
|
||||||
proceedings-location journal-location book-location
|
|
||||||
techrpt-location dissertation-location
|
|
||||||
author-name org-author-name
|
author-name org-author-name
|
||||||
(contract-out
|
(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
|
other-authors
|
||||||
editor
|
editor
|
||||||
abbreviate-given-names)
|
abbreviate-given-names)
|
||||||
|
@ -485,12 +493,12 @@
|
||||||
#:pages [pages #f]
|
#:pages [pages #f]
|
||||||
#:series [series #f]
|
#:series [series #f]
|
||||||
#:volume [volume #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
|
[s (if series
|
||||||
@elem{@|s|, @(format "~a" series)}
|
@elem{@|s|, @to-string[series]}
|
||||||
s)]
|
s)]
|
||||||
[s (if volume
|
[s (if volume
|
||||||
@elem{@|s| volume @(format "~a" volume)}
|
@elem{@|s| volume @to-string[volume]}
|
||||||
s)]
|
s)]
|
||||||
[s (if pages
|
[s (if pages
|
||||||
@elem{@|s|, pp. @(to-string (car pages))--@(to-string (cadr pages))}
|
@elem{@|s|, pp. @(to-string (car pages))--@(to-string (cadr pages))}
|
||||||
|
@ -502,7 +510,7 @@
|
||||||
#:pages [pages #f]
|
#:pages [pages #f]
|
||||||
#:number [number #f]
|
#:number [number #f]
|
||||||
#:volume [volume #f])
|
#:volume [volume #f])
|
||||||
(let* ([s @italic{@|location|}]
|
(let* ([s @italic{@to-string[location]}]
|
||||||
[s (if volume
|
[s (if volume
|
||||||
@elem{@|s| @(to-string volume)}
|
@elem{@|s| @(to-string volume)}
|
||||||
s)]
|
s)]
|
||||||
|
@ -518,12 +526,12 @@
|
||||||
#:edition [edition #f]
|
#:edition [edition #f]
|
||||||
#:publisher [publisher #f])
|
#:publisher [publisher #f])
|
||||||
(let* ([s (if edition
|
(let* ([s (if edition
|
||||||
@elem{@(string-titlecase edition) edition}
|
@elem{@(string-titlecase (to-string edition)) edition}
|
||||||
#f)]
|
#f)]
|
||||||
[s (if publisher
|
[s (if publisher
|
||||||
(if s
|
(if s
|
||||||
@elem{@|s|. @|publisher|}
|
@elem{@|s|. @to-string[publisher]}
|
||||||
publisher)
|
@elem{@to-string[publisher]})
|
||||||
s)])
|
s)])
|
||||||
(unless s
|
(unless s
|
||||||
(error 'book-location "no arguments"))
|
(error 'book-location "no arguments"))
|
||||||
|
@ -532,12 +540,12 @@
|
||||||
(define (techrpt-location
|
(define (techrpt-location
|
||||||
#:institution org
|
#:institution org
|
||||||
#:number num)
|
#:number num)
|
||||||
@elem{@|org|, @|num|})
|
@elem{@to-string[org], @to-string[num]})
|
||||||
|
|
||||||
(define (dissertation-location
|
(define (dissertation-location
|
||||||
#:institution org
|
#:institution org
|
||||||
#:degree [degree "PhD"])
|
#:degree [degree "PhD"])
|
||||||
@elem{@|degree| dissertation, @|org|})
|
@elem{@to-string[degree] dissertation, @to-string[org]})
|
||||||
|
|
||||||
;; ----------------------------------------
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,56 @@
|
||||||
#lang racket
|
#lang racket/base
|
||||||
|
|
||||||
(require scriblib/autobib)
|
(require rackunit scriblib/autobib)
|
||||||
|
|
||||||
|
(test-case "define-cite"
|
||||||
|
;; Check that `define-cite` binds the expected identifiers
|
||||||
|
|
||||||
(let ()
|
(let ()
|
||||||
(define-cite cite citet gen-bib)
|
(define-cite cite citet gen-bib)
|
||||||
cite citet gen-bib
|
(check-pred values (void cite citet gen-bib)))
|
||||||
(void))
|
|
||||||
|
|
||||||
(let ()
|
(let ()
|
||||||
(define-cite cite citet gen-bib
|
(define-cite cite citet gen-bib
|
||||||
#:cite-author cite-author
|
#:cite-author cite-author
|
||||||
#:cite-year cite-year)
|
#:cite-year cite-year)
|
||||||
cite citet gen-bib cite-author cite-year
|
(check-pred values (void cite citet gen-bib cite-author cite-year))))
|
||||||
(void))
|
|
||||||
|
(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"))))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user