summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/perl/cpan/HTTP-Tiny/t/003_agent.t
blob: 6962c66832ea3481d7bb8c9b93f962f62f2742fe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!perl

use strict;
use warnings;

use Test::More tests => 8;
use HTTP::Tiny;

# a couple tests to ensure that we get the default agent expected, the coorect
# agent when specified, and the correct agent when specifified with a space at
# the end of the string (as LWP::UserAgent does)


my $default = 'HTTP-Tiny/' . (HTTP::Tiny->VERSION || 0);

{
    my $ua = HTTP::Tiny->new();
    is $ua->agent, $default, 'default agent string is as expected';
}

{
    my $ua = HTTP::Tiny->new(agent => 'something else');
    is $ua->agent, 'something else', 'agent string is as expected';
}

{
    my $ua = HTTP::Tiny->new(agent => 'something else ');
    is
        $ua->agent,
        "something else $default",
        'agent string is as properly appended to',
        ;
}

{
    my $ua = HTTP::Tiny->new();

    is( HTTP::Tiny->_agent(), $default, 'check _agent on class' );
    is $ua->_agent(), $default, 'check _agent on object';

    $ua->agent(undef);
    is $ua->agent, undef, 'agent string is empty';

    $ua->agent('something else');
    is $ua->agent, 'something else', 'agent string is as expected';

    $ua->agent('something else ');
    is
        $ua->agent,
        "something else $default",
        'agent string is as properly appended to',
        ;
}