libpath-ruby 0.2.2 → 0.2.2.1
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 +71 -71
- data/lib/libpath/constants/windows.rb +72 -72
- data/lib/libpath/constants.rb +18 -19
- data/lib/libpath/diagnostics/parameter_checking.rb +25 -25
- data/lib/libpath/diagnostics.rb +1 -1
- data/lib/libpath/exceptions/libpath_base_exception.rb +13 -13
- data/lib/libpath/exceptions/malformed_name_exception.rb +23 -22
- data/lib/libpath/exceptions.rb +1 -1
- data/lib/libpath/form/unix.rb +104 -103
- data/lib/libpath/form/windows.rb +200 -199
- data/lib/libpath/form.rb +18 -18
- data/lib/libpath/internal_/array.rb +53 -53
- data/lib/libpath/internal_/platform.rb +24 -24
- data/lib/libpath/internal_/string.rb +18 -18
- data/lib/libpath/internal_/unix/form.rb +116 -116
- data/lib/libpath/internal_/windows/drive.rb +59 -59
- data/lib/libpath/internal_/windows/form.rb +189 -189
- data/lib/libpath/libpath.rb +3 -0
- data/lib/libpath/path/unix.rb +114 -112
- data/lib/libpath/path/windows.rb +120 -118
- data/lib/libpath/path.rb +18 -20
- data/lib/libpath/util/unix.rb +258 -258
- data/lib/libpath/util/windows.rb +400 -400
- data/lib/libpath/util.rb +18 -19
- data/lib/libpath/version.rb +23 -24
- 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
@@ -7,16 +7,16 @@ this_dir = File.expand_path(File.dirname(__FILE__))
|
|
7
7
|
# all tc_*rb in current directory
|
8
8
|
Dir[File.join(this_dir, 'tc_*rb')].each do |file|
|
9
9
|
|
10
|
-
|
10
|
+
$stderr.puts "requiring file '#{file}'" if $DEBUG
|
11
11
|
|
12
|
-
|
12
|
+
require file
|
13
13
|
end
|
14
14
|
|
15
15
|
# all ts_*rb in immediate sub-directories
|
16
16
|
Dir[File.join(this_dir, '*', 'ts_*rb')].each do |file|
|
17
17
|
|
18
|
-
|
18
|
+
$stderr.puts "requiring file '#{file}'" if $DEBUG
|
19
19
|
|
20
|
-
|
20
|
+
require file
|
21
21
|
end
|
22
22
|
|
data/test/unit/tc_version.rb
CHANGED
@@ -8,40 +8,43 @@ require 'test/unit'
|
|
8
8
|
|
9
9
|
class Test_version < Test::Unit::TestCase
|
10
10
|
|
11
|
-
|
11
|
+
def test_has_VERSION
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
assert defined? LibPath::VERSION
|
14
|
+
end
|
15
15
|
|
16
|
-
|
16
|
+
def test_has_VERSION_MAJOR
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
assert defined? LibPath::VERSION_MAJOR
|
19
|
+
end
|
20
20
|
|
21
|
-
|
21
|
+
def test_has_VERSION_MINOR
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
assert defined? LibPath::VERSION_MINOR
|
24
|
+
end
|
25
25
|
|
26
|
-
|
26
|
+
def test_has_VERSION_REVISION
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
assert defined? LibPath::VERSION_REVISION
|
29
|
+
end
|
30
30
|
|
31
|
-
|
31
|
+
def test_VERSION_has_consistent_format
|
32
32
|
|
33
|
-
|
33
|
+
if LibPath::VERSION_SUBPATCH
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
assert_equal LibPath::VERSION, "#{LibPath::VERSION_MAJOR}.#{LibPath::VERSION_MINOR}.#{LibPath::VERSION_PATCH}.#{LibPath::VERSION_SUBPATCH}"
|
36
|
+
else
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
assert_equal LibPath::VERSION, "#{LibPath::VERSION_MAJOR}.#{LibPath::VERSION_MINOR}.#{LibPath::VERSION_PATCH}"
|
39
|
+
end
|
40
|
+
end
|
41
41
|
|
42
|
-
|
42
|
+
def test_VERSION_greater_than
|
43
43
|
|
44
|
-
|
45
|
-
|
44
|
+
assert_operator LibPath::VERSION, :>=, '0.1.0'
|
45
|
+
end
|
46
46
|
end
|
47
47
|
|
48
|
+
|
49
|
+
# ############################## end of file ############################# #
|
50
|
+
|
data/test/unit/ts_all.rb
CHANGED
@@ -7,16 +7,16 @@ this_dir = File.expand_path(File.dirname(__FILE__))
|
|
7
7
|
# all tc_*rb in current directory
|
8
8
|
Dir[File.join(this_dir, 'tc_*rb')].each do |file|
|
9
9
|
|
10
|
-
|
10
|
+
$stderr.puts "requiring file '#{file}'" if $DEBUG
|
11
11
|
|
12
|
-
|
12
|
+
require file
|
13
13
|
end
|
14
14
|
|
15
15
|
# all ts_*rb in immediate sub-directories
|
16
16
|
Dir[File.join(this_dir, '*', 'ts_*rb')].each do |file|
|
17
17
|
|
18
|
-
|
18
|
+
$stderr.puts "requiring file '#{file}'" if $DEBUG
|
19
19
|
|
20
|
-
|
20
|
+
require file
|
21
21
|
end
|
22
22
|
|
@@ -2,178 +2,183 @@
|
|
2
2
|
|
3
3
|
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 3), 'lib')
|
4
4
|
|
5
|
+
|
5
6
|
require 'libpath/util'
|
6
7
|
|
7
8
|
require 'test/unit'
|
8
9
|
|
9
10
|
require 'libpath/internal_/platform'
|
10
11
|
|
12
|
+
|
11
13
|
class Test_LibPath_Util_combine_paths < Test::Unit::TestCase
|
12
14
|
|
13
|
-
|
15
|
+
F = ::LibPath::Util
|
14
16
|
|
15
|
-
|
17
|
+
def test_no_arguments
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
+
assert_equal '', F.combine_paths()
|
20
|
+
end
|
19
21
|
|
20
|
-
|
22
|
+
def test_single_argument
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
assert_equal ' ', F.combine_paths(' ')
|
25
|
+
assert_equal 'a', F.combine_paths('a')
|
26
|
+
assert_equal 'abcdef/ghi/jkl.mno', F.combine_paths('abcdef/ghi/jkl.mno')
|
27
|
+
assert_equal '/', F.combine_paths('/')
|
28
|
+
end
|
27
29
|
|
28
|
-
|
30
|
+
def test_relative_cases
|
29
31
|
|
30
|
-
|
32
|
+
if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
|
31
33
|
|
32
|
-
|
34
|
+
assert_equal 'a\\b\\c/d', F.combine_paths('a', 'b', 'c/d')
|
33
35
|
|
34
|
-
|
36
|
+
assert_equal 'a\\b', F.combine_paths('', 'a', '', '', 'b')
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
+
assert_equal 'a\\ \\b', F.combine_paths('', 'a', '', ' ', 'b')
|
39
|
+
else
|
38
40
|
|
39
|
-
|
41
|
+
assert_equal 'a/b/c/d', F.combine_paths('a', 'b', 'c/d')
|
40
42
|
|
41
|
-
|
43
|
+
assert_equal 'a/b', F.combine_paths('', 'a', '', '', 'b')
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
45
|
+
assert_equal 'a/ /b', F.combine_paths('', 'a', '', ' ', 'b')
|
46
|
+
end
|
47
|
+
end
|
46
48
|
|
47
|
-
|
49
|
+
def test_tail_absolute_cases
|
48
50
|
|
49
|
-
|
51
|
+
assert_equal '/', F.combine_paths('a', '/')
|
50
52
|
|
51
|
-
|
53
|
+
assert_equal '/', F.combine_paths('a/b/c/d', '/')
|
52
54
|
|
53
|
-
|
55
|
+
assert_equal '/', F.combine_paths('a', 'b', '/')
|
54
56
|
|
55
|
-
|
57
|
+
if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
59
|
+
assert_equal 'X:/', F.combine_paths('a', 'X:/')
|
60
|
+
assert_equal 'X:\\', F.combine_paths('a', 'X:\\')
|
61
|
+
assert_equal '\\\\?\\X:\\', F.combine_paths('a', '\\\\?\\X:\\')
|
62
|
+
end
|
63
|
+
end
|
62
64
|
|
63
|
-
|
65
|
+
if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
|
64
66
|
|
65
|
-
|
67
|
+
def test_tail_absolute_cases_2
|
66
68
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
69
|
+
assert_equal 'Y:/', F.combine_paths('a', 'X:/', 'Y:/')
|
70
|
+
assert_equal 'Y:\\', F.combine_paths('a', 'X:/', 'Y:\\')
|
71
|
+
assert_equal 'Y:\\', F.combine_paths('a', '\\\\?\\X:/', 'Y:\\')
|
72
|
+
assert_equal '\\\\?\\Y:\\', F.combine_paths('a', 'X:/', '\\\\?\\Y:\\')
|
73
|
+
end
|
72
74
|
|
73
|
-
|
75
|
+
def test_tail_absolute_cases_3
|
74
76
|
|
75
|
-
|
76
|
-
|
77
|
-
|
77
|
+
assert_equal 'X:\\', F.combine_paths('a', 'X:', '\\')
|
78
|
+
assert_equal 'X:\\', F.combine_paths('a', '\\', 'X:')
|
79
|
+
assert_equal 'X:\\', F.combine_paths('X:', 'a', '\\')
|
78
80
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
81
|
+
assert_equal '\\\\?\\X:\\', F.combine_paths('a', '\\\\?\\X:', '\\')
|
82
|
+
assert_equal '\\\\?\\X:\\', F.combine_paths('a', '\\', '\\\\?\\X:')
|
83
|
+
assert_equal '\\\\?\\X:\\', F.combine_paths('\\\\?\\X:', 'a', '\\')
|
84
|
+
end
|
83
85
|
|
84
|
-
|
86
|
+
def test_tail_absolute_cases_4
|
85
87
|
|
86
|
-
|
88
|
+
assert_equal 'Z:\\', F.combine_paths('a', 'X:/', '\\', 'Z:')
|
87
89
|
|
88
|
-
|
90
|
+
assert_equal '\\\\?\\Z:\\', F.combine_paths('a', '\\\\?\\X:/', '\\', '\\\\?\\Z:')
|
89
91
|
|
90
|
-
|
91
|
-
|
92
|
+
assert_equal '\\\\?\\UNC\\server\\share/abc', F.combine_paths('a', '\\\\?\\X:/', '/abc', '\\\\?\\UNC\\server\\share')
|
93
|
+
end
|
92
94
|
|
93
|
-
|
95
|
+
def test_tail_absolute_cases_5
|
94
96
|
|
95
|
-
|
97
|
+
assert_equal 'Z:\\dir\\a\\b', F.combine_paths('a', 'X:/y', '\\dir', 'Z:', 'a', 'b')
|
96
98
|
|
97
|
-
|
99
|
+
assert_equal 'Z:\\dir\\a\\b', F.combine_paths('a', '\\\\?\\X:/y', '\\dir', 'Z:', 'a', 'b')
|
98
100
|
|
99
|
-
|
100
|
-
|
101
|
+
assert_equal '\\\\?\\Z:\\dir\\a\\b', F.combine_paths('a', 'X:/y', '\\dir', '\\\\?\\Z:', 'a', 'b')
|
102
|
+
end
|
101
103
|
|
102
|
-
|
104
|
+
def test_tail_absolute_cases_6
|
103
105
|
|
104
|
-
|
105
|
-
|
106
|
+
assert_equal 'Z:\\b', F.combine_paths('a', 'X:/', 'Z:', 'a', '\\', 'b')
|
107
|
+
end
|
106
108
|
|
107
|
-
|
109
|
+
def test_tail_absolute_cases_7
|
108
110
|
|
109
|
-
|
110
|
-
|
111
|
+
assert_equal 'Z:\\a\\c\\b', F.combine_paths('a', 'X:/', '\\a', 'c', 'Z:', 'b')
|
112
|
+
end
|
111
113
|
|
112
|
-
|
114
|
+
def test_tail_absolute_cases_8
|
113
115
|
|
114
|
-
|
115
|
-
|
116
|
+
assert_equal 'X:/y\\b', F.combine_paths('a', '\\a', 'c', 'Z:', 'X:/y', 'b')
|
117
|
+
end
|
116
118
|
|
117
|
-
|
119
|
+
def test_tail_absolute_cases_9
|
118
120
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
121
|
+
assert_equal 'Z:\\y\\b', F.combine_paths('a', '\\a', 'c', 'X:\\y', 'Z:', 'b')
|
122
|
+
assert_equal 'Z:/y\\b', F.combine_paths('a', '\\a', 'c', 'X:/y', 'Z:', 'b')
|
123
|
+
end
|
124
|
+
end
|
123
125
|
|
124
|
-
|
126
|
+
def test_tail_absolute_cases_10
|
125
127
|
|
126
|
-
|
128
|
+
if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
|
127
129
|
|
128
|
-
|
129
|
-
|
130
|
-
|
130
|
+
assert_equal 'X:\\dir-1\\dir-2\\b', F.combine_paths('a', '\\a', 'c', 'X:/y', '\\dir-1\\dir-2', 'b')
|
131
|
+
assert_equal 'X:\\dir-1/dir-2\\b', F.combine_paths('a', '\\a', 'c', 'X:/y', '\\dir-1/dir-2', 'b')
|
132
|
+
end
|
131
133
|
|
132
|
-
|
134
|
+
assert_equal '/', F.combine_paths('a', '/')
|
133
135
|
|
134
|
-
|
136
|
+
assert_equal '/', F.combine_paths('a/b/c/d', '/')
|
135
137
|
|
136
|
-
|
137
|
-
|
138
|
+
assert_equal '/', F.combine_paths('a', 'b', '/')
|
139
|
+
end
|
138
140
|
|
139
|
-
|
141
|
+
if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
|
140
142
|
|
141
|
-
|
143
|
+
def test_drive_only
|
142
144
|
|
143
|
-
|
144
|
-
|
145
|
+
assert_equal 'D:', F.combine_paths('D:')
|
146
|
+
assert_equal 'D:dir-1\\dir-2', F.combine_paths('D:', 'dir-1\\dir-2')
|
145
147
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
148
|
+
assert_equal '\\\\?\\D:', F.combine_paths('\\\\?\\D:')
|
149
|
+
assert_equal '\\\\?\\D:dir-1\\dir-2', F.combine_paths('\\\\?\\D:', 'dir-1\\dir-2')
|
150
|
+
end
|
151
|
+
end
|
150
152
|
|
151
|
-
|
153
|
+
def test_embedded_absolute_cases
|
152
154
|
|
153
|
-
|
155
|
+
if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
|
154
156
|
|
155
|
-
|
156
|
-
|
157
|
-
|
157
|
+
assert_equal '/a\\b\\c/d', F.combine_paths('x/y/z', 'z', '/a', 'b', 'c/d')
|
158
|
+
assert_equal '\\a\\b\\c/d', F.combine_paths('x/y/z', 'z', '\\a', 'b', 'c/d')
|
159
|
+
else
|
158
160
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
161
|
+
assert_equal '/a/b/c/d', F.combine_paths('x/y/z', 'z', '/a', 'b', 'c/d')
|
162
|
+
assert_equal '/a/b/c/d', F.combine_paths('x/y/z', 'z', '/a', 'b', 'c/d')
|
163
|
+
end
|
164
|
+
end
|
163
165
|
|
164
|
-
|
166
|
+
def test_multiple_embedded_absolute_cases
|
165
167
|
|
166
|
-
|
168
|
+
if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
|
167
169
|
|
168
|
-
|
170
|
+
assert_equal '/a\\b\\c/d', F.combine_paths('x/y/z', '/z', '/a', 'b', 'c/d')
|
169
171
|
|
170
|
-
|
171
|
-
|
172
|
+
assert_equal '/a\\b\\c/d', F.combine_paths('x/y/z', '/z', '/a', 'b', 'c/d')
|
173
|
+
else
|
172
174
|
|
173
|
-
|
175
|
+
assert_equal '/a/b/c/d', F.combine_paths('x/y/z', '/z', '/a', 'b', 'c/d')
|
174
176
|
|
175
|
-
|
176
|
-
|
177
|
-
|
177
|
+
assert_equal '/a/b/c/d', F.combine_paths('x/y/z', '/z', '/a', 'b', 'c/d')
|
178
|
+
end
|
179
|
+
end
|
178
180
|
end
|
179
181
|
|
182
|
+
|
183
|
+
# ############################## end of file ############################# #
|
184
|
+
|
@@ -2,18 +2,23 @@
|
|
2
2
|
|
3
3
|
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 3), 'lib')
|
4
4
|
|
5
|
+
|
5
6
|
require 'libpath/util'
|
6
7
|
|
7
8
|
require 'test/unit'
|
8
9
|
|
9
10
|
require 'libpath/internal_/platform'
|
10
11
|
|
12
|
+
|
11
13
|
class Test_LibPath_Util_derive_relative_path < Test::Unit::TestCase
|
12
14
|
|
13
|
-
|
15
|
+
F = ::LibPath::Util
|
14
16
|
|
15
|
-
|
17
|
+
def test_nils
|
16
18
|
|
17
|
-
|
19
|
+
end
|
18
20
|
end
|
19
21
|
|
22
|
+
|
23
|
+
# ############################## end of file ############################# #
|
24
|
+
|