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
|
#!/usr/bin/env perl
# Check the creation of the templater
use warnings;
use strict;
use Test::More;
use Log::Report;
use File::Basename qw(dirname);
dispatcher close => 'default';
(my $incl) = grep -d, 't/templates', 'templates';
$incl or die "where are my templates?";
my $lexicon = dirname($incl) .'/lexicons';
-d $lexicon or mkdir $lexicon or die "$lexicon: $!";
use_ok 'Log::Report::Template';
my $templater = Log::Report::Template->new(INCLUDE_PATH => $incl);
isa_ok $templater, 'Log::Report::Template';
### Construct textdomain 'first'
my $first = $templater->addTextdomain(name => 'first', lexicon => $lexicon);
isa_ok $first, 'Log::Report::Template::Textdomain';
is $first->function, 'loc', 'default function';
ok $first->expectedIn($incl), 'expectedIn';
my $f2 = textdomain 'first';
ok defined $f2, 'recover domain';
is $first, $f2;
#dispatcher close => 'default';
eval { $templater->addTextdomain(name => 'first') };
is $@, "error: extension to domain 'first' already exists\n", 'no redefine';
eval { $templater->addTextdomain(name => 'error1', only_in_directory => '/tmp')};
is $@, "error: directory /tmp not in INCLUDE_PATH, used by addTextdomain(only_in_directory)\n", 'outside INCLUDE_PATH';
#eval { $templater->addTextdomain(name => 'error2') };
#is $@, "error: textdomain 'error2' does not specify the lexicon directory\n", 'no lexicon';
eval { $templater->addTextdomain(name => 'error3', lexicon => $lexicon) };
is $@, "error: translation function 'loc' already in use by textdomain 'first'\n", 'same function again';
### Construct textdomain 'second'
my $second = $templater->addTextdomain
( name => 'second'
, lexicon => $lexicon
, translation_function => 'S'
, only_in_directory => $incl
);
isa_ok $second, 'Log::Report::Template::Textdomain';
is $second->function, 'S', 'function S';
ok $second->expectedIn($incl), 'expectedIn';
ok ! $second->expectedIn('/tmp'), 'not expectedIn';
done_testing;
|