X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/be6ca4c4e99c40f4c4763147c798a6f144dadc0c..740c909abbe97151f14768de9476505c1f06badd:/t/po.t diff --git a/t/po.t b/t/po.t index da0bd68a7..ccb508bef 100755 --- a/t/po.t +++ b/t/po.t @@ -3,6 +3,7 @@ use warnings; use strict; use File::Temp qw{tempdir}; +use utf8; BEGIN { unless (eval { require Locale::Po4a::Chooser }) { @@ -17,7 +18,7 @@ BEGIN { } } -use Test::More tests => 109; +use Test::More; BEGIN { use_ok("IkiWiki"); } @@ -44,7 +45,7 @@ $config{po_slave_languages} = { es => 'Castellano', fr => "Français" }; -$config{po_translatable_pages}='index or test1 or test2 or translatable'; +$config{po_translatable_pages}='index or test1 or test2 or translatable or debian*'; $config{po_link_to}='negotiated'; IkiWiki::loadplugins(); ok(IkiWiki::loadplugin('meta'), "meta plugin loaded"); @@ -67,8 +68,19 @@ $pagesources{'translatable'}='translatable.mdwn'; $pagesources{'translatable.fr'}='translatable.fr.po'; $pagesources{'translatable.es'}='translatable.es.po'; $pagesources{'nontranslatable'}='nontranslatable.mdwn'; +$pagesources{'debian911356'}='debian911356.mdwn'; +$pagesources{'debian911356ish'}='debian911356ish.mdwn'; +$pagesources{'debian911356.fr'}='debian911356.fr.po'; +$pagesources{'debian911356ish.fr'}='debian911356ish.fr.po'; +$pagesources{'debian911356-inlined'}='debian911356-inlined.mdwn'; +$pagesources{'debian911356-inlined.fr'}='debian911356-inlined.fr.po'; +$pagesources{'templates/feedlink.tmpl'}='templates/feedlink.tmpl'; +$pagesources{'templates/inlinepage.tmpl'}='templates/inlinepage.tmpl'; +my $now=time; foreach my $page (keys %pagesources) { $IkiWiki::pagecase{lc $page}=$page; + $IkiWiki::pagectime{$page}=$now; + $IkiWiki::pagemtime{$page}=$now; } ### populate srcdir @@ -80,6 +92,82 @@ writefile('test2.mdwn', $config{srcdir}, 'test2 content'); writefile('test3.mdwn', $config{srcdir}, 'test3 content'); writefile('translatable.mdwn', $config{srcdir}, '[[nontranslatable]]'); writefile('nontranslatable.mdwn', $config{srcdir}, '[[/]] [[translatable]]'); +writefile('debian911356.mdwn', $config{srcdir}, < +EOF +# Make inlines' appearance predictable so we can screen-scrape them +writefile('templates/inlinepage.tmpl', $config{srcdir}, < +
+ + +EOF ### istranslatable/istranslation # we run these tests twice because memoization attempts made them @@ -135,7 +223,7 @@ is_deeply(\@{$links{'index.fr'}}, ['translatable.fr', 'nontranslatable'], "$msgp is_deeply(\@{$links{'translatable'}}, ['nontranslatable'], "$msgprefix translatable"); is_deeply(\@{$links{'translatable.es'}}, ['nontranslatable'], "$msgprefix translatable.es"); is_deeply(\@{$links{'translatable.fr'}}, ['nontranslatable'], "$msgprefix translatable.fr"); -is_deeply(\@{$links{'nontranslatable'}}, ['/', 'translatable', 'translatable.fr', 'translatable.es'], "$msgprefix nontranslatable"); +is_deeply([sort @{$links{'nontranslatable'}}], [sort('/', 'translatable', 'translatable.fr', 'translatable.es')], "$msgprefix nontranslatable"); $config{po_link_to}='current'; $msgprefix="links (po_link_to=current)"; @@ -146,7 +234,7 @@ is_deeply(\@{$links{'index.fr'}}, [ (map bestlink('index.fr', $_), ('translatabl is_deeply(\@{$links{'translatable'}}, [bestlink('translatable', 'nontranslatable')], "$msgprefix translatable"); is_deeply(\@{$links{'translatable.es'}}, ['nontranslatable'], "$msgprefix translatable.es"); is_deeply(\@{$links{'translatable.fr'}}, ['nontranslatable'], "$msgprefix translatable.fr"); -is_deeply(\@{$links{'nontranslatable'}}, ['/', 'translatable', 'translatable.fr', 'translatable.es'], "$msgprefix nontranslatable"); +is_deeply([sort @{$links{'nontranslatable'}}], [sort('/', 'translatable', 'translatable.fr', 'translatable.es')], "$msgprefix nontranslatable"); ### targetpage $config{usedirs}=0; @@ -241,3 +329,184 @@ ok(! IkiWiki::Plugin::po::istranslatedto('nontranslatable', 'es')); ok(! IkiWiki::Plugin::po::istranslatedto('nontranslatable', 'cz')); ok(! IkiWiki::Plugin::po::istranslatedto('test1.es', 'fr')); ok(! IkiWiki::Plugin::po::istranslatedto('test1.fr', 'es')); + +### islanguagecode +ok(IkiWiki::Plugin::po::islanguagecode('en')); +ok(IkiWiki::Plugin::po::islanguagecode('es')); +ok(IkiWiki::Plugin::po::islanguagecode('arn')); +ok(! IkiWiki::Plugin::po::islanguagecode('es_')); +ok(! IkiWiki::Plugin::po::islanguagecode('_en')); + +# Actually render translated pages +use IkiWiki::Render; + +my %output; +foreach my $page (sort keys %pagesources) { + my $source = "$config{srcdir}/$pagesources{$page}"; + if (-e $source) { + IkiWiki::scan($pagesources{$page}); + } +} + +# This is the most complicated case, so use this while we test rendering +$config{po_link_to}='current'; + +foreach my $page (sort keys %pagesources) { + my $source = "$config{srcdir}/$pagesources{$page}"; + if (-e $source && defined IkiWiki::pagetype($pagesources{$page})) { + IkiWiki::scan($pagesources{$page}); + my $content = readfile($source); + #print STDERR "-------------------------------------\n"; + #print STDERR "SOURCE: $page: $content\n"; + $content = IkiWiki::filter($page, $page, $content); + #print STDERR "FILTERED: $page: $content\n"; + $content = IkiWiki::preprocess($page, $page, $content); + #print STDERR "PREPROCESSED: $page: $content\n"; + $content = IkiWiki::linkify($page, $page, $content); + #print STDERR "LINKIFIED: $page: $content\n"; + $content = IkiWiki::htmlize($page, $page, IkiWiki::pagetype($pagesources{$page}), $content); + #print STDERR "HTMLIZED: $page: $content\n"; + IkiWiki::run_hooks(format => sub { + $content=shift->( + page => $page, + content => $content, + ); + }); + #print STDERR "FORMATTED: $page: $content\n"; + $output{$page} = $content; + } +} + +like($output{index}, qr{ +

+ + translatable + \s* + + nontranslatable + +

+}sx); + +like($output{'index.es'}, qr{ +

+ + translatable + \s* + + nontranslatable + +

+}sx); + +like($output{'index.fr'}, qr{ +

+ + translatable + \s* + + nontranslatable + +

+}sx); + +like($output{'translatable'}, qr{ + + nontranslatable + +}sx); + +TODO: { +local $TODO = 'was [[/]] meant to be a link to the index?'; +unlike($output{'nontranslatable'}, qr{ + class=.createlink. +}sx); +}; +like($output{'nontranslatable'}, qr{ + + translatable + +}sx); + +like($output{debian911356}, qr{ +

Before\sfirst\sinline

+ \s* +

English\scontent

+ \s* +

Between\sinlines

+ \s* +

English\scontent

+ \s* +

After\sinlines

+}sx); + +like($output{'debian911356.fr'}, qr{ +

Avant\sla\spremière\sinline

+ \s* +

Contenu\sfrançais

+ \s* +

Entre\sles\sinlines

+ \s* +

Contenu\sfrançais

+ \s* +

Après\sles\sinlines

+}sx); + +# Variation of Debian #911356 without using raw inlines. +like($output{debian911356ish}, qr{ +

Before\sfirst\sinline

+ \s* + + \s* + + \s* +
debian911356-inlined
+ \s* +

English\scontent

+ \s* + + \s* +

Between\sinlines

+ \s* + + \s* + + \s* +
debian911356-inlined
+ \s* +

English\scontent

+ \s* + + \s* +

After\sinlines

+}sx); + +like($output{'debian911356ish.fr'}, qr{ +

Avant\sla\spremière\sinline

+ \s* + + \s* + + \s* +
debian911356-inlined\.fr
+ \s* +

Contenu\sfrançais

+ \s* + + \s* +

Entre\sles\sinlines

+ \s* + + \s* + + \s* +
debian911356-inlined\.fr
+ \s* +

Contenu\sfrançais

+ \s* + + \s* +

Après\sles\sinlines

+}sx); + +done_testing;