aboutsummaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorSimon McVittie <smcv@debian.org>2011-11-12 16:02:20 +0000
committerSimon McVittie <smcv@debian.org>2011-11-12 16:02:20 +0000
commit903a5a314f1f5d833dbc208ce128f24195b40e4b (patch)
treedfebe734bb3b3dd296ea02b10c815bb0aa741aa9 /t
parent272e0b2f17c33c625b494b07f581da400066a216 (diff)
downloadikiwiki-903a5a314f1f5d833dbc208ce128f24195b40e4b.tar
ikiwiki-903a5a314f1f5d833dbc208ce128f24195b40e4b.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.
Diffstat (limited to 't')
-rwxr-xr-xt/cmp_path.t48
-rwxr-xr-xt/pagespec_match_list.t4
2 files changed, 50 insertions, 2 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");
diff --git a/t/pagespec_match_list.t b/t/pagespec_match_list.t
index 244ad9159..7ff178aad 100755
--- a/t/pagespec_match_list.t
+++ b/t/pagespec_match_list.t
@@ -12,7 +12,7 @@ IkiWiki::checkconfig();
{
package IkiWiki::SortSpec;
- sub cmp_path { $a cmp $b }
+ sub cmp_raw_path { $a cmp $b }
}
%pagesources=(
@@ -53,7 +53,7 @@ is_deeply([pagespec_match_list("foo", "post/*", sort => "title", num => 50, reve
is_deeply([pagespec_match_list("foo", "post/*", sort => "title",
filter => sub { $_[0] =~ /3/}) ],
["post/1", "post/2"]);
-is_deeply([pagespec_match_list("foo", "*", sort => "path", num => 2)],
+is_deeply([pagespec_match_list("foo", "*", sort => "raw_path", num => 2)],
["bar", "foo"]);
is_deeply([pagespec_match_list("foo", "foo* or bar*",
sort => "-age title")], # oldest first, break ties by title