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,630 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 4), 'lib')
4
+
5
+ require 'libpath/path/windows'
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_Windows < 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_Windows_module_exists
26
+
27
+ assert defined?(::LibPath::Path::Windows)
28
+ end
29
+
30
+ def test_LibPath_Path_Windows_ParsedPath_class_exists
31
+
32
+ assert defined?(::LibPath::Path::Windows::ParsedPath)
33
+ end
34
+ end
35
+
36
+ class Test_LibPath_Path_Windows_ParsedPath < Test::Unit::TestCase
37
+
38
+ include ::LibPath::Path::Windows
39
+
40
+ def test_nil
41
+
42
+ assert_raise(::ArgumentError) { ParsedPath.new(nil) }
43
+ end
44
+
45
+ def test_empty
46
+
47
+ assert_raise(::ArgumentError) { ParsedPath.new('') }
48
+ end
49
+
50
+ def test_root
51
+
52
+ pp = ParsedPath.new('C:\\')
53
+
54
+ assert_equal 'C:\\', pp.given_path
55
+ assert_equal 'C:\\', pp.absolute_path
56
+ assert_equal 'C:\\', pp.compare_path
57
+ assert_equal 'C:', pp.volume
58
+ assert_equal '\\', pp.directory
59
+ assert_equal 'C:\\', pp.directory_path
60
+ assert_equal 'C:\\', 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.volume}#{pp.directory_parts.join}#{pp.basename}"
75
+ end
76
+
77
+ def test_root_lower_drive_letter
78
+
79
+ pp = ParsedPath.new('c:\\')
80
+
81
+ assert_equal 'c:\\', pp.given_path
82
+ assert_equal 'c:\\', pp.absolute_path
83
+ assert_equal 'C:\\', pp.compare_path
84
+ assert_equal 'c:', pp.volume
85
+ assert_equal '\\', pp.directory
86
+ assert_equal 'c:\\', pp.directory_path
87
+ assert_equal 'c:\\', pp.dirname
88
+ assert_equal [ '\\' ], pp.directory_parts
89
+ assert_nil pp.file_full_name
90
+ assert_nil pp.basename
91
+ assert_nil pp.file_name_only
92
+ assert_nil pp.stem
93
+ assert_nil pp.file_extension
94
+ assert_nil pp.extension
95
+ assert_nil pp.search_directory
96
+ assert_nil pp.search_relative_path
97
+ assert_nil pp.search_relative_directory_path
98
+ assert_nil pp.search_relative_directory_parts
99
+
100
+ assert_equal pp.directory, pp.directory_parts.join
101
+ assert_equal pp.absolute_path, "#{pp.volume}#{pp.directory_parts.join}#{pp.basename}"
102
+ end
103
+
104
+ def test_root_from_srd_1
105
+
106
+ srd = 'C:/dir-1/dir-2'
107
+
108
+ pp = ParsedPath.new('C:\\', srd)
109
+
110
+ assert_equal 'C:\\', pp.given_path
111
+ assert_equal 'C:\\', pp.absolute_path
112
+ assert_equal 'C:\\', pp.compare_path
113
+ assert_equal 'C:', pp.volume
114
+ assert_equal '\\', pp.directory
115
+ assert_equal 'C:\\', pp.directory_path
116
+ assert_equal 'C:\\', 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 'C:\\dir-1\\dir-2\\', 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.volume}#{pp.directory_parts.join}#{pp.basename}"
131
+ end
132
+
133
+ def test_root_UNC_form2
134
+
135
+ pp = ParsedPath.new('\\\\server\\share\\')
136
+
137
+ assert_equal '\\\\server\\share\\', pp.given_path
138
+ assert_equal '\\\\server\\share\\', pp.absolute_path
139
+ assert_equal '\\\\server\\share\\', pp.compare_path
140
+ assert_equal '\\\\server\\share', pp.volume
141
+ assert_equal '\\', pp.directory
142
+ assert_equal '\\\\server\\share\\', pp.directory_path
143
+ assert_equal '\\\\server\\share\\', pp.dirname
144
+ assert_equal [ '\\' ], pp.directory_parts
145
+ assert_nil pp.file_full_name
146
+ assert_nil pp.basename
147
+ assert_nil pp.file_name_only
148
+ assert_nil pp.stem
149
+ assert_nil pp.file_extension
150
+ assert_nil pp.extension
151
+ assert_nil pp.search_directory
152
+ assert_nil pp.search_relative_path
153
+ assert_nil pp.search_relative_directory_path
154
+ assert_nil pp.search_relative_directory_parts
155
+
156
+ assert_equal pp.directory, pp.directory_parts.join
157
+ assert_equal pp.absolute_path, "#{pp.volume}#{pp.directory_parts.join}#{pp.basename}"
158
+ end
159
+
160
+ def test_root_UNC_form3
161
+
162
+ pp = ParsedPath.new('\\\\?\\C:\\')
163
+
164
+ assert_equal '\\\\?\\C:\\', pp.given_path
165
+ assert_equal '\\\\?\\C:\\', pp.absolute_path
166
+ assert_equal '\\\\?\\C:\\', pp.compare_path
167
+ assert_equal '\\\\?\\C:', pp.volume
168
+ assert_equal '\\', pp.directory
169
+ assert_equal '\\\\?\\C:\\', pp.directory_path
170
+ assert_equal '\\\\?\\C:\\', pp.dirname
171
+ assert_equal [ '\\' ], 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_nil pp.search_directory
179
+ assert_nil pp.search_relative_path
180
+ assert_nil pp.search_relative_directory_path
181
+ assert_nil pp.search_relative_directory_parts
182
+
183
+ assert_equal pp.directory, pp.directory_parts.join
184
+ assert_equal pp.absolute_path, "#{pp.volume}#{pp.directory_parts.join}#{pp.basename}"
185
+ end
186
+
187
+ def test_root_UNC_form4
188
+
189
+ pp = ParsedPath.new('\\\\?\\server\\share\\')
190
+
191
+ assert_equal '\\\\?\\server\\share\\', pp.given_path
192
+ assert_equal '\\\\?\\server\\share\\', pp.absolute_path
193
+ assert_equal '\\\\?\\server\\share\\', pp.compare_path
194
+ assert_equal '\\\\?\\server\\share', pp.volume
195
+ assert_equal '\\', pp.directory
196
+ assert_equal '\\\\?\\server\\share\\', pp.directory_path
197
+ assert_equal '\\\\?\\server\\share\\', pp.dirname
198
+ assert_equal [ '\\' ], pp.directory_parts
199
+ assert_nil pp.file_full_name
200
+ assert_nil pp.basename
201
+ assert_nil pp.file_name_only
202
+ assert_nil pp.stem
203
+ assert_nil pp.file_extension
204
+ assert_nil pp.extension
205
+ assert_nil pp.search_directory
206
+ assert_nil pp.search_relative_path
207
+ assert_nil pp.search_relative_directory_path
208
+ assert_nil pp.search_relative_directory_parts
209
+
210
+ assert_equal pp.directory, pp.directory_parts.join
211
+ assert_equal pp.absolute_path, "#{pp.volume}#{pp.directory_parts.join}#{pp.basename}"
212
+ end
213
+
214
+ def test_root_UNC_form5
215
+
216
+ pp = ParsedPath.new('\\\\?\\UNC\\server\\share\\')
217
+
218
+ assert_equal '\\\\?\\UNC\\server\\share\\', pp.given_path
219
+ assert_equal '\\\\?\\UNC\\server\\share\\', pp.absolute_path
220
+ assert_equal '\\\\?\\UNC\\server\\share\\', pp.compare_path
221
+ assert_equal '\\\\?\\UNC\\server\\share', pp.volume
222
+ assert_equal '\\', pp.directory
223
+ assert_equal '\\\\?\\UNC\\server\\share\\', pp.directory_path
224
+ assert_equal '\\\\?\\UNC\\server\\share\\', pp.dirname
225
+ assert_equal [ '\\' ], pp.directory_parts
226
+ assert_nil pp.file_full_name
227
+ assert_nil pp.basename
228
+ assert_nil pp.file_name_only
229
+ assert_nil pp.stem
230
+ assert_nil pp.file_extension
231
+ assert_nil pp.extension
232
+ assert_nil pp.search_directory
233
+ assert_nil pp.search_relative_path
234
+ assert_nil pp.search_relative_directory_path
235
+ assert_nil pp.search_relative_directory_parts
236
+
237
+ assert_equal pp.directory, pp.directory_parts.join
238
+ assert_equal pp.absolute_path, "#{pp.volume}#{pp.directory_parts.join}#{pp.basename}"
239
+ end
240
+
241
+ def test_root_UNC_form6
242
+
243
+ pp = ParsedPath.new('\\\\.\\{some-device-id}\\')
244
+
245
+ assert_equal '\\\\.\\{some-device-id}\\', pp.given_path
246
+ assert_equal '\\\\.\\{some-device-id}\\', pp.absolute_path
247
+ assert_equal '\\\\.\\{some-device-id}\\', pp.compare_path
248
+ assert_equal '\\\\.\\{some-device-id}', pp.volume
249
+ assert_equal '\\', pp.directory
250
+ assert_equal '\\\\.\\{some-device-id}\\', pp.directory_path
251
+ assert_equal '\\\\.\\{some-device-id}\\', pp.dirname
252
+ assert_equal [ '\\' ], pp.directory_parts
253
+ assert_nil pp.file_full_name
254
+ assert_nil pp.basename
255
+ assert_nil pp.file_name_only
256
+ assert_nil pp.stem
257
+ assert_nil pp.file_extension
258
+ assert_nil pp.extension
259
+ assert_nil pp.search_directory
260
+ assert_nil pp.search_relative_path
261
+ assert_nil pp.search_relative_directory_path
262
+ assert_nil pp.search_relative_directory_parts
263
+
264
+ assert_equal pp.directory, pp.directory_parts.join
265
+ assert_equal pp.absolute_path, "#{pp.volume}#{pp.directory_parts.join}#{pp.basename}"
266
+ end
267
+
268
+ def test_rooted_one_dir
269
+
270
+ pp = ParsedPath.new('G:\\\\abc\\\\')
271
+
272
+ assert_equal 'G:\\\\abc\\\\', pp.given_path
273
+ assert_equal 'G:\\abc\\', pp.absolute_path
274
+ assert_equal 'G:\\ABC\\', pp.compare_path
275
+ assert_equal '\\abc\\', pp.directory
276
+ assert_equal 'G:', pp.volume
277
+ assert_equal 'G:\\abc\\', pp.directory_path
278
+ assert_equal 'G:\\abc\\', pp.dirname
279
+ assert_equal [ '\\', 'abc\\' ], pp.directory_parts
280
+ assert_nil pp.file_full_name
281
+ assert_nil pp.basename
282
+ assert_nil pp.file_name_only
283
+ assert_nil pp.stem
284
+ assert_nil pp.file_extension
285
+ assert_nil pp.extension
286
+ assert_nil pp.search_directory
287
+ assert_nil pp.search_relative_path
288
+ assert_nil pp.search_relative_directory_path
289
+ assert_nil pp.search_relative_directory_parts
290
+
291
+ assert_equal pp.directory, pp.directory_parts.join
292
+ assert_equal pp.absolute_path, "#{pp.volume}#{pp.directory_parts.join}#{pp.basename}"
293
+ end
294
+
295
+ def test_rooted_one_dir_with_trailing_dot
296
+
297
+ pp = ParsedPath.new('G:\\abc\\.')
298
+
299
+ assert_equal 'G:\\abc\\.', pp.given_path
300
+ assert_equal 'G:\\abc\\', pp.absolute_path
301
+ assert_equal 'G:\\ABC\\', pp.compare_path
302
+ assert_equal 'G:', pp.volume
303
+ assert_equal '\\abc\\', pp.directory
304
+ assert_equal 'G:\\abc\\', pp.directory_path
305
+ assert_equal 'G:\\abc\\', pp.dirname
306
+ assert_equal [ '\\', 'abc\\' ], pp.directory_parts
307
+ assert_nil pp.file_full_name
308
+ assert_nil pp.basename
309
+ assert_nil pp.file_name_only
310
+ assert_nil pp.stem
311
+ assert_nil pp.file_extension
312
+ assert_nil pp.extension
313
+ assert_nil pp.search_directory
314
+ assert_nil pp.search_relative_path
315
+ assert_nil pp.search_relative_directory_path
316
+ assert_nil pp.search_relative_directory_parts
317
+
318
+ assert_equal pp.directory, pp.directory_parts.join
319
+ assert_equal pp.absolute_path, "#{pp.volume}#{pp.directory_parts.join}#{pp.basename}"
320
+ end
321
+
322
+ def test_rooted_one_file
323
+
324
+ pp = ParsedPath.new('G:\\file.ext')
325
+
326
+ assert_equal 'G:\\file.ext', pp.given_path
327
+ assert_equal 'G:\\file.ext', pp.absolute_path
328
+ assert_equal 'G:\\FILE.EXT', pp.compare_path
329
+ assert_equal 'G:', pp.volume
330
+ assert_equal '\\', pp.directory
331
+ assert_equal 'G:\\', pp.directory_path
332
+ assert_equal 'G:\\', pp.dirname
333
+ assert_equal [ '\\' ], pp.directory_parts
334
+ assert_equal 'file.ext', pp.file_full_name
335
+ assert_equal 'file.ext', pp.basename
336
+ assert_equal 'file', pp.file_name_only
337
+ assert_equal 'file', pp.stem
338
+ assert_equal '.ext', pp.file_extension
339
+ assert_equal '.ext', pp.extension
340
+ assert_nil pp.search_directory
341
+ assert_nil pp.search_relative_path
342
+ assert_nil pp.search_relative_directory_path
343
+ assert_nil pp.search_relative_directory_parts
344
+
345
+ assert_equal pp.directory, pp.directory_parts.join
346
+ assert_equal pp.absolute_path, "#{pp.volume}#{pp.directory_parts.join}#{pp.basename}"
347
+ end
348
+
349
+ def test_rooted_one_file_without_extension
350
+
351
+ pp = ParsedPath.new('G:\\file')
352
+
353
+ assert_equal 'G:\\file', pp.given_path
354
+ assert_equal 'G:\\file', pp.absolute_path
355
+ assert_equal 'G:\\FILE', pp.compare_path
356
+ assert_equal 'G:', pp.volume
357
+ assert_equal '\\', pp.directory
358
+ assert_equal 'G:\\', pp.directory_path
359
+ assert_equal 'G:\\', pp.dirname
360
+ assert_equal [ '\\' ], pp.directory_parts
361
+ assert_equal 'file', pp.file_full_name
362
+ assert_equal 'file', pp.basename
363
+ assert_equal 'file', pp.file_name_only
364
+ assert_equal 'file', pp.stem
365
+ assert_nil pp.file_extension
366
+ assert_nil pp.extension
367
+ assert_nil pp.search_directory
368
+ assert_nil pp.search_relative_path
369
+ assert_nil pp.search_relative_directory_path
370
+ assert_nil pp.search_relative_directory_parts
371
+
372
+ assert_equal pp.directory, pp.directory_parts.join
373
+ assert_equal pp.absolute_path, "#{pp.volume}#{pp.directory_parts.join}#{pp.basename}"
374
+ end
375
+
376
+ def test_rooted_one_file_without_stem
377
+
378
+ pp = ParsedPath.new('H:\\.ext')
379
+
380
+ assert_equal 'H:\\.ext', pp.given_path
381
+ assert_equal 'H:\\.ext', pp.absolute_path
382
+ assert_equal 'H:\\.EXT', pp.compare_path
383
+ assert_equal 'H:', pp.volume
384
+ assert_equal '\\', pp.directory
385
+ assert_equal 'H:\\', pp.directory_path
386
+ assert_equal 'H:\\', pp.dirname
387
+ assert_equal [ '\\' ], pp.directory_parts
388
+ assert_equal '.ext', pp.file_full_name
389
+ assert_equal '.ext', pp.basename
390
+ assert_nil pp.file_name_only
391
+ assert_nil pp.stem
392
+ assert_equal '.ext', pp.file_extension
393
+ assert_equal '.ext', pp.extension
394
+ assert_nil pp.search_directory
395
+ assert_nil pp.search_relative_path
396
+ assert_nil pp.search_relative_directory_path
397
+ assert_nil pp.search_relative_directory_parts
398
+
399
+ assert_equal pp.directory, pp.directory_parts.join
400
+ assert_equal pp.absolute_path, "#{pp.volume}#{pp.directory_parts.join}#{pp.basename}"
401
+ end
402
+
403
+ def test_rooted_one_long_path
404
+
405
+ pp = ParsedPath.new('C:/dir-1/dir-2/dir-3/dir-4/./dir-5/dir-6/../file.ext')
406
+
407
+ assert_equal 'C:/dir-1/dir-2/dir-3/dir-4/./dir-5/dir-6/../file.ext', pp.given_path
408
+ assert_equal 'C:/dir-1/dir-2/dir-3/dir-4/dir-5/file.ext', pp.absolute_path
409
+ assert_equal 'C:/DIR-1/DIR-2/DIR-3/DIR-4/DIR-5/FILE.EXT', pp.compare_path
410
+ assert_equal 'C:', pp.volume
411
+ assert_equal '/dir-1/dir-2/dir-3/dir-4/dir-5/', pp.directory
412
+ assert_equal 'C:/dir-1/dir-2/dir-3/dir-4/dir-5/', pp.directory_path
413
+ assert_equal 'C:/dir-1/dir-2/dir-3/dir-4/dir-5/', pp.dirname
414
+ assert_equal [ '/', 'dir-1/', 'dir-2/', 'dir-3/', 'dir-4/', 'dir-5/' ], pp.directory_parts
415
+ assert_equal 'file.ext', pp.file_full_name
416
+ assert_equal 'file.ext', pp.basename
417
+ assert_equal 'file', pp.file_name_only
418
+ assert_equal 'file', pp.stem
419
+ assert_equal '.ext', pp.file_extension
420
+ assert_equal '.ext', pp.extension
421
+ assert_nil pp.search_directory
422
+ assert_nil pp.search_relative_path
423
+ assert_nil pp.search_relative_directory_path
424
+ assert_nil pp.search_relative_directory_parts
425
+
426
+ assert_equal pp.directory, pp.directory_parts.join
427
+ assert_equal pp.absolute_path, "#{pp.volume}#{pp.directory_parts.join}#{pp.basename}"
428
+ end
429
+
430
+ def test_rooted_one_long_path_from_srd1
431
+
432
+ srd = 'C:\\dir-1\\dir-2\\dir-C\\dir-D'
433
+ pp = ParsedPath.new('C:/dir-1/dir-2/dir-3/dir-4/./dir-5/dir-6/../file.ext', srd)
434
+
435
+ assert_equal 'C:/dir-1/dir-2/dir-3/dir-4/./dir-5/dir-6/../file.ext', pp.given_path
436
+ assert_equal 'C:/dir-1/dir-2/dir-3/dir-4/dir-5/file.ext', pp.absolute_path
437
+ assert_equal 'C:/DIR-1/DIR-2/DIR-3/DIR-4/DIR-5/FILE.EXT', pp.compare_path
438
+ assert_equal 'C:', pp.volume
439
+ assert_equal '/dir-1/dir-2/dir-3/dir-4/dir-5/', pp.directory
440
+ assert_equal 'C:/dir-1/dir-2/dir-3/dir-4/dir-5/', pp.directory_path
441
+ assert_equal 'C:/dir-1/dir-2/dir-3/dir-4/dir-5/', pp.dirname
442
+ assert_equal [ '/', 'dir-1/', 'dir-2/', 'dir-3/', 'dir-4/', 'dir-5/' ], pp.directory_parts
443
+ assert_equal 'file.ext', pp.file_full_name
444
+ assert_equal 'file.ext', pp.basename
445
+ assert_equal 'file', pp.file_name_only
446
+ assert_equal 'file', pp.stem
447
+ assert_equal '.ext', pp.file_extension
448
+ assert_equal '.ext', pp.extension
449
+ assert_equal 'C:\\dir-1\\dir-2\\dir-C\\dir-D\\', pp.search_directory
450
+ assert_equal '..\\..\\dir-3\\dir-4\\dir-5\\file.ext', pp.search_relative_path
451
+ assert_equal '..\\..\\dir-3\\dir-4\\dir-5\\', pp.search_relative_directory_path
452
+ assert_equal [ '..\\', '..\\', 'dir-3\\', 'dir-4\\', 'dir-5\\' ], pp.search_relative_directory_parts
453
+
454
+ assert_equal pp.directory, pp.directory_parts.join
455
+ assert_equal pp.absolute_path, "#{pp.volume}#{pp.directory_parts.join}#{pp.basename}"
456
+ end
457
+
458
+ def test_rooted_one_long_path_missing_volume
459
+
460
+ pp = ParsedPath.new('/dir-1/dir-2/dir-3/dir-4/./dir-5/dir-6/../file.ext', pwd: 'D:\\')
461
+
462
+ assert_equal '/dir-1/dir-2/dir-3/dir-4/./dir-5/dir-6/../file.ext', pp.given_path
463
+ assert_equal 'D:/dir-1/dir-2/dir-3/dir-4/dir-5/file.ext', pp.absolute_path
464
+ assert_equal 'D:/DIR-1/DIR-2/DIR-3/DIR-4/DIR-5/FILE.EXT', pp.compare_path
465
+ assert_equal 'D:', pp.volume
466
+ assert_equal '/dir-1/dir-2/dir-3/dir-4/dir-5/', pp.directory
467
+ assert_equal 'D:/dir-1/dir-2/dir-3/dir-4/dir-5/', pp.directory_path
468
+ assert_equal 'D:/dir-1/dir-2/dir-3/dir-4/dir-5/', pp.dirname
469
+ assert_equal [ '/', 'dir-1/', 'dir-2/', 'dir-3/', 'dir-4/', 'dir-5/' ], pp.directory_parts
470
+ assert_equal 'file.ext', pp.file_full_name
471
+ assert_equal 'file.ext', pp.basename
472
+ assert_equal 'file', pp.file_name_only
473
+ assert_equal 'file', pp.stem
474
+ assert_equal '.ext', pp.file_extension
475
+ assert_equal '.ext', pp.extension
476
+ assert_nil pp.search_directory
477
+ assert_nil pp.search_relative_path
478
+ assert_nil pp.search_relative_directory_path
479
+ assert_nil pp.search_relative_directory_parts
480
+
481
+ assert_equal pp.directory, pp.directory_parts.join
482
+ assert_equal pp.absolute_path, "#{pp.volume}#{pp.directory_parts.join}#{pp.basename}"
483
+ end
484
+
485
+ def test_rooted_one_long_path_with_short_directory_names
486
+
487
+ pp = ParsedPath.new('C:/1/2/3/4/./5/6/../file.ext')
488
+
489
+ assert_equal 'C:/1/2/3/4/./5/6/../file.ext', pp.given_path
490
+ assert_equal 'C:/1/2/3/4/5/file.ext', pp.absolute_path
491
+ assert_equal 'C:/1/2/3/4/5/FILE.EXT', pp.compare_path
492
+ assert_equal 'C:', pp.volume
493
+ assert_equal '/1/2/3/4/5/', pp.directory
494
+ assert_equal 'C:/1/2/3/4/5/', pp.directory_path
495
+ assert_equal 'C:/1/2/3/4/5/', pp.dirname
496
+ assert_equal [ '/', '1/', '2/', '3/', '4/', '5/' ], pp.directory_parts
497
+ assert_equal 'file.ext', pp.file_full_name
498
+ assert_equal 'file.ext', pp.basename
499
+ assert_equal 'file', pp.file_name_only
500
+ assert_equal 'file', pp.stem
501
+ assert_equal '.ext', pp.file_extension
502
+ assert_equal '.ext', pp.extension
503
+ assert_nil pp.search_directory
504
+ assert_nil pp.search_relative_path
505
+ assert_nil pp.search_relative_directory_path
506
+ assert_nil pp.search_relative_directory_parts
507
+
508
+ assert_equal pp.directory, pp.directory_parts.join
509
+ assert_equal pp.absolute_path, "#{pp.volume}#{pp.directory_parts.join}#{pp.basename}"
510
+ end
511
+
512
+ def test_unrooted_one_file
513
+
514
+ pwd = '/some-directory'
515
+
516
+ pp = ParsedPath.new('file.ext', pwd: pwd)
517
+
518
+ assert_equal 'file.ext', pp.given_path
519
+ assert_equal '/some-directory\\file.ext', pp.absolute_path
520
+ assert_equal '/SOME-DIRECTORY\\FILE.EXT', pp.compare_path
521
+ assert_nil pp.volume
522
+ assert_equal '/some-directory\\', pp.directory
523
+ assert_equal '/some-directory\\', pp.directory_path
524
+ assert_equal '/some-directory\\', pp.dirname
525
+ assert_equal [ '/', 'some-directory\\' ], pp.directory_parts
526
+ assert_equal 'file.ext', pp.file_full_name
527
+ assert_equal 'file.ext', pp.basename
528
+ assert_equal 'file', pp.file_name_only
529
+ assert_equal 'file', pp.stem
530
+ assert_equal '.ext', pp.file_extension
531
+ assert_equal '.ext', pp.extension
532
+ assert_nil pp.search_directory
533
+ assert_nil pp.search_relative_path
534
+ assert_nil pp.search_relative_directory_path
535
+ assert_nil pp.search_relative_directory_parts
536
+
537
+ assert_equal pp.directory, pp.directory_parts.join
538
+ assert_equal pp.absolute_path, "#{pp.volume}#{pp.directory_parts.join}#{pp.basename}"
539
+ end
540
+
541
+ def test_unrooted_dir_file
542
+
543
+ pwd = '/some-directory'
544
+
545
+ pp = ParsedPath.new('sub-dir/file.ext', pwd: pwd)
546
+
547
+ assert_equal 'sub-dir/file.ext', pp.given_path
548
+ assert_equal '/some-directory\\sub-dir/file.ext', pp.absolute_path
549
+ assert_equal '/SOME-DIRECTORY\\SUB-DIR/FILE.EXT', pp.compare_path
550
+ assert_nil pp.volume
551
+ assert_equal '/some-directory\\sub-dir/', pp.directory
552
+ assert_equal '/some-directory\\sub-dir/', pp.directory_path
553
+ assert_equal '/some-directory\\sub-dir/', pp.dirname
554
+ assert_equal [ '/', 'some-directory\\', 'sub-dir/' ], pp.directory_parts
555
+ assert_equal 'file.ext', pp.file_full_name
556
+ assert_equal 'file.ext', pp.basename
557
+ assert_equal 'file', pp.file_name_only
558
+ assert_equal 'file', pp.stem
559
+ assert_equal '.ext', pp.file_extension
560
+ assert_equal '.ext', pp.extension
561
+ assert_nil pp.search_directory
562
+ assert_nil pp.search_relative_path
563
+ assert_nil pp.search_relative_directory_path
564
+ assert_nil pp.search_relative_directory_parts
565
+
566
+ assert_equal pp.directory, pp.directory_parts.join
567
+ assert_equal pp.absolute_path, "#{pp.volume}#{pp.directory_parts.join}#{pp.basename}"
568
+ end
569
+
570
+ def test_unrooted_dir_file_2
571
+
572
+ locator = Object.new
573
+
574
+ locator.define_singleton_method(:pwd) { '/some-directory' }
575
+
576
+ pp = ParsedPath.new('sub-dir/file.ext', locator: locator)
577
+
578
+ assert_equal 'sub-dir/file.ext', pp.given_path
579
+ assert_equal '/some-directory\\sub-dir/file.ext', pp.absolute_path
580
+ assert_equal '/SOME-DIRECTORY\\SUB-DIR/FILE.EXT', pp.compare_path
581
+ assert_nil pp.volume
582
+ assert_equal '/some-directory\\sub-dir/', pp.directory
583
+ assert_equal '/some-directory\\sub-dir/', pp.directory_path
584
+ assert_equal '/some-directory\\sub-dir/', pp.dirname
585
+ assert_equal [ '/', 'some-directory\\', 'sub-dir/' ], pp.directory_parts
586
+ assert_equal 'file.ext', pp.file_full_name
587
+ assert_equal 'file.ext', pp.basename
588
+ assert_equal 'file', pp.file_name_only
589
+ assert_equal 'file', pp.stem
590
+ assert_equal '.ext', pp.file_extension
591
+ assert_equal '.ext', pp.extension
592
+ assert_nil pp.search_directory
593
+ assert_nil pp.search_relative_path
594
+ assert_nil pp.search_relative_directory_path
595
+ assert_nil pp.search_relative_directory_parts
596
+
597
+ assert_equal pp.directory, pp.directory_parts.join
598
+ assert_equal pp.absolute_path, "#{pp.volume}#{pp.directory_parts.join}#{pp.basename}"
599
+ end
600
+
601
+ def test_rooted_UNC_form_5
602
+
603
+ gp = '\\\\?\\UNC\\127.0.0.1:3000\\shared-stuff\\dir-1\\dir-1.2\\file.ext'
604
+
605
+ pp = ParsedPath.new(gp)
606
+
607
+ assert_equal gp, pp.given_path
608
+ assert_equal gp, pp.absolute_path
609
+ assert_equal '\\\\?\\UNC\\127.0.0.1:3000\\shared-stuff\\DIR-1\\DIR-1.2\\FILE.EXT', pp.compare_path
610
+ assert_equal '\\\\?\\UNC\\127.0.0.1:3000\\shared-stuff', pp.volume
611
+ assert_equal '\\dir-1\\dir-1.2\\', pp.directory
612
+ assert_equal '\\\\?\\UNC\\127.0.0.1:3000\\shared-stuff\\dir-1\\dir-1.2\\', pp.directory_path
613
+ assert_equal '\\\\?\\UNC\\127.0.0.1:3000\\shared-stuff\\dir-1\\dir-1.2\\', pp.dirname
614
+ assert_equal [ '\\', 'dir-1\\', 'dir-1.2\\' ], pp.directory_parts
615
+ assert_equal 'file.ext', pp.file_full_name
616
+ assert_equal 'file.ext', pp.basename
617
+ assert_equal 'file', pp.file_name_only
618
+ assert_equal 'file', pp.stem
619
+ assert_equal '.ext', pp.file_extension
620
+ assert_equal '.ext', pp.extension
621
+ assert_nil pp.search_directory
622
+ assert_nil pp.search_relative_path
623
+ assert_nil pp.search_relative_directory_path
624
+ assert_nil pp.search_relative_directory_parts
625
+
626
+ assert_equal pp.directory, pp.directory_parts.join
627
+ assert_equal pp.absolute_path, "#{pp.volume}#{pp.directory_parts.join}#{pp.basename}"
628
+ end
629
+ end
630
+