Improved tests. Removed Path::Class dependency
Christian Hansen [Wed, 12 Oct 2005 17:58:56 +0000 (17:58 +0000)]
Makefile.PL
lib/HTTP/Body/MultiPart.pm
t/01use.t
t/04multipart.t [new file with mode: 0644]
t/05urlencoded.t [new file with mode: 0644]
t/data/multipart/003-results.yml

index dad4cdf..427d0db 100644 (file)
@@ -6,12 +6,10 @@ WriteMakefile(
     NAME         => 'HTTP::Body',
     VERSION_FROM => 'lib/HTTP/Body.pm',
     PREREQ_PM    => {
-        YAML         => 0,
-        Data::Dumper => 0,
-        IO::File     => 0,
-        List::Util   => 0,
         Carp         => 0,
         File::Temp   => '0.14',
-        Path::Class  => 0
+        IO::File     => 0,
+        List::Util   => 0,
+        YAML         => 0
     }
 );
index 5972fbc..cc8f805 100644 (file)
@@ -223,8 +223,7 @@ sub parse_body {
     if ( $index < 0 ) {
 
         # make sure we have enough buffer to detect end delimiter
-        my $length =
-          length( $self->{buffer} ) - ( length( $self->delimiter_end ) + 2 );
+        my $length = length( $self->{buffer} ) - ( length( $self->delimiter_end ) + 2 );
 
         unless ( $length > 0 ) {
             return 0;
index b31a2d9..f99b715 100644 (file)
--- a/t/01use.t
+++ b/t/01use.t
@@ -1,57 +1,9 @@
+#!perl
+
 use Test::More 'no_plan';
 
 use strict;
-use FindBin;
-use_ok 'HTTP::Body';
-use YAML 'LoadFile';
-use Path::Class;
-use Data::Dumper;
-
-for my $format (qw/multipart urlencoded/) {
-
-    for my $match ( glob file( $FindBin::Bin, 'data', $format, '*.dat' ) ) {
-        my $file = file($match);
-        my $name = $file->basename;
-        $name =~ /^(\d+)-.*/;
-        my $num     = $1;
-        my $headers = LoadFile( file( $FindBin::Bin, 'data', $format, "$num-headers.yml" ) );
-        my $results = LoadFile( file( $FindBin::Bin, 'data', $format, "$num-results.yml" ) );
-        my $content = $file->open('<');
-        my $body    = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
-
-        binmode $content, ':raw';
-
-        while ( $content->read( my $buffer, 1024 ) ) {
-            $body->add($buffer);
-        }
+use warnings;
 
-        if ( $ENV{HTTP_BODY_DEBUG} ) {
-            warn Dumper( $body->param );
-            warn Dumper( $body->upload );
-            warn Dumper( $body->body );
-
-            warn "state          : " . $body->state;
-            warn "length         : " . $body->length;
-            warn "content length : " . $body->content_length;
-            warn "body length    : " . ( $body->body->stat )[7] if $body->body;
-            warn "buffer         : " . $body->buffer if $body->buffer;
-        }
-        
-        for my $field ( keys %{ $body->upload } ) {
-
-            my $value = $body->upload->{$field};
-
-            for ( ( ref($value) eq 'ARRAY' ) ? @{$value} : $value ) {
-                delete $_->{tempname};
-            }
-        }
-
-        is_deeply( $body->body, $results->{body}, "$num-$format body" );
-        is_deeply( $body->param, $results->{param}, "$num-$format param" );
-        is_deeply( $body->upload, $results->{upload}, "$num-$format upload" );
-        cmp_ok( $body->state, 'eq', 'done', "$num-$format state" );
-        cmp_ok( $body->length, '==', $headers->{'Content-Length'}, "$num-$format length" );
-    }
-}
+use_ok 'HTTP::Body';
 
-1;
diff --git a/t/04multipart.t b/t/04multipart.t
new file mode 100644 (file)
index 0000000..75a7f89
--- /dev/null
@@ -0,0 +1,44 @@
+#!perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 55;
+
+use Cwd;
+use HTTP::Body;
+use File::Spec::Functions;
+use IO::File;
+use YAML;
+
+my $path = catdir( getcwd(), 't', 'data', 'multipart' );
+
+for ( my $i = 1; $i <= 11; $i++ ) {
+
+    my $test    = sprintf( "%.3d", $i );
+    my $headers = YAML::LoadFile( catfile( $path, "$test-headers.yml" ) );
+    my $results = YAML::LoadFile( catfile( $path, "$test-results.yml" ) );
+    my $content = IO::File->new( catfile( $path, "$test-content.dat" ) );
+    my $body    = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
+
+    binmode $content, ':raw';
+
+    while ( $content->read( my $buffer, 1024 ) ) {
+        $body->add($buffer);
+    }
+    
+    for my $field ( keys %{ $body->upload } ) {
+
+        my $value = $body->upload->{$field};
+
+        for ( ( ref($value) eq 'ARRAY' ) ? @{$value} : $value ) {
+            delete $_->{tempname};
+        }
+    }
+
+    is_deeply( $body->body, $results->{body}, "$test MultiPart body" );
+    is_deeply( $body->param, $results->{param}, "$test MultiPart param" );
+    is_deeply( $body->upload, $results->{upload}, "$test MultiPart upload" );
+    cmp_ok( $body->state, 'eq', 'done', "$test MultiPart state" );
+    cmp_ok( $body->length, '==', $headers->{'Content-Length'}, "$test MultiPart length" );
+}
diff --git a/t/05urlencoded.t b/t/05urlencoded.t
new file mode 100644 (file)
index 0000000..afcc020
--- /dev/null
@@ -0,0 +1,35 @@
+#!perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 5;
+
+use Cwd;
+use HTTP::Body;
+use File::Spec::Functions;
+use IO::File;
+use YAML;
+
+my $path = catdir( getcwd(), 't', 'data', 'urlencoded' );
+
+for ( my $i = 1; $i <= 1; $i++ ) {
+
+    my $test    = sprintf( "%.3d", $i );
+    my $headers = YAML::LoadFile( catfile( $path, "$test-headers.yml" ) );
+    my $results = YAML::LoadFile( catfile( $path, "$test-results.yml" ) );
+    my $content = IO::File->new( catfile( $path, "$test-content.dat" ) );
+    my $body    = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
+
+    binmode $content, ':raw';
+
+    while ( $content->read( my $buffer, 1024 ) ) {
+        $body->add($buffer);
+    }
+
+    is_deeply( $body->body, $results->{body}, "$test UrlEncoded body" );
+    is_deeply( $body->param, $results->{param}, "$test UrlEncoded param" );
+    is_deeply( $body->upload, $results->{upload}, "$test UrlEncoded upload" );
+    cmp_ok( $body->state, 'eq', 'done', "$test UrlEncoded state" );
+    cmp_ok( $body->length, '==', $headers->{'Content-Length'}, "$test UrlEncoded length" );
+}
index f92a61c..09c0c57 100644 (file)
@@ -5,10 +5,7 @@ param:
     - A
     - B
   text1: Ratione accusamus aspernatur aliquam
-  textarea: |-
-    Voluptatem cumque voluptate sit recusandae at. Et quas facere rerum unde esse. Sit est et voluptatem. Vel temporibus velit neque odio non.
-    
-    Molestias rerum ut sapiente facere repellendus illo. Eum nulla quis aut. Quidem voluptas vitae ipsam officia voluptatibus eveniet. Aspernatur cupiditate ratione aliquam quidem corrupti. Eos sunt rerum non optio culpa.
+  textarea: "Voluptatem cumque voluptate sit recusandae at. Et quas facere rerum unde esse. Sit est et voluptatem. Vel temporibus velit neque odio non.\n\nMolestias rerum ut sapiente facere repellendus illo. Eum nulla quis aut. Quidem voluptas vitae ipsam officia voluptatibus eveniet. Aspernatur cupiditate ratione aliquam quidem corrupti. Eos sunt rerum non optio culpa."
 upload:
   upload:
     - filename: hello.pl