X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/d1e5affbc254766f50bd44681a25d12957c870c9..8f6cfbfade6018732495addce11f6d5e93e0b723:/t/po.t diff --git a/t/po.t b/t/po.t index e9d5ac35f..b6885a37e 100755 --- a/t/po.t +++ b/t/po.t @@ -17,7 +17,7 @@ BEGIN { } } -use Test::More tests => 45; +use Test::More tests => 65; BEGIN { use_ok("IkiWiki"); } @@ -64,52 +64,70 @@ foreach my $page (keys %pagesources) { $IkiWiki::pagecase{lc $page}=$page; } +### populate srcdir +writefile('index.mdwn', $config{srcdir}, '[[translatable]] [[nontranslatable]]'); +writefile('test1.mdwn', $config{srcdir}, 'test1 content'); +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]]'); + ### istranslatable/istranslation # we run these tests twice because memoization attempts made them # succeed once every two tries... +foreach (1, 2) { ok(IkiWiki::Plugin::po::istranslatable('index'), "index is translatable"); -ok(IkiWiki::Plugin::po::istranslatable('index'), "index is translatable"); -ok(! IkiWiki::Plugin::po::istranslatable('index.fr'), "index.fr is not translatable"); +ok(IkiWiki::Plugin::po::istranslatable('/index'), "/index is translatable"); ok(! IkiWiki::Plugin::po::istranslatable('index.fr'), "index.fr is not translatable"); ok(! IkiWiki::Plugin::po::istranslatable('index.es'), "index.es is not translatable"); -ok(! IkiWiki::Plugin::po::istranslatable('index.es'), "index.es is not translatable"); -ok(! IkiWiki::Plugin::po::istranslation('index'), "index is not a translation"); +ok(! IkiWiki::Plugin::po::istranslatable('/index.fr'), "/index.fr is not translatable"); ok(! IkiWiki::Plugin::po::istranslation('index'), "index is not a translation"); ok(IkiWiki::Plugin::po::istranslation('index.fr'), "index.fr is a translation"); -ok(IkiWiki::Plugin::po::istranslation('index.fr'), "index.fr is a translation"); -ok(IkiWiki::Plugin::po::istranslation('index.es'), "index.es is a translation"); ok(IkiWiki::Plugin::po::istranslation('index.es'), "index.es is a translation"); +ok(IkiWiki::Plugin::po::istranslation('/index.fr'), "/index.fr is a translation"); ok(IkiWiki::Plugin::po::istranslatable('test2'), "test2 is translatable"); -ok(IkiWiki::Plugin::po::istranslatable('test2'), "test2 is translatable"); -ok(! IkiWiki::Plugin::po::istranslation('test2'), "test2 is not a translation"); ok(! IkiWiki::Plugin::po::istranslation('test2'), "test2 is not a translation"); ok(! IkiWiki::Plugin::po::istranslatable('test3'), "test3 is not translatable"); -ok(! IkiWiki::Plugin::po::istranslatable('test3'), "test3 is not translatable"); -ok(! IkiWiki::Plugin::po::istranslation('test3'), "test3 is not a translation"); ok(! IkiWiki::Plugin::po::istranslation('test3'), "test3 is not a translation"); +} ### links -writefile('index.mdwn', $config{srcdir}, '[[translatable]] [[nontranslatable]]'); -writefile('translatable.mdwn', $config{srcdir}, '[[nontranslatable]]'); -writefile('nontranslatable.mdwn', $config{srcdir}, '[[/]] [[translatable]]'); -map IkiWiki::Plugin::po::refreshpot(srcfile($_)), ('index.mdwn', 'translatable.mdwn'); require IkiWiki::Render; -foreach my $masterfile_rel ('index.mdwn', 'translatable.mdwn') { - my $masterfile=srcfile($masterfile_rel); - my @pofiles=IkiWiki::Plugin::po::pofiles($masterfile); - IkiWiki::Plugin::po::refreshpot($masterfile); - IkiWiki::Plugin::po::refreshpofiles($masterfile, @pofiles); - IkiWiki::scan($masterfile_rel); - map IkiWiki::scan(IkiWiki::abs2rel($_, $config{srcdir})), @pofiles; + +sub refresh_n_scan(@) { + my @masterfiles_rel=@_; + foreach my $masterfile_rel (@masterfiles_rel) { + my $masterfile=srcfile($masterfile_rel); + IkiWiki::scan($masterfile_rel); + next unless IkiWiki::Plugin::po::istranslatable(pagename($masterfile_rel)); + my @pofiles=IkiWiki::Plugin::po::pofiles($masterfile); + IkiWiki::Plugin::po::refreshpot($masterfile); + IkiWiki::Plugin::po::refreshpofiles($masterfile, @pofiles); + map IkiWiki::scan(IkiWiki::abs2rel($_, $config{srcdir})), @pofiles; + } } -IkiWiki::scan('nontranslatable.mdwn'); -is_deeply(\@{$links{'index'}}, ['translatable', 'nontranslatable'], 'index'); -is_deeply(\@{$links{'index.es'}}, ['translatable.es', 'nontranslatable'], 'index.es'); -is_deeply(\@{$links{'index.fr'}}, ['translatable.fr', 'nontranslatable'], 'index.fr'); -is_deeply(\@{$links{'translatable'}}, ['nontranslatable'], 'translatable'); -is_deeply(\@{$links{'translatable.es'}}, ['nontranslatable'], 'translatable.es'); -is_deeply(\@{$links{'translatable.fr'}}, ['nontranslatable'], 'translatable.fr'); -is_deeply(\@{$links{'nontranslatable'}}, ['/', 'translatable', 'translatable.fr', 'translatable.es'], 'nontranslatable'); + +$config{po_link_to}='negotiated'; +$msgprefix="links (po_link_to=negotiated)"; +refresh_n_scan('index.mdwn', 'translatable.mdwn', 'nontranslatable.mdwn'); +is_deeply(\@{$links{'index'}}, ['translatable', 'nontranslatable'], "$msgprefix index"); +is_deeply(\@{$links{'index.es'}}, ['translatable.es', 'nontranslatable'], "$msgprefix index.es"); +is_deeply(\@{$links{'index.fr'}}, ['translatable.fr', 'nontranslatable'], "$msgprefix index.fr"); +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"); + +$config{po_link_to}='current'; +$msgprefix="links (po_link_to=current)"; +refresh_n_scan('index.mdwn', 'translatable.mdwn', 'nontranslatable.mdwn'); +is_deeply(\@{$links{'index'}}, ['translatable', 'nontranslatable'], "$msgprefix index"); +is_deeply(\@{$links{'index.es'}}, [ map bestlink('index.es', $_), ('translatable.es', 'nontranslatable')], "$msgprefix index.es"); +is_deeply(\@{$links{'index.fr'}}, [ map bestlink('index.fr', $_), ('translatable.fr', 'nontranslatable')], "$msgprefix index.fr"); +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"); ### targetpage $config{usedirs}=0; @@ -125,6 +143,18 @@ is(targetpage('test1.fr', 'html'), 'test1/index.fr.html', "$msgprefix test1.fr") is(targetpage('test3', 'html'), 'test3/index.html', "$msgprefix test3 (non-translatable page)"); is(targetpage('test3.es', 'html'), 'test3.es/index.html', "$msgprefix test3.es (non-translatable page)"); +### urlto -> index +$config{po_link_to}='current'; +$msgprefix="urlto (po_link_to=current)"; +is(urlto('', 'index'), './index.en.html', "$msgprefix index -> ''"); +is(urlto('', 'nontranslatable'), '../index.en.html', "$msgprefix nontranslatable -> ''"); +is(urlto('', 'translatable.fr'), '../index.fr.html', "$msgprefix translatable.fr -> ''"); +$config{po_link_to}='negotiated'; +$msgprefix="urlto (po_link_to=negotiated)"; +is(urlto('', 'index'), './', "$msgprefix index -> ''"); +is(urlto('', 'nontranslatable'), '../', "$msgprefix nontranslatable -> ''"); +is(urlto('', 'translatable.fr'), '../', "$msgprefix translatable.fr -> ''"); + ### bestlink $config{po_link_to}='current'; $msgprefix="bestlink (po_link_to=current)"; @@ -132,7 +162,7 @@ is(bestlink('test1.fr', 'test2'), 'test2.fr', "$msgprefix test1.fr -> test2"); is(bestlink('test1.fr', 'test2.es'), 'test2.es', "$msgprefix test1.fr -> test2.es"); $config{po_link_to}='negotiated'; $msgprefix="bestlink (po_link_to=negotiated)"; -is(bestlink('test1.fr', 'test2'), 'test2', "$msgprefix test1.fr -> test2"); +is(bestlink('test1.fr', 'test2'), 'test2.fr', "$msgprefix test1.fr -> test2"); is(bestlink('test1.fr', 'test2.es'), 'test2.es', "$msgprefix test1.fr -> test2.es"); ### beautify_urlpath @@ -142,5 +172,6 @@ is(IkiWiki::beautify_urlpath('test1/index.en.html'), './test1/index.en.html', "$ is(IkiWiki::beautify_urlpath('test1/index.fr.html'), './test1/index.fr.html', "$msgprefix test1/index.fr.html"); $config{po_link_to}='negotiated'; $msgprefix="beautify_urlpath (po_link_to=negotiated)"; +is(IkiWiki::beautify_urlpath('test1/index.html'), './test1/', "$msgprefix test1/index.html"); is(IkiWiki::beautify_urlpath('test1/index.en.html'), './test1/', "$msgprefix test1/index.en.html"); -is(IkiWiki::beautify_urlpath('test1/index.fr.html'), './test1/index.fr.html', "$msgprefix test1/index.fr.html"); +is(IkiWiki::beautify_urlpath('test1/index.fr.html'), './test1/', "$msgprefix test1/index.fr.html");