File: 03-addressbook.t

package info (click to toggle)
libtext-vcard-perl 2.10-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 176 kB
  • sloc: perl: 836; makefile: 4
file content (81 lines) | stat: -rw-r--r-- 1,976 bytes parent folder | download | duplicates (2)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/perl -w

use strict;
use Data::Dumper;

use lib qw(./lib);

use Test::More  tests => 13;

local $SIG{__WARN__} = sub { die $_[0] };

# Check we can load module
BEGIN { use_ok( 'Text::vCard::Addressbook' ); }

#####
# load
#####
my $load = Text::vCard::Addressbook->load(['t/simple.vcf']);
isa_ok($load,'Text::vCard::Addressbook');

eval {
	Text::vCard::Addressbook->load(['i/do/not/exist']);
};
like($@,qr/Unable to read file/,'load() - croak when file does not exist');

######
# new()
######

# Can we create an empty address book
my $newadbk = Text::vCard::Addressbook->new();
isa_ok($newadbk,'Text::vCard::Addressbook');

eval{
	Text::vCard::Addressbook->new({'source_file' => 'i/do/not/exist'});
};
like($@,qr/Unable to read file/,'new() - croak when unable to read file');

eval {
	Text::vCard::Addressbook::new(undef);
};
like($@,qr/Use of uninitialized value/,'new() - ok error when no proto supplied');

my $foo = Text::vCard::Addressbook::new('foo::bar');
is(ref($foo),'foo::bar','new() - Can use as a base class');

my $hash = Text::vCard::Addressbook::new({foo => 'bar'});
is(ref($hash),'HASH','new() - retruns HASH when supplied hash');

eval {
  Text::vCard::Addressbook->new({ 'source_file' => 't/mix_type.vcf'});
};
like($@,qr/This file contains FOO/,'new() - carp on non VCARD format');
#####
# add_vcard()
#####
# Create a new vCard
my $vcard = $newadbk->add_vcard();
isa_ok($vcard,'Text::vCard');

# Add a node to it
my $address = $vcard->add_node({
	'node_type' => 'ADR',
});

# Add some data to the address.
$address->street('19 The mews');
$address->city('Buffyvill');

#####
# vcards
#####
# Now get it out of the address book
my $card_a = $newadbk->vcards();
is(ref($card_a),'ARRAY','vcards() - returns array ref when in context');
is($card_a->[0]->get({ 'node_type' => 'ADR'})->[0]->street(),'19 The mews','exstracted address ok'),

my @vcard_list = $newadbk->vcards();
is(scalar(@vcard_list),1,'vcards() returns array when in context');