Minimal pod, and removed req on YAML - tests will skip all if not found
[catagits/HTTP-Body.git] / t / 05urlencoded.t
CommitLineData
a9df1200 1#!perl
2
3use strict;
4use warnings;
5
1084e914 6use Test::More
7
8eval { require YAML; import YAML 'LoadFile'; };
9if ($@) {
10 eval { require YAML::Syck; import YAML::Syck 'LoadFile'; }
11}
12
13plan skip_all => 'Tests need YAML or YAML::Syck' if $@;
14
15plan tests => 5;
a9df1200 16
17use Cwd;
18use HTTP::Body;
19use File::Spec::Functions;
20use IO::File;
a9df1200 21
22my $path = catdir( getcwd(), 't', 'data', 'urlencoded' );
23
24for ( my $i = 1; $i <= 1; $i++ ) {
25
26 my $test = sprintf( "%.3d", $i );
27 my $headers = YAML::LoadFile( catfile( $path, "$test-headers.yml" ) );
28 my $results = YAML::LoadFile( catfile( $path, "$test-results.yml" ) );
29 my $content = IO::File->new( catfile( $path, "$test-content.dat" ) );
30 my $body = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
31
32 binmode $content, ':raw';
33
34 while ( $content->read( my $buffer, 1024 ) ) {
35 $body->add($buffer);
36 }
37
38 is_deeply( $body->body, $results->{body}, "$test UrlEncoded body" );
39 is_deeply( $body->param, $results->{param}, "$test UrlEncoded param" );
40 is_deeply( $body->upload, $results->{upload}, "$test UrlEncoded upload" );
41 cmp_ok( $body->state, 'eq', 'done', "$test UrlEncoded state" );
42 cmp_ok( $body->length, '==', $headers->{'Content-Length'}, "$test UrlEncoded length" );
43}