aboutsummaryrefslogtreecommitdiff
path: root/t/cmp_path.t
blob: 9de79f49ba2e92ec01ba07e980e5151e7ed7ea7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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");