File: 20_custom_format.t

package info (click to toggle)
libnet-mac-perl 2.103622-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch, wheezy
  • size: 220 kB
  • ctags: 25
  • sloc: perl: 1,709; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 928 bytes parent folder | download | duplicates (4)
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
use Test::More tests => 6;
#use Test::More qw(no_plan);
BEGIN { use_ok('Net::MAC') };

# test class method
eval{ Net::MAC->set_format_for( 'Custom' ) };
like($@, qr/missing HASH ref custom format/, 'missing HASH ref custom format');

my $rc = eval{
    Net::MAC->set_format_for(
        Custom => {
            base => 16,
            bit_group => 16,
            delimiter => '~',
        },
    )
};
ok($rc, 'Class method set_format_for set the new format');

my $macaddr = '01ab~01ab~01ab';

#eval{ Net::MAC->new(mac => $macaddr) };
#like($@, qr/invalid MAC format/, 'unspecified custom format dies');

my $mac = eval{ Net::MAC->new(mac => $macaddr, format => 'Custom') };
isa_ok($mac, 'Net::MAC', 'known custom format succeeds');

is($mac->as_Cisco, '01ab.01ab.01ab', 'as_foo working from custom format');

is(Net::MAC->new(mac => '01ab.01ab.01ab')->as_Custom,
    '01ab~01ab~01ab', 'as_Custom working from Cisco format');