X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/2b4e76a96124384fd4c53490373a443d46365ed8..52f09a63a1b5715e3b8f364ebf3518cd1cf27b26:/t/po.t diff --git a/t/po.t b/t/po.t index 79e087318..444743cac 100755 --- a/t/po.t +++ b/t/po.t @@ -17,7 +17,7 @@ BEGIN { } } -use Test::More tests => 59; +use Test::More tests => 68; BEGIN { use_ok("IkiWiki"); } @@ -42,8 +42,8 @@ $config{po_slave_languages} = { $config{po_translatable_pages}='index or test1 or test2 or translatable'; $config{po_link_to}='negotiated'; IkiWiki::loadplugins(); -IkiWiki::checkconfig(); ok(IkiWiki::loadplugin('po'), "po plugin loaded"); +IkiWiki::checkconfig(); ### seed %pagesources and %pagecase $pagesources{'index'}='index.mdwn'; @@ -61,32 +61,42 @@ $pagesources{'translatable.fr'}='translatable.fr.po'; $pagesources{'translatable.es'}='translatable.es.po'; $pagesources{'nontranslatable'}='nontranslatable.mdwn'; foreach my $page (keys %pagesources) { - $IkiWiki::pagecase{lc $page}=$page; + $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::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'), "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"); +} + +### pofiles + +my @pofiles = IkiWiki::Plugin::po::pofiles(srcfile("index.mdwn")); +ok( @pofiles, "pofiles is defined"); +ok( @pofiles == 2, "pofiles has correct size"); +is_deeply(\@pofiles, ["$config{srcdir}/index.es.po", "$config{srcdir}/index.fr.po"], "pofiles content is correct"); ### links require IkiWiki::Render; @@ -104,16 +114,12 @@ sub refresh_n_scan(@) { } } -writefile('index.mdwn', $config{srcdir}, '[[translatable]] [[nontranslatable]]'); -writefile('translatable.mdwn', $config{srcdir}, '[[nontranslatable]]'); -writefile('nontranslatable.mdwn', $config{srcdir}, '[[/]] [[translatable]]'); - $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{'index.es'}}, ['translatable.es', 'nontranslatable', 'SandBox', 'ikiwiki'], "$msgprefix index.es"); +is_deeply(\@{$links{'index.fr'}}, ['translatable.fr', 'nontranslatable', 'SandBox', 'ikiwiki'], "$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"); @@ -123,8 +129,8 @@ $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{'index.es'}}, [ (map bestlink('index.es', $_), ('translatable.es', 'nontranslatable')), 'SandBox', 'ikiwiki'], "$msgprefix index.es"); +is_deeply(\@{$links{'index.fr'}}, [ (map bestlink('index.fr', $_), ('translatable.fr', 'nontranslatable')), 'SandBox', 'ikiwiki'], "$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"); @@ -148,13 +154,13 @@ is(targetpage('test3.es', 'html'), 'test3.es/index.html', "$msgprefix test3.es ( $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 -> ''"); +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 -> ''"); +is(urlto('', 'nontranslatable'), '../', "$msgprefix nontranslatable -> ''"); +is(urlto('', 'translatable.fr'), '../', "$msgprefix translatable.fr -> ''"); ### bestlink $config{po_link_to}='current';