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