APR-HTTP-Headers-Compat

 view release on metacpan or  search on metacpan

t/compat/base/headers.t  view on Meta::CPAN

#!perl -w

use strict;

use Test::More tests => 163;
use APR::Pool;
use APR::Table;
use APR::HTTP::Headers::Compat;

my ( $h, $h2 );
sub j { join( "|", @_ ) }

my $Pool = APR::Pool->new;

sub mk(@) {
  my $table = APR::Table::make( $Pool, 10 );
  return APR::HTTP::Headers::Compat->new( $table, @_ );
}

$h = mk;
ok( $h );
is( ref( $h ),     "APR::HTTP::Headers::Compat" );
is( $h->as_string, "" );

$h = mk(
  foo => "bar",
  foo => "baaaaz",
  Foo => "baz"
);
is( $h->as_string, "Foo: bar\nFoo: baaaaz\nFoo: baz\n" );

$h = mk( foo => [ "bar", "baz" ] );
is( $h->as_string, "Foo: bar\nFoo: baz\n" );

$h = mk( foo => 1, bar => 2, foo_bar => 3 );
is( $h->as_string,        "Bar: 2\nFoo: 1\nFoo-Bar: 3\n" );
is( $h->as_string( ";" ), "Bar: 2;Foo: 1;Foo-Bar: 3;" );

is( $h->header( "Foo" ),            1 );
is( $h->header( "FOO" ),            1 );
is( j( $h->header( "foo" ) ),       1 );
is( $h->header( "foo-bar" ),        3 );
is( $h->header( "foo_bar" ),        3 );
is( $h->header( "Not-There" ),      undef );
is( j( $h->header( "Not-There" ) ), "" );
is( eval { $h->header }, undef );
ok( $@ );

is( $h->header( "Foo", 11 ), 1 );
is( $h->header( "Foo", [ 1, 1 ] ), 11 );
is( $h->header( "Foo" ),      "1, 1" );
is( j( $h->header( "Foo" ) ), "1|1" );
is( $h->header( foo => 11, Foo => 12, bar => 22 ), 2 );
is( $h->header( "Foo" ), "11, 12" );
is( $h->header( "Bar" ), 22 );
is( $h->header( "Bar", undef ), 22 );
is( j( $h->header( "bar", 22 ) ), "" );

$h->push_header( Bar => 22 );
is( $h->header( "Bar" ), "22, 22" );
$h->push_header( Bar => [ 23 .. 25 ] );
is( $h->header( "Bar" ),      "22, 22, 23, 24, 25" );
is( j( $h->header( "Bar" ) ), "22|22|23|24|25" );

$h->clear;
$h->header( Foo => 1 );
is( $h->as_string, "Foo: 1\n" );
$h->init_header( Foo => 2 );
$h->init_header( Bar => 2 );
is( $h->as_string, "Bar: 2\nFoo: 1\n" );
$h->init_header( Foo => [ 2, 3 ] );
$h->init_header( Baz => [ 2, 3 ] );
is( $h->as_string, "Bar: 2\nBaz: 2\nBaz: 3\nFoo: 1\n" );

eval { $h->init_header( A => 1, B => 2, C => 3 ) };



( run in 1.852 second using v1.01-cache-2.11-cpan-5735350b133 )