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,65 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 4), 'lib')
4
+
5
+ require 'libpath/util/unix'
6
+
7
+ require 'test/unit'
8
+
9
+ class Test_LibPath_Util_Unix_combine_paths < Test::Unit::TestCase
10
+
11
+ F = ::LibPath::Util::Unix
12
+
13
+ def test_no_arguments
14
+
15
+ assert_equal '', F.combine_paths()
16
+ end
17
+
18
+ def test_single_argument
19
+
20
+ assert_equal ' ', F.combine_paths(' ')
21
+ assert_equal 'a', F.combine_paths('a')
22
+ assert_equal 'abcdef/ghi/jkl.mno', F.combine_paths('abcdef/ghi/jkl.mno')
23
+ assert_equal '/', F.combine_paths('/')
24
+ end
25
+
26
+ def test_relative_cases
27
+
28
+ assert_equal 'a/b/c/d', F.combine_paths('a', 'b', 'c/d')
29
+ assert_equal 'a/b/c/d', F.combine_paths('a', 'b/', 'c/d')
30
+
31
+ assert_equal 'a/b', F.combine_paths('', 'a', '', '', 'b')
32
+
33
+ assert_equal 'a/ /b', F.combine_paths('', 'a', '', ' ', 'b')
34
+ end
35
+
36
+ def test_tail_absolute_cases
37
+
38
+ assert_equal '/', F.combine_paths('a', '/')
39
+
40
+ assert_equal '/', F.combine_paths('a/b/c/d', '/')
41
+
42
+ assert_equal '/', F.combine_paths('a', 'b', '/')
43
+ end
44
+
45
+ def test_dots
46
+
47
+ assert_equal 'a/.', F.combine_paths('a', '.')
48
+ assert_equal 'a', F.combine_paths('a', '.', elide_single_dots: true)
49
+
50
+ assert_equal 'a/b', F.combine_paths('a', '.', 'b', elide_single_dots: true)
51
+ assert_equal 'a/b', F.combine_paths('a', './', 'b', elide_single_dots: true)
52
+ assert_equal '/./b', F.combine_paths('a', '/.', 'b', elide_single_dots: true)
53
+ end
54
+
55
+ def test_embedded_absolute_cases
56
+
57
+ assert_equal '/a/b/c/d', F.combine_paths('x/y/z', 'z', '/a', 'b', 'c/d')
58
+ end
59
+
60
+ def test_multiple_embedded_absolute_cases
61
+
62
+ assert_equal '/a/b/c/d', F.combine_paths('x/y/z', '/z', '/a', 'b', 'c/d')
63
+ end
64
+ end
65
+
@@ -0,0 +1,123 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 4), 'lib')
4
+
5
+ require 'libpath/util/unix'
6
+
7
+ require 'test/unit'
8
+
9
+ class Test_LibPath_Util_Unix_derive_relative_path < Test::Unit::TestCase
10
+
11
+ M = ::LibPath::Util::Unix
12
+
13
+ def test_nils_and_empties
14
+
15
+ # to get nowhere from nowhere, go nowhere
16
+ assert_nil M.derive_relative_path(nil, nil)
17
+ assert_nil M.derive_relative_path('', nil)
18
+ assert_equal '', M.derive_relative_path('', '')
19
+ assert_equal '', M.derive_relative_path(nil, '')
20
+
21
+ # to get somewhere from nowhere, just go there
22
+ assert_equal 'abc', M.derive_relative_path(nil, 'abc')
23
+ assert_equal 'abc', M.derive_relative_path('', 'abc')
24
+
25
+ # to get nowhere from anywhere else, go nowhere
26
+ assert_nil M.derive_relative_path('dir', nil)
27
+ assert_equal '', M.derive_relative_path('dir', '')
28
+ end
29
+
30
+ def test_same_location
31
+
32
+ assert_equal '.', M.derive_relative_path('.', '.')
33
+ assert_equal '.', M.derive_relative_path('..', '..')
34
+
35
+ assert_equal '.', M.derive_relative_path('abc', 'abc')
36
+ assert_equal './', M.derive_relative_path('abc/', 'abc/')
37
+ assert_equal './', M.derive_relative_path('abc', 'abc/')
38
+
39
+ assert_equal './', M.derive_relative_path('/', '/')
40
+
41
+ assert_equal '.', M.derive_relative_path('./abc', 'abc')
42
+ assert_equal '.', M.derive_relative_path('./abc/', 'abc')
43
+ assert_equal './', M.derive_relative_path('./abc', 'abc/')
44
+ assert_equal './', M.derive_relative_path('./abc/', 'abc/')
45
+
46
+ assert_equal '.', M.derive_relative_path('/abc', '/abc')
47
+ assert_equal '.', M.derive_relative_path('/abc/', '/abc')
48
+ assert_equal './', M.derive_relative_path('/abc/', '/abc/')
49
+ assert_equal '../', M.derive_relative_path('/abc/', '/')
50
+
51
+ assert_equal '../../', M.derive_relative_path('/abc/def/', '/')
52
+ assert_equal '../../', M.derive_relative_path('/abc/def/', '/')
53
+ end
54
+
55
+ def test_from_here
56
+
57
+ assert_equal 'abc', M.derive_relative_path('.', 'abc')
58
+ assert_equal 'abc', M.derive_relative_path('./', 'abc')
59
+ assert_equal 'abc/', M.derive_relative_path('.', 'abc/')
60
+ assert_equal 'abc/', M.derive_relative_path('./', 'abc/')
61
+
62
+ assert_equal('abc/', M.derive_relative_path('/dir1/dir2', '/dir1/dir2/abc/'))
63
+ assert_equal('.', M.derive_relative_path('/dir1/dir2/abc', '/dir1/dir2/abc'))
64
+ assert_equal('./', M.derive_relative_path('/dir1/dir2/abc', '/dir1/dir2/abc/'))
65
+ end
66
+
67
+ def test_ones_above
68
+
69
+ assert_equal '../', M.derive_relative_path('.', '..')
70
+
71
+ assert_equal '../', M.derive_relative_path('abc/def', 'abc')
72
+
73
+ assert_equal '../', M.derive_relative_path('abc/def/ghi', 'abc/def')
74
+ assert_equal '../', M.derive_relative_path('abc/def/ghi', 'abc/def/')
75
+
76
+ assert_equal '../', M.derive_relative_path('abc/def/./ghi', 'abc/def')
77
+ assert_equal '../', M.derive_relative_path('abc/def/ghi/jkl/..', 'abc/def')
78
+ assert_equal '../', M.derive_relative_path('abc/def/ghi/jkl/../', 'abc/def')
79
+ assert_equal '../', M.derive_relative_path('abc/def/ghi/jkl/..', 'abc/def/')
80
+
81
+ assert_equal '../../', M.derive_relative_path('abc/def/ghi/jkl/', 'abc/def')
82
+
83
+ assert_equal '../../', M.derive_relative_path('/dir1/dir2/dir3/dir4', '/dir1/dir2')
84
+ end
85
+
86
+ def test_ones_below
87
+
88
+ assert_equal 'dir-1/', M.derive_relative_path('..', '.', pwd: '/dir-1/')
89
+
90
+ assert_equal '../', M.derive_relative_path('.', '..', pwd: '/dir-1/')
91
+
92
+ assert_equal 'def', M.derive_relative_path('abc', 'abc/def')
93
+
94
+ assert_equal 'def/ghi', M.derive_relative_path('abc', 'abc/def/ghi')
95
+ end
96
+
97
+ def test_ones_across
98
+
99
+ assert_equal '../e-1', M.derive_relative_path('abc/d-1', 'abc/e-1')
100
+ assert_equal '../e-1', M.derive_relative_path('abc/d-1/', 'abc/e-1')
101
+
102
+ assert_equal '../e-1/e-2', M.derive_relative_path('abc/d-1/', 'abc/e-1/e-2')
103
+ assert_equal '../../e-1/e-2', M.derive_relative_path('abc/d-1/d-2/', 'abc/e-1/e-2')
104
+ end
105
+
106
+ def test_simple_cases
107
+
108
+ assert_equal 'def', M.derive_relative_path('/abc', '/abc/def')
109
+ end
110
+
111
+ def test_absolute_path_cases
112
+
113
+ assert_equal '../../def', M.derive_relative_path('ghi', '/def', pwd: '/abc')
114
+
115
+ assert_equal '../def', M.derive_relative_path('abc', '/def', pwd: '/')
116
+ end
117
+
118
+ def test_both_relative
119
+
120
+ assert_equal '../def', M.derive_relative_path('abc', 'def', pwd: '/')
121
+ end
122
+ end
123
+
@@ -0,0 +1,117 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 4), 'lib')
4
+
5
+ require 'libpath/util/unix'
6
+
7
+ require 'test/unit'
8
+
9
+ class Test_LibPath_Util_Unix_make_path_absolute < Test::Unit::TestCase
10
+
11
+ F = ::LibPath::Util::Unix
12
+
13
+ def test_nil
14
+
15
+ if $DEBUG
16
+
17
+ assert_raise(::ArgumentError) { F.make_path_absolute(nil) }
18
+ else
19
+
20
+ assert_nil F.make_path_absolute(nil)
21
+ end
22
+ end
23
+
24
+ def test_empty
25
+
26
+ assert_equal '', F.make_path_absolute('')
27
+ end
28
+
29
+ def test_absolute_paths
30
+
31
+ assert_equal '/', F.make_path_absolute('/')
32
+ assert_equal '/.', F.make_path_absolute('/.')
33
+ assert_equal '/a', F.make_path_absolute('/a')
34
+ assert_equal '/a/.', F.make_path_absolute('/a/.')
35
+ end
36
+
37
+ def test_absolute_paths_with_canonicalisation
38
+
39
+ options = { make_canonical: true }
40
+
41
+ assert_equal '/', F.make_path_absolute('/', **options)
42
+ assert_equal '/', F.make_path_absolute('/.', **options)
43
+ assert_equal '/a', F.make_path_absolute('/a', **options)
44
+ assert_equal '/a/', F.make_path_absolute('/a/.', **options)
45
+ end
46
+
47
+ def test_relative_path_with_fixed_pwd
48
+
49
+ pwd = '/some-path/or-other'
50
+
51
+ assert_equal '/some-path/or-other/.', F.make_path_absolute('.', pwd: pwd)
52
+ assert_equal '/some-path/or-other/', F.make_path_absolute('.', pwd: pwd, make_canonical: true)
53
+
54
+ assert_equal '/some-path/or-other/abc', F.make_path_absolute('abc', pwd: pwd)
55
+ assert_equal '/some-path/or-other/abc', F.make_path_absolute('abc', pwd: pwd, make_canonical: true)
56
+
57
+ assert_equal '/some-path/or-other/./abc', F.make_path_absolute('./abc', pwd: pwd)
58
+ assert_equal '/some-path/or-other/abc', F.make_path_absolute('./abc', pwd: pwd, make_canonical: true)
59
+
60
+ assert_equal '/some-path/or-other/./abc/', F.make_path_absolute('./abc/', pwd: pwd)
61
+ assert_equal '/some-path/or-other/abc/', F.make_path_absolute('./abc/', pwd: pwd, make_canonical: true)
62
+
63
+ assert_equal '/some-path/or-other/def/../abc', F.make_path_absolute('def/../abc', pwd: pwd)
64
+ assert_equal '/some-path/or-other/abc', F.make_path_absolute('def/../abc', pwd: pwd, make_canonical: true)
65
+
66
+ assert_equal '/some-path/or-other/def/../abc/', F.make_path_absolute('def/../abc/', pwd: pwd)
67
+ assert_equal '/some-path/or-other/abc/', F.make_path_absolute('def/../abc/', pwd: pwd, make_canonical: true)
68
+ end
69
+
70
+ def test_relative_path_with_fixed_home
71
+
72
+ home = '/Users/libpath-tester'
73
+
74
+ assert_equal '/Users/libpath-tester/.', F.make_path_absolute('~/.', home: home)
75
+ assert_equal '/Users/libpath-tester/', F.make_path_absolute('~/.', home: home, make_canonical: true)
76
+
77
+ assert_equal '/Users/libpath-tester/abc', F.make_path_absolute('~/abc', home: home)
78
+ assert_equal '/Users/libpath-tester/abc', F.make_path_absolute('~/abc', home: home, make_canonical: true)
79
+
80
+ assert_equal '/Users/libpath-tester/./abc', F.make_path_absolute('~/./abc', home: home)
81
+ assert_equal '/Users/libpath-tester/abc', F.make_path_absolute('~/./abc', home: home, make_canonical: true)
82
+
83
+ assert_equal '/Users/libpath-tester/./abc/', F.make_path_absolute('~/./abc/', home: home)
84
+ assert_equal '/Users/libpath-tester/abc/', F.make_path_absolute('~/./abc/', home: home, make_canonical: true)
85
+
86
+ assert_equal '/Users/libpath-tester/def/../abc', F.make_path_absolute('~/def/../abc', home: home)
87
+ assert_equal '/Users/libpath-tester/abc', F.make_path_absolute('~/def/../abc', home: home, make_canonical: true)
88
+
89
+ assert_equal '/Users/libpath-tester/def/../abc/', F.make_path_absolute('~/def/../abc/', home: home)
90
+ assert_equal '/Users/libpath-tester/abc/', F.make_path_absolute('~/def/../abc/', home: home, make_canonical: true)
91
+ end
92
+
93
+ def test_nonhome_tilde_with_fixed_pwd
94
+
95
+ pwd = '/some-path/or-other'
96
+
97
+ assert_equal '/some-path/or-other/~.', F.make_path_absolute('~.', pwd: pwd)
98
+ assert_equal '/some-path/or-other/~.', F.make_path_absolute('~.', pwd: pwd, make_canonical: true)
99
+
100
+ assert_equal '/some-path/or-other/~abc', F.make_path_absolute('~abc', pwd: pwd)
101
+ assert_equal '/some-path/or-other/~abc', F.make_path_absolute('~abc', pwd: pwd, make_canonical: true)
102
+
103
+ assert_equal '/some-path/or-other/~./abc', F.make_path_absolute('~./abc', pwd: pwd)
104
+ assert_equal '/some-path/or-other/~./abc', F.make_path_absolute('~./abc', pwd: pwd, make_canonical: true)
105
+
106
+ assert_equal '/some-path/or-other/~./abc/', F.make_path_absolute('~./abc/', pwd: pwd)
107
+ assert_equal '/some-path/or-other/~./abc/', F.make_path_absolute('~./abc/', pwd: pwd, make_canonical: true)
108
+
109
+ assert_equal '/some-path/or-other/~def/../abc', F.make_path_absolute('~def/../abc', pwd: pwd)
110
+ assert_equal '/some-path/or-other/abc', F.make_path_absolute('~def/../abc', pwd: pwd, make_canonical: true)
111
+
112
+ assert_equal '/some-path/or-other/~def/../abc/', F.make_path_absolute('~def/../abc/', pwd: pwd)
113
+ assert_equal '/some-path/or-other/abc/', F.make_path_absolute('~def/../abc/', pwd: pwd, make_canonical: true)
114
+ end
115
+
116
+ end
117
+
@@ -0,0 +1,139 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 4), 'lib')
4
+
5
+ require 'libpath/util/unix'
6
+
7
+ require 'test/unit'
8
+
9
+ class Test_LibPath_Util_Unix_make_path_canonical < Test::Unit::TestCase
10
+
11
+ F = ::LibPath::Util::Unix
12
+
13
+ def test_empty
14
+
15
+ assert_equal '', F.make_path_canonical('')
16
+ end
17
+
18
+ def test_one_dot
19
+
20
+ assert_equal './', F.make_path_canonical('.')
21
+ assert_equal './', F.make_path_canonical('./')
22
+ assert_equal './', F.make_path_canonical('./.')
23
+ assert_equal './', F.make_path_canonical('./.')
24
+ assert_equal './', F.make_path_canonical('././')
25
+ assert_equal './', F.make_path_canonical('.//./')
26
+ assert_equal './', F.make_path_canonical('.////./')
27
+ assert_equal './', F.make_path_canonical('././.')
28
+ assert_equal './', F.make_path_canonical('./././')
29
+ end
30
+
31
+ def test_two_dots
32
+
33
+ assert_equal '../', F.make_path_canonical('..')
34
+ assert_equal '../', F.make_path_canonical('../')
35
+ assert_equal '../', F.make_path_canonical('../.')
36
+ assert_equal '../', F.make_path_canonical('.././')
37
+ assert_equal '../', F.make_path_canonical('..//./')
38
+ assert_equal '../', F.make_path_canonical('..////./')
39
+ assert_equal '../', F.make_path_canonical('.././.')
40
+ end
41
+
42
+ def test_unresolveable
43
+
44
+ assert_equal '../', F.make_path_canonical('..')
45
+ assert_equal '../', F.make_path_canonical('../')
46
+
47
+ assert_equal '../dir-1', F.make_path_canonical('../dir-1')
48
+ assert_equal '../dir-1/', F.make_path_canonical('../dir-1/')
49
+
50
+ assert_equal '../../', F.make_path_canonical('../..')
51
+ assert_equal '../../', F.make_path_canonical('../../')
52
+
53
+ assert_equal '../../dir-1', F.make_path_canonical('../../dir-1')
54
+ assert_equal '../../dir-1/', F.make_path_canonical('../../dir-1/')
55
+ end
56
+
57
+ def test_partially_resolveable
58
+
59
+ assert_equal '../', F.make_path_canonical('../dir-1/..')
60
+ assert_equal '../', F.make_path_canonical('../dir-1/../')
61
+
62
+ assert_equal '../abc', F.make_path_canonical('../dir-1/../abc')
63
+ assert_equal '../abc/', F.make_path_canonical('../dir-1/../abc/')
64
+
65
+ assert_equal '../../', F.make_path_canonical('../../dir-1/..')
66
+ assert_equal '../../', F.make_path_canonical('../../dir-1/../')
67
+
68
+ assert_equal '../../abc', F.make_path_canonical('../../dir-1/../abc')
69
+ assert_equal '../../abc/', F.make_path_canonical('../../dir-1/../abc/')
70
+
71
+ assert_equal '/dir.14/', F.make_path_canonical('/dir.14/dir.2/..')
72
+ assert_equal 'dir.14/', F.make_path_canonical('dir.14/dir.2/..')
73
+
74
+ assert_equal '/', F.make_path_canonical('/dir.14/dir.2/../..')
75
+ assert_equal '/', F.make_path_canonical('/dir.14/dir.2/../../..')
76
+ assert_equal './', F.make_path_canonical('dir.14/dir.2/../..')
77
+ end
78
+
79
+ def test_basenames
80
+
81
+ assert_equal 'a', F.make_path_canonical('a')
82
+
83
+ assert_equal 'file.ext', F.make_path_canonical('file.ext')
84
+
85
+ assert_equal '../', F.make_path_canonical('..')
86
+ end
87
+
88
+ def test_no_dots
89
+
90
+ assert_equal 'abc/def', F.make_path_canonical('abc/def')
91
+ assert_equal 'abc/def', F.make_path_canonical('abc//def')
92
+ assert_equal 'abc/def', F.make_path_canonical('abc///def')
93
+ end
94
+
95
+ def test_one_dots_directories
96
+
97
+ assert_equal 'abc', F.make_path_canonical('./abc')
98
+ assert_equal 'abc/', F.make_path_canonical('./abc/')
99
+
100
+ assert_equal 'abc', F.make_path_canonical('././abc')
101
+ assert_equal 'abc/', F.make_path_canonical('././abc/')
102
+
103
+ assert_equal 'abc', F.make_path_canonical('./././././././././abc')
104
+ assert_equal 'abc/', F.make_path_canonical('./././././././././abc/')
105
+
106
+ assert_equal 'abc/', F.make_path_canonical('abc/.')
107
+ assert_equal 'abc/', F.make_path_canonical('abc/./')
108
+
109
+ assert_equal 'abc/', F.make_path_canonical('./abc/.')
110
+ assert_equal 'abc/', F.make_path_canonical('./abc/./')
111
+ end
112
+
113
+ def test_two_dots_directories
114
+
115
+ assert_equal '../', F.make_path_canonical('..')
116
+ assert_equal '../', F.make_path_canonical('../')
117
+
118
+ assert_equal '../abc', F.make_path_canonical('../abc')
119
+ assert_equal '../abc/', F.make_path_canonical('../abc/')
120
+
121
+ assert_equal './', F.make_path_canonical('abc/..')
122
+ assert_equal './', F.make_path_canonical('abc/../')
123
+
124
+ assert_equal 'def', F.make_path_canonical('abc/../def')
125
+ assert_equal 'def/', F.make_path_canonical('abc/../def/')
126
+
127
+ assert_equal './', F.make_path_canonical('abc/../def/..')
128
+ assert_equal './', F.make_path_canonical('abc/../def/../')
129
+
130
+ assert_equal '../dir-2/', F.make_path_canonical('../dir-1/../dir-2/')
131
+ assert_equal '../dir-2', F.make_path_canonical('../dir-1/../dir-2')
132
+ assert_equal '/dir-2', F.make_path_canonical('/../dir-1/../dir-2')
133
+ assert_equal '/', F.make_path_canonical('/../')
134
+ assert_equal '/', F.make_path_canonical('/..')
135
+ assert_equal('/', F.make_path_canonical('/dir.14/dir.2/../..'))
136
+ assert_equal('/', F.make_path_canonical('/dir.14/dir.2/../../..'))
137
+ end
138
+ end
139
+