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,564 +2,568 @@
|
|
2
2
|
|
3
3
|
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 4), 'lib')
|
4
4
|
|
5
|
-
require 'libpath/path/unix'
|
6
5
|
|
7
|
-
require '
|
6
|
+
require 'libpath/path/unix'
|
8
7
|
|
9
8
|
require 'xqsr3/extensions/test/unit'
|
9
|
+
require 'test/unit'
|
10
10
|
|
11
11
|
require 'libpath/internal_/platform'
|
12
12
|
|
13
|
+
|
13
14
|
class Test_existence_of_namespace_LibPath_Path_Unix < Test::Unit::TestCase
|
14
15
|
|
15
|
-
|
16
|
+
def test_LibPath_module_exists
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
assert defined?(::LibPath)
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
+
def test_LibPath_Path_module_exists
|
21
22
|
|
22
|
-
|
23
|
-
|
23
|
+
assert defined?(::LibPath::Path)
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
+
def test_LibPath_Path_Unix_module_exists
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
assert defined?(::LibPath::Path::Unix)
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
+
def test_LibPath_Path_Unix_ParsedPath_class_exists
|
31
32
|
|
32
|
-
|
33
|
-
|
33
|
+
assert defined?(::LibPath::Path::Unix::ParsedPath)
|
34
|
+
end
|
34
35
|
end
|
35
36
|
|
36
37
|
class Test_LibPath_Path_Unix_ParsedPath < Test::Unit::TestCase
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
39
|
+
include ::LibPath::Path::Unix
|
40
|
+
|
41
|
+
def test_nil
|
42
|
+
|
43
|
+
assert_raise(::ArgumentError) { ParsedPath.new(nil) }
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_empty
|
47
|
+
|
48
|
+
assert_raise(::ArgumentError) { ParsedPath.new('') }
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_root
|
52
|
+
|
53
|
+
pp = ParsedPath.new('/')
|
54
|
+
|
55
|
+
assert_equal '/', pp.given_path
|
56
|
+
assert_equal '/', pp.absolute_path
|
57
|
+
assert_equal '/', pp.compare_path
|
58
|
+
assert_equal '/', pp.directory
|
59
|
+
assert_equal '/', pp.directory_path
|
60
|
+
assert_equal '/', pp.dirname
|
61
|
+
assert_equal [ '/' ], pp.directory_parts
|
62
|
+
assert_nil pp.file_full_name
|
63
|
+
assert_nil pp.basename
|
64
|
+
assert_nil pp.file_name_only
|
65
|
+
assert_nil pp.stem
|
66
|
+
assert_nil pp.file_extension
|
67
|
+
assert_nil pp.extension
|
68
|
+
assert_nil pp.search_directory
|
69
|
+
assert_nil pp.search_relative_path
|
70
|
+
assert_nil pp.search_relative_directory_path
|
71
|
+
assert_nil pp.search_relative_directory_parts
|
72
|
+
|
73
|
+
assert_equal pp.directory, pp.directory_parts.join
|
74
|
+
assert_equal pp.absolute_path, "#{pp.directory_parts.join}#{pp.basename}"
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_root_from_srd_1
|
78
|
+
|
79
|
+
srd = '/dir-1/dir-2'
|
80
|
+
|
81
|
+
pp = ParsedPath.new('/', srd)
|
82
|
+
|
83
|
+
assert_equal '/', pp.given_path
|
84
|
+
assert_equal '/', pp.absolute_path
|
85
|
+
assert_equal '/', pp.compare_path
|
86
|
+
assert_equal '/', pp.directory
|
87
|
+
assert_equal '/', pp.directory_path
|
88
|
+
assert_equal '/', pp.dirname
|
89
|
+
assert_equal [ '/' ], pp.directory_parts
|
90
|
+
assert_nil pp.file_full_name
|
91
|
+
assert_nil pp.basename
|
92
|
+
assert_nil pp.file_name_only
|
93
|
+
assert_nil pp.stem
|
94
|
+
assert_nil pp.file_extension
|
95
|
+
assert_nil pp.extension
|
96
|
+
assert_equal '/dir-1/dir-2/', pp.search_directory
|
97
|
+
assert_equal '../../', pp.search_relative_path
|
98
|
+
assert_equal '../../', pp.search_relative_directory_path
|
99
|
+
assert_equal [ '../', '../' ], pp.search_relative_directory_parts
|
100
|
+
|
101
|
+
assert_equal pp.directory, pp.directory_parts.join
|
102
|
+
assert_equal pp.absolute_path, "#{pp.directory_parts.join}#{pp.basename}"
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_root_from_srd_2
|
106
|
+
|
107
|
+
srd = '/'
|
108
|
+
|
109
|
+
pp = ParsedPath.new('/', srd)
|
110
|
+
|
111
|
+
assert_equal '/', pp.given_path
|
112
|
+
assert_equal '/', pp.absolute_path
|
113
|
+
assert_equal '/', pp.compare_path
|
114
|
+
assert_equal '/', pp.directory
|
115
|
+
assert_equal '/', pp.directory_path
|
116
|
+
assert_equal '/', pp.dirname
|
117
|
+
assert_equal [ '/' ], pp.directory_parts
|
118
|
+
assert_nil pp.file_full_name
|
119
|
+
assert_nil pp.basename
|
120
|
+
assert_nil pp.file_name_only
|
121
|
+
assert_nil pp.stem
|
122
|
+
assert_nil pp.file_extension
|
123
|
+
assert_nil pp.extension
|
124
|
+
assert_equal '/', pp.search_directory
|
125
|
+
assert_equal './', pp.search_relative_path
|
126
|
+
assert_equal './', pp.search_relative_directory_path
|
127
|
+
assert_equal [ './' ], pp.search_relative_directory_parts
|
128
|
+
|
129
|
+
assert_equal pp.directory, pp.directory_parts.join
|
130
|
+
assert_equal pp.absolute_path, "#{pp.directory_parts.join}#{pp.basename}"
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_rooted_one_dir
|
134
|
+
|
135
|
+
pp = ParsedPath.new('/abc/')
|
136
|
+
|
137
|
+
assert_equal '/abc/', pp.given_path
|
138
|
+
assert_equal '/abc/', pp.absolute_path
|
139
|
+
assert_equal '/abc/', pp.compare_path
|
140
|
+
assert_equal '/abc/', pp.directory
|
141
|
+
assert_equal '/abc/', pp.directory_path
|
142
|
+
assert_equal '/abc/', pp.dirname
|
143
|
+
assert_equal [ '/', 'abc/' ], pp.directory_parts
|
144
|
+
assert_nil pp.file_full_name
|
145
|
+
assert_nil pp.basename
|
146
|
+
assert_nil pp.file_name_only
|
147
|
+
assert_nil pp.stem
|
148
|
+
assert_nil pp.file_extension
|
149
|
+
assert_nil pp.extension
|
150
|
+
assert_nil pp.search_directory
|
151
|
+
assert_nil pp.search_relative_path
|
152
|
+
assert_nil pp.search_relative_directory_path
|
153
|
+
assert_nil pp.search_relative_directory_parts
|
154
|
+
|
155
|
+
assert_equal pp.directory, pp.directory_parts.join
|
156
|
+
assert_equal pp.absolute_path, "#{pp.directory_parts.join}#{pp.basename}"
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_rooted_one_dir_from_srd
|
160
|
+
|
161
|
+
srd = '/dir-1/dir-2'
|
162
|
+
|
163
|
+
pp = ParsedPath.new('/abc/', srd)
|
164
|
+
|
165
|
+
assert_equal '/abc/', pp.given_path
|
166
|
+
assert_equal '/abc/', pp.absolute_path
|
167
|
+
assert_equal '/abc/', pp.compare_path
|
168
|
+
assert_equal '/abc/', pp.directory
|
169
|
+
assert_equal '/abc/', pp.directory_path
|
170
|
+
assert_equal '/abc/', pp.dirname
|
171
|
+
assert_equal [ '/', 'abc/' ], pp.directory_parts
|
172
|
+
assert_nil pp.file_full_name
|
173
|
+
assert_nil pp.basename
|
174
|
+
assert_nil pp.file_name_only
|
175
|
+
assert_nil pp.stem
|
176
|
+
assert_nil pp.file_extension
|
177
|
+
assert_nil pp.extension
|
178
|
+
assert_equal '/dir-1/dir-2/', pp.search_directory
|
179
|
+
assert_equal '../../abc/', pp.search_relative_path
|
180
|
+
assert_equal '../../abc/', pp.search_relative_directory_path
|
181
|
+
assert_equal [ '../', '../', 'abc/' ], pp.search_relative_directory_parts
|
182
|
+
|
183
|
+
assert_equal pp.directory, pp.directory_parts.join
|
184
|
+
assert_equal pp.absolute_path, "#{pp.directory_parts.join}#{pp.basename}"
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_rooted_one_dir_with_trailing_dot
|
188
|
+
|
189
|
+
pp = ParsedPath.new('/abc/.')
|
190
|
+
|
191
|
+
assert_equal '/abc/.', pp.given_path
|
192
|
+
assert_equal '/abc/', pp.absolute_path
|
193
|
+
assert_equal '/abc/', pp.compare_path
|
194
|
+
assert_equal '/abc/', pp.directory
|
195
|
+
assert_equal '/abc/', pp.directory_path
|
196
|
+
assert_equal '/abc/', pp.dirname
|
197
|
+
assert_equal [ '/', 'abc/' ], pp.directory_parts
|
198
|
+
assert_nil pp.file_full_name
|
199
|
+
assert_nil pp.basename
|
200
|
+
assert_nil pp.file_name_only
|
201
|
+
assert_nil pp.stem
|
202
|
+
assert_nil pp.file_extension
|
203
|
+
assert_nil pp.extension
|
204
|
+
assert_nil pp.search_directory
|
205
|
+
assert_nil pp.search_relative_path
|
206
|
+
assert_nil pp.search_relative_directory_path
|
207
|
+
assert_nil pp.search_relative_directory_parts
|
208
|
+
|
209
|
+
assert_equal pp.directory, pp.directory_parts.join
|
210
|
+
assert_equal pp.absolute_path, "#{pp.directory_parts.join}#{pp.basename}"
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_rooted_one_file
|
214
|
+
|
215
|
+
pp = ParsedPath.new('/file.ext')
|
216
|
+
|
217
|
+
assert_equal '/file.ext', pp.given_path
|
218
|
+
assert_equal '/file.ext', pp.absolute_path
|
219
|
+
assert_equal '/file.ext', pp.compare_path
|
220
|
+
assert_equal '/', pp.directory
|
221
|
+
assert_equal '/', pp.directory_path
|
222
|
+
assert_equal '/', pp.dirname
|
223
|
+
assert_equal [ '/' ], pp.directory_parts
|
224
|
+
assert_equal 'file.ext', pp.file_full_name
|
225
|
+
assert_equal 'file.ext', pp.basename
|
226
|
+
assert_equal 'file', pp.file_name_only
|
227
|
+
assert_equal 'file', pp.stem
|
228
|
+
assert_equal '.ext', pp.file_extension
|
229
|
+
assert_equal '.ext', pp.extension
|
230
|
+
assert_nil pp.search_directory
|
231
|
+
assert_nil pp.search_relative_path
|
232
|
+
assert_nil pp.search_relative_directory_path
|
233
|
+
assert_nil pp.search_relative_directory_parts
|
234
|
+
|
235
|
+
assert_equal pp.directory, pp.directory_parts.join
|
236
|
+
assert_equal pp.absolute_path, "#{pp.directory_parts.join}#{pp.basename}"
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_rooted_one_file_from_srd1
|
240
|
+
|
241
|
+
srd = '/dir-1/dir-2'
|
242
|
+
|
243
|
+
pp = ParsedPath.new('/file.ext', srd)
|
244
|
+
|
245
|
+
assert_equal '/file.ext', pp.given_path
|
246
|
+
assert_equal '/file.ext', pp.absolute_path
|
247
|
+
assert_equal '/file.ext', pp.compare_path
|
248
|
+
assert_equal '/', pp.directory
|
249
|
+
assert_equal '/', pp.directory_path
|
250
|
+
assert_equal '/', pp.dirname
|
251
|
+
assert_equal [ '/' ], pp.directory_parts
|
252
|
+
assert_equal 'file.ext', pp.file_full_name
|
253
|
+
assert_equal 'file.ext', pp.basename
|
254
|
+
assert_equal 'file', pp.file_name_only
|
255
|
+
assert_equal 'file', pp.stem
|
256
|
+
assert_equal '.ext', pp.file_extension
|
257
|
+
assert_equal '.ext', pp.extension
|
258
|
+
assert_equal '/dir-1/dir-2/', pp.search_directory
|
259
|
+
assert_equal '../../file.ext', pp.search_relative_path
|
260
|
+
assert_equal '../../', pp.search_relative_directory_path
|
261
|
+
assert_equal [ '../', '../' ], pp.search_relative_directory_parts
|
262
|
+
|
263
|
+
assert_equal pp.directory, pp.directory_parts.join
|
264
|
+
assert_equal pp.absolute_path, "#{pp.directory_parts.join}#{pp.basename}"
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_rooted_one_file_without_extension
|
268
|
+
|
269
|
+
pp = ParsedPath.new('/file')
|
270
|
+
|
271
|
+
assert_equal '/file', pp.given_path
|
272
|
+
assert_equal '/file', pp.absolute_path
|
273
|
+
assert_equal '/file', pp.compare_path
|
274
|
+
assert_equal '/', pp.directory
|
275
|
+
assert_equal '/', pp.directory_path
|
276
|
+
assert_equal '/', pp.dirname
|
277
|
+
assert_equal [ '/' ], pp.directory_parts
|
278
|
+
assert_equal 'file', pp.file_full_name
|
279
|
+
assert_equal 'file', pp.basename
|
280
|
+
assert_equal 'file', pp.file_name_only
|
281
|
+
assert_equal 'file', pp.stem
|
282
|
+
assert_nil pp.file_extension
|
283
|
+
assert_nil pp.extension
|
284
|
+
assert_nil pp.search_directory
|
285
|
+
assert_nil pp.search_relative_path
|
286
|
+
assert_nil pp.search_relative_directory_path
|
287
|
+
assert_nil pp.search_relative_directory_parts
|
288
|
+
|
289
|
+
assert_equal pp.directory, pp.directory_parts.join
|
290
|
+
assert_equal pp.absolute_path, "#{pp.directory_parts.join}#{pp.basename}"
|
291
|
+
end
|
292
|
+
|
293
|
+
def test_rooted_one_file_without_stem
|
294
|
+
|
295
|
+
pp = ParsedPath.new('/.ext')
|
296
|
+
|
297
|
+
assert_equal '/.ext', pp.given_path
|
298
|
+
assert_equal '/.ext', pp.absolute_path
|
299
|
+
assert_equal '/.ext', pp.compare_path
|
300
|
+
assert_equal '/', pp.directory
|
301
|
+
assert_equal '/', pp.directory_path
|
302
|
+
assert_equal '/', pp.dirname
|
303
|
+
assert_equal [ '/' ], pp.directory_parts
|
304
|
+
assert_equal '.ext', pp.file_full_name
|
305
|
+
assert_equal '.ext', pp.basename
|
306
|
+
assert_nil pp.file_name_only
|
307
|
+
assert_nil pp.stem
|
308
|
+
assert_equal '.ext', pp.file_extension
|
309
|
+
assert_equal '.ext', pp.extension
|
310
|
+
assert_nil pp.search_directory
|
311
|
+
assert_nil pp.search_relative_path
|
312
|
+
assert_nil pp.search_relative_directory_path
|
313
|
+
assert_nil pp.search_relative_directory_parts
|
314
|
+
|
315
|
+
assert_equal pp.directory, pp.directory_parts.join
|
316
|
+
assert_equal pp.absolute_path, "#{pp.directory_parts.join}#{pp.basename}"
|
317
|
+
end
|
318
|
+
|
319
|
+
def test_rooted_one_long_path
|
320
|
+
|
321
|
+
pp = ParsedPath.new('/dir-1/dir-2/dir-3/dir-4/./dir-5/dir-6/../file.ext')
|
322
|
+
|
323
|
+
assert_equal '/dir-1/dir-2/dir-3/dir-4/./dir-5/dir-6/../file.ext', pp.given_path
|
324
|
+
assert_equal '/dir-1/dir-2/dir-3/dir-4/dir-5/file.ext', pp.absolute_path
|
325
|
+
assert_equal '/dir-1/dir-2/dir-3/dir-4/dir-5/file.ext', pp.compare_path
|
326
|
+
assert_equal '/dir-1/dir-2/dir-3/dir-4/dir-5/', pp.directory
|
327
|
+
assert_equal '/dir-1/dir-2/dir-3/dir-4/dir-5/', pp.directory_path
|
328
|
+
assert_equal '/dir-1/dir-2/dir-3/dir-4/dir-5/', pp.dirname
|
329
|
+
assert_equal [ '/', 'dir-1/', 'dir-2/', 'dir-3/', 'dir-4/', 'dir-5/' ], pp.directory_parts
|
330
|
+
assert_equal 'file.ext', pp.file_full_name
|
331
|
+
assert_equal 'file.ext', pp.basename
|
332
|
+
assert_equal 'file', pp.file_name_only
|
333
|
+
assert_equal 'file', pp.stem
|
334
|
+
assert_equal '.ext', pp.file_extension
|
335
|
+
assert_equal '.ext', pp.extension
|
336
|
+
assert_nil pp.search_directory
|
337
|
+
assert_nil pp.search_relative_path
|
338
|
+
assert_nil pp.search_relative_directory_path
|
339
|
+
assert_nil pp.search_relative_directory_parts
|
340
|
+
|
341
|
+
assert_equal pp.directory, pp.directory_parts.join
|
342
|
+
assert_equal pp.absolute_path, "#{pp.directory_parts.join}#{pp.basename}"
|
343
|
+
end
|
344
|
+
|
345
|
+
def test_rooted_one_long_path_with_short_directory_names
|
346
|
+
|
347
|
+
pp = ParsedPath.new('/1/2/3/4/./5/6/../file.ext')
|
348
|
+
|
349
|
+
assert_equal '/1/2/3/4/./5/6/../file.ext', pp.given_path
|
350
|
+
assert_equal '/1/2/3/4/5/file.ext', pp.absolute_path
|
351
|
+
assert_equal '/1/2/3/4/5/file.ext', pp.compare_path
|
352
|
+
assert_equal '/1/2/3/4/5/', pp.directory
|
353
|
+
assert_equal '/1/2/3/4/5/', pp.directory_path
|
354
|
+
assert_equal '/1/2/3/4/5/', pp.dirname
|
355
|
+
assert_equal [ '/', '1/', '2/', '3/', '4/', '5/' ], pp.directory_parts
|
356
|
+
assert_equal 'file.ext', pp.file_full_name
|
357
|
+
assert_equal 'file.ext', pp.basename
|
358
|
+
assert_equal 'file', pp.file_name_only
|
359
|
+
assert_equal 'file', pp.stem
|
360
|
+
assert_equal '.ext', pp.file_extension
|
361
|
+
assert_equal '.ext', pp.extension
|
362
|
+
assert_nil pp.search_directory
|
363
|
+
assert_nil pp.search_relative_path
|
364
|
+
assert_nil pp.search_relative_directory_path
|
365
|
+
assert_nil pp.search_relative_directory_parts
|
366
|
+
|
367
|
+
assert_equal pp.directory, pp.directory_parts.join
|
368
|
+
assert_equal pp.absolute_path, "#{pp.directory_parts.join}#{pp.basename}"
|
369
|
+
end
|
370
|
+
|
371
|
+
def test_unrooted_one_file
|
372
|
+
|
373
|
+
pwd = '/some-directory'
|
374
|
+
|
375
|
+
pp = ParsedPath.new('file.ext', pwd: pwd)
|
376
|
+
|
377
|
+
assert_equal 'file.ext', pp.given_path
|
378
|
+
assert_equal '/some-directory/file.ext', pp.absolute_path
|
379
|
+
assert_equal '/some-directory/file.ext', pp.compare_path
|
380
|
+
assert_equal '/some-directory/', pp.directory
|
381
|
+
assert_equal '/some-directory/', pp.directory_path
|
382
|
+
assert_equal '/some-directory/', pp.dirname
|
383
|
+
assert_equal [ '/', 'some-directory/' ], pp.directory_parts
|
384
|
+
assert_equal 'file.ext', pp.file_full_name
|
385
|
+
assert_equal 'file.ext', pp.basename
|
386
|
+
assert_equal 'file', pp.file_name_only
|
387
|
+
assert_equal 'file', pp.stem
|
388
|
+
assert_equal '.ext', pp.file_extension
|
389
|
+
assert_equal '.ext', pp.extension
|
390
|
+
assert_nil pp.search_directory
|
391
|
+
assert_nil pp.search_relative_path
|
392
|
+
assert_nil pp.search_relative_directory_path
|
393
|
+
assert_nil pp.search_relative_directory_parts
|
394
|
+
|
395
|
+
assert_equal pp.directory, pp.directory_parts.join
|
396
|
+
assert_equal pp.absolute_path, "#{pp.directory_parts.join}#{pp.basename}"
|
397
|
+
end
|
398
|
+
|
399
|
+
def test_unrooted_one_file_from_srd
|
400
|
+
|
401
|
+
pwd = '/some-directory'
|
402
|
+
srd = '/dir-1/dir-2/'
|
403
|
+
|
404
|
+
pp = ParsedPath.new('file.ext', srd, pwd: pwd)
|
405
|
+
|
406
|
+
assert_equal 'file.ext', pp.given_path
|
407
|
+
assert_equal '/some-directory/file.ext', pp.absolute_path
|
408
|
+
assert_equal '/some-directory/file.ext', pp.compare_path
|
409
|
+
assert_equal '/some-directory/', pp.directory
|
410
|
+
assert_equal '/some-directory/', pp.directory_path
|
411
|
+
assert_equal '/some-directory/', pp.dirname
|
412
|
+
assert_equal [ '/', 'some-directory/' ], pp.directory_parts
|
413
|
+
assert_equal 'file.ext', pp.file_full_name
|
414
|
+
assert_equal 'file.ext', pp.basename
|
415
|
+
assert_equal 'file', pp.file_name_only
|
416
|
+
assert_equal 'file', pp.stem
|
417
|
+
assert_equal '.ext', pp.file_extension
|
418
|
+
assert_equal '.ext', pp.extension
|
419
|
+
assert_equal srd, pp.search_directory
|
420
|
+
assert_equal '../../some-directory/file.ext', pp.search_relative_path
|
421
|
+
assert_equal '../../some-directory/', pp.search_relative_directory_path
|
422
|
+
assert_equal [ '../', '../', 'some-directory/' ], pp.search_relative_directory_parts
|
423
|
+
|
424
|
+
assert_equal pp.directory, pp.directory_parts.join
|
425
|
+
assert_equal pp.absolute_path, "#{pp.directory_parts.join}#{pp.basename}"
|
426
|
+
end
|
427
|
+
|
428
|
+
def test_unrooted_dir_file
|
429
|
+
|
430
|
+
pwd = '/some-directory'
|
431
|
+
|
432
|
+
pp = ParsedPath.new('sub-dir/file.ext', pwd: pwd)
|
433
|
+
|
434
|
+
assert_equal 'sub-dir/file.ext', pp.given_path
|
435
|
+
assert_equal '/some-directory/sub-dir/file.ext', pp.absolute_path
|
436
|
+
assert_equal '/some-directory/sub-dir/file.ext', pp.compare_path
|
437
|
+
assert_equal '/some-directory/sub-dir/', pp.directory
|
438
|
+
assert_equal '/some-directory/sub-dir/', pp.directory_path
|
439
|
+
assert_equal '/some-directory/sub-dir/', pp.dirname
|
440
|
+
assert_equal [ '/', 'some-directory/', 'sub-dir/' ], pp.directory_parts
|
441
|
+
assert_equal 'file.ext', pp.file_full_name
|
442
|
+
assert_equal 'file.ext', pp.basename
|
443
|
+
assert_equal 'file', pp.file_name_only
|
444
|
+
assert_equal 'file', pp.stem
|
445
|
+
assert_equal '.ext', pp.file_extension
|
446
|
+
assert_equal '.ext', pp.extension
|
447
|
+
assert_nil pp.search_directory
|
448
|
+
assert_nil pp.search_relative_path
|
449
|
+
assert_nil pp.search_relative_directory_path
|
450
|
+
assert_nil pp.search_relative_directory_parts
|
451
|
+
|
452
|
+
assert_equal pp.directory, pp.directory_parts.join
|
453
|
+
assert_equal pp.absolute_path, "#{pp.directory_parts.join}#{pp.basename}"
|
454
|
+
end
|
455
|
+
|
456
|
+
def test_unrooted_dir_file_2
|
457
|
+
|
458
|
+
locator = Object.new
|
459
|
+
|
460
|
+
locator.define_singleton_method(:pwd) { '/some-directory' }
|
461
|
+
|
462
|
+
pp = ParsedPath.new('sub-dir/file.ext', locator: locator)
|
463
|
+
|
464
|
+
assert_equal 'sub-dir/file.ext', pp.given_path
|
465
|
+
assert_equal '/some-directory/sub-dir/file.ext', pp.absolute_path
|
466
|
+
assert_equal '/some-directory/sub-dir/file.ext', pp.compare_path
|
467
|
+
assert_equal '/some-directory/sub-dir/', pp.directory
|
468
|
+
assert_equal '/some-directory/sub-dir/', pp.directory_path
|
469
|
+
assert_equal '/some-directory/sub-dir/', pp.dirname
|
470
|
+
assert_equal [ '/', 'some-directory/', 'sub-dir/' ], pp.directory_parts
|
471
|
+
assert_equal 'file.ext', pp.file_full_name
|
472
|
+
assert_equal 'file.ext', pp.basename
|
473
|
+
assert_equal 'file', pp.file_name_only
|
474
|
+
assert_equal 'file', pp.stem
|
475
|
+
assert_equal '.ext', pp.file_extension
|
476
|
+
assert_equal '.ext', pp.extension
|
477
|
+
assert_nil pp.search_directory
|
478
|
+
assert_nil pp.search_relative_path
|
479
|
+
assert_nil pp.search_relative_directory_path
|
480
|
+
assert_nil pp.search_relative_directory_parts
|
481
|
+
|
482
|
+
assert_equal pp.directory, pp.directory_parts.join
|
483
|
+
assert_equal pp.absolute_path, "#{pp.directory_parts.join}#{pp.basename}"
|
484
|
+
end
|
485
|
+
|
486
|
+
def test_recls_stat_case_1
|
487
|
+
|
488
|
+
pwd = '/Users/matthewwilson/dev/freelibs/recls/100/recls.Ruby/trunk/'
|
489
|
+
srd = '.'
|
490
|
+
|
491
|
+
pp = ParsedPath.new('.', srd, pwd: pwd)
|
492
|
+
|
493
|
+
assert_equal '.', pp.given_path
|
494
|
+
assert_equal pwd, pp.absolute_path
|
495
|
+
assert_equal pwd, pp.compare_path
|
496
|
+
assert_equal pwd, pp.directory
|
497
|
+
assert_equal pwd, pp.directory_path
|
498
|
+
assert_equal pwd, pp.dirname
|
499
|
+
assert_equal [ '/', 'Users/', 'matthewwilson/', 'dev/', 'freelibs/', 'recls/', '100/', 'recls.Ruby/', 'trunk/' ], pp.directory_parts
|
500
|
+
assert_nil pp.file_full_name
|
501
|
+
assert_nil pp.basename
|
502
|
+
assert_nil pp.file_name_only
|
503
|
+
assert_nil pp.stem
|
504
|
+
assert_nil pp.file_extension
|
505
|
+
assert_nil pp.extension
|
506
|
+
assert_equal pwd, pp.search_directory
|
507
|
+
assert_equal './', pp.search_relative_path
|
508
|
+
assert_equal './', pp.search_relative_directory_path
|
509
|
+
assert_equal [ './' ], pp.search_relative_directory_parts
|
510
|
+
end
|
511
|
+
|
512
|
+
def test_recls_stat_case_2
|
513
|
+
|
514
|
+
pwd = '/Users/matthewwilson/dev/freelibs/recls/100/recls.Ruby/trunk/'
|
515
|
+
home = '/Users/matthewwilson'
|
516
|
+
srd = '~'
|
517
|
+
|
518
|
+
pp = ParsedPath.new('.', srd, home: home, pwd: pwd)
|
519
|
+
|
520
|
+
assert_equal '.', pp.given_path
|
521
|
+
assert_equal pwd, pp.absolute_path
|
522
|
+
assert_equal pwd, pp.compare_path
|
523
|
+
assert_equal pwd, pp.directory
|
524
|
+
assert_equal pwd, pp.directory_path
|
525
|
+
assert_equal pwd, pp.dirname
|
526
|
+
assert_equal [ '/', 'Users/', 'matthewwilson/', 'dev/', 'freelibs/', 'recls/', '100/', 'recls.Ruby/', 'trunk/' ], pp.directory_parts
|
527
|
+
assert_nil pp.file_full_name
|
528
|
+
assert_nil pp.basename
|
529
|
+
assert_nil pp.file_name_only
|
530
|
+
assert_nil pp.stem
|
531
|
+
assert_nil pp.file_extension
|
532
|
+
assert_nil pp.extension
|
533
|
+
assert_equal '/Users/matthewwilson/', pp.search_directory
|
534
|
+
assert_equal 'dev/freelibs/recls/100/recls.Ruby/trunk/', pp.search_relative_path
|
535
|
+
assert_equal 'dev/freelibs/recls/100/recls.Ruby/trunk/', pp.search_relative_directory_path
|
536
|
+
assert_equal [ 'dev/', 'freelibs/', 'recls/', '100/', 'recls.Ruby/', 'trunk/' ], pp.search_relative_directory_parts
|
537
|
+
end
|
538
|
+
|
539
|
+
def test_recls_stat_case_3
|
540
|
+
|
541
|
+
pwd = '/Users/matthewwilson/dev/freelibs/recls/100/recls.Ruby/trunk/'
|
542
|
+
home = '/Users/matthewwilson'
|
543
|
+
srd = '.'
|
544
|
+
|
545
|
+
pp = ParsedPath.new('~', srd, home: home, pwd: pwd)
|
546
|
+
|
547
|
+
assert_equal '~', pp.given_path
|
548
|
+
assert_equal '/Users/matthewwilson/', pp.absolute_path
|
549
|
+
assert_equal '/Users/matthewwilson/', pp.compare_path
|
550
|
+
assert_equal '/Users/matthewwilson/', pp.directory
|
551
|
+
assert_equal '/Users/matthewwilson/', pp.directory_path
|
552
|
+
assert_equal '/Users/matthewwilson/', pp.dirname
|
553
|
+
assert_equal [ '/', 'Users/', 'matthewwilson/' ], pp.directory_parts
|
554
|
+
assert_nil pp.file_full_name
|
555
|
+
assert_nil pp.basename
|
556
|
+
assert_nil pp.file_name_only
|
557
|
+
assert_nil pp.stem
|
558
|
+
assert_nil pp.file_extension
|
559
|
+
assert_nil pp.extension
|
560
|
+
assert_equal pwd, pp.search_directory
|
561
|
+
assert_equal '../../../../../../', pp.search_relative_path
|
562
|
+
assert_equal '../../../../../../', pp.search_relative_directory_path
|
563
|
+
assert_equal [ '../', '../', '../', '../', '../', '../' ], pp.search_relative_directory_parts
|
564
|
+
end
|
564
565
|
end
|
565
566
|
|
567
|
+
|
568
|
+
# ############################## end of file ############################# #
|
569
|
+
|