(use test) (include "../isbn.scm") (import isbn) (include "../openlibrary.scm") (import openlibrary) (test-group "ISBN-10" (test "normal isbn" #t (valid-isbn? "3895760633")) (test "isbn with X as check digit" #t (valid-isbn? "052103311X")) (test "dashes as separators" #t (valid-isbn? "0-521-03311-X")) (test "spaces as separators" #t (valid-isbn? "0 521 03311 X")) (test "spaces and dashes (should fail but we are forgiving" #t (valid-isbn? "0-521-03311 X")) (test "uncommon separator places" #t (valid-isbn? "0-5--2-1--03-3-1-1X")) (test "wrong number" #f (valid-isbn? "1123122312"))) (test-group "ISBN-13" (test "normal isbn-13" #t (valid-isbn? "9780387202488")) (test "isbn with 0 check digit (10)" #t (valid-isbn? "9783937514390"))) (test-group "ISBN classification" (test "ISBN-10" 10 (isbn-type "3895760633")) (test "ISBN-13" 13 (isbn-type "978-8-17525-766-5")) (test "Invalid ISBN" #f (isbn-type "1123122312"))) (test-group "ISBN upgrade" (test "normal isbn" "9788175257665" (isbn10->isbn13 "817525766-0")) (test "isbn with X as check digit" "9780521033114" (isbn10->isbn13 "052103311X"))) (test-group "normalize-isbn" (test "Normalize ISBN-13 (with 10 check digit)" "9783937514390" (normalize-isbn "978-3-937514-39-0")) (test "Normalize ISBN-10 (with 10 check digit)" "052103311X" (normalize-isbn "0-521-03311-X"))) (define literate-programming '((title . "Literate programming") (authors ("Donald Knuth")) (publisher ("Center for the Study of Language and Information")) (publishing-date . "1992") (number-of-pages . 368) (cover-urls ("small" . "http://covers.openlibrary.org/b/id/7102451-S.jpg") ("large" . "http://covers.openlibrary.org/b/id/7102451-L.jpg") ("medium" . "http://covers.openlibrary.org/b/id/7102451-M.jpg")) (isbn-numbers (("0937073806" "0937073814"))))) (define literate-programming-simplified '((title . "Literate programming") (authors ("Donald Knuth")) (publishing-date . "1992") (number-of-pages . 368))) (test-group "openlibrary.org API" (test "Requesting entry for ISBN-10 09370-73890-6" literate-programming (isbn->alist "0937073806")) (test "Requesting same ISBN with restricted return values" literate-programming-simplified (isbn->alist "0937073806" '(title authors publishing-date number-of-pages)))) (test-exit)