App-olson

 view release on metacpan or  search on metacpan

t/attr.t  view on Meta::CPAN

use warnings;
use strict;

use Params::Classify qw(is_ref);
use Test::More tests => 33;

BEGIN { use_ok "App::olson"; }

sub pa($) {
	my($txt) = @_;
	pos($txt) = undef;
	my $attr = App::olson::_parse_attribute_from_gmatch(\$txt);
	$txt =~ /\G\z/gc or die "extraneous matter after attribute\n";
	return $attr;
}

sub san($) {
	return $_[0] unless is_ref($_[0], "HASH");
	my %attr = %{$_[0]};
	foreach(keys %attr) {
		$attr{$_} = "CODE" if is_ref($attr{$_}, "CODE");
	}
	return \%attr;
}

eval { pa("") };
is $@, "missing attribute name\n";

eval { pa("\@now") };
is $@, "missing attribute name\n";

eval { pa("foo") };
is $@, "no such attribute class `foo'\n";

eval { pa("foo\@now") };
is $@, "no such attribute class `foo'\n";

my $a = pa("z");
is_deeply san($a), {
	type => $App::olson::type{zone_name},
	check_value => "CODE",
	cost => 0,
	get_needs => { z=>undef },
	xget => "CODE",
};
is $a->{xget}->({ z=>"Europe/London" }), "Europe/London";
is_deeply san(pa("zone_name")), san($a);

$a = pa("a");
is_deeply san($a), {
	type => $App::olson::type{area_name},
	check_value => "CODE",
	cost => 1,
	get_needs => { z=>undef },
	xget => "CODE",
};
is $a->{xget}->({ z=>"Europe/London" }), "Europe";
is_deeply san(pa("area_name")), san($a);

$a = pa("c");
is_deeply san($a), {
	type => $App::olson::type{country_code},
	check_value => "CODE",
	cost => 0,
	get_needs => { c=>undef },
	xget => "CODE",
};
is $a->{xget}->({ c=>"GB" }), "GB";
is_deeply san(pa("country_code")), san($a);



( run in 1.880 second using v1.01-cache-2.11-cpan-364913b4093 )