1#!perl
2use strict;
3use warnings;
4
5use Test::More 0.88;
6
7use HTTP::Tiny;
8
9# blank slate for testing
10delete $ENV{no_proxy};
11
12{
13    my $c = HTTP::Tiny->new();
14    is_deeply( $c->no_proxy, [], "no no_proxy given" );
15}
16
17my @cases = (
18    #<<< No perltidy
19    {
20        no_proxy => [
21            undef,
22            [],
23        ],
24        expect => [],
25    },
26    {
27        no_proxy => [
28            "localhost",
29            ["localhost"],
30        ],
31        expect => ["localhost"],
32    },
33    {
34        no_proxy => [
35            "localhost,example.com",
36            "localhost, example.com",
37            [qw/localhost example.com/]
38        ],
39        expect   => [ "localhost", "example.com" ],
40    },
41    #>>>
42);
43
44for my $c (@cases) {
45    for my $no_proxy ( @{ $c->{no_proxy} } ) {
46        my $label =
47           !defined $no_proxy ? 'undef'
48          : ref $no_proxy     ? "[qw/@$no_proxy/]"
49          :                     "'$no_proxy'";
50
51        # Can't test environment with array ref (ENV stringifies in new perls)
52        if ( ref $no_proxy ) {
53            my $ht = HTTP::Tiny->new( no_proxy => $no_proxy );
54            is_deeply( $ht->no_proxy, $c->{expect}, "new(no_proxy => $label)" );
55        }
56        else {
57            {
58                local $ENV{no_proxy} = $no_proxy;
59                my $ht = HTTP::Tiny->new();
60                is_deeply( $ht->no_proxy, $c->{expect}, "\$ENV{no_proxy} = $label" );
61            }
62            {
63                local $ENV{no_proxy} = "Shouldnt,see,this";
64                my $ht = HTTP::Tiny->new( no_proxy => $no_proxy );
65                is_deeply( $ht->no_proxy, $c->{expect},
66                    "new(no_proxy => $label) versus other \$ENV{no_proxy}" );
67            }
68        }
69    }
70}
71
72done_testing();
73