| 1 | use strict; |
| 2 | use warnings; |
| 3 | use Test::More; |
| 4 | use HTTP::Parser::XS qw/:all/; |
| 5 | |
| 6 | use Data::Dumper; |
| 7 | |
| 8 | my $tests = <<'__HEADERS'; |
| 9 | HOGE |
| 10 | |
| 11 | ---------- |
| 12 | -1 |
| 13 | ---------- |
| 14 | HTTP/1.0 200 OK |
| 15 | ---------- |
| 16 | -2 |
| 17 | ---------- |
| 18 | HTTP/1.0 200 OK |
| 19 | Content-Type: text/html |
| 20 | X-Test: 1 |
| 21 | X-Test: 2 |
| 22 | |
| 23 | hogehoge |
| 24 | ---------- |
| 25 | 61 |
| 26 | ---------- |
| 27 | HTTP/1.0 200 OK |
| 28 | Content-Type: text/html |
| 29 | X-Test: 1 |
| 30 | X-Test: 2 |
| 31 | |
| 32 | hogehoge |
| 33 | ---------- |
| 34 | 62 |
| 35 | ---------- |
| 36 | HTTP/1.0 200 OK |
| 37 | Content-Type: text/html |
| 38 | ---------- |
| 39 | -2 |
| 40 | __HEADERS |
| 41 | |
| 42 | |
| 43 | |
| 44 | my @tests = split '-'x10, $tests; |
| 45 | my $i = 0; |
| 46 | while (@tests) { |
| 47 | $i++; |
| 48 | my $header = shift @tests; |
| 49 | my $expect = shift @tests; |
| 50 | $header =~ s/^\n//; |
| 51 | last unless $expect; |
| 52 | my $res = []; |
| 53 | my ($ret) = parse_http_response($header, HEADERS_AS_HASHREF); |
| 54 | my $r = eval($expect); |
| 55 | is( $ret, $r, "test-$i"); |
| 56 | } |
| 57 | |
| 58 | done_testing; |
| 59 |