Debian Codegraph @

dist/Locale-Maketext/t/04_use_external_lex_cache.t

raw
1 use Test::More tests => 11;
2
3 BEGIN {
4 use_ok('Locale::Maketext');
5 };
6
7 package MyTestLocale;
8
9 @MyTestLocale::ISA = qw(Locale::Maketext);
10 %MyTestLocale::Lexicon = ();
11 %MyTestLocale::Lexicon = (); # to avoid warnings
12
13 package MyTestLocale::fr;
14
15 @MyTestLocale::fr::ISA = qw(MyTestLocale);
16
17 %MyTestLocale::fr::Lexicon = (
18 '_AUTO' => 1,
19 'Hello World' => 'Bonjour Monde',
20 );
21
22 package main;
23
24 my $lh = MyTestLocale->get_handle('fr');
25 $lh->{'use_external_lex_cache'} = 1;
26 ok(exists $MyTestLocale::fr::Lexicon{'Hello World'} && !ref $MyTestLocale::fr::Lexicon{'Hello World'}, 'lex value not a ref');
27
28 is($lh->maketext('Hello World'), 'Bonjour Monde', 'renders correctly first time');
29 ok(exists $lh->{'_external_lex_cache'}{'Hello World'} && ref $lh->{'_external_lex_cache'}{'Hello World'}, 'compiled into lex_cache');
30 ok(exists $MyTestLocale::fr::Lexicon{'Hello World'} && !ref $MyTestLocale::fr::Lexicon{'Hello World'}, 'lex value still not a ref');
31
32 is($lh->maketext('Hello World'), 'Bonjour Monde', 'renders correctly second time time');
33 ok(exists $lh->{'_external_lex_cache'}{'Hello World'} && ref $lh->{'_external_lex_cache'}{'Hello World'}, 'still compiled into lex_cache');
34 ok(exists $MyTestLocale::fr::Lexicon{'Hello World'} && !ref $MyTestLocale::fr::Lexicon{'Hello World'}, 'lex value still not a ref');
35
36 is($lh->maketext('This is not a key'), 'This is not a key', '_AUTO renders correctly first time');
37 ok(exists $lh->{'_external_lex_cache'}{'This is not a key'} && ref $lh->{'_external_lex_cache'}{'This is not a key'}, '_AUTO compiled into lex_cache');
38 ok(!exists $MyTestLocale::fr::Lexicon{'This is not a key'}, '_AUTO lex value not added to lex');