libpath-ruby 0.2.2 → 0.2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +33 -0
- data/README.md +25 -8
- data/examples/path_from_arg0.md +43 -43
- data/examples/path_from_arg0.rb +25 -23
- data/lib/libpath/constants/unix.rb +74 -74
- data/lib/libpath/constants/windows.rb +75 -75
- data/lib/libpath/constants.rb +20 -20
- data/lib/libpath/diagnostics/parameter_checking.rb +27 -26
- data/lib/libpath/diagnostics.rb +1 -1
- data/lib/libpath/exceptions/libpath_base_exception.rb +20 -21
- data/lib/libpath/exceptions/malformed_name_exception.rb +27 -27
- data/lib/libpath/exceptions.rb +1 -1
- data/lib/libpath/form/unix.rb +118 -118
- data/lib/libpath/form/windows.rb +228 -214
- data/lib/libpath/form.rb +20 -21
- data/lib/libpath/internal_/array.rb +57 -57
- data/lib/libpath/internal_/platform.rb +30 -31
- data/lib/libpath/internal_/string.rb +25 -20
- data/lib/libpath/internal_/unix/form.rb +124 -119
- data/lib/libpath/internal_/windows/drive.rb +80 -75
- data/lib/libpath/internal_/windows/form.rb +205 -194
- data/lib/libpath/libpath.rb +4 -1
- data/lib/libpath/path/unix.rb +120 -118
- data/lib/libpath/path/windows.rb +126 -124
- data/lib/libpath/path.rb +21 -21
- data/lib/libpath/util/unix.rb +261 -261
- data/lib/libpath/util/windows.rb +403 -403
- data/lib/libpath/util.rb +20 -20
- data/lib/libpath/version.rb +25 -26
- data/lib/libpath.rb +1 -1
- data/test/performance/benchmark_drive_letter.rb +50 -10
- data/test/performance/benchmark_gsub_string_or_regex.rb +27 -23
- data/test/performance/benchmark_rindex2.rb +56 -48
- data/test/performance/benchmark_split.rb +16 -10
- data/test/unit/compare/ts_all.rb +4 -4
- data/test/unit/equate/ts_all.rb +4 -4
- data/test/unit/equate/unix/ts_all.rb +4 -4
- data/test/unit/equate/windows/ts_all.rb +4 -4
- data/test/unit/exceptions/tc_libpath_base_exception.rb +10 -8
- data/test/unit/exceptions/tc_malformed_name_exception.rb +14 -12
- data/test/unit/exceptions/ts_all.rb +4 -4
- data/test/unit/form/tc_absolute_functions.rb +242 -240
- data/test/unit/form/ts_all.rb +4 -4
- data/test/unit/form/unix/tc_absolute_functions.rb +158 -155
- data/test/unit/form/unix/ts_all.rb +4 -4
- data/test/unit/form/windows/tc_absolute_functions.rb +628 -625
- data/test/unit/form/windows/ts_all.rb +4 -4
- data/test/unit/internal_/tc_array.rb +36 -32
- data/test/unit/internal_/ts_all.rb +4 -4
- data/test/unit/internal_/unix/form/tc_slash_functions.rb +38 -35
- data/test/unit/internal_/unix/form/ts_all.rb +4 -4
- data/test/unit/internal_/unix/tc_split_path.rb +387 -384
- data/test/unit/internal_/unix/ts_all.rb +4 -4
- data/test/unit/internal_/windows/form/tc_get_windows_volume.rb +157 -153
- data/test/unit/internal_/windows/form/tc_slash_functions.rb +39 -35
- data/test/unit/internal_/windows/form/ts_all.rb +4 -4
- data/test/unit/internal_/windows/tc_split_path.rb +874 -869
- data/test/unit/internal_/windows/ts_all.rb +4 -4
- data/test/unit/parse/ts_all.rb +4 -4
- data/test/unit/path/tc_path.rb +732 -732
- data/test/unit/path/ts_all.rb +4 -4
- data/test/unit/path/unix/tc_path.rb +544 -540
- data/test/unit/path/unix/ts_all.rb +4 -4
- data/test/unit/path/windows/tc_path.rb +608 -603
- data/test/unit/path/windows/ts_all.rb +4 -4
- data/test/unit/tc_version.rb +25 -22
- data/test/unit/ts_all.rb +4 -4
- data/test/unit/util/tc_combine_paths.rb +110 -105
- data/test/unit/util/tc_derive_relative_path.rb +8 -3
- data/test/unit/util/tc_make_path_canonical.rb +142 -138
- data/test/unit/util/ts_all.rb +4 -4
- data/test/unit/util/unix/tc_combine_paths.rb +38 -34
- data/test/unit/util/unix/tc_derive_relative_path.rb +80 -75
- data/test/unit/util/unix/tc_make_path_absolute.rb +74 -70
- data/test/unit/util/unix/tc_make_path_canonical.rb +95 -90
- data/test/unit/util/unix/ts_all.rb +4 -4
- data/test/unit/util/windows/tc_combine_paths.rb +82 -77
- data/test/unit/util/windows/tc_derive_relative_path.rb +98 -93
- data/test/unit/util/windows/tc_make_path_absolute.rb +105 -101
- data/test/unit/util/windows/tc_make_path_canonical.rb +158 -153
- data/test/unit/util/windows/ts_all.rb +4 -4
- metadata +9 -8
@@ -2,122 +2,127 @@
|
|
2
2
|
|
3
3
|
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 4), 'lib')
|
4
4
|
|
5
|
+
|
5
6
|
require 'libpath/util/unix'
|
6
7
|
|
7
8
|
require 'test/unit'
|
8
9
|
|
10
|
+
|
9
11
|
class Test_LibPath_Util_Unix_derive_relative_path < Test::Unit::TestCase
|
10
12
|
|
11
|
-
|
13
|
+
M = ::LibPath::Util::Unix
|
12
14
|
|
13
|
-
|
15
|
+
def test_nils_and_empties
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
# to get nowhere from nowhere, go nowhere
|
18
|
+
assert_nil M.derive_relative_path(nil, nil)
|
19
|
+
assert_nil M.derive_relative_path('', nil)
|
20
|
+
assert_equal '', M.derive_relative_path('', '')
|
21
|
+
assert_equal '', M.derive_relative_path(nil, '')
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
# to get somewhere from nowhere, just go there
|
24
|
+
assert_equal 'abc', M.derive_relative_path(nil, 'abc')
|
25
|
+
assert_equal 'abc', M.derive_relative_path('', 'abc')
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
# to get nowhere from anywhere else, go nowhere
|
28
|
+
assert_nil M.derive_relative_path('dir', nil)
|
29
|
+
assert_equal '', M.derive_relative_path('dir', '')
|
30
|
+
end
|
29
31
|
|
30
|
-
|
32
|
+
def test_same_location
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
+
assert_equal '.', M.derive_relative_path('.', '.')
|
35
|
+
assert_equal '.', M.derive_relative_path('..', '..')
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
assert_equal '.', M.derive_relative_path('abc', 'abc')
|
38
|
+
assert_equal './', M.derive_relative_path('abc/', 'abc/')
|
39
|
+
assert_equal './', M.derive_relative_path('abc', 'abc/')
|
38
40
|
|
39
|
-
|
41
|
+
assert_equal './', M.derive_relative_path('/', '/')
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
assert_equal '.', M.derive_relative_path('./abc', 'abc')
|
44
|
+
assert_equal '.', M.derive_relative_path('./abc/', 'abc')
|
45
|
+
assert_equal './', M.derive_relative_path('./abc', 'abc/')
|
46
|
+
assert_equal './', M.derive_relative_path('./abc/', 'abc/')
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
assert_equal '.', M.derive_relative_path('/abc', '/abc')
|
49
|
+
assert_equal '.', M.derive_relative_path('/abc/', '/abc')
|
50
|
+
assert_equal './', M.derive_relative_path('/abc/', '/abc/')
|
51
|
+
assert_equal '../', M.derive_relative_path('/abc/', '/')
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
53
|
+
assert_equal '../../', M.derive_relative_path('/abc/def/', '/')
|
54
|
+
assert_equal '../../', M.derive_relative_path('/abc/def/', '/')
|
55
|
+
end
|
54
56
|
|
55
|
-
|
57
|
+
def test_from_here
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
assert_equal 'abc', M.derive_relative_path('.', 'abc')
|
60
|
+
assert_equal 'abc', M.derive_relative_path('./', 'abc')
|
61
|
+
assert_equal 'abc/', M.derive_relative_path('.', 'abc/')
|
62
|
+
assert_equal 'abc/', M.derive_relative_path('./', 'abc/')
|
61
63
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
64
|
+
assert_equal('abc/', M.derive_relative_path('/dir1/dir2', '/dir1/dir2/abc/'))
|
65
|
+
assert_equal('.', M.derive_relative_path('/dir1/dir2/abc', '/dir1/dir2/abc'))
|
66
|
+
assert_equal('./', M.derive_relative_path('/dir1/dir2/abc', '/dir1/dir2/abc/'))
|
67
|
+
end
|
66
68
|
|
67
|
-
|
69
|
+
def test_ones_above
|
68
70
|
|
69
|
-
|
71
|
+
assert_equal '../', M.derive_relative_path('.', '..')
|
70
72
|
|
71
|
-
|
73
|
+
assert_equal '../', M.derive_relative_path('abc/def', 'abc')
|
72
74
|
|
73
|
-
|
74
|
-
|
75
|
+
assert_equal '../', M.derive_relative_path('abc/def/ghi', 'abc/def')
|
76
|
+
assert_equal '../', M.derive_relative_path('abc/def/ghi', 'abc/def/')
|
75
77
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
78
|
+
assert_equal '../', M.derive_relative_path('abc/def/./ghi', 'abc/def')
|
79
|
+
assert_equal '../', M.derive_relative_path('abc/def/ghi/jkl/..', 'abc/def')
|
80
|
+
assert_equal '../', M.derive_relative_path('abc/def/ghi/jkl/../', 'abc/def')
|
81
|
+
assert_equal '../', M.derive_relative_path('abc/def/ghi/jkl/..', 'abc/def/')
|
80
82
|
|
81
|
-
|
83
|
+
assert_equal '../../', M.derive_relative_path('abc/def/ghi/jkl/', 'abc/def')
|
82
84
|
|
83
|
-
|
84
|
-
|
85
|
+
assert_equal '../../', M.derive_relative_path('/dir1/dir2/dir3/dir4', '/dir1/dir2')
|
86
|
+
end
|
85
87
|
|
86
|
-
|
88
|
+
def test_ones_below
|
87
89
|
|
88
|
-
|
90
|
+
assert_equal 'dir-1/', M.derive_relative_path('..', '.', pwd: '/dir-1/')
|
89
91
|
|
90
|
-
|
92
|
+
assert_equal '../', M.derive_relative_path('.', '..', pwd: '/dir-1/')
|
91
93
|
|
92
|
-
|
94
|
+
assert_equal 'def', M.derive_relative_path('abc', 'abc/def')
|
93
95
|
|
94
|
-
|
95
|
-
|
96
|
+
assert_equal 'def/ghi', M.derive_relative_path('abc', 'abc/def/ghi')
|
97
|
+
end
|
96
98
|
|
97
|
-
|
99
|
+
def test_ones_across
|
98
100
|
|
99
|
-
|
100
|
-
|
101
|
+
assert_equal '../e-1', M.derive_relative_path('abc/d-1', 'abc/e-1')
|
102
|
+
assert_equal '../e-1', M.derive_relative_path('abc/d-1/', 'abc/e-1')
|
101
103
|
|
102
|
-
|
103
|
-
|
104
|
-
|
104
|
+
assert_equal '../e-1/e-2', M.derive_relative_path('abc/d-1/', 'abc/e-1/e-2')
|
105
|
+
assert_equal '../../e-1/e-2', M.derive_relative_path('abc/d-1/d-2/', 'abc/e-1/e-2')
|
106
|
+
end
|
105
107
|
|
106
|
-
|
108
|
+
def test_simple_cases
|
107
109
|
|
108
|
-
|
109
|
-
|
110
|
+
assert_equal 'def', M.derive_relative_path('/abc', '/abc/def')
|
111
|
+
end
|
110
112
|
|
111
|
-
|
113
|
+
def test_absolute_path_cases
|
112
114
|
|
113
|
-
|
115
|
+
assert_equal '../../def', M.derive_relative_path('ghi', '/def', pwd: '/abc')
|
114
116
|
|
115
|
-
|
116
|
-
|
117
|
+
assert_equal '../def', M.derive_relative_path('abc', '/def', pwd: '/')
|
118
|
+
end
|
117
119
|
|
118
|
-
|
120
|
+
def test_both_relative
|
119
121
|
|
120
|
-
|
121
|
-
|
122
|
+
assert_equal '../def', M.derive_relative_path('abc', 'def', pwd: '/')
|
123
|
+
end
|
122
124
|
end
|
123
125
|
|
126
|
+
|
127
|
+
# ############################## end of file ############################# #
|
128
|
+
|
@@ -2,116 +2,120 @@
|
|
2
2
|
|
3
3
|
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 4), 'lib')
|
4
4
|
|
5
|
+
|
5
6
|
require 'libpath/util/unix'
|
6
7
|
|
7
8
|
require 'test/unit'
|
8
9
|
|
9
|
-
class Test_LibPath_Util_Unix_make_path_absolute < Test::Unit::TestCase
|
10
10
|
|
11
|
-
|
11
|
+
class Test_LibPath_Util_Unix_make_path_absolute < Test::Unit::TestCase
|
12
12
|
|
13
|
-
|
13
|
+
F = ::LibPath::Util::Unix
|
14
14
|
|
15
|
-
|
15
|
+
def test_nil
|
16
16
|
|
17
|
-
|
18
|
-
else
|
17
|
+
if $DEBUG
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
end
|
19
|
+
assert_raise(::ArgumentError) { F.make_path_absolute(nil) }
|
20
|
+
else
|
23
21
|
|
24
|
-
|
22
|
+
assert_nil F.make_path_absolute(nil)
|
23
|
+
end
|
24
|
+
end
|
25
25
|
|
26
|
-
|
27
|
-
end
|
26
|
+
def test_empty
|
28
27
|
|
29
|
-
|
28
|
+
assert_equal '', F.make_path_absolute('')
|
29
|
+
end
|
30
30
|
|
31
|
-
|
32
|
-
assert_equal '/.', F.make_path_absolute('/.')
|
33
|
-
assert_equal '/a', F.make_path_absolute('/a')
|
34
|
-
assert_equal '/a/.', F.make_path_absolute('/a/.')
|
35
|
-
end
|
31
|
+
def test_absolute_paths
|
36
32
|
|
37
|
-
|
33
|
+
assert_equal '/', F.make_path_absolute('/')
|
34
|
+
assert_equal '/.', F.make_path_absolute('/.')
|
35
|
+
assert_equal '/a', F.make_path_absolute('/a')
|
36
|
+
assert_equal '/a/.', F.make_path_absolute('/a/.')
|
37
|
+
end
|
38
38
|
|
39
|
-
|
39
|
+
def test_absolute_paths_with_canonicalisation
|
40
40
|
|
41
|
-
|
42
|
-
assert_equal '/', F.make_path_absolute('/.', **options)
|
43
|
-
assert_equal '/a', F.make_path_absolute('/a', **options)
|
44
|
-
assert_equal '/a/', F.make_path_absolute('/a/.', **options)
|
45
|
-
end
|
41
|
+
options = { make_canonical: true }
|
46
42
|
|
47
|
-
|
43
|
+
assert_equal '/', F.make_path_absolute('/', **options)
|
44
|
+
assert_equal '/', F.make_path_absolute('/.', **options)
|
45
|
+
assert_equal '/a', F.make_path_absolute('/a', **options)
|
46
|
+
assert_equal '/a/', F.make_path_absolute('/a/.', **options)
|
47
|
+
end
|
48
48
|
|
49
|
-
|
49
|
+
def test_relative_path_with_fixed_pwd
|
50
50
|
|
51
|
-
|
52
|
-
assert_equal '/some-path/or-other/', F.make_path_absolute('.', pwd: pwd, make_canonical: true)
|
51
|
+
pwd = '/some-path/or-other'
|
53
52
|
|
54
|
-
|
55
|
-
|
53
|
+
assert_equal '/some-path/or-other/.', F.make_path_absolute('.', pwd: pwd)
|
54
|
+
assert_equal '/some-path/or-other/', F.make_path_absolute('.', pwd: pwd, make_canonical: true)
|
56
55
|
|
57
|
-
|
58
|
-
|
56
|
+
assert_equal '/some-path/or-other/abc', F.make_path_absolute('abc', pwd: pwd)
|
57
|
+
assert_equal '/some-path/or-other/abc', F.make_path_absolute('abc', pwd: pwd, make_canonical: true)
|
59
58
|
|
60
|
-
|
61
|
-
|
59
|
+
assert_equal '/some-path/or-other/./abc', F.make_path_absolute('./abc', pwd: pwd)
|
60
|
+
assert_equal '/some-path/or-other/abc', F.make_path_absolute('./abc', pwd: pwd, make_canonical: true)
|
62
61
|
|
63
|
-
|
64
|
-
|
62
|
+
assert_equal '/some-path/or-other/./abc/', F.make_path_absolute('./abc/', pwd: pwd)
|
63
|
+
assert_equal '/some-path/or-other/abc/', F.make_path_absolute('./abc/', pwd: pwd, make_canonical: true)
|
65
64
|
|
66
|
-
|
67
|
-
|
68
|
-
end
|
65
|
+
assert_equal '/some-path/or-other/def/../abc', F.make_path_absolute('def/../abc', pwd: pwd)
|
66
|
+
assert_equal '/some-path/or-other/abc', F.make_path_absolute('def/../abc', pwd: pwd, make_canonical: true)
|
69
67
|
|
70
|
-
|
68
|
+
assert_equal '/some-path/or-other/def/../abc/', F.make_path_absolute('def/../abc/', pwd: pwd)
|
69
|
+
assert_equal '/some-path/or-other/abc/', F.make_path_absolute('def/../abc/', pwd: pwd, make_canonical: true)
|
70
|
+
end
|
71
71
|
|
72
|
-
|
72
|
+
def test_relative_path_with_fixed_home
|
73
73
|
|
74
|
-
|
75
|
-
assert_equal '/Users/libpath-tester/', F.make_path_absolute('~/.', home: home, make_canonical: true)
|
74
|
+
home = '/Users/libpath-tester'
|
76
75
|
|
77
|
-
|
78
|
-
|
76
|
+
assert_equal '/Users/libpath-tester/.', F.make_path_absolute('~/.', home: home)
|
77
|
+
assert_equal '/Users/libpath-tester/', F.make_path_absolute('~/.', home: home, make_canonical: true)
|
79
78
|
|
80
|
-
|
81
|
-
|
79
|
+
assert_equal '/Users/libpath-tester/abc', F.make_path_absolute('~/abc', home: home)
|
80
|
+
assert_equal '/Users/libpath-tester/abc', F.make_path_absolute('~/abc', home: home, make_canonical: true)
|
82
81
|
|
83
|
-
|
84
|
-
|
82
|
+
assert_equal '/Users/libpath-tester/./abc', F.make_path_absolute('~/./abc', home: home)
|
83
|
+
assert_equal '/Users/libpath-tester/abc', F.make_path_absolute('~/./abc', home: home, make_canonical: true)
|
85
84
|
|
86
|
-
|
87
|
-
|
85
|
+
assert_equal '/Users/libpath-tester/./abc/', F.make_path_absolute('~/./abc/', home: home)
|
86
|
+
assert_equal '/Users/libpath-tester/abc/', F.make_path_absolute('~/./abc/', home: home, make_canonical: true)
|
88
87
|
|
89
|
-
|
90
|
-
|
91
|
-
end
|
88
|
+
assert_equal '/Users/libpath-tester/def/../abc', F.make_path_absolute('~/def/../abc', home: home)
|
89
|
+
assert_equal '/Users/libpath-tester/abc', F.make_path_absolute('~/def/../abc', home: home, make_canonical: true)
|
92
90
|
|
93
|
-
|
91
|
+
assert_equal '/Users/libpath-tester/def/../abc/', F.make_path_absolute('~/def/../abc/', home: home)
|
92
|
+
assert_equal '/Users/libpath-tester/abc/', F.make_path_absolute('~/def/../abc/', home: home, make_canonical: true)
|
93
|
+
end
|
94
94
|
|
95
|
-
|
95
|
+
def test_nonhome_tilde_with_fixed_pwd
|
96
96
|
|
97
|
-
|
98
|
-
assert_equal '/some-path/or-other/~.', F.make_path_absolute('~.', pwd: pwd, make_canonical: true)
|
97
|
+
pwd = '/some-path/or-other'
|
99
98
|
|
100
|
-
|
101
|
-
|
99
|
+
assert_equal '/some-path/or-other/~.', F.make_path_absolute('~.', pwd: pwd)
|
100
|
+
assert_equal '/some-path/or-other/~.', F.make_path_absolute('~.', pwd: pwd, make_canonical: true)
|
102
101
|
|
103
|
-
|
104
|
-
|
102
|
+
assert_equal '/some-path/or-other/~abc', F.make_path_absolute('~abc', pwd: pwd)
|
103
|
+
assert_equal '/some-path/or-other/~abc', F.make_path_absolute('~abc', pwd: pwd, make_canonical: true)
|
105
104
|
|
106
|
-
|
107
|
-
|
105
|
+
assert_equal '/some-path/or-other/~./abc', F.make_path_absolute('~./abc', pwd: pwd)
|
106
|
+
assert_equal '/some-path/or-other/~./abc', F.make_path_absolute('~./abc', pwd: pwd, make_canonical: true)
|
108
107
|
|
109
|
-
|
110
|
-
|
108
|
+
assert_equal '/some-path/or-other/~./abc/', F.make_path_absolute('~./abc/', pwd: pwd)
|
109
|
+
assert_equal '/some-path/or-other/~./abc/', F.make_path_absolute('~./abc/', pwd: pwd, make_canonical: true)
|
111
110
|
|
112
|
-
|
113
|
-
|
114
|
-
end
|
111
|
+
assert_equal '/some-path/or-other/~def/../abc', F.make_path_absolute('~def/../abc', pwd: pwd)
|
112
|
+
assert_equal '/some-path/or-other/abc', F.make_path_absolute('~def/../abc', pwd: pwd, make_canonical: true)
|
115
113
|
|
114
|
+
assert_equal '/some-path/or-other/~def/../abc/', F.make_path_absolute('~def/../abc/', pwd: pwd)
|
115
|
+
assert_equal '/some-path/or-other/abc/', F.make_path_absolute('~def/../abc/', pwd: pwd, make_canonical: true)
|
116
|
+
end
|
116
117
|
end
|
117
118
|
|
119
|
+
|
120
|
+
# ############################## end of file ############################# #
|
121
|
+
|