libpath-ruby 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +61 -0
- data/examples/path_from_arg0.md +99 -0
- data/examples/path_from_arg0.rb +55 -0
- data/lib/libpath.rb +12 -0
- data/lib/libpath/constants.rb +42 -0
- data/lib/libpath/constants/unix.rb +146 -0
- data/lib/libpath/constants/windows.rb +147 -0
- data/lib/libpath/diagnostics.rb +6 -0
- data/lib/libpath/diagnostics/parameter_checking.rb +46 -0
- data/lib/libpath/exceptions.rb +7 -0
- data/lib/libpath/exceptions/libpath_base_exception.rb +77 -0
- data/lib/libpath/exceptions/malformed_name_exception.rb +85 -0
- data/lib/libpath/form.rb +42 -0
- data/lib/libpath/form/unix.rb +215 -0
- data/lib/libpath/form/windows.rb +358 -0
- data/lib/libpath/internal_/array.rb +96 -0
- data/lib/libpath/internal_/platform.rb +53 -0
- data/lib/libpath/internal_/string.rb +33 -0
- data/lib/libpath/internal_/unix/form.rb +160 -0
- data/lib/libpath/internal_/windows/drive.rb +84 -0
- data/lib/libpath/internal_/windows/form.rb +281 -0
- data/lib/libpath/libpath.rb +6 -0
- data/lib/libpath/path.rb +43 -0
- data/lib/libpath/path/unix.rb +170 -0
- data/lib/libpath/path/windows.rb +176 -0
- data/lib/libpath/util.rb +42 -0
- data/lib/libpath/util/unix.rb +414 -0
- data/lib/libpath/util/windows.rb +636 -0
- data/lib/libpath/version.rb +73 -0
- data/test/performance/benchmark_drive_letter.rb +31 -0
- data/test/performance/benchmark_gsub_string_or_regex.rb +45 -0
- data/test/performance/benchmark_rindex2.rb +109 -0
- data/test/performance/benchmark_split.rb +32 -0
- data/test/unit/compare/ts_all.rb +22 -0
- data/test/unit/equate/ts_all.rb +22 -0
- data/test/unit/equate/unix/ts_all.rb +22 -0
- data/test/unit/equate/windows/ts_all.rb +22 -0
- data/test/unit/exceptions/tc_libpath_base_exception.rb +27 -0
- data/test/unit/exceptions/tc_malformed_name_exception.rb +31 -0
- data/test/unit/exceptions/ts_all.rb +22 -0
- data/test/unit/form/tc_absolute_functions.rb +369 -0
- data/test/unit/form/ts_all.rb +22 -0
- data/test/unit/form/unix/tc_absolute_functions.rb +269 -0
- data/test/unit/form/unix/ts_all.rb +22 -0
- data/test/unit/form/windows/tc_absolute_functions.rb +854 -0
- data/test/unit/form/windows/ts_all.rb +22 -0
- data/test/unit/internal_/tc_array.rb +62 -0
- data/test/unit/internal_/ts_all.rb +22 -0
- data/test/unit/internal_/unix/form/tc_slash_functions.rb +60 -0
- data/test/unit/internal_/unix/form/ts_all.rb +22 -0
- data/test/unit/internal_/unix/tc_split_path.rb +396 -0
- data/test/unit/internal_/unix/ts_all.rb +22 -0
- data/test/unit/internal_/windows/form/tc_get_windows_volume.rb +220 -0
- data/test/unit/internal_/windows/form/tc_slash_functions.rb +61 -0
- data/test/unit/internal_/windows/form/ts_all.rb +22 -0
- data/test/unit/internal_/windows/tc_split_path.rb +881 -0
- data/test/unit/internal_/windows/ts_all.rb +22 -0
- data/test/unit/parse/ts_all.rb +22 -0
- data/test/unit/path/tc_path.rb +778 -0
- data/test/unit/path/ts_all.rb +22 -0
- data/test/unit/path/unix/tc_path.rb +565 -0
- data/test/unit/path/unix/ts_all.rb +22 -0
- data/test/unit/path/windows/tc_path.rb +630 -0
- data/test/unit/path/windows/ts_all.rb +22 -0
- data/test/unit/tc_version.rb +47 -0
- data/test/unit/ts_all.rb +22 -0
- data/test/unit/util/tc_combine_paths.rb +179 -0
- data/test/unit/util/tc_derive_relative_path.rb +19 -0
- data/test/unit/util/tc_make_path_canonical.rb +228 -0
- data/test/unit/util/ts_all.rb +22 -0
- data/test/unit/util/unix/tc_combine_paths.rb +65 -0
- data/test/unit/util/unix/tc_derive_relative_path.rb +123 -0
- data/test/unit/util/unix/tc_make_path_absolute.rb +117 -0
- data/test/unit/util/unix/tc_make_path_canonical.rb +139 -0
- data/test/unit/util/unix/ts_all.rb +22 -0
- data/test/unit/util/windows/tc_combine_paths.rb +131 -0
- data/test/unit/util/windows/tc_derive_relative_path.rb +155 -0
- data/test/unit/util/windows/tc_make_path_absolute.rb +163 -0
- data/test/unit/util/windows/tc_make_path_canonical.rb +220 -0
- data/test/unit/util/windows/ts_all.rb +22 -0
- metadata +144 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# executes all other tests
|
4
|
+
|
5
|
+
this_dir = File.expand_path(File.dirname(__FILE__))
|
6
|
+
|
7
|
+
# all tc_*rb in current directory
|
8
|
+
Dir[File.join(this_dir, 'tc_*rb')].each do |file|
|
9
|
+
|
10
|
+
$stderr.puts "requiring file '#{file}'" if $DEBUG
|
11
|
+
|
12
|
+
require file
|
13
|
+
end
|
14
|
+
|
15
|
+
# all ts_*rb in immediate sub-directories
|
16
|
+
Dir[File.join(this_dir, '*', 'ts_*rb')].each do |file|
|
17
|
+
|
18
|
+
$stderr.puts "requiring file '#{file}'" if $DEBUG
|
19
|
+
|
20
|
+
require file
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,369 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 3), 'lib')
|
4
|
+
|
5
|
+
require 'libpath/form'
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
require 'xqsr3/extensions/test/unit'
|
10
|
+
|
11
|
+
require 'libpath/internal_/platform'
|
12
|
+
|
13
|
+
class Test_existence_of_namespace_LibPath_Form < Test::Unit::TestCase
|
14
|
+
|
15
|
+
def test_LibPath_module_exists
|
16
|
+
|
17
|
+
assert defined?(::LibPath)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_LibPath_Form_module_exists
|
21
|
+
|
22
|
+
assert defined?(::LibPath::Form)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Test_path_is_absolute < Test::Unit::TestCase
|
27
|
+
|
28
|
+
include ::LibPath::Form
|
29
|
+
|
30
|
+
if $DEBUG
|
31
|
+
|
32
|
+
def test_with_nil
|
33
|
+
|
34
|
+
assert_raise(::ArgumentError) { path_is_absolute?(nil) }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_empty
|
39
|
+
|
40
|
+
assert_false path_is_absolute?('')
|
41
|
+
end
|
42
|
+
|
43
|
+
if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
|
44
|
+
|
45
|
+
def test_absolute_paths_from_UNC
|
46
|
+
|
47
|
+
assert_false path_is_absolute?('\\\\')
|
48
|
+
assert_false path_is_absolute?('\\\\server')
|
49
|
+
assert_false path_is_absolute?('\\\\server\\')
|
50
|
+
assert_false path_is_absolute?('\\\\server\\share')
|
51
|
+
|
52
|
+
assert path_is_absolute?('\\\\server\\the-share_name\\')
|
53
|
+
assert path_is_absolute?('\\\\server\\the-share_name\\\\')
|
54
|
+
assert path_is_absolute?('\\\\server\\the-share_name\\dir')
|
55
|
+
assert path_is_absolute?('\\\\server\\the-share_name\\dir\\')
|
56
|
+
|
57
|
+
assert path_is_absolute?('\\\\101.2.303.4\\the-share_name\\')
|
58
|
+
assert path_is_absolute?('\\\\101.2.303.4\\the-share_name\\\\')
|
59
|
+
assert path_is_absolute?('\\\\101.2.303.4\\the-share_name\\dir')
|
60
|
+
assert path_is_absolute?('\\\\101.2.303.4\\the-share_name\\dir\\')
|
61
|
+
|
62
|
+
assert path_is_absolute?('\\\\::1/128\\the-share_name\\')
|
63
|
+
assert path_is_absolute?('\\\\::1/128\\the-share_name\\\\')
|
64
|
+
assert path_is_absolute?('\\\\::1/128\\the-share_name\\dir')
|
65
|
+
assert path_is_absolute?('\\\\::1/128\\the-share_name\\dir\\')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
|
70
|
+
|
71
|
+
def test_absolute_paths_from_drive
|
72
|
+
|
73
|
+
assert path_is_absolute?('C:\\')
|
74
|
+
assert path_is_absolute?('C:\\abc')
|
75
|
+
assert path_is_absolute?('C:\\abc\\')
|
76
|
+
|
77
|
+
assert_false path_is_absolute?('C:')
|
78
|
+
assert_false path_is_absolute?('C:abc')
|
79
|
+
assert_false path_is_absolute?('C:abc\\')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_absolute_paths_from_root
|
84
|
+
|
85
|
+
if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
|
86
|
+
|
87
|
+
assert_false path_is_absolute?('\\')
|
88
|
+
assert_false path_is_absolute?('\\\\')
|
89
|
+
assert_false path_is_absolute?('\\abc')
|
90
|
+
|
91
|
+
assert_false path_is_absolute?('/')
|
92
|
+
assert_false path_is_absolute?('//')
|
93
|
+
assert_false path_is_absolute?('/abc')
|
94
|
+
else
|
95
|
+
|
96
|
+
assert path_is_absolute?('/')
|
97
|
+
assert path_is_absolute?('//')
|
98
|
+
assert path_is_absolute?('/abc')
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_absolute_paths_from_home
|
103
|
+
|
104
|
+
assert path_is_absolute?('~')
|
105
|
+
assert path_is_absolute?('~/')
|
106
|
+
assert path_is_absolute?('~/abc')
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_relative_paths
|
110
|
+
|
111
|
+
assert_false path_is_absolute?('abc')
|
112
|
+
assert_false path_is_absolute?('abc/')
|
113
|
+
assert_false path_is_absolute?('a/')
|
114
|
+
|
115
|
+
assert_false path_is_absolute?('~abc')
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
class Test_path_is_homed < Test::Unit::TestCase
|
120
|
+
|
121
|
+
include ::LibPath::Form
|
122
|
+
|
123
|
+
if $DEBUG
|
124
|
+
|
125
|
+
def test_with_nil
|
126
|
+
|
127
|
+
assert_raise(::ArgumentError) { path_is_homed?(nil) }
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_empty
|
132
|
+
|
133
|
+
assert_false path_is_homed?('')
|
134
|
+
end
|
135
|
+
|
136
|
+
if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
|
137
|
+
|
138
|
+
def test_absolute_paths_from_UNC
|
139
|
+
|
140
|
+
assert_false path_is_homed?('\\\\')
|
141
|
+
assert_false path_is_homed?('\\\\server')
|
142
|
+
assert_false path_is_homed?('\\\\server\\')
|
143
|
+
assert_false path_is_homed?('\\\\server\\share')
|
144
|
+
|
145
|
+
assert_false path_is_homed?('\\\\server\\the-share_name\\')
|
146
|
+
assert_false path_is_homed?('\\\\server\\the-share_name\\\\')
|
147
|
+
assert_false path_is_homed?('\\\\server\\the-share_name\\dir')
|
148
|
+
assert_false path_is_homed?('\\\\server\\the-share_name\\dir\\')
|
149
|
+
|
150
|
+
assert_false path_is_homed?('\\\\101.2.303.4\\the-share_name\\')
|
151
|
+
assert_false path_is_homed?('\\\\101.2.303.4\\the-share_name\\\\')
|
152
|
+
assert_false path_is_homed?('\\\\101.2.303.4\\the-share_name\\dir')
|
153
|
+
assert_false path_is_homed?('\\\\101.2.303.4\\the-share_name\\dir\\')
|
154
|
+
|
155
|
+
assert_false path_is_homed?('\\\\::1/128\\the-share_name\\')
|
156
|
+
assert_false path_is_homed?('\\\\::1/128\\the-share_name\\\\')
|
157
|
+
assert_false path_is_homed?('\\\\::1/128\\the-share_name\\dir')
|
158
|
+
assert_false path_is_homed?('\\\\::1/128\\the-share_name\\dir\\')
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
|
163
|
+
|
164
|
+
def test_absolute_paths_from_drive
|
165
|
+
|
166
|
+
assert_false path_is_homed?('C:\\')
|
167
|
+
assert_false path_is_homed?('C:\\abc')
|
168
|
+
assert_false path_is_homed?('C:\\abc\\')
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_absolute_paths_from_root
|
173
|
+
|
174
|
+
if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
|
175
|
+
|
176
|
+
assert_false path_is_homed?('\\')
|
177
|
+
assert_false path_is_homed?('\\\\')
|
178
|
+
assert_false path_is_homed?('\\abc')
|
179
|
+
end
|
180
|
+
|
181
|
+
assert_false path_is_homed?('/')
|
182
|
+
assert_false path_is_homed?('//')
|
183
|
+
assert_false path_is_homed?('/abc')
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_absolute_paths_from_home
|
187
|
+
|
188
|
+
assert path_is_homed?('~')
|
189
|
+
assert path_is_homed?('~/')
|
190
|
+
assert path_is_homed?('~/abc')
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_relative_paths
|
194
|
+
|
195
|
+
assert_false path_is_homed?('abc')
|
196
|
+
assert_false path_is_homed?('abc/')
|
197
|
+
assert_false path_is_homed?('a/')
|
198
|
+
|
199
|
+
assert_false path_is_homed?('~abc')
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
class Test_path_is_rooteds < Test::Unit::TestCase
|
204
|
+
|
205
|
+
include ::LibPath::Form
|
206
|
+
|
207
|
+
if $DEBUG
|
208
|
+
|
209
|
+
def test_with_nil
|
210
|
+
|
211
|
+
assert_raise(::ArgumentError) { path_is_rooted?(nil) }
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_empty
|
216
|
+
|
217
|
+
assert_false path_is_rooted?('')
|
218
|
+
end
|
219
|
+
|
220
|
+
if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
|
221
|
+
|
222
|
+
def test_absolute_paths_from_UNC
|
223
|
+
|
224
|
+
assert_false path_is_rooted?('\\\\')
|
225
|
+
assert_false path_is_rooted?('\\\\server')
|
226
|
+
assert_false path_is_rooted?('\\\\server\\')
|
227
|
+
assert_false path_is_rooted?('\\\\server\\share')
|
228
|
+
|
229
|
+
assert path_is_rooted?('\\\\server\\the-share_name\\')
|
230
|
+
assert path_is_rooted?('\\\\server\\the-share_name\\\\')
|
231
|
+
assert path_is_rooted?('\\\\server\\the-share_name\\dir')
|
232
|
+
assert path_is_rooted?('\\\\server\\the-share_name\\dir\\')
|
233
|
+
|
234
|
+
assert path_is_rooted?('\\\\101.2.303.4\\the-share_name\\')
|
235
|
+
assert path_is_rooted?('\\\\101.2.303.4\\the-share_name\\\\')
|
236
|
+
assert path_is_rooted?('\\\\101.2.303.4\\the-share_name\\dir')
|
237
|
+
assert path_is_rooted?('\\\\101.2.303.4\\the-share_name\\dir\\')
|
238
|
+
|
239
|
+
assert path_is_rooted?('\\\\::1/128\\the-share_name\\')
|
240
|
+
assert path_is_rooted?('\\\\::1/128\\the-share_name\\\\')
|
241
|
+
assert path_is_rooted?('\\\\::1/128\\the-share_name\\dir')
|
242
|
+
assert path_is_rooted?('\\\\::1/128\\the-share_name\\dir\\')
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
|
247
|
+
|
248
|
+
def test_absolute_paths_from_drive
|
249
|
+
|
250
|
+
assert path_is_rooted?('C:\\')
|
251
|
+
assert path_is_rooted?('C:\\abc')
|
252
|
+
assert path_is_rooted?('C:\\abc\\')
|
253
|
+
|
254
|
+
assert_false path_is_rooted?('C:')
|
255
|
+
assert_false path_is_rooted?('C:abc')
|
256
|
+
assert_false path_is_rooted?('C:abc\\')
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_absolute_paths_from_root
|
261
|
+
|
262
|
+
if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
|
263
|
+
|
264
|
+
assert path_is_rooted?('\\')
|
265
|
+
assert_false path_is_rooted?('\\\\')
|
266
|
+
assert path_is_rooted?('\\abc')
|
267
|
+
end
|
268
|
+
|
269
|
+
assert path_is_rooted?('/')
|
270
|
+
assert path_is_rooted?('//')
|
271
|
+
assert path_is_rooted?('/abc')
|
272
|
+
end
|
273
|
+
|
274
|
+
def test_absolute_paths_from_home
|
275
|
+
|
276
|
+
assert_false path_is_rooted?('~')
|
277
|
+
assert_false path_is_rooted?('~/')
|
278
|
+
assert_false path_is_rooted?('~/abc')
|
279
|
+
end
|
280
|
+
|
281
|
+
def test_relative_paths
|
282
|
+
|
283
|
+
assert_false path_is_rooted?('abc')
|
284
|
+
assert_false path_is_rooted?('abc/')
|
285
|
+
assert_false path_is_rooted?('a/')
|
286
|
+
|
287
|
+
assert_false path_is_rooted?('~abc')
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
|
292
|
+
|
293
|
+
class Test_path_is_UNCs < Test::Unit::TestCase
|
294
|
+
|
295
|
+
include ::LibPath::Form
|
296
|
+
|
297
|
+
if $DEBUG
|
298
|
+
|
299
|
+
def test_with_nil
|
300
|
+
|
301
|
+
assert_raise(::ArgumentError) { path_is_UNC?(nil) }
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
def test_empty
|
306
|
+
|
307
|
+
assert_false path_is_UNC?('')
|
308
|
+
end
|
309
|
+
|
310
|
+
def test_absolute_paths_from_drive
|
311
|
+
|
312
|
+
assert_false path_is_UNC?('C:\\')
|
313
|
+
assert_false path_is_UNC?('C:\\\\')
|
314
|
+
assert_false path_is_UNC?('C:\\abc\\')
|
315
|
+
end
|
316
|
+
|
317
|
+
def test_absolute_paths_from_UNC
|
318
|
+
|
319
|
+
assert_false path_is_UNC?('\\\\')
|
320
|
+
assert_false path_is_UNC?('\\\\server')
|
321
|
+
assert_false path_is_UNC?('\\\\server\\')
|
322
|
+
assert path_is_UNC?('\\\\server\\share')
|
323
|
+
|
324
|
+
assert path_is_UNC?('\\\\server\\the-share_name\\')
|
325
|
+
assert path_is_UNC?('\\\\server\\the-share_name\\\\')
|
326
|
+
assert path_is_UNC?('\\\\server\\the-share_name\\dir')
|
327
|
+
assert path_is_UNC?('\\\\server\\the-share_name\\dir\\')
|
328
|
+
|
329
|
+
assert path_is_UNC?('\\\\101.2.303.4\\the-share_name\\')
|
330
|
+
assert path_is_UNC?('\\\\101.2.303.4\\the-share_name\\\\')
|
331
|
+
assert path_is_UNC?('\\\\101.2.303.4\\the-share_name\\dir')
|
332
|
+
assert path_is_UNC?('\\\\101.2.303.4\\the-share_name\\dir\\')
|
333
|
+
|
334
|
+
assert path_is_UNC?('\\\\::1/128\\the-share_name\\')
|
335
|
+
assert path_is_UNC?('\\\\::1/128\\the-share_name\\\\')
|
336
|
+
assert path_is_UNC?('\\\\::1/128\\the-share_name\\dir')
|
337
|
+
assert path_is_UNC?('\\\\::1/128\\the-share_name\\dir\\')
|
338
|
+
end
|
339
|
+
|
340
|
+
def test_absolute_paths_from_root
|
341
|
+
|
342
|
+
assert_false path_is_UNC?('\\')
|
343
|
+
assert_false path_is_UNC?('\\\\')
|
344
|
+
assert_false path_is_UNC?('\\abc')
|
345
|
+
|
346
|
+
assert_false path_is_UNC?('/')
|
347
|
+
assert_false path_is_UNC?('//')
|
348
|
+
assert_false path_is_UNC?('/abc')
|
349
|
+
end
|
350
|
+
|
351
|
+
def test_absolute_paths_from_home
|
352
|
+
|
353
|
+
assert_false path_is_UNC?('~')
|
354
|
+
assert_false path_is_UNC?('~/')
|
355
|
+
assert_false path_is_UNC?('~/abc')
|
356
|
+
end
|
357
|
+
|
358
|
+
def test_relative_paths
|
359
|
+
|
360
|
+
assert_false path_is_UNC?('abc')
|
361
|
+
assert_false path_is_UNC?('abc/')
|
362
|
+
assert_false path_is_UNC?('a/')
|
363
|
+
|
364
|
+
assert_false path_is_UNC?('~abc')
|
365
|
+
end
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# executes all other tests
|
4
|
+
|
5
|
+
this_dir = File.expand_path(File.dirname(__FILE__))
|
6
|
+
|
7
|
+
# all tc_*rb in current directory
|
8
|
+
Dir[File.join(this_dir, 'tc_*rb')].each do |file|
|
9
|
+
|
10
|
+
$stderr.puts "requiring file '#{file}'" if $DEBUG
|
11
|
+
|
12
|
+
require file
|
13
|
+
end
|
14
|
+
|
15
|
+
# all ts_*rb in immediate sub-directories
|
16
|
+
Dir[File.join(this_dir, '*', 'ts_*rb')].each do |file|
|
17
|
+
|
18
|
+
$stderr.puts "requiring file '#{file}'" if $DEBUG
|
19
|
+
|
20
|
+
require file
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,269 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 4), 'lib')
|
4
|
+
|
5
|
+
require 'libpath/form/unix'
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
require 'xqsr3/extensions/test/unit'
|
10
|
+
|
11
|
+
class Test_existence_of_namespace_LibPath_Form_Unix < Test::Unit::TestCase
|
12
|
+
|
13
|
+
def test_LibPath_module_exists
|
14
|
+
|
15
|
+
assert defined?(::LibPath)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_LibPath_Form_module_exists
|
19
|
+
|
20
|
+
assert defined?(::LibPath::Form)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_LibPath_Form_Unix_module_exists
|
24
|
+
|
25
|
+
assert defined?(::LibPath::Form::Unix)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Test_classify_path_Unix < Test::Unit::TestCase
|
30
|
+
|
31
|
+
include ::LibPath::Form::Unix
|
32
|
+
|
33
|
+
def test_with_nil
|
34
|
+
|
35
|
+
if $DEBUG
|
36
|
+
|
37
|
+
assert_raise(::ArgumentError) { classify_path(nil) }
|
38
|
+
else
|
39
|
+
|
40
|
+
assert_nil classify_path(nil)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_empty
|
45
|
+
|
46
|
+
assert_nil classify_path('')
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_absolute
|
50
|
+
|
51
|
+
assert_equal :absolute, classify_path('/')
|
52
|
+
|
53
|
+
assert_equal :absolute, classify_path('/abc')
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_homed
|
57
|
+
|
58
|
+
assert_equal :homed, classify_path('~')
|
59
|
+
|
60
|
+
assert_equal :homed, classify_path('~/')
|
61
|
+
|
62
|
+
assert_equal :homed, classify_path('~/abc')
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_relative
|
66
|
+
|
67
|
+
assert_equal :relative, classify_path('abc')
|
68
|
+
|
69
|
+
assert_equal :relative, classify_path('~~')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class Test_name_is_malformed_Unix < Test::Unit::TestCase
|
74
|
+
|
75
|
+
include ::LibPath::Form::Unix
|
76
|
+
|
77
|
+
def test_with_nil
|
78
|
+
|
79
|
+
assert name_is_malformed?(nil)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_empty
|
83
|
+
|
84
|
+
assert_false name_is_malformed?('')
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_absolute_paths_from_root
|
88
|
+
|
89
|
+
assert_false name_is_malformed?('/')
|
90
|
+
assert_false name_is_malformed?('//')
|
91
|
+
assert_false name_is_malformed?('/abc')
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_absolute_paths_from_home
|
95
|
+
|
96
|
+
assert_false name_is_malformed?('~')
|
97
|
+
assert_false name_is_malformed?('~/')
|
98
|
+
assert_false name_is_malformed?('~/abc')
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_relative_paths
|
102
|
+
|
103
|
+
assert_false name_is_malformed?('abc')
|
104
|
+
assert_false name_is_malformed?('abc/')
|
105
|
+
assert_false name_is_malformed?('a/')
|
106
|
+
|
107
|
+
assert_false name_is_malformed?('~abc')
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_innate_invalid_characters
|
111
|
+
|
112
|
+
assert name_is_malformed?("\0")
|
113
|
+
assert name_is_malformed?("a\0")
|
114
|
+
assert name_is_malformed?("\0a")
|
115
|
+
|
116
|
+
assert name_is_malformed?("\0", reject_shell_characters: true)
|
117
|
+
assert name_is_malformed?("a\0", reject_shell_characters: true)
|
118
|
+
assert name_is_malformed?("\0a", reject_shell_characters: true)
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_shell_invalid_characters
|
122
|
+
|
123
|
+
assert_false name_is_malformed?('*')
|
124
|
+
assert_false name_is_malformed?('?')
|
125
|
+
assert_false name_is_malformed?('|')
|
126
|
+
|
127
|
+
assert name_is_malformed?('*', reject_shell_characters: true)
|
128
|
+
assert name_is_malformed?('?', reject_shell_characters: true)
|
129
|
+
assert name_is_malformed?('|', reject_shell_characters: true)
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_path_name_separators
|
133
|
+
|
134
|
+
assert_false name_is_malformed?('/')
|
135
|
+
|
136
|
+
assert name_is_malformed?('/', reject_path_name_separators: true)
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_path_separators
|
140
|
+
|
141
|
+
assert_false name_is_malformed?(':')
|
142
|
+
|
143
|
+
assert name_is_malformed?(':', reject_path_separators: true)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
class Test_path_is_absolute_Unix < Test::Unit::TestCase
|
148
|
+
|
149
|
+
include ::LibPath::Form::Unix
|
150
|
+
|
151
|
+
if $DEBUG
|
152
|
+
|
153
|
+
def test_with_nil
|
154
|
+
|
155
|
+
assert_raise(::ArgumentError) { path_is_absolute?(nil) }
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_empty
|
160
|
+
|
161
|
+
assert_false path_is_absolute?('')
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_absolute_paths_from_root
|
165
|
+
|
166
|
+
assert path_is_absolute?('/')
|
167
|
+
assert path_is_absolute?('//')
|
168
|
+
assert path_is_absolute?('/abc')
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_absolute_paths_from_home
|
172
|
+
|
173
|
+
assert path_is_absolute?('~')
|
174
|
+
assert path_is_absolute?('~/')
|
175
|
+
assert path_is_absolute?('~/abc')
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_relative_paths
|
179
|
+
|
180
|
+
assert_false path_is_absolute?('abc')
|
181
|
+
assert_false path_is_absolute?('abc/')
|
182
|
+
assert_false path_is_absolute?('a/')
|
183
|
+
|
184
|
+
assert_false path_is_absolute?('~abc')
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
class Test_path_is_homed_Unix < Test::Unit::TestCase
|
189
|
+
|
190
|
+
include ::LibPath::Form::Unix
|
191
|
+
|
192
|
+
if $DEBUG
|
193
|
+
|
194
|
+
def test_with_nil
|
195
|
+
|
196
|
+
assert_raise(::ArgumentError) { path_is_homed?(nil) }
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_empty
|
201
|
+
|
202
|
+
assert_false path_is_homed?('')
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_absolute_paths_from_root
|
206
|
+
|
207
|
+
assert_false path_is_homed?('/')
|
208
|
+
assert_false path_is_homed?('//')
|
209
|
+
assert_false path_is_homed?('/abc')
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_absolute_paths_from_home
|
213
|
+
|
214
|
+
assert path_is_homed?('~')
|
215
|
+
assert path_is_homed?('~/')
|
216
|
+
assert path_is_homed?('~/abc')
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_relative_paths
|
220
|
+
|
221
|
+
assert_false path_is_homed?('abc')
|
222
|
+
assert_false path_is_homed?('abc/')
|
223
|
+
assert_false path_is_homed?('a/')
|
224
|
+
|
225
|
+
assert_false path_is_homed?('~abc')
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
class Test_path_is_rooted_Unix < Test::Unit::TestCase
|
230
|
+
|
231
|
+
include ::LibPath::Form::Unix
|
232
|
+
|
233
|
+
if $DEBUG
|
234
|
+
|
235
|
+
def test_with_nil
|
236
|
+
|
237
|
+
assert_raise(::ArgumentError) { path_is_rooted?(nil) }
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_empty
|
242
|
+
|
243
|
+
assert_false path_is_rooted?('')
|
244
|
+
end
|
245
|
+
|
246
|
+
def test_absolute_paths_from_root
|
247
|
+
|
248
|
+
assert path_is_rooted?('/')
|
249
|
+
assert path_is_rooted?('//')
|
250
|
+
assert path_is_rooted?('/abc')
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_absolute_paths_from_home
|
254
|
+
|
255
|
+
assert_false path_is_rooted?('~')
|
256
|
+
assert_false path_is_rooted?('~/')
|
257
|
+
assert_false path_is_rooted?('~/abc')
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_relative_paths
|
261
|
+
|
262
|
+
assert_false path_is_rooted?('abc')
|
263
|
+
assert_false path_is_rooted?('abc/')
|
264
|
+
assert_false path_is_rooted?('a/')
|
265
|
+
|
266
|
+
assert_false path_is_rooted?('~abc')
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|