Adding tests
svn: r6455
This commit is contained in:
parent
6f4bbf80d1
commit
636e5bd9c1
|
@ -1,7 +1,3 @@
|
|||
;; this is a trivial implementation of the connection-manger interface that
|
||||
;; uses timeouts instead of a queued-model.
|
||||
|
||||
;; the queued-model is also fully implemented but won't be used at this time.
|
||||
(module connection-manager mzscheme
|
||||
(require "connection-structs.ss"
|
||||
"timer.ss"
|
||||
|
|
|
@ -4,18 +4,12 @@
|
|||
(lib "string.ss"))
|
||||
(require "util.ss")
|
||||
(provide/contract
|
||||
[read-mime-types (path? . -> . hash-table?)]
|
||||
[make-get-mime-type (path? . -> . (path? . -> . bytes?))])
|
||||
|
||||
;; make-get-mime-type : path? -> path? -> bytes?
|
||||
;; determine the mime type based on the filename's suffix
|
||||
;;
|
||||
;; Notes (GregP):
|
||||
;; 1. Can we determine the mime type based on file contents?
|
||||
;; 2. Assuming that 7-bit ASCII is correct for mime-type
|
||||
(define (make-get-mime-type a-path)
|
||||
(let ([MIME-TYPE-TABLE (make-hash-table)]
|
||||
[DEFAULT-MIME-TYPE #"text/plain; charset=utf-8"]
|
||||
[file-suffix-regexp (byte-regexp #".*\\.([^\\.]*$)")])
|
||||
; read-mime-types : path? -> hash-table?
|
||||
(define (read-mime-types a-path)
|
||||
(define MIME-TYPE-TABLE (make-hash-table))
|
||||
(with-input-from-file a-path
|
||||
(lambda ()
|
||||
(let loop ()
|
||||
|
@ -32,6 +26,19 @@
|
|||
(loop)]
|
||||
[_
|
||||
(loop)]))))
|
||||
MIME-TYPE-TABLE)
|
||||
|
||||
;; make-get-mime-type : path? -> path? -> bytes?
|
||||
;; determine the mime type based on the filename's suffix
|
||||
;;
|
||||
;; Notes (GregP):
|
||||
;; 1. Can we determine the mime type based on file contents?
|
||||
;; 2. Assuming that 7-bit ASCII is correct for mime-type
|
||||
(define (make-get-mime-type a-path)
|
||||
(let ([MIME-TYPE-TABLE (read-mime-types a-path)]
|
||||
[DEFAULT-MIME-TYPE #"text/plain; charset=utf-8"]
|
||||
[file-suffix-regexp (byte-regexp #".*\\.([^\\.]*$)")])
|
||||
|
||||
(lambda (path)
|
||||
(match (regexp-match file-suffix-regexp (path->bytes path))
|
||||
[(list path-bytes sffx)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||
(provide dispatch-files-tests)
|
||||
|
||||
; XXX
|
||||
(define dispatch-files-tests
|
||||
(test-suite
|
||||
"Files")))
|
|
@ -2,6 +2,7 @@
|
|||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||
(provide dispatch-lang-tests)
|
||||
|
||||
; XXX
|
||||
(define dispatch-lang-tests
|
||||
(test-suite
|
||||
"Web Language")))
|
|
@ -2,6 +2,7 @@
|
|||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||
(provide dispatch-passwords-tests)
|
||||
|
||||
; XXX
|
||||
(define dispatch-passwords-tests
|
||||
(test-suite
|
||||
"Passwords")))
|
|
@ -2,6 +2,7 @@
|
|||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||
(provide dispatch-servlets-tests)
|
||||
|
||||
; XXX
|
||||
(define dispatch-servlets-tests
|
||||
(test-suite
|
||||
"Servlets")))
|
|
@ -2,6 +2,7 @@
|
|||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||
(provide abort-resume-tests)
|
||||
|
||||
; XXX
|
||||
(define abort-resume-tests
|
||||
(test-suite
|
||||
"Abort Resume")))
|
|
@ -2,6 +2,7 @@
|
|||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||
(provide web-cells-tests)
|
||||
|
||||
; XXX
|
||||
(define web-cells-tests
|
||||
(test-suite
|
||||
"Web Cells")))
|
|
@ -2,6 +2,7 @@
|
|||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||
(provide web-extras-tests)
|
||||
|
||||
; XXX
|
||||
(define web-extras-tests
|
||||
(test-suite
|
||||
"Web Extras")))
|
|
@ -2,6 +2,7 @@
|
|||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||
(provide web-tests)
|
||||
|
||||
; XXX
|
||||
(define web-tests
|
||||
(test-suite
|
||||
"Web")))
|
|
@ -2,6 +2,7 @@
|
|||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||
(provide cache-table-tests)
|
||||
|
||||
; XXX
|
||||
(define cache-table-tests
|
||||
(test-suite
|
||||
"Cache Table")))
|
|
@ -2,6 +2,7 @@
|
|||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||
(provide connection-manager-tests)
|
||||
|
||||
; XXX
|
||||
(define connection-manager-tests
|
||||
(test-suite
|
||||
"Connection Manager")))
|
|
@ -1,7 +1,42 @@
|
|||
(module mime-types-test mzscheme
|
||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2))
|
||||
(lib "file.ss")
|
||||
(lib "mime-types.ss" "web-server" "private"))
|
||||
(provide mime-types-tests)
|
||||
|
||||
(define test-file (make-temporary-file))
|
||||
(with-output-to-file test-file
|
||||
(lambda ()
|
||||
(printf #<<END
|
||||
video/mp4 mp4
|
||||
video/mpeg mpeg mpg mpe
|
||||
END
|
||||
))
|
||||
'replace)
|
||||
|
||||
(define mime-types-tests
|
||||
(test-suite
|
||||
"MIME Types")))
|
||||
"MIME Types"
|
||||
|
||||
(test-case
|
||||
"Distribution mime.types parses"
|
||||
(check-not-false (read-mime-types (build-path (collection-path "web-server") "default-web-root" "mime.types"))))
|
||||
|
||||
(test-case
|
||||
"Test file parses"
|
||||
(check-not-false (read-mime-types test-file)))
|
||||
(test-case
|
||||
"Default mime-type given"
|
||||
(check-equal? ((make-get-mime-type test-file) (build-path "test.html")) #"text/plain; charset=utf-8"))
|
||||
(test-case
|
||||
"MIME type resolves (single in file)"
|
||||
(check-equal? ((make-get-mime-type test-file) (build-path "test.mp4")) #"video/mp4"))
|
||||
(test-case
|
||||
"MIME type resolves (multiple in file)"
|
||||
(check-equal? ((make-get-mime-type test-file) (build-path "test.mpeg")) #"video/mpeg"))
|
||||
(test-case
|
||||
"MIME type resolves (multiple in file)"
|
||||
(check-equal? ((make-get-mime-type test-file) (build-path "test.mpg")) #"video/mpeg"))
|
||||
(test-case
|
||||
"MIME type resolves (multiple in file)"
|
||||
(check-equal? ((make-get-mime-type test-file) (build-path "test.mpe")) #"video/mpeg")))))
|
|
@ -36,6 +36,7 @@
|
|||
(lambda (f s) s)))
|
||||
|
||||
|
||||
; XXX
|
||||
(define request-tests
|
||||
(test-suite
|
||||
"Request Parsing"
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||
(provide response-tests)
|
||||
|
||||
; XXX
|
||||
(define response-tests
|
||||
(test-suite
|
||||
"HTTP Responses")))
|
|
@ -3,6 +3,7 @@
|
|||
(lib "servlet.ss" "web-server"))
|
||||
(provide servlet-tests)
|
||||
|
||||
; XXX
|
||||
(define servlet-tests
|
||||
(test-suite
|
||||
"Servlets")))
|
|
@ -2,6 +2,7 @@
|
|||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||
(provide session-tests)
|
||||
|
||||
; XXX
|
||||
(define session-tests
|
||||
(test-suite
|
||||
"Sessions")))
|
|
@ -2,6 +2,7 @@
|
|||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||
(provide url-param-tests)
|
||||
|
||||
; XXX
|
||||
(define url-param-tests
|
||||
(test-suite
|
||||
"URL Parameters")))
|
|
@ -2,6 +2,7 @@
|
|||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||
(provide util-tests)
|
||||
|
||||
; XXX
|
||||
(define util-tests
|
||||
(test-suite
|
||||
"Utilities")))
|
|
@ -3,6 +3,7 @@
|
|||
(lib "servlet.ss" "web-server"))
|
||||
(provide servlet-tests)
|
||||
|
||||
; XXX
|
||||
(define servlet-tests
|
||||
(test-suite
|
||||
"Servlets")))
|
|
@ -2,6 +2,7 @@
|
|||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||
(provide basic-auth-tests)
|
||||
|
||||
; XXX
|
||||
(define basic-auth-tests
|
||||
(test-suite
|
||||
"BASIC Authentication")))
|
|
@ -1,7 +1,33 @@
|
|||
(module bindings-test mzscheme
|
||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2))
|
||||
(lib "bindings.ss" "web-server" "servlet"))
|
||||
(provide bindings-tests)
|
||||
|
||||
(define bs `([foo . 3] [foos . 1] [foos . 2]))
|
||||
|
||||
(define bindings-tests
|
||||
(test-suite
|
||||
"Bindings")))
|
||||
"Bindings"
|
||||
|
||||
(test-case
|
||||
"exists-binding? - true"
|
||||
(check-true (exists-binding? 'foo bs)))
|
||||
(test-case
|
||||
"exists-binding? - false"
|
||||
(check-false (exists-binding? 'bar bs)))
|
||||
|
||||
(test-case
|
||||
"extract-bindings"
|
||||
(check-equal? (extract-bindings 'foos bs) (list 1 2)))
|
||||
|
||||
(test-case
|
||||
"extract-binding/single - success"
|
||||
(check-equal? (extract-binding/single 'foo bs) 3))
|
||||
(test-case
|
||||
"extract-binding/single - failure"
|
||||
(check-exn (lambda (exn) (regexp-match "not found" (exn-message exn)))
|
||||
(lambda () (extract-binding/single 'bar bs) 3)))
|
||||
(test-case
|
||||
"extract-binding/single - multiple"
|
||||
(check-exn (lambda (exn) (regexp-match "multiple times" (exn-message exn)))
|
||||
(lambda () (extract-binding/single 'foos bs) 3))))))
|
|
@ -2,6 +2,7 @@
|
|||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||
(provide helpers-tests)
|
||||
|
||||
; XXX
|
||||
(define helpers-tests
|
||||
(test-suite
|
||||
"Helpers")))
|
|
@ -2,6 +2,7 @@
|
|||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||
(provide servlet-url-tests)
|
||||
|
||||
; XXX
|
||||
(define servlet-url-tests
|
||||
(test-suite
|
||||
"Servlet URLs")))
|
|
@ -2,6 +2,7 @@
|
|||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||
(provide web-tests)
|
||||
|
||||
; XXX
|
||||
(define web-tests
|
||||
(test-suite
|
||||
"Web")))
|
Loading…
Reference in New Issue
Block a user