libpath-ruby 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +61 -0
  3. data/examples/path_from_arg0.md +99 -0
  4. data/examples/path_from_arg0.rb +55 -0
  5. data/lib/libpath.rb +12 -0
  6. data/lib/libpath/constants.rb +42 -0
  7. data/lib/libpath/constants/unix.rb +146 -0
  8. data/lib/libpath/constants/windows.rb +147 -0
  9. data/lib/libpath/diagnostics.rb +6 -0
  10. data/lib/libpath/diagnostics/parameter_checking.rb +46 -0
  11. data/lib/libpath/exceptions.rb +7 -0
  12. data/lib/libpath/exceptions/libpath_base_exception.rb +77 -0
  13. data/lib/libpath/exceptions/malformed_name_exception.rb +85 -0
  14. data/lib/libpath/form.rb +42 -0
  15. data/lib/libpath/form/unix.rb +215 -0
  16. data/lib/libpath/form/windows.rb +358 -0
  17. data/lib/libpath/internal_/array.rb +96 -0
  18. data/lib/libpath/internal_/platform.rb +53 -0
  19. data/lib/libpath/internal_/string.rb +33 -0
  20. data/lib/libpath/internal_/unix/form.rb +160 -0
  21. data/lib/libpath/internal_/windows/drive.rb +84 -0
  22. data/lib/libpath/internal_/windows/form.rb +281 -0
  23. data/lib/libpath/libpath.rb +6 -0
  24. data/lib/libpath/path.rb +43 -0
  25. data/lib/libpath/path/unix.rb +170 -0
  26. data/lib/libpath/path/windows.rb +176 -0
  27. data/lib/libpath/util.rb +42 -0
  28. data/lib/libpath/util/unix.rb +414 -0
  29. data/lib/libpath/util/windows.rb +636 -0
  30. data/lib/libpath/version.rb +73 -0
  31. data/test/performance/benchmark_drive_letter.rb +31 -0
  32. data/test/performance/benchmark_gsub_string_or_regex.rb +45 -0
  33. data/test/performance/benchmark_rindex2.rb +109 -0
  34. data/test/performance/benchmark_split.rb +32 -0
  35. data/test/unit/compare/ts_all.rb +22 -0
  36. data/test/unit/equate/ts_all.rb +22 -0
  37. data/test/unit/equate/unix/ts_all.rb +22 -0
  38. data/test/unit/equate/windows/ts_all.rb +22 -0
  39. data/test/unit/exceptions/tc_libpath_base_exception.rb +27 -0
  40. data/test/unit/exceptions/tc_malformed_name_exception.rb +31 -0
  41. data/test/unit/exceptions/ts_all.rb +22 -0
  42. data/test/unit/form/tc_absolute_functions.rb +369 -0
  43. data/test/unit/form/ts_all.rb +22 -0
  44. data/test/unit/form/unix/tc_absolute_functions.rb +269 -0
  45. data/test/unit/form/unix/ts_all.rb +22 -0
  46. data/test/unit/form/windows/tc_absolute_functions.rb +854 -0
  47. data/test/unit/form/windows/ts_all.rb +22 -0
  48. data/test/unit/internal_/tc_array.rb +62 -0
  49. data/test/unit/internal_/ts_all.rb +22 -0
  50. data/test/unit/internal_/unix/form/tc_slash_functions.rb +60 -0
  51. data/test/unit/internal_/unix/form/ts_all.rb +22 -0
  52. data/test/unit/internal_/unix/tc_split_path.rb +396 -0
  53. data/test/unit/internal_/unix/ts_all.rb +22 -0
  54. data/test/unit/internal_/windows/form/tc_get_windows_volume.rb +220 -0
  55. data/test/unit/internal_/windows/form/tc_slash_functions.rb +61 -0
  56. data/test/unit/internal_/windows/form/ts_all.rb +22 -0
  57. data/test/unit/internal_/windows/tc_split_path.rb +881 -0
  58. data/test/unit/internal_/windows/ts_all.rb +22 -0
  59. data/test/unit/parse/ts_all.rb +22 -0
  60. data/test/unit/path/tc_path.rb +778 -0
  61. data/test/unit/path/ts_all.rb +22 -0
  62. data/test/unit/path/unix/tc_path.rb +565 -0
  63. data/test/unit/path/unix/ts_all.rb +22 -0
  64. data/test/unit/path/windows/tc_path.rb +630 -0
  65. data/test/unit/path/windows/ts_all.rb +22 -0
  66. data/test/unit/tc_version.rb +47 -0
  67. data/test/unit/ts_all.rb +22 -0
  68. data/test/unit/util/tc_combine_paths.rb +179 -0
  69. data/test/unit/util/tc_derive_relative_path.rb +19 -0
  70. data/test/unit/util/tc_make_path_canonical.rb +228 -0
  71. data/test/unit/util/ts_all.rb +22 -0
  72. data/test/unit/util/unix/tc_combine_paths.rb +65 -0
  73. data/test/unit/util/unix/tc_derive_relative_path.rb +123 -0
  74. data/test/unit/util/unix/tc_make_path_absolute.rb +117 -0
  75. data/test/unit/util/unix/tc_make_path_canonical.rb +139 -0
  76. data/test/unit/util/unix/ts_all.rb +22 -0
  77. data/test/unit/util/windows/tc_combine_paths.rb +131 -0
  78. data/test/unit/util/windows/tc_derive_relative_path.rb +155 -0
  79. data/test/unit/util/windows/tc_make_path_absolute.rb +163 -0
  80. data/test/unit/util/windows/tc_make_path_canonical.rb +220 -0
  81. data/test/unit/util/windows/ts_all.rb +22 -0
  82. 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,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,778 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 3), 'lib')
4
+
5
+ require 'libpath/path'
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_Path < Test::Unit::TestCase
14
+
15
+ def test_LibPath_module_exists
16
+
17
+ assert defined?(::LibPath)
18
+ end
19
+
20
+ def test_LibPath_Path_module_exists
21
+
22
+ assert defined?(::LibPath::Path)
23
+ end
24
+
25
+ def test_LibPath_Path_ParsedPath_class_exists
26
+
27
+ assert defined?(::LibPath::Path::ParsedPath)
28
+ end
29
+ end
30
+
31
+ class Test_LibPath_Path_ParsedPath < Test::Unit::TestCase
32
+
33
+ include ::LibPath::Path
34
+
35
+ def test_nil
36
+
37
+ assert_raise(::ArgumentError) { ParsedPath.new(nil) }
38
+ end
39
+
40
+ def test_empty
41
+
42
+ assert_raise(::ArgumentError) { ParsedPath.new('') }
43
+ end
44
+
45
+ def test_root
46
+
47
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
48
+
49
+ pp = ParsedPath.new('C:\\')
50
+
51
+ assert_equal 'C:\\', pp.given_path
52
+ assert_equal 'C:\\', pp.absolute_path
53
+ assert_equal 'C:\\', pp.compare_path
54
+ assert_equal 'C:', pp.volume
55
+ assert_equal '\\', pp.directory
56
+ assert_equal 'C:\\', pp.directory_path
57
+ assert_equal 'C:\\', pp.dirname
58
+ assert_equal [ '\\' ], pp.directory_parts
59
+
60
+ volume = pp.volume
61
+ else
62
+
63
+ pp = ParsedPath.new('/')
64
+
65
+ assert_equal '/', pp.given_path
66
+ assert_equal '/', pp.absolute_path
67
+ assert_equal '/', pp.compare_path
68
+ assert_equal '/', pp.directory
69
+ assert_equal '/', pp.directory_path
70
+ assert_equal '/', pp.dirname
71
+ assert_equal [ '/' ], pp.directory_parts
72
+
73
+ volume = nil
74
+ end
75
+ assert_nil pp.file_full_name
76
+ assert_nil pp.basename
77
+ assert_nil pp.file_name_only
78
+ assert_nil pp.stem
79
+ assert_nil pp.file_extension
80
+ assert_nil pp.extension
81
+ assert_nil pp.search_directory
82
+ assert_nil pp.search_relative_path
83
+ assert_nil pp.search_relative_directory_path
84
+ assert_nil pp.search_relative_directory_parts
85
+
86
+ assert_equal pp.directory, pp.directory_parts.join
87
+ assert_equal pp.absolute_path, "#{volume}#{pp.directory_parts.join}#{pp.basename}"
88
+ end
89
+
90
+ def test_root_from_srd_1
91
+
92
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
93
+
94
+ srd = 'C:/dir-1/dir-2'
95
+
96
+ pp = ParsedPath.new('C:\\', srd)
97
+
98
+ assert_equal 'C:\\', pp.given_path
99
+ assert_equal 'C:\\', pp.absolute_path
100
+ assert_equal 'C:\\', pp.compare_path
101
+ assert_equal 'C:', pp.volume
102
+ assert_equal '\\', pp.directory
103
+ assert_equal 'C:\\', pp.directory_path
104
+ assert_equal 'C:\\', pp.dirname
105
+ assert_equal [ '\\' ], pp.directory_parts
106
+
107
+ volume = pp.volume
108
+ else
109
+
110
+ srd = '/dir-1/dir-2'
111
+
112
+ pp = ParsedPath.new('/', srd)
113
+
114
+ assert_equal '/', pp.given_path
115
+ assert_equal '/', pp.absolute_path
116
+ assert_equal '/', pp.compare_path
117
+ assert_equal '/', pp.directory
118
+ assert_equal '/', pp.directory_path
119
+ assert_equal '/', pp.dirname
120
+ assert_equal [ '/' ], pp.directory_parts
121
+
122
+ volume = nil
123
+ end
124
+ assert_nil pp.file_full_name
125
+ assert_nil pp.basename
126
+ assert_nil pp.file_name_only
127
+ assert_nil pp.stem
128
+ assert_nil pp.file_extension
129
+ assert_nil pp.extension
130
+
131
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
132
+
133
+ assert_equal 'C:\\dir-1\\dir-2\\', pp.search_directory
134
+ assert_equal '..\\..\\', pp.search_relative_path
135
+ assert_equal '..\\..\\', pp.search_relative_directory_path
136
+ assert_equal [ '..\\', '..\\' ], pp.search_relative_directory_parts
137
+ else
138
+
139
+ assert_equal '/dir-1/dir-2/', pp.search_directory
140
+ assert_equal '../../', pp.search_relative_path
141
+ assert_equal '../../', pp.search_relative_directory_path
142
+ assert_equal [ '../', '../' ], pp.search_relative_directory_parts
143
+ end
144
+
145
+ assert_equal pp.directory, pp.directory_parts.join
146
+ assert_equal pp.absolute_path, "#{volume}#{pp.directory_parts.join}#{pp.basename}"
147
+ end
148
+
149
+ def test_root_from_srd_2
150
+
151
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
152
+
153
+ srd = 'C:/'
154
+
155
+ pp = ParsedPath.new('C:\\', srd)
156
+
157
+ assert_equal 'C:\\', pp.given_path
158
+ assert_equal 'C:\\', pp.absolute_path
159
+ assert_equal 'C:\\', pp.compare_path
160
+ assert_equal 'C:', pp.volume
161
+ assert_equal '\\', pp.directory
162
+ assert_equal 'C:\\', pp.directory_path
163
+ assert_equal 'C:\\', pp.dirname
164
+ assert_equal [ '\\' ], pp.directory_parts
165
+
166
+ volume = pp.volume
167
+ else
168
+
169
+ srd = '/'
170
+
171
+ pp = ParsedPath.new('/', srd)
172
+
173
+ assert_equal '/', pp.given_path
174
+ assert_equal '/', pp.absolute_path
175
+ assert_equal '/', pp.compare_path
176
+ assert_equal '/', pp.directory
177
+ assert_equal '/', pp.directory_path
178
+ assert_equal '/', pp.dirname
179
+ assert_equal [ '/' ], pp.directory_parts
180
+
181
+ volume = nil
182
+ end
183
+ assert_nil pp.file_full_name
184
+ assert_nil pp.basename
185
+ assert_nil pp.file_name_only
186
+ assert_nil pp.stem
187
+ assert_nil pp.file_extension
188
+ assert_nil pp.extension
189
+
190
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
191
+
192
+ assert_equal 'C:\\', pp.search_directory
193
+ assert_equal '.\\', pp.search_relative_path
194
+ assert_equal '.\\', pp.search_relative_directory_path
195
+ assert_equal [ '.\\' ], pp.search_relative_directory_parts
196
+ else
197
+
198
+ assert_equal '/', pp.search_directory
199
+ assert_equal './', pp.search_relative_path
200
+ assert_equal './', pp.search_relative_directory_path
201
+ assert_equal [ './' ], pp.search_relative_directory_parts
202
+ end
203
+
204
+ assert_equal pp.directory, pp.directory_parts.join
205
+ assert_equal pp.absolute_path, "#{volume}#{pp.directory_parts.join}#{pp.basename}"
206
+ end
207
+
208
+ def test_rooted_one_dir
209
+
210
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
211
+
212
+ pp = ParsedPath.new('G:\\abc\\')
213
+
214
+ assert_equal 'G:\\abc\\', pp.given_path
215
+ assert_equal 'G:\\abc\\', pp.absolute_path
216
+ assert_equal 'G:\\ABC\\', pp.compare_path
217
+ assert_equal '\\abc\\', pp.directory
218
+ assert_equal 'G:', pp.volume
219
+ assert_equal 'G:\\abc\\', pp.directory_path
220
+ assert_equal 'G:\\abc\\', pp.dirname
221
+ assert_equal [ '\\', 'abc\\' ], pp.directory_parts
222
+
223
+ volume = pp.volume
224
+ else
225
+
226
+ pp = ParsedPath.new('/abc//')
227
+
228
+ assert_equal '/abc//', pp.given_path
229
+ assert_equal '/abc/', pp.absolute_path
230
+ assert_equal '/abc/', pp.compare_path
231
+ assert_equal '/abc/', pp.directory
232
+ assert_equal '/abc/', pp.directory_path
233
+ assert_equal '/abc/', pp.dirname
234
+ assert_equal [ '/', 'abc/' ], pp.directory_parts
235
+
236
+ volume = nil
237
+ end
238
+ assert_nil pp.file_full_name
239
+ assert_nil pp.basename
240
+ assert_nil pp.file_name_only
241
+ assert_nil pp.stem
242
+ assert_nil pp.file_extension
243
+ assert_nil pp.extension
244
+ assert_nil pp.search_directory
245
+ assert_nil pp.search_relative_path
246
+ assert_nil pp.search_relative_directory_path
247
+ assert_nil pp.search_relative_directory_parts
248
+
249
+ assert_equal pp.directory, pp.directory_parts.join
250
+ assert_equal pp.absolute_path, "#{volume}#{pp.directory_parts.join}#{pp.basename}"
251
+ end
252
+
253
+ def test_rooted_one_dir_from_srd
254
+
255
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
256
+
257
+ srd = 'G:/dir-1/dir-2'
258
+
259
+ pp = ParsedPath.new('G:\\\\abc\\\\', srd)
260
+
261
+ assert_equal 'G:\\\\abc\\\\', pp.given_path
262
+ assert_equal 'G:\\abc\\', pp.absolute_path
263
+ assert_equal 'G:\\ABC\\', pp.compare_path
264
+ assert_equal '\\abc\\', pp.directory
265
+ assert_equal 'G:', pp.volume
266
+ assert_equal 'G:\\abc\\', pp.directory_path
267
+ assert_equal 'G:\\abc\\', pp.dirname
268
+ assert_equal [ '\\', 'abc\\' ], pp.directory_parts
269
+
270
+ volume = pp.volume
271
+ else
272
+
273
+ srd = '/dir-1/dir-2'
274
+
275
+ pp = ParsedPath.new('//abc//', srd)
276
+
277
+ assert_equal '//abc//', pp.given_path
278
+ assert_equal '/abc/', pp.absolute_path
279
+ assert_equal '/abc/', pp.compare_path
280
+ assert_equal '/abc/', pp.directory
281
+ assert_equal '/abc/', pp.directory_path
282
+ assert_equal '/abc/', pp.dirname
283
+ assert_equal [ '/', 'abc/' ], pp.directory_parts
284
+
285
+ volume = nil
286
+ end
287
+ assert_nil pp.file_full_name
288
+ assert_nil pp.basename
289
+ assert_nil pp.file_name_only
290
+ assert_nil pp.stem
291
+ assert_nil pp.file_extension
292
+ assert_nil pp.extension
293
+
294
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
295
+
296
+ assert_equal 'G:\\dir-1\\dir-2\\', pp.search_directory
297
+ assert_equal '..\\..\\abc\\', pp.search_relative_path
298
+ assert_equal '..\\..\\abc\\', pp.search_relative_directory_path
299
+ assert_equal [ '..\\', '..\\', 'abc\\' ], pp.search_relative_directory_parts
300
+ else
301
+
302
+ end
303
+
304
+ assert_equal pp.directory, pp.directory_parts.join
305
+ assert_equal pp.absolute_path, "#{volume}#{pp.directory_parts.join}#{pp.basename}"
306
+ end
307
+
308
+ def test_rooted_one_dir_with_trailing_dot
309
+
310
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
311
+
312
+ pp = ParsedPath.new('G:\\abc\\.')
313
+
314
+ assert_equal 'G:\\abc\\.', pp.given_path
315
+ assert_equal 'G:\\abc\\', pp.absolute_path
316
+ assert_equal 'G:\\ABC\\', pp.compare_path
317
+ assert_equal 'G:', pp.volume
318
+ assert_equal '\\abc\\', pp.directory
319
+ assert_equal 'G:\\abc\\', pp.directory_path
320
+ assert_equal 'G:\\abc\\', pp.dirname
321
+ assert_equal [ '\\', 'abc\\' ], pp.directory_parts
322
+
323
+ volume = pp.volume
324
+ else
325
+
326
+ pp = ParsedPath.new('/abc/.')
327
+
328
+ assert_equal '/abc/.', pp.given_path
329
+ assert_equal '/abc/', pp.absolute_path
330
+ assert_equal '/abc/', pp.compare_path
331
+ assert_equal '/abc/', pp.directory
332
+ assert_equal '/abc/', pp.directory_path
333
+ assert_equal '/abc/', pp.dirname
334
+ assert_equal [ '/', 'abc/' ], pp.directory_parts
335
+
336
+ volume = nil
337
+ end
338
+ assert_nil pp.file_full_name
339
+ assert_nil pp.basename
340
+ assert_nil pp.file_name_only
341
+ assert_nil pp.stem
342
+ assert_nil pp.file_extension
343
+ assert_nil pp.extension
344
+ assert_nil pp.search_directory
345
+ assert_nil pp.search_relative_path
346
+ assert_nil pp.search_relative_directory_path
347
+ assert_nil pp.search_relative_directory_parts
348
+
349
+ assert_equal pp.directory, pp.directory_parts.join
350
+ assert_equal pp.absolute_path, "#{volume}#{pp.directory_parts.join}#{pp.basename}"
351
+ end
352
+
353
+ def test_rooted_one_file
354
+
355
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
356
+
357
+ pp = ParsedPath.new('G:\\file.ext')
358
+
359
+ assert_equal 'G:\\file.ext', pp.given_path
360
+ assert_equal 'G:\\file.ext', pp.absolute_path
361
+ assert_equal 'G:\\FILE.EXT', pp.compare_path
362
+ assert_equal 'G:', pp.volume
363
+ assert_equal '\\', pp.directory
364
+ assert_equal 'G:\\', pp.directory_path
365
+ assert_equal 'G:\\', pp.dirname
366
+ assert_equal [ '\\' ], pp.directory_parts
367
+
368
+ volume = pp.volume
369
+ else
370
+
371
+ pp = ParsedPath.new('/file.ext')
372
+
373
+ assert_equal '/file.ext', pp.given_path
374
+ assert_equal '/file.ext', pp.absolute_path
375
+ assert_equal '/file.ext', pp.compare_path
376
+ assert_equal '/', pp.directory
377
+ assert_equal '/', pp.directory_path
378
+ assert_equal '/', pp.dirname
379
+ assert_equal [ '/' ], pp.directory_parts
380
+
381
+ volume = nil
382
+ end
383
+ assert_equal 'file.ext', pp.file_full_name
384
+ assert_equal 'file.ext', pp.basename
385
+ assert_equal 'file', pp.file_name_only
386
+ assert_equal 'file', pp.stem
387
+ assert_equal '.ext', pp.file_extension
388
+ assert_equal '.ext', pp.extension
389
+ assert_nil pp.search_directory
390
+ assert_nil pp.search_relative_path
391
+ assert_nil pp.search_relative_directory_path
392
+ assert_nil pp.search_relative_directory_parts
393
+
394
+ assert_equal pp.directory, pp.directory_parts.join
395
+ assert_equal pp.absolute_path, "#{volume}#{pp.directory_parts.join}#{pp.basename}"
396
+ end
397
+
398
+ def test_rooted_one_file_without_extension
399
+
400
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
401
+
402
+ pp = ParsedPath.new('G:\\file')
403
+
404
+ assert_equal 'G:\\file', pp.given_path
405
+ assert_equal 'G:\\file', pp.absolute_path
406
+ assert_equal 'G:\\FILE', pp.compare_path
407
+ assert_equal 'G:', pp.volume
408
+ assert_equal '\\', pp.directory
409
+ assert_equal 'G:\\', pp.directory_path
410
+ assert_equal 'G:\\', pp.dirname
411
+ assert_equal [ '\\' ], pp.directory_parts
412
+
413
+ volume = pp.volume
414
+ else
415
+
416
+ pp = ParsedPath.new('/file')
417
+
418
+ assert_equal '/file', pp.given_path
419
+ assert_equal '/file', pp.absolute_path
420
+ assert_equal '/file', pp.compare_path
421
+ assert_equal '/', pp.directory
422
+ assert_equal '/', pp.directory_path
423
+ assert_equal '/', pp.dirname
424
+ assert_equal [ '/' ], pp.directory_parts
425
+
426
+ volume = nil
427
+ end
428
+ assert_equal 'file', pp.file_full_name
429
+ assert_equal 'file', pp.basename
430
+ assert_equal 'file', pp.file_name_only
431
+ assert_equal 'file', pp.stem
432
+ assert_nil pp.file_extension
433
+ assert_nil pp.extension
434
+ assert_nil pp.search_directory
435
+ assert_nil pp.search_relative_path
436
+ assert_nil pp.search_relative_directory_path
437
+ assert_nil pp.search_relative_directory_parts
438
+
439
+ assert_equal pp.directory, pp.directory_parts.join
440
+ assert_equal pp.absolute_path, "#{volume}#{pp.directory_parts.join}#{pp.basename}"
441
+ end
442
+
443
+ def test_rooted_one_file_without_stem
444
+
445
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
446
+
447
+ pp = ParsedPath.new('H:\\.ext')
448
+
449
+ assert_equal 'H:\\.ext', pp.given_path
450
+ assert_equal 'H:\\.ext', pp.absolute_path
451
+ assert_equal 'H:\\.EXT', pp.compare_path
452
+ assert_equal 'H:', pp.volume
453
+ assert_equal '\\', pp.directory
454
+ assert_equal 'H:\\', pp.directory_path
455
+ assert_equal 'H:\\', pp.dirname
456
+ assert_equal [ '\\' ], pp.directory_parts
457
+
458
+ volume = pp.volume
459
+ else
460
+
461
+ pp = ParsedPath.new('/.ext')
462
+
463
+ assert_equal '/.ext', pp.given_path
464
+ assert_equal '/.ext', pp.absolute_path
465
+ assert_equal '/.ext', pp.compare_path
466
+ assert_equal '/', pp.directory
467
+ assert_equal '/', pp.directory_path
468
+ assert_equal '/', pp.dirname
469
+ assert_equal [ '/' ], pp.directory_parts
470
+
471
+ volume = nil
472
+ end
473
+ assert_equal '.ext', pp.file_full_name
474
+ assert_equal '.ext', pp.basename
475
+ assert_nil pp.file_name_only
476
+ assert_nil pp.stem
477
+ assert_equal '.ext', pp.file_extension
478
+ assert_equal '.ext', pp.extension
479
+ assert_nil pp.search_directory
480
+ assert_nil pp.search_relative_path
481
+ assert_nil pp.search_relative_directory_path
482
+ assert_nil pp.search_relative_directory_parts
483
+
484
+ assert_equal pp.directory, pp.directory_parts.join
485
+ assert_equal pp.absolute_path, "#{volume}#{pp.directory_parts.join}#{pp.basename}"
486
+ end
487
+
488
+ def test_rooted_one_long_path
489
+
490
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
491
+
492
+ pp = ParsedPath.new('C:/dir-1/dir-2/dir-3/dir-4/./dir-5/dir-6/../file.ext')
493
+
494
+ assert_equal 'C:/dir-1/dir-2/dir-3/dir-4/./dir-5/dir-6/../file.ext', pp.given_path
495
+ assert_equal 'C:/dir-1/dir-2/dir-3/dir-4/dir-5/file.ext', pp.absolute_path
496
+ assert_equal 'C:/DIR-1/DIR-2/DIR-3/DIR-4/DIR-5/FILE.EXT', pp.compare_path
497
+ assert_equal 'C:', pp.volume
498
+ assert_equal '/dir-1/dir-2/dir-3/dir-4/dir-5/', pp.directory
499
+ assert_equal 'C:/dir-1/dir-2/dir-3/dir-4/dir-5/', pp.directory_path
500
+ assert_equal 'C:/dir-1/dir-2/dir-3/dir-4/dir-5/', pp.dirname
501
+ assert_equal [ '/', 'dir-1/', 'dir-2/', 'dir-3/', 'dir-4/', 'dir-5/' ], pp.directory_parts
502
+
503
+ volume = pp.volume
504
+ else
505
+
506
+ pp = ParsedPath.new('/dir-1/dir-2/dir-3/dir-4/./dir-5/dir-6/../file.ext')
507
+
508
+ assert_equal '/dir-1/dir-2/dir-3/dir-4/./dir-5/dir-6/../file.ext', pp.given_path
509
+ assert_equal '/dir-1/dir-2/dir-3/dir-4/dir-5/file.ext', pp.absolute_path
510
+ assert_equal '/dir-1/dir-2/dir-3/dir-4/dir-5/file.ext', pp.compare_path
511
+ assert_equal '/dir-1/dir-2/dir-3/dir-4/dir-5/', pp.directory
512
+ assert_equal '/dir-1/dir-2/dir-3/dir-4/dir-5/', pp.directory_path
513
+ assert_equal '/dir-1/dir-2/dir-3/dir-4/dir-5/', pp.dirname
514
+ assert_equal [ '/', 'dir-1/', 'dir-2/', 'dir-3/', 'dir-4/', 'dir-5/' ], pp.directory_parts
515
+
516
+ volume = nil
517
+ end
518
+ assert_equal 'file.ext', pp.file_full_name
519
+ assert_equal 'file.ext', pp.basename
520
+ assert_equal 'file', pp.file_name_only
521
+ assert_equal 'file', pp.stem
522
+ assert_equal '.ext', pp.file_extension
523
+ assert_equal '.ext', pp.extension
524
+ assert_nil pp.search_directory
525
+ assert_nil pp.search_relative_path
526
+ assert_nil pp.search_relative_directory_path
527
+ assert_nil pp.search_relative_directory_parts
528
+
529
+ assert_equal pp.directory, pp.directory_parts.join
530
+ assert_equal pp.absolute_path, "#{volume}#{pp.directory_parts.join}#{pp.basename}"
531
+ end
532
+
533
+ def test_rooted_one_long_path_with_short_directory_names
534
+
535
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
536
+
537
+ pp = ParsedPath.new('C:/1/2/3/4/./5/6/../file.ext')
538
+
539
+ assert_equal 'C:/1/2/3/4/./5/6/../file.ext', pp.given_path
540
+ assert_equal 'C:/1/2/3/4/5/file.ext', pp.absolute_path
541
+ assert_equal 'C:/1/2/3/4/5/FILE.EXT', pp.compare_path
542
+ assert_equal 'C:', pp.volume
543
+ assert_equal '/1/2/3/4/5/', pp.directory
544
+ assert_equal 'C:/1/2/3/4/5/', pp.directory_path
545
+ assert_equal 'C:/1/2/3/4/5/', pp.dirname
546
+ assert_equal [ '/', '1/', '2/', '3/', '4/', '5/' ], pp.directory_parts
547
+
548
+ volume = pp.volume
549
+ else
550
+
551
+ pp = ParsedPath.new('/1/2/3/4/./5/6/../file.ext')
552
+
553
+ assert_equal '/1/2/3/4/./5/6/../file.ext', pp.given_path
554
+ assert_equal '/1/2/3/4/5/file.ext', pp.absolute_path
555
+ assert_equal '/1/2/3/4/5/file.ext', pp.compare_path
556
+ assert_equal '/1/2/3/4/5/', pp.directory
557
+ assert_equal '/1/2/3/4/5/', pp.directory_path
558
+ assert_equal '/1/2/3/4/5/', pp.dirname
559
+ assert_equal [ '/', '1/', '2/', '3/', '4/', '5/' ], pp.directory_parts
560
+
561
+ volume = nil
562
+ end
563
+ assert_equal 'file.ext', pp.file_full_name
564
+ assert_equal 'file.ext', pp.basename
565
+ assert_equal 'file', pp.file_name_only
566
+ assert_equal 'file', pp.stem
567
+ assert_equal '.ext', pp.file_extension
568
+ assert_equal '.ext', pp.extension
569
+ assert_nil pp.search_directory
570
+ assert_nil pp.search_relative_path
571
+ assert_nil pp.search_relative_directory_path
572
+ assert_nil pp.search_relative_directory_parts
573
+
574
+ assert_equal pp.directory, pp.directory_parts.join
575
+ assert_equal pp.absolute_path, "#{volume}#{pp.directory_parts.join}#{pp.basename}"
576
+ end
577
+
578
+ def test_unrooted_one_file
579
+
580
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
581
+
582
+ pwd = '/some-directory'
583
+
584
+ pp = ParsedPath.new('file.ext', pwd: pwd)
585
+
586
+ assert_equal 'file.ext', pp.given_path
587
+ assert_equal '/some-directory\\file.ext', pp.absolute_path
588
+ assert_equal '/SOME-DIRECTORY\\FILE.EXT', pp.compare_path
589
+ assert_nil pp.volume
590
+ assert_equal '/some-directory\\', pp.directory
591
+ assert_equal '/some-directory\\', pp.directory_path
592
+ assert_equal '/some-directory\\', pp.dirname
593
+ assert_equal [ '/', 'some-directory\\' ], pp.directory_parts
594
+
595
+ volume = pp.volume
596
+ else
597
+
598
+ pwd = '/some-directory'
599
+
600
+ pp = ParsedPath.new('file.ext', pwd: pwd)
601
+
602
+ assert_equal 'file.ext', pp.given_path
603
+ assert_equal '/some-directory/file.ext', pp.absolute_path
604
+ assert_equal '/some-directory/file.ext', pp.compare_path
605
+ assert_equal '/some-directory/', pp.directory
606
+ assert_equal '/some-directory/', pp.directory_path
607
+ assert_equal '/some-directory/', pp.dirname
608
+ assert_equal [ '/', 'some-directory/' ], pp.directory_parts
609
+
610
+ volume = nil
611
+ end
612
+ assert_equal 'file.ext', pp.file_full_name
613
+ assert_equal 'file.ext', pp.basename
614
+ assert_equal 'file', pp.file_name_only
615
+ assert_equal 'file', pp.stem
616
+ assert_equal '.ext', pp.file_extension
617
+ assert_equal '.ext', pp.extension
618
+ assert_nil pp.search_directory
619
+ assert_nil pp.search_relative_path
620
+ assert_nil pp.search_relative_directory_path
621
+ assert_nil pp.search_relative_directory_parts
622
+
623
+ assert_equal pp.directory, pp.directory_parts.join
624
+ assert_equal pp.absolute_path, "#{volume}#{pp.directory_parts.join}#{pp.basename}"
625
+ end
626
+
627
+ def test_unrooted_one_file_from_srd
628
+
629
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
630
+
631
+ pwd = '/some-directory'
632
+ srd = '/dir-1/dir-2/'
633
+
634
+ pp = ParsedPath.new('file.ext', pwd: pwd)
635
+
636
+ assert_equal 'file.ext', pp.given_path
637
+ assert_equal '/some-directory\\file.ext', pp.absolute_path
638
+ assert_equal '/SOME-DIRECTORY\\FILE.EXT', pp.compare_path
639
+ assert_nil pp.volume
640
+ assert_equal '/some-directory\\', pp.directory
641
+ assert_equal '/some-directory\\', pp.directory_path
642
+ assert_equal '/some-directory\\', pp.dirname
643
+ assert_equal [ '/', 'some-directory\\' ], pp.directory_parts
644
+
645
+ volume = pp.volume
646
+ else
647
+
648
+ pwd = '/some-directory'
649
+ srd = '/dir-1/dir-2/'
650
+
651
+ pp = ParsedPath.new('file.ext', pwd: pwd)
652
+
653
+ assert_equal 'file.ext', pp.given_path
654
+ assert_equal '/some-directory/file.ext', pp.absolute_path
655
+ assert_equal '/some-directory/file.ext', pp.compare_path
656
+ assert_equal '/some-directory/', pp.directory
657
+ assert_equal '/some-directory/', pp.directory_path
658
+ assert_equal '/some-directory/', pp.dirname
659
+ assert_equal [ '/', 'some-directory/' ], pp.directory_parts
660
+
661
+ volume = nil
662
+ end
663
+ assert_equal 'file.ext', pp.file_full_name
664
+ assert_equal 'file.ext', pp.basename
665
+ assert_equal 'file', pp.file_name_only
666
+ assert_equal 'file', pp.stem
667
+ assert_equal '.ext', pp.file_extension
668
+ assert_equal '.ext', pp.extension
669
+ assert_nil pp.search_directory
670
+ assert_nil pp.search_relative_path
671
+ assert_nil pp.search_relative_directory_path
672
+ assert_nil pp.search_relative_directory_parts
673
+
674
+ assert_equal pp.directory, pp.directory_parts.join
675
+ assert_equal pp.absolute_path, "#{volume}#{pp.directory_parts.join}#{pp.basename}"
676
+ end
677
+
678
+ def test_unrooted_dir_file
679
+
680
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
681
+
682
+ pwd = '/some-directory'
683
+
684
+ pp = ParsedPath.new('sub-dir/file.ext', pwd: pwd)
685
+
686
+ assert_equal 'sub-dir/file.ext', pp.given_path
687
+ assert_equal '/some-directory\\sub-dir/file.ext', pp.absolute_path
688
+ assert_equal '/SOME-DIRECTORY\\SUB-DIR/FILE.EXT', pp.compare_path
689
+ assert_nil pp.volume
690
+ assert_equal '/some-directory\\sub-dir/', pp.directory
691
+ assert_equal '/some-directory\\sub-dir/', pp.directory_path
692
+ assert_equal '/some-directory\\sub-dir/', pp.dirname
693
+ assert_equal [ '/', 'some-directory\\', 'sub-dir/' ], pp.directory_parts
694
+
695
+ volume = pp.volume
696
+ else
697
+
698
+ pwd = '/some-directory'
699
+
700
+ pp = ParsedPath.new('sub-dir/file.ext', pwd: pwd)
701
+
702
+ assert_equal 'sub-dir/file.ext', pp.given_path
703
+ assert_equal '/some-directory/sub-dir/file.ext', pp.absolute_path
704
+ assert_equal '/some-directory/sub-dir/file.ext', pp.compare_path
705
+ assert_equal '/some-directory/sub-dir/', pp.directory
706
+ assert_equal '/some-directory/sub-dir/', pp.directory_path
707
+ assert_equal '/some-directory/sub-dir/', pp.dirname
708
+ assert_equal [ '/', 'some-directory/', 'sub-dir/' ], pp.directory_parts
709
+
710
+ volume = nil
711
+ end
712
+ assert_equal 'file.ext', pp.file_full_name
713
+ assert_equal 'file.ext', pp.basename
714
+ assert_equal 'file', pp.file_name_only
715
+ assert_equal 'file', pp.stem
716
+ assert_equal '.ext', pp.file_extension
717
+ assert_equal '.ext', pp.extension
718
+ assert_nil pp.search_directory
719
+ assert_nil pp.search_relative_path
720
+ assert_nil pp.search_relative_directory_path
721
+ assert_nil pp.search_relative_directory_parts
722
+
723
+ assert_equal pp.directory, pp.directory_parts.join
724
+ assert_equal pp.absolute_path, "#{volume}#{pp.directory_parts.join}#{pp.basename}"
725
+ end
726
+
727
+ def test_unrooted_dir_file_2
728
+
729
+ locator = Object.new
730
+
731
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
732
+
733
+ locator.define_singleton_method(:pwd) { '/some-directory' }
734
+
735
+ pp = ParsedPath.new('sub-dir/file.ext', locator: locator)
736
+
737
+ assert_equal 'sub-dir/file.ext', pp.given_path
738
+ assert_equal '/some-directory\\sub-dir/file.ext', pp.absolute_path
739
+ assert_equal '/SOME-DIRECTORY\\SUB-DIR/FILE.EXT', pp.compare_path
740
+ assert_nil pp.volume
741
+ assert_equal '/some-directory\\sub-dir/', pp.directory
742
+ assert_equal '/some-directory\\sub-dir/', pp.directory_path
743
+ assert_equal '/some-directory\\sub-dir/', pp.dirname
744
+ assert_equal [ '/', 'some-directory\\', 'sub-dir/' ], pp.directory_parts
745
+
746
+ volume = pp.volume
747
+ else
748
+
749
+ locator.define_singleton_method(:pwd) { '/some-directory' }
750
+
751
+ pp = ParsedPath.new('sub-dir/file.ext', locator: locator)
752
+
753
+ assert_equal 'sub-dir/file.ext', pp.given_path
754
+ assert_equal '/some-directory/sub-dir/file.ext', pp.absolute_path
755
+ assert_equal '/some-directory/sub-dir/file.ext', pp.compare_path
756
+ assert_equal '/some-directory/sub-dir/', pp.directory
757
+ assert_equal '/some-directory/sub-dir/', pp.directory_path
758
+ assert_equal '/some-directory/sub-dir/', pp.dirname
759
+ assert_equal [ '/', 'some-directory/', 'sub-dir/' ], pp.directory_parts
760
+
761
+ volume = nil
762
+ end
763
+ assert_equal 'file.ext', pp.file_full_name
764
+ assert_equal 'file.ext', pp.basename
765
+ assert_equal 'file', pp.file_name_only
766
+ assert_equal 'file', pp.stem
767
+ assert_equal '.ext', pp.file_extension
768
+ assert_equal '.ext', pp.extension
769
+ assert_nil pp.search_directory
770
+ assert_nil pp.search_relative_path
771
+ assert_nil pp.search_relative_directory_path
772
+ assert_nil pp.search_relative_directory_parts
773
+
774
+ assert_equal pp.directory, pp.directory_parts.join
775
+ assert_equal pp.absolute_path, "#{volume}#{pp.directory_parts.join}#{pp.basename}"
776
+ end
777
+ end
778
+