afcc020083fcf02f53191f881068bc9cb50208d2
[catagits/HTTP-Body.git] / t / 05urlencoded.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 5;
7
8 use Cwd;
9 use HTTP::Body;
10 use File::Spec::Functions;
11 use IO::File;
12 use YAML;
13
14 my $path = catdir( getcwd(), 't', 'data', 'urlencoded' );
15
16 for ( my $i = 1; $i <= 1; $i++ ) {
17
18     my $test    = sprintf( "%.3d", $i );
19     my $headers = YAML::LoadFile( catfile( $path, "$test-headers.yml" ) );
20     my $results = YAML::LoadFile( catfile( $path, "$test-results.yml" ) );
21     my $content = IO::File->new( catfile( $path, "$test-content.dat" ) );
22     my $body    = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
23
24     binmode $content, ':raw';
25
26     while ( $content->read( my $buffer, 1024 ) ) {
27         $body->add($buffer);
28     }
29
30     is_deeply( $body->body, $results->{body}, "$test UrlEncoded body" );
31     is_deeply( $body->param, $results->{param}, "$test UrlEncoded param" );
32     is_deeply( $body->upload, $results->{upload}, "$test UrlEncoded upload" );
33     cmp_ok( $body->state, 'eq', 'done', "$test UrlEncoded state" );
34     cmp_ok( $body->length, '==', $headers->{'Content-Length'}, "$test UrlEncoded length" );
35 }