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
|
#!/usr/bin/perl -w
use strict;
use lib qw(./lib);
use Test::More tests => 5;
use Data::Dumper;
# Check we can load module
BEGIN { use_ok( 'Text::vCard::Addressbook' ); }
local $SIG{__WARN__} = sub { die $_[0] };
my @data = (
'BEGIN:VCARD',
'item1.X-ABADR:uk',
'item2.X-ABADR:uk',
'N:T-surname;T-first;;;',
'TEL;pref;home:020 666 6666',
'TEL;cell:0777 777 7777',
'item2.ADR;work:;;Test Road;Test City;;Test Postcode;Test Country',
'item1.ADR;TYPE=pref,home:;;Pref Test Road;Pref Test City;;Pref Test Postcode;Pref Test Country',
'VERSION:3.0',
'FN:T-firstname T-surname',
'END:VCARD',
);
#######
# Test new()
#######
my $adbk = Text::vCard::Addressbook->new({ 'source_file' => 't/apple_version3.vcf'});
my $vcf = $adbk->export();
#print $vcf;
like($vcf,qr/TYPE=work/,'export() - added type def');
my @lines = split("\r\n",$vcf);
is($lines[0],'BEGIN:VCARD','export() - First line correct');
is($lines[$#lines],'END:VCARD','export() - Last line correct');
$adbk->set_encoding('utf-8');
@data = (
'BEGIN:VCARD',
'item1.X-ABADR;charset=utf-8:uk',
'item2.X-ABADR;charset=utf-8:uk',
'N;charset=utf-8:T-surname;T-first;;;',
'TEL;charset=utf-8;TYPE=pref,home:020 666 6666',
'TEL;charset=utf-8;TYPE=cell:0777 777 7777',
'item2.ADR;charset=utf-8;TYPE=work:;;Test Road;Test City;;Test Postcode;Test Country',
'item1.ADR;charset=utf-8;TYPE=pref,home:;;Pref Test Road;Pref Test City;;Pref Test Postcode;Pref Test Country',
'VERSION;charset=utf-8:3.0',
'FN;charset=utf-8:T-firstname T-surname',
'END:VCARD',
);
@lines = split ( "\r\n" , $adbk->export());
is_deeply(\@lines,\@data,'set_encoding() - returned data matched that expected');
#is_deeply(\@lines,\@data,'export() - returned data matched that expected');
#my $notes = Text::vCard::Addressbook->new({ 'source_file' => 't/notes.vcf'});
#print Dumper($notes);
#my $res = $notes->export();
#print Dumper($res);
|