move locate_head() to remote.c
[git/mjg.git] / t / t0060-path-utils.sh
blob8336114f9820aa5972d38efe316de7d9e39bcc5c
1 #!/bin/sh
3 # Copyright (c) 2008 David Reiss
6 test_description='Test various path utilities'
8 . ./test-lib.sh
10 norm_abs() {
11 test_expect_success "normalize absolute: $1 => $2" \
12 "test \"\$(test-path-utils normalize_path_copy '$1')\" = '$2'"
15 ancestor() {
16 test_expect_success "longest ancestor: $1 $2 => $3" \
17 "test \"\$(test-path-utils longest_ancestor_length '$1' '$2')\" = '$3'"
20 norm_abs "" ""
21 norm_abs / /
22 norm_abs // /
23 norm_abs /// /
24 norm_abs /. /
25 norm_abs /./ /
26 norm_abs /./.. ++failed++
27 norm_abs /../. ++failed++
28 norm_abs /./../.// ++failed++
29 norm_abs /dir/.. /
30 norm_abs /dir/sub/../.. /
31 norm_abs /dir/sub/../../.. ++failed++
32 norm_abs /dir /dir
33 norm_abs /dir// /dir/
34 norm_abs /./dir /dir
35 norm_abs /dir/. /dir/
36 norm_abs /dir///./ /dir/
37 norm_abs /dir//sub/.. /dir/
38 norm_abs /dir/sub/../ /dir/
39 norm_abs //dir/sub/../. /dir/
40 norm_abs /dir/s1/../s2/ /dir/s2/
41 norm_abs /d1/s1///s2/..//../s3/ /d1/s3/
42 norm_abs /d1/s1//../s2/../../d2 /d2
43 norm_abs /d1/.../d2 /d1/.../d2
44 norm_abs /d1/..././../d2 /d1/d2
46 ancestor / "" -1
47 ancestor / / -1
48 ancestor /foo "" -1
49 ancestor /foo : -1
50 ancestor /foo ::. -1
51 ancestor /foo ::..:: -1
52 ancestor /foo / 0
53 ancestor /foo /fo -1
54 ancestor /foo /foo -1
55 ancestor /foo /foo/ -1
56 ancestor /foo /bar -1
57 ancestor /foo /bar/ -1
58 ancestor /foo /foo/bar -1
59 ancestor /foo /foo:/bar/ -1
60 ancestor /foo /foo/:/bar/ -1
61 ancestor /foo /foo::/bar/ -1
62 ancestor /foo /:/foo:/bar/ 0
63 ancestor /foo /foo:/:/bar/ 0
64 ancestor /foo /:/bar/:/foo 0
65 ancestor /foo/bar "" -1
66 ancestor /foo/bar / 0
67 ancestor /foo/bar /fo -1
68 ancestor /foo/bar foo -1
69 ancestor /foo/bar /foo 4
70 ancestor /foo/bar /foo/ 4
71 ancestor /foo/bar /foo/ba -1
72 ancestor /foo/bar /:/fo 0
73 ancestor /foo/bar /foo:/foo/ba 4
74 ancestor /foo/bar /bar -1
75 ancestor /foo/bar /bar/ -1
76 ancestor /foo/bar /fo: -1
77 ancestor /foo/bar :/fo -1
78 ancestor /foo/bar /foo:/bar/ 4
79 ancestor /foo/bar /:/foo:/bar/ 4
80 ancestor /foo/bar /foo:/:/bar/ 4
81 ancestor /foo/bar /:/bar/:/fo 0
82 ancestor /foo/bar /:/bar/ 0
83 ancestor /foo/bar :://foo/. 4
84 ancestor /foo/bar :://foo/.:: 4
85 ancestor /foo/bar //foo/./::/bar 4
86 ancestor /foo/bar ::/bar -1
88 test_expect_success 'strip_path_suffix' '
89 test c:/msysgit = $(test-path-utils strip_path_suffix \
90 c:/msysgit/libexec//git-core libexec/git-core)
92 test_done