2008-05-20 08:48:54 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2008 David Reiss
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='Test various path utilities'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
norm_abs() {
|
2009-02-07 16:08:30 +01:00
|
|
|
test_expect_success "normalize absolute: $1 => $2" \
|
|
|
|
"test \"\$(test-path-utils normalize_path_copy '$1')\" = '$2'"
|
2008-05-20 08:48:54 +02:00
|
|
|
}
|
|
|
|
|
2008-05-20 08:49:26 +02:00
|
|
|
ancestor() {
|
2009-02-07 16:08:30 +01:00
|
|
|
test_expect_success "longest ancestor: $1 $2 => $3" \
|
|
|
|
"test \"\$(test-path-utils longest_ancestor_length '$1' '$2')\" = '$3'"
|
2008-05-20 08:49:26 +02:00
|
|
|
}
|
|
|
|
|
2009-02-07 16:08:30 +01:00
|
|
|
norm_abs "" ""
|
2008-05-20 08:48:54 +02:00
|
|
|
norm_abs / /
|
|
|
|
norm_abs // /
|
|
|
|
norm_abs /// /
|
|
|
|
norm_abs /. /
|
|
|
|
norm_abs /./ /
|
2009-02-07 16:08:30 +01:00
|
|
|
norm_abs /./.. ++failed++
|
|
|
|
norm_abs /../. ++failed++
|
|
|
|
norm_abs /./../.// ++failed++
|
2008-05-20 08:48:54 +02:00
|
|
|
norm_abs /dir/.. /
|
|
|
|
norm_abs /dir/sub/../.. /
|
2009-02-07 16:08:30 +01:00
|
|
|
norm_abs /dir/sub/../../.. ++failed++
|
2008-05-20 08:48:54 +02:00
|
|
|
norm_abs /dir /dir
|
2009-02-07 16:08:30 +01:00
|
|
|
norm_abs /dir// /dir/
|
2008-05-20 08:48:54 +02:00
|
|
|
norm_abs /./dir /dir
|
2009-02-07 16:08:30 +01:00
|
|
|
norm_abs /dir/. /dir/
|
|
|
|
norm_abs /dir///./ /dir/
|
|
|
|
norm_abs /dir//sub/.. /dir/
|
|
|
|
norm_abs /dir/sub/../ /dir/
|
|
|
|
norm_abs //dir/sub/../. /dir/
|
|
|
|
norm_abs /dir/s1/../s2/ /dir/s2/
|
|
|
|
norm_abs /d1/s1///s2/..//../s3/ /d1/s3/
|
2008-05-20 08:48:54 +02:00
|
|
|
norm_abs /d1/s1//../s2/../../d2 /d2
|
|
|
|
norm_abs /d1/.../d2 /d1/.../d2
|
|
|
|
norm_abs /d1/..././../d2 /d1/d2
|
|
|
|
|
2008-05-20 08:49:26 +02:00
|
|
|
ancestor / "" -1
|
|
|
|
ancestor / / -1
|
|
|
|
ancestor /foo "" -1
|
|
|
|
ancestor /foo : -1
|
|
|
|
ancestor /foo ::. -1
|
|
|
|
ancestor /foo ::..:: -1
|
|
|
|
ancestor /foo / 0
|
|
|
|
ancestor /foo /fo -1
|
|
|
|
ancestor /foo /foo -1
|
|
|
|
ancestor /foo /foo/ -1
|
|
|
|
ancestor /foo /bar -1
|
|
|
|
ancestor /foo /bar/ -1
|
|
|
|
ancestor /foo /foo/bar -1
|
|
|
|
ancestor /foo /foo:/bar/ -1
|
|
|
|
ancestor /foo /foo/:/bar/ -1
|
|
|
|
ancestor /foo /foo::/bar/ -1
|
|
|
|
ancestor /foo /:/foo:/bar/ 0
|
|
|
|
ancestor /foo /foo:/:/bar/ 0
|
|
|
|
ancestor /foo /:/bar/:/foo 0
|
|
|
|
ancestor /foo/bar "" -1
|
|
|
|
ancestor /foo/bar / 0
|
|
|
|
ancestor /foo/bar /fo -1
|
|
|
|
ancestor /foo/bar foo -1
|
|
|
|
ancestor /foo/bar /foo 4
|
|
|
|
ancestor /foo/bar /foo/ 4
|
|
|
|
ancestor /foo/bar /foo/ba -1
|
|
|
|
ancestor /foo/bar /:/fo 0
|
|
|
|
ancestor /foo/bar /foo:/foo/ba 4
|
|
|
|
ancestor /foo/bar /bar -1
|
|
|
|
ancestor /foo/bar /bar/ -1
|
|
|
|
ancestor /foo/bar /fo: -1
|
|
|
|
ancestor /foo/bar :/fo -1
|
|
|
|
ancestor /foo/bar /foo:/bar/ 4
|
|
|
|
ancestor /foo/bar /:/foo:/bar/ 4
|
|
|
|
ancestor /foo/bar /foo:/:/bar/ 4
|
|
|
|
ancestor /foo/bar /:/bar/:/fo 0
|
|
|
|
ancestor /foo/bar /:/bar/ 0
|
|
|
|
ancestor /foo/bar :://foo/. 4
|
|
|
|
ancestor /foo/bar :://foo/.:: 4
|
|
|
|
ancestor /foo/bar //foo/./::/bar 4
|
|
|
|
ancestor /foo/bar ::/bar -1
|
|
|
|
|
2008-05-20 08:48:54 +02:00
|
|
|
test_done
|