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
|
|
@@ -2,219 +2,223 @@
|
|
2
2
|
|
3
3
|
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 5), 'lib')
|
4
4
|
|
5
|
+
|
5
6
|
require 'libpath/internal_/windows/form'
|
6
7
|
|
7
8
|
require 'test/unit'
|
8
9
|
|
10
|
+
|
9
11
|
class Test_Internal_Windows_Form_get_windows_volume < Test::Unit::TestCase
|
10
12
|
|
11
|
-
|
13
|
+
F = ::LibPath::Internal_::Windows::Form
|
12
14
|
|
13
|
-
|
15
|
+
def test_empty_string
|
14
16
|
|
15
|
-
|
17
|
+
r = F.get_windows_volume('')
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
assert_kind_of ::Array, r
|
20
|
+
assert_equal 3, r.size
|
21
|
+
assert_nil r[0]
|
22
|
+
assert_equal '', r[1]
|
23
|
+
assert_equal :form_0, r[2]
|
24
|
+
end
|
23
25
|
|
24
|
-
|
26
|
+
def test_no_seps
|
25
27
|
|
26
|
-
|
28
|
+
r = F.get_windows_volume('abc')
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
assert_kind_of ::Array, r
|
31
|
+
assert_equal 3, r.size
|
32
|
+
assert_nil r[0]
|
33
|
+
assert_equal 'abc', r[1]
|
34
|
+
assert_equal :form_0, r[2]
|
35
|
+
end
|
34
36
|
|
35
|
-
|
37
|
+
def test_homed
|
36
38
|
|
37
|
-
|
39
|
+
r = F.get_windows_volume('~')
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
assert_kind_of ::Array, r
|
42
|
+
assert_equal 3, r.size
|
43
|
+
assert_nil r[0]
|
44
|
+
assert_equal '~', r[1]
|
45
|
+
assert_equal :form_0, r[2]
|
46
|
+
end
|
45
47
|
|
46
|
-
|
48
|
+
def test_rooted
|
47
49
|
|
48
|
-
|
50
|
+
r = F.get_windows_volume('\\abc')
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
assert_kind_of ::Array, r
|
53
|
+
assert_equal 3, r.size
|
54
|
+
assert_nil r[0]
|
55
|
+
assert_equal '\\abc', r[1]
|
56
|
+
assert_equal :form_0, r[2]
|
57
|
+
end
|
56
58
|
|
57
|
-
|
59
|
+
def test_drive_standard
|
58
60
|
|
59
|
-
|
61
|
+
r = F.get_windows_volume('h:')
|
60
62
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
assert_kind_of ::Array, r
|
64
|
+
assert_equal 3, r.size
|
65
|
+
assert_equal 'h:', r[0]
|
66
|
+
assert_equal '', r[1]
|
67
|
+
assert_equal :form_1, r[2]
|
66
68
|
|
67
|
-
|
69
|
+
r = F.get_windows_volume('X:\\')
|
68
70
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
assert_kind_of ::Array, r
|
72
|
+
assert_equal 3, r.size
|
73
|
+
assert_equal 'X:', r[0]
|
74
|
+
assert_equal '\\', r[1]
|
75
|
+
assert_equal :form_1, r[2]
|
74
76
|
|
75
|
-
|
77
|
+
r = F.get_windows_volume('X:\\abc')
|
76
78
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
79
|
+
assert_kind_of ::Array, r
|
80
|
+
assert_equal 3, r.size
|
81
|
+
assert_equal 'X:', r[0]
|
82
|
+
assert_equal '\\abc', r[1]
|
83
|
+
assert_equal :form_1, r[2]
|
82
84
|
|
83
|
-
|
85
|
+
r = F.get_windows_volume('X:/abc')
|
84
86
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
87
|
+
assert_kind_of ::Array, r
|
88
|
+
assert_equal 3, r.size
|
89
|
+
assert_equal 'X:', r[0]
|
90
|
+
assert_equal '/abc', r[1]
|
91
|
+
assert_equal :form_1, r[2]
|
92
|
+
end
|
91
93
|
|
92
|
-
|
94
|
+
def test_device
|
93
95
|
|
94
|
-
|
96
|
+
r = F.get_windows_volume('\\\\.\\the-device-name\\file')
|
95
97
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
98
|
+
assert_kind_of ::Array, r
|
99
|
+
assert_equal 3, r.size
|
100
|
+
assert_equal '\\\\.\\the-device-name', r[0]
|
101
|
+
assert_equal '\\file', r[1]
|
102
|
+
assert_equal :form_6, r[2]
|
101
103
|
|
102
|
-
|
104
|
+
r = F.get_windows_volume('\\\\.\\the-device-name')
|
103
105
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
106
|
+
assert_kind_of ::Array, r
|
107
|
+
assert_equal 3, r.size
|
108
|
+
assert_equal '\\\\.\\the-device-name', r[0]
|
109
|
+
assert_equal '', r[1]
|
110
|
+
assert_equal :form_6, r[2]
|
111
|
+
end
|
110
112
|
|
111
|
-
|
113
|
+
def test_drive_long
|
112
114
|
|
113
|
-
|
115
|
+
r = F.get_windows_volume('\\\\?\\h:')
|
114
116
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
117
|
+
assert_kind_of ::Array, r
|
118
|
+
assert_equal 3, r.size
|
119
|
+
assert_equal '\\\\?\\h:', r[0]
|
120
|
+
assert_equal '', r[1]
|
121
|
+
assert_equal :form_3, r[2]
|
120
122
|
|
121
|
-
|
123
|
+
r = F.get_windows_volume('\\\\?\\X:\\')
|
122
124
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
125
|
+
assert_kind_of ::Array, r
|
126
|
+
assert_equal 3, r.size
|
127
|
+
assert_equal '\\\\?\\X:', r[0]
|
128
|
+
assert_equal '\\', r[1]
|
129
|
+
assert_equal :form_3, r[2]
|
128
130
|
|
129
|
-
|
131
|
+
r = F.get_windows_volume('\\\\?\\X:\\abc')
|
130
132
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
133
|
+
assert_kind_of ::Array, r
|
134
|
+
assert_equal 3, r.size
|
135
|
+
assert_equal '\\\\?\\X:', r[0]
|
136
|
+
assert_equal '\\abc', r[1]
|
137
|
+
assert_equal :form_3, r[2]
|
136
138
|
|
137
|
-
|
139
|
+
r = F.get_windows_volume('\\\\?\\X:/abc')
|
138
140
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
141
|
+
assert_kind_of ::Array, r
|
142
|
+
assert_equal 3, r.size
|
143
|
+
assert_equal '\\\\?\\X:', r[0]
|
144
|
+
assert_equal '/abc', r[1]
|
145
|
+
assert_equal :form_3, r[2]
|
146
|
+
end
|
145
147
|
|
146
|
-
|
148
|
+
def test_UNC_standard
|
147
149
|
|
148
|
-
|
150
|
+
r = F.get_windows_volume('\\\\the-server-name\\the-share-name')
|
149
151
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
152
|
+
assert_kind_of ::Array, r
|
153
|
+
assert_equal 3, r.size
|
154
|
+
assert_equal '\\\\the-server-name\\the-share-name', r[0]
|
155
|
+
assert_equal '', r[1]
|
156
|
+
assert_equal :form_2, r[2]
|
155
157
|
|
156
|
-
|
158
|
+
r = F.get_windows_volume('\\\\the-server-name\\the-share-name\\')
|
157
159
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
160
|
+
assert_kind_of ::Array, r
|
161
|
+
assert_equal 3, r.size
|
162
|
+
assert_equal '\\\\the-server-name\\the-share-name', r[0]
|
163
|
+
assert_equal '\\', r[1]
|
164
|
+
assert_equal :form_2, r[2]
|
163
165
|
|
164
|
-
|
166
|
+
r = F.get_windows_volume('\\\\the-server-name\\the-share-name\\file.ext')
|
165
167
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
168
|
+
assert_kind_of ::Array, r
|
169
|
+
assert_equal 3, r.size
|
170
|
+
assert_equal '\\\\the-server-name\\the-share-name', r[0]
|
171
|
+
assert_equal '\\file.ext', r[1]
|
172
|
+
assert_equal :form_2, r[2]
|
173
|
+
end
|
172
174
|
|
173
|
-
|
175
|
+
def test_UNC_long
|
174
176
|
|
175
|
-
|
177
|
+
r = F.get_windows_volume('\\\\?\\the-server-name\\the-share-name')
|
176
178
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
179
|
+
assert_kind_of ::Array, r
|
180
|
+
assert_equal 3, r.size
|
181
|
+
assert_equal '\\\\?\\the-server-name\\the-share-name', r[0]
|
182
|
+
assert_equal '', r[1]
|
183
|
+
assert_equal :form_4, r[2]
|
182
184
|
|
183
|
-
|
185
|
+
r = F.get_windows_volume('\\\\?\\the-server-name\\the-share-name\\')
|
184
186
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
187
|
+
assert_kind_of ::Array, r
|
188
|
+
assert_equal 3, r.size
|
189
|
+
assert_equal '\\\\?\\the-server-name\\the-share-name', r[0]
|
190
|
+
assert_equal '\\', r[1]
|
191
|
+
assert_equal :form_4, r[2]
|
190
192
|
|
191
|
-
|
193
|
+
r = F.get_windows_volume('\\\\?\\the-server-name\\the-share-name\\file.ext')
|
192
194
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
195
|
+
assert_kind_of ::Array, r
|
196
|
+
assert_equal 3, r.size
|
197
|
+
assert_equal '\\\\?\\the-server-name\\the-share-name', r[0]
|
198
|
+
assert_equal '\\file.ext', r[1]
|
199
|
+
assert_equal :form_4, r[2]
|
200
|
+
end
|
199
201
|
|
200
|
-
|
202
|
+
def test_UNC_full
|
201
203
|
|
202
|
-
|
204
|
+
r = F.get_windows_volume('\\\\?\\UNC\\the-server-name\\the-share-name')
|
203
205
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
206
|
+
assert_kind_of ::Array, r
|
207
|
+
assert_equal 3, r.size
|
208
|
+
assert_equal '\\\\?\\UNC\\the-server-name\\the-share-name', r[0]
|
209
|
+
assert_equal '', r[1]
|
210
|
+
assert_equal :form_5, r[2]
|
209
211
|
|
210
|
-
|
212
|
+
r = F.get_windows_volume('\\\\?\\UNC\\the-server-name\\the-share-name\\')
|
211
213
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
214
|
+
assert_kind_of ::Array, r
|
215
|
+
assert_equal 3, r.size
|
216
|
+
assert_equal '\\\\?\\UNC\\the-server-name\\the-share-name', r[0]
|
217
|
+
assert_equal '\\', r[1]
|
218
|
+
assert_equal :form_5, r[2]
|
219
|
+
end
|
218
220
|
end
|
219
221
|
|
220
222
|
|
223
|
+
# ############################## end of file ############################# #
|
224
|
+
|
@@ -2,60 +2,64 @@
|
|
2
2
|
|
3
3
|
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 5), 'lib')
|
4
4
|
|
5
|
+
|
5
6
|
require 'libpath/internal_/windows/form'
|
6
7
|
|
7
8
|
require 'test/unit'
|
8
9
|
|
9
10
|
require 'xqsr3/extensions/test/unit'
|
10
11
|
|
12
|
+
|
11
13
|
class Test_Internal_Windows_Form_slash_functions < Test::Unit::TestCase
|
12
14
|
|
13
|
-
|
15
|
+
F = ::LibPath::Internal_::Windows::Form
|
14
16
|
|
15
|
-
|
17
|
+
def test_char_is_path_name_separator?
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
+
assert_false F.char_is_path_name_separator?('')
|
20
|
+
assert_false F.char_is_path_name_separator?('a')
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
assert F.char_is_path_name_separator?('/')
|
23
|
+
assert F.char_is_path_name_separator?('\\')
|
24
|
+
end
|
23
25
|
|
24
|
-
|
26
|
+
def test_append_trailing_slash
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
assert_equal '\\', F.append_trailing_slash('')
|
29
|
+
assert_equal '/', F.append_trailing_slash('/')
|
30
|
+
assert_equal 'a\\', F.append_trailing_slash('a')
|
31
|
+
assert_equal 'a/', F.append_trailing_slash('a/')
|
32
|
+
end
|
31
33
|
|
32
|
-
|
34
|
+
def test_get_trailing_slash
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
assert_nil F.get_trailing_slash('')
|
37
|
+
assert_equal '/', F.get_trailing_slash('/')
|
38
|
+
assert_nil F.get_trailing_slash('a')
|
39
|
+
assert_equal '\\', F.get_trailing_slash('\\')
|
40
|
+
assert_equal '/', F.get_trailing_slash('a/')
|
41
|
+
end
|
40
42
|
|
41
|
-
|
43
|
+
def test_has_trailing_slash
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
assert_false F.has_trailing_slash?('')
|
46
|
+
assert_true F.has_trailing_slash?('/')
|
47
|
+
assert_false F.has_trailing_slash?('a')
|
48
|
+
assert_true F.has_trailing_slash?('\\')
|
49
|
+
assert_true F.has_trailing_slash?('a/')
|
50
|
+
end
|
49
51
|
|
50
|
-
|
52
|
+
def test_trim_trailing_slash
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
54
|
+
assert_equal '', F.trim_trailing_slash('')
|
55
|
+
assert_equal '', F.trim_trailing_slash('/')
|
56
|
+
assert_equal 'a', F.trim_trailing_slash('a')
|
57
|
+
assert_equal '', F.trim_trailing_slash('\\')
|
58
|
+
assert_equal 'a', F.trim_trailing_slash('a/')
|
59
|
+
assert_equal 'a', F.trim_trailing_slash('a\\')
|
60
|
+
end
|
59
61
|
end
|
60
62
|
|
61
63
|
|
64
|
+
# ############################## end of file ############################# #
|
65
|
+
|
@@ -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
|
|