(use test yelp) ;; NOTE: the following (include...) is intentionally missing and cannot be ;; automated easily. The Yelp API requires individual developers hold their ;; own API keys. See the egg's documentation for more information. ;; (include "../../ywsid.scm") (define phone "4154376800") (define pretty-phone "(415)437-6800") (define lat "37.761398") (define lon "-122.424003") (define lat-br "37.5") (define lon-br "-122.2") (define loc "380 alabama st, san francisco ca") (define ino "(415)922-3121") (define-syntax test-case (syntax-rules () ((test-case thing) (test-assert (valid? thing))))) (let-values (((y status) (by-phone pretty-phone))) (test-assert "success" (eq? status 'yelp-success)) (test-assert "validity" (valid? y)) (test-assert "json structure" (vector? y)) (test "display-info" #t (<= 128 (string-length (with-output-to-string (lambda () (display-info y)))))) (test-assert "decode" (< 1 (string-length (with-output-to-string (lambda() (decode y)))))) (test-assert "query" (string=? phone (find y "businesses.phone"))) (test-assert "multi-dotted query" (string=? "Mission" (find y "businesses.neighborhoods.name"))) (let ((r (find y "businesses.reviews"))) (test "json array" 3 (length r)) (test-assert "array decode" (< 1 (string-length (with-output-to-string (lambda() (decode r)))))) (test-assert "array match" (string=? (find r "id") (find (list-ref r 0) "id")))) (let ((m (find y "message"))) (test-assert "message decode" (< 1 (string-length (with-output-to-string (lambda () (decode m)))))) (test-assert "message find" (string=? "OK" (find m "text"))))) (let-values (((y status) (by-phone ino))) (test "categories" #t (<= 128 (string-length (with-output-to-string (lambda () (display-info y))))))) (test-case (by-phone phone)) (test-case (hood-for-address loc)) (test-case (hood-for-address loc #:cc "US")) (test-case (hood-for-geocode lat lon)) (test-case (near-address "tokyo a go-go" "valencia st. san francisco")) (test-case (near-address "vietnamese" loc)) (test-case (near-address "vietnamese" loc #:number 1)) (test-case (near-address "vietnamese" loc #:number 1 #:cc "US")) (test-case (near-address "vietnamese" loc #:number 1 #:category "restaurants")) (test-case (near-address "cassanovas" loc #:category "divebars+lounges")) (test-case (near-geocode "pizza" lat lon)) (test-case (near-geocode "pizza" lat lon #:number 1)) (test-case (near-geocode "pizza" lat lon #:number 1 #:radius 1)) (test-case (near-geobox "pizza" lat lon lat-br lon-br)) (test-case (near-geobox "pizza" lat lon lat-br lon-br #:number 1)) (test-case (near-geobox "pizza" lat lon lat-br lon-br #:number 1 #:category "restaurants")) (set-ywsid! "bogus") (let-values (((y status) (by-phone pretty-phone))) (test-assert "ywsid text" (string=? "Invalid YWSID" y)) (test-assert "ywsid code" (eq? 'invalid-ywsid status)))