File: unwrap.t

package info (click to toggle)
libtext-vcard-perl 3.09-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 356 kB
  • sloc: perl: 1,537; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 1,220 bytes parent folder | download | duplicates (3)
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
use Test::Most;

use Directory::Scratch;
use Path::Tiny;
use vCard;

# vCard files should have lines that are a max of 75 octets.  When they are too
# long the lines are wrapped.  The first character on continued line must be a
# space or a tab.  This test makes sure that works.
# see http://tools.ietf.org/search/rfc6350#section-3.2

my $in_file = path( 't', 'unwrap.vcf' );
note "Importing $in_file with Addressbook->load()";

my $address_book = Text::vCard::Addressbook->load( [$in_file] );
my $vcard = $address_book->vcards->[0];

my $expected_content = $in_file->slurp_utf8;
my $actual_content   = $vcard->as_string();

# the order in the vcard keys is not preserved so we wil test the only the wrapped lines
my $N    =  qr(/(N;CH[^\r]\r\n(?:[ \t][^\r]*\r\n)*)/s);
my $ADR  =  qr(/(ADR;[^\r]\r\n(?:[ \t][^\r]*\r\n)*)/s);
my $NOTE =  qr(/(NOTE[^\r]\r\n(?:[ \t][^\r]*\r\n)*)/s);


is $actual_content =~ $N,$expected_content =~ $N, 'vCard->as_string() N ?';
is $actual_content =~ $ADR,$expected_content =~ $ADR, 'vCard->as_string() ADR key?';
is $actual_content =~ $NOTE,$expected_content =~ $NOTE, 'vCard->as_string() NOTE key?';

is $address_book->export(), $actual_content, 'Addressbook->export()';

done_testing;