Bump version to 2.4.2 for development of next release
[gnu-stow.git] / t / join_paths.t
blob40c5a8fc978d4ad6c9b9b57dbfee4cd293f39a78
1 #!/usr/bin/perl
3 # This file is part of GNU Stow.
5 # GNU Stow is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # GNU Stow is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see https://www.gnu.org/licenses/.
19 # Testing join_paths();
22 use strict;
23 use warnings;
25 use Stow::Util qw(join_paths set_debug_level);
27 #set_debug_level(4);
29 use Test::More tests => 22;
31 my @TESTS = (
32 [['a/b/c', 'd/e/f'], 'a/b/c/d/e/f' => 'simple'],
33 [['a/b/c', '/d/e/f'], '/d/e/f' => 'relative then absolute'],
34 [['/a/b/c', 'd/e/f'], '/a/b/c/d/e/f' => 'absolute then relative'],
35 [['/a/b/c', '/d/e/f'], '/d/e/f' => 'two absolutes'],
36 [['/a/b/c/', '/d/e/f/'], '/d/e/f' => 'two absolutes with trailing /'],
37 [['///a/b///c//', '/d///////e/f'], '/d/e/f' => "multiple /'s, absolute"],
38 [['///a/b///c//', 'd///////e/f'], '/a/b/c/d/e/f' => "multiple /'s, relative"],
39 [['', 'a/b/c'], 'a/b/c' => 'first empty'],
40 [['a/b/c', ''], 'a/b/c' => 'second empty'],
41 [['/', 'a/b/c'], '/a/b/c' => 'first is /'],
42 [['a/b/c', '/'], '/' => 'second is /'],
43 [['../a1/b1/../c1/', 'a2/../b2/e2'], '../a1/c1/b2/e2' => 'relative with ../'],
44 [['../a1/b1/../c1/', '/a2/../b2/e2'], '/b2/e2' => 'absolute with ../'],
45 [['../a1/../../c1', 'a2/../../'], '../..' => 'lots of ../'],
46 [['./', '../a2'], '../a2' => 'drop any "./"'],
47 [['./a1', '../../a2'], '../a2' => 'drop any "./foo"'],
48 [['a/b/c', '.'], 'a/b/c' => '. on RHS'],
49 [['a/b/c', '.', 'd/e'], 'a/b/c/d/e' => '. in middle'],
50 [['0', 'a/b'], '0/a/b' => '0 at start'],
51 [['/0', 'a/b'], '/0/a/b' => '/0 at start'],
52 [['a/b/c', '0', 'd/e'], 'a/b/c/0/d/e' => '0 in middle'],
53 [['a/b', '0'], 'a/b/0' => '0 at end'],
56 for my $test (@TESTS) {
57 my ($inputs, $expected, $scenario) = @$test;
58 my $got = join_paths(@$inputs);
59 my $descr = "$scenario: in=[" . join(', ', map "'$_'", @$inputs) . "] exp=[$expected] got=[$got]";
60 is($got, $expected, $descr);