factor/extra/http/server/server-tests.factor

80 lines
2.5 KiB
Factor
Raw Normal View History

2008-02-25 15:53:18 -05:00
USING: http.server tools.test kernel namespaces accessors
2008-03-20 16:30:59 -04:00
io http math sequences assocs ;
2008-03-01 17:00:45 -05:00
IN: http.server.tests
2007-09-20 18:09:08 -04:00
2008-03-11 04:39:09 -04:00
[
<request>
"www.apple.com" >>host
"/xxx/bar" >>path
{ { "a" "b" } } >>query
request set
[ "http://www.apple.com:80/xxx/bar?a=b" ] [ f f derive-url ] unit-test
[ "http://www.apple.com:80/xxx/baz?a=b" ] [ "baz" f derive-url ] unit-test
[ "http://www.apple.com:80/xxx/baz?c=d" ] [ "baz" { { "c" "d" } } derive-url ] unit-test
[ "http://www.apple.com:80/xxx/bar?c=d" ] [ f { { "c" "d" } } derive-url ] unit-test
[ "http://www.apple.com:80/flip?a=b" ] [ "/flip" f derive-url ] unit-test
[ "http://www.apple.com:80/flip?c=d" ] [ "/flip" { { "c" "d" } } derive-url ] unit-test
[ "http://www.jedit.org" ] [ "http://www.jedit.org" f derive-url ] unit-test
[ "http://www.jedit.org?a=b" ] [ "http://www.jedit.org" { { "a" "b" } } derive-url ] unit-test
] with-scope
2008-02-29 01:57:38 -05:00
TUPLE: mock-responder path ;
2008-02-25 15:53:18 -05:00
2008-02-29 01:57:38 -05:00
C: <mock-responder> mock-responder
2008-02-25 15:53:18 -05:00
2008-02-29 01:57:38 -05:00
M: mock-responder call-responder
2008-03-11 04:39:09 -04:00
nip
2008-02-25 15:53:18 -05:00
path>> on
"text/plain" <content> ;
: check-dispatch ( tag path -- ? )
over off
2008-03-11 04:39:09 -04:00
main-responder get call-responder
2008-02-29 01:57:38 -05:00
write-response get ;
2008-02-25 15:53:18 -05:00
[
2008-02-29 01:57:38 -05:00
<dispatcher>
"foo" <mock-responder> "foo" add-responder
"bar" <mock-responder> "bar" add-responder
<dispatcher>
"123" <mock-responder> "123" add-responder
2008-02-25 15:53:18 -05:00
"default" <mock-responder> >>default
2008-02-29 01:57:38 -05:00
"baz" add-responder
2008-03-11 04:39:09 -04:00
main-responder set
2008-02-25 15:53:18 -05:00
2008-02-29 01:57:38 -05:00
[ "foo" ] [
2008-03-11 04:39:09 -04:00
"foo" main-responder get find-responder path>> nip
2008-02-29 01:57:38 -05:00
] unit-test
[ "bar" ] [
2008-03-11 04:39:09 -04:00
"bar" main-responder get find-responder path>> nip
2008-02-29 01:57:38 -05:00
] unit-test
2008-02-25 15:53:18 -05:00
[ t ] [ "foo" "foo" check-dispatch ] unit-test
[ f ] [ "foo" "bar" check-dispatch ] unit-test
[ t ] [ "bar" "bar" check-dispatch ] unit-test
[ t ] [ "default" "baz/xxx" check-dispatch ] unit-test
2008-02-29 01:57:38 -05:00
[ t ] [ "default" "baz/xxx//" check-dispatch ] unit-test
[ t ] [ "default" "/baz/xxx//" check-dispatch ] unit-test
2008-02-25 15:53:18 -05:00
[ t ] [ "123" "baz/123" check-dispatch ] unit-test
2008-02-29 01:57:38 -05:00
[ t ] [ "123" "baz///123" check-dispatch ] unit-test
2008-02-25 15:53:18 -05:00
[ t ] [
<request>
"baz" >>path
2008-03-11 04:39:09 -04:00
request set
"baz" main-responder get call-responder
2008-02-25 15:53:18 -05:00
dup code>> 300 399 between? >r
2008-02-29 01:57:38 -05:00
header>> "location" swap at "baz/" tail? r> and
2008-02-25 15:53:18 -05:00
] unit-test
] with-scope
2008-03-03 03:19:36 -05:00
[
<dispatcher>
"default" <mock-responder> >>default
2008-03-11 04:39:09 -04:00
main-responder set
2008-03-03 03:19:36 -05:00
2008-03-11 04:39:09 -04:00
[ "/default" ] [ "/default" main-responder get find-responder drop ] unit-test
2008-03-03 03:19:36 -05:00
] with-scope