diff options
author | Simon McVittie <smcv@debian.org> | 2011-11-12 16:02:20 +0000 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-12-06 14:26:34 -0400 |
commit | ea313b8133e65947d07c1e13b41584f7582d99e1 (patch) | |
tree | 8c9027c1ab34735b2b1d6137080f33aa72402fe6 /t/cmp_path.t | |
parent | 5333c113d62acd0b82551e499863abaf749a6a1f (diff) | |
download | ikiwiki-ea313b8133e65947d07c1e13b41584f7582d99e1.tar ikiwiki-ea313b8133e65947d07c1e13b41584f7582d99e1.tar.gz |
Add path and path_natural sort orders
These correspond to title and title_natural, but compare the entire
path: a < a/b < a/z < ab < b.
(cherry picked from commit 903a5a314f1f5d833dbc208ce128f24195b40e4b)
Diffstat (limited to 't/cmp_path.t')
-rwxr-xr-x | t/cmp_path.t | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/t/cmp_path.t b/t/cmp_path.t new file mode 100755 index 000000000..9de79f49b --- /dev/null +++ b/t/cmp_path.t @@ -0,0 +1,48 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Test::More tests => 25; + +BEGIN { use_ok("IkiWiki"); } + +%config=IkiWiki::defaultconfig(); +$config{srcdir}=$config{destdir}="/dev/null"; +IkiWiki::checkconfig(); + +sub test { + my ($before, $after) = @_; + + $IkiWiki::SortSpec::a = $before; + $IkiWiki::SortSpec::b = $after; + my $r = IkiWiki::SortSpec::cmp_path(); + + if ($before eq $after) { + is($r, 0); + } + else { + is($r, -1); + } + + $IkiWiki::SortSpec::a = $after; + $IkiWiki::SortSpec::b = $before; + $r = IkiWiki::SortSpec::cmp_path(); + + if ($before eq $after) { + is($r, 0); + } + else { + is($r, 1); + } + + is_deeply([IkiWiki::SortSpec::sort_pages(\&IkiWiki::SortSpec::cmp_path, $before, $after)], + [$before, $after]); + is_deeply([IkiWiki::SortSpec::sort_pages(\&IkiWiki::SortSpec::cmp_path, $after, $before)], + [$before, $after]); +} + +test("a/b/c", "a/b/c"); +test("a/b", "a/c"); +test("a/z", "z/a"); +test("a", "a/b"); +test("a", "a/b"); +test("a/z", "ab"); |