From 3e3dc478fc9b4eb90681df89156dfcc8f7f81481 Mon Sep 17 00:00:00 2001 From: franck cuny Date: Mon, 13 Sep 2010 13:31:56 +0200 Subject: initial import --- t/spore-response/body.t | 21 +++++++++++++++++++++ t/spore-response/headers.t | 20 ++++++++++++++++++++ t/spore-response/new.t | 34 ++++++++++++++++++++++++++++++++++ t/spore-response/response.t | 23 +++++++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 t/spore-response/body.t create mode 100644 t/spore-response/headers.t create mode 100644 t/spore-response/new.t create mode 100644 t/spore-response/response.t (limited to 't/spore-response') diff --git a/t/spore-response/body.t b/t/spore-response/body.t new file mode 100644 index 0000000..2a35d6b --- /dev/null +++ b/t/spore-response/body.t @@ -0,0 +1,21 @@ +use strict; +use warnings; +use Test::More; +use Net::HTTP::Spore::Response; +use URI; + +sub r($) { + my $res = Net::HTTP::Spore::Response->new(200); + $res->body(@_); + return $res->finalize->[2]; +} + +is_deeply r "Hello World", "Hello World"; +is_deeply r [ "Hello", "World" ], [ "Hello", "World" ]; + +{ + my $uri = URI->new("foo"); # stringified object + is_deeply r $uri, $uri; +} + +done_testing; diff --git a/t/spore-response/headers.t b/t/spore-response/headers.t new file mode 100644 index 0000000..b9cf319 --- /dev/null +++ b/t/spore-response/headers.t @@ -0,0 +1,20 @@ +use strict; +use warnings; + +use Test::More; +use Net::HTTP::Spore::Response; + +my $status = 200; +my $body = '{"foo":1}'; +my $ct = 'application/json'; +my $cl = length($body); + +my $response = + Net::HTTP::Spore::Response->new( $status, + [ 'Content-Type', $ct, 'Content-Length', length($body) ], $body ); + +is $response->content_type, $ct; +is $response->content_length, $cl; +is $response->status, 200; + +done_testing; diff --git a/t/spore-response/new.t b/t/spore-response/new.t new file mode 100644 index 0000000..fb271ab --- /dev/null +++ b/t/spore-response/new.t @@ -0,0 +1,34 @@ +use strict; +use warnings; +use Test::More; +use Net::HTTP::Spore::Response; + +{ + my $res = Net::HTTP::Spore::Response->new(302); + is $res->status, 302; + is $res->code, 302; +} + +{ + my $res = Net::HTTP::Spore::Response->new(200, [ 'Content-Type' => 'text/plain' ]); + is $res->content_type, 'text/plain'; +} + +{ + my $res = Net::HTTP::Spore::Response->new(200, { 'Content-Type' => 'text/plain' }); + is $res->content_type, 'text/plain'; +} + +{ + my $res = Net::HTTP::Spore::Response->new(200); + $res->content_type('image/png'); + is $res->content_type, 'image/png'; +} + +{ + my $res = Net::HTTP::Spore::Response->new(200); + $res->header('X-Foo' => "bar"); + is $res->header('X-Foo'), "bar"; +} + +done_testing; diff --git a/t/spore-response/response.t b/t/spore-response/response.t new file mode 100644 index 0000000..56be6d2 --- /dev/null +++ b/t/spore-response/response.t @@ -0,0 +1,23 @@ +use strict; +use warnings; +use Test::More; +use Net::HTTP::Spore::Response; + +sub res { + my $res = Net::HTTP::Spore::Response->new; + my %v = @_; + while ( my ( $k, $v ) = each %v ) { + $res->$k($v); + } + $res->finalize; +} + +is_deeply( + res( + status => 200, + body => 'hello', + ), + [ 200, +[], 'hello' ] +); + +done_testing; -- cgit 1.4.1