Data-Header-Fields

 view release on metacpan or  search on metacpan

t/01_Data-v.t  view on Meta::CPAN

#!/usr/bin/perl

use strict;
use warnings;

use Test::More 'no_plan';
#use Test::More tests => 10;
use Test::Differences;
use Test::Exception;
use Test::Deep;

use FindBin qw($Bin);
use lib "$Bin/lib";

BEGIN {
	use_ok ( 'Data::v' ) or exit;
}

exit main();

sub main {
	my $vcard      = Data::v::Card->new();

	my $vcard_line3 = Data::v::Card::Line->new(
		'line'   => "VERSION:2.1\n",
		'parent' => $vcard,
	);
	is($vcard_line3->get_key_param_value('encoding'), undef, 'get_key_param_value()');
	cmp_ok($vcard_line3->value, 'eq', "2.1", 'value()');
	is($vcard_line3->as_string, "VERSION:2.1\n", 'line->as_string()');

	my $vcard_line = Data::v::Card::Line->new(
		'line'   => "PHOTO;VALUE=URL;TYPE=GIF:http://www.example.com/dir_photos/my_photo.gif\n",
		'parent' => $vcard,
	);
	$vcard_line->line_changed;
	is($vcard_line->version, '2.1', 'default vcard version is 2.1');
	is($vcard_line->key, 'PHOTO', 'line key');
	cmp_ok($vcard_line->value, 'eq', 'http://www.example.com/dir_photos/my_photo.gif', 'line value');
	cmp_deeply([
		map { {'name'=>$_->name, 'value'=>$_->value} } @{$vcard_line->params}],
		[{'name' => 'VALUE', 'value' => 'URL'}, {'name' => 'TYPE', 'value' => 'GIF'}],
		'key params'
	);
	cmp_deeply(
		[ map { {'name'=>$_->name, 'value'=>$_->value} } $vcard_line->get_key_params('type') ],
		[ {'name' => 'TYPE', 'value' => 'GIF'} ],
		'get_key_params()',
	);
	cmp_deeply($vcard_line->as_string, "PHOTO;VALUE=URL;GIF:http://www.example.com/dir_photos/my_photo.gif\n", 'line->as_string() v2.1');
	my $vcard_line5 = Data::v::Card::Line->new(
		'line'   => "TEL;WORK;VOICE:(111) 555-1212\n",
		'parent' => $vcard,
	);
	$vcard_line5->line_changed;
	cmp_deeply([ map { $_->{'value'} } $vcard_line5->get_key_params('type')], [ 'WORK', 'VOICE' ], 'get_key_params() multiple types 2.1');
	is($vcard_line5->as_string, "TEL;WORK;VOICE:(111) 555-1212\n", 'line->as_string() with double type 2.1');
	$vcard_line5->set_key_param('LANGUAGE' => 'de');
	$vcard_line5->rm_key_param('TYPE');
	is($vcard_line5->as_string, "TEL;LANGUAGE=de:(111) 555-1212\n", 'line->as_string() with language, no type');
	$vcard_line5->set_key_param('LANGUAGE' => 'de-at');
	$vcard_line5->set_key_param('TYPE' => ['FAX', 'VOICE']);
	is($vcard_line5->as_string, "TEL;LANGUAGE=de-at;FAX;VOICE:(111) 555-1212\n", 'line->as_string() with language update, type fax,voice');
	$vcard_line5->set_key_param('TYPE' => ['VOICE']);
	$vcard_line5->set_key_param('LANGUAGE' => undef);
	is($vcard_line5->as_string, "TEL;VOICE:(111) 555-1212\n", 'line->as_string() with voice only now');

	$vcard->set_value('VERSION' => '3.0');



( run in 1.458 second using v1.01-cache-2.11-cpan-df04353d9ac )