This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Locale::Maketext external cache support
[perl5.git] / dist / Locale-Maketext / t / 04_use_external_lex_cache.t
1 use Test::More tests => 11;
2
3 BEGIN {
4     chdir 't';
5     unshift @INC, qw(lib ../lib);
6     use_ok('Locale::Maketext');
7 };
8
9 package MyTestLocale;
10
11 @MyTestLocale::ISA = qw(Locale::Maketext);
12 %MyTestLocale::Lexicon = ();
13 %MyTestLocale::Lexicon = (); # to avoid warnings
14
15 package MyTestLocale::fr;
16
17 @MyTestLocale::fr::ISA = qw(MyTestLocale);
18
19 %MyTestLocale::fr::Lexicon = (
20     '_AUTO' => 1,
21     'Hello World' => 'Bonjour Monde',
22 );
23
24 package main;
25
26 my $lh = MyTestLocale->get_handle('fr');
27 $lh->{'use_external_lex_cache'} = 1;
28 ok(exists $MyTestLocale::fr::Lexicon{'Hello World'} && !ref $MyTestLocale::fr::Lexicon{'Hello World'}, 'lex value not a ref');
29
30 is($lh->maketext('Hello World'), 'Bonjour Monde', 'renders correctly first time');
31 ok(exists $lh->{'_external_lex_cache'}{'Hello World'} && ref $lh->{'_external_lex_cache'}{'Hello World'}, 'compiled into lex_cache');
32 ok(exists $MyTestLocale::fr::Lexicon{'Hello World'} && !ref $MyTestLocale::fr::Lexicon{'Hello World'}, 'lex value still not a ref');
33
34 is($lh->maketext('Hello World'), 'Bonjour Monde', 'renders correctly second time time');
35 ok(exists $lh->{'_external_lex_cache'}{'Hello World'} && ref $lh->{'_external_lex_cache'}{'Hello World'}, 'still compiled into lex_cache');
36 ok(exists $MyTestLocale::fr::Lexicon{'Hello World'} && !ref $MyTestLocale::fr::Lexicon{'Hello World'}, 'lex value still not a ref');
37
38 is($lh->maketext('This is not a key'), 'This is not a key', '_AUTO renders correctly first time');
39 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');
40 ok(!exists $MyTestLocale::fr::Lexicon{'This is not a key'}, '_AUTO lex value not added to lex');