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,47 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 2), 'lib')
4
+
5
+ require 'libpath/version'
6
+
7
+ require 'test/unit'
8
+
9
+ class Test_version < Test::Unit::TestCase
10
+
11
+ def test_has_VERSION
12
+
13
+ assert defined? LibPath::VERSION
14
+ end
15
+
16
+ def test_has_VERSION_MAJOR
17
+
18
+ assert defined? LibPath::VERSION_MAJOR
19
+ end
20
+
21
+ def test_has_VERSION_MINOR
22
+
23
+ assert defined? LibPath::VERSION_MINOR
24
+ end
25
+
26
+ def test_has_VERSION_REVISION
27
+
28
+ assert defined? LibPath::VERSION_REVISION
29
+ end
30
+
31
+ def test_VERSION_has_consistent_format
32
+
33
+ if LibPath::VERSION_SUBPATCH
34
+
35
+ assert_equal LibPath::VERSION, "#{LibPath::VERSION_MAJOR}.#{LibPath::VERSION_MINOR}.#{LibPath::VERSION_PATCH}.#{LibPath::VERSION_SUBPATCH}"
36
+ else
37
+
38
+ assert_equal LibPath::VERSION, "#{LibPath::VERSION_MAJOR}.#{LibPath::VERSION_MINOR}.#{LibPath::VERSION_PATCH}"
39
+ end
40
+ end
41
+
42
+ def test_VERSION_greater_than
43
+
44
+ assert_operator LibPath::VERSION, :>=, '0.1.0'
45
+ end
46
+ end
47
+
@@ -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,179 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 3), 'lib')
4
+
5
+ require 'libpath/util'
6
+
7
+ require 'test/unit'
8
+
9
+ require 'libpath/internal_/platform'
10
+
11
+ class Test_LibPath_Util_combine_paths < Test::Unit::TestCase
12
+
13
+ F = ::LibPath::Util
14
+
15
+ def test_no_arguments
16
+
17
+ assert_equal '', F.combine_paths()
18
+ end
19
+
20
+ def test_single_argument
21
+
22
+ assert_equal ' ', F.combine_paths(' ')
23
+ assert_equal 'a', F.combine_paths('a')
24
+ assert_equal 'abcdef/ghi/jkl.mno', F.combine_paths('abcdef/ghi/jkl.mno')
25
+ assert_equal '/', F.combine_paths('/')
26
+ end
27
+
28
+ def test_relative_cases
29
+
30
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
31
+
32
+ assert_equal 'a\\b\\c/d', F.combine_paths('a', 'b', 'c/d')
33
+
34
+ assert_equal 'a\\b', F.combine_paths('', 'a', '', '', 'b')
35
+
36
+ assert_equal 'a\\ \\b', F.combine_paths('', 'a', '', ' ', 'b')
37
+ else
38
+
39
+ assert_equal 'a/b/c/d', F.combine_paths('a', 'b', 'c/d')
40
+
41
+ assert_equal 'a/b', F.combine_paths('', 'a', '', '', 'b')
42
+
43
+ assert_equal 'a/ /b', F.combine_paths('', 'a', '', ' ', 'b')
44
+ end
45
+ end
46
+
47
+ def test_tail_absolute_cases
48
+
49
+ assert_equal '/', F.combine_paths('a', '/')
50
+
51
+ assert_equal '/', F.combine_paths('a/b/c/d', '/')
52
+
53
+ assert_equal '/', F.combine_paths('a', 'b', '/')
54
+
55
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
56
+
57
+ assert_equal 'X:/', F.combine_paths('a', 'X:/')
58
+ assert_equal 'X:\\', F.combine_paths('a', 'X:\\')
59
+ assert_equal '\\\\?\\X:\\', F.combine_paths('a', '\\\\?\\X:\\')
60
+ end
61
+ end
62
+
63
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
64
+
65
+ def test_tail_absolute_cases_2
66
+
67
+ assert_equal 'Y:/', F.combine_paths('a', 'X:/', 'Y:/')
68
+ assert_equal 'Y:\\', F.combine_paths('a', 'X:/', 'Y:\\')
69
+ assert_equal 'Y:\\', F.combine_paths('a', '\\\\?\\X:/', 'Y:\\')
70
+ assert_equal '\\\\?\\Y:\\', F.combine_paths('a', 'X:/', '\\\\?\\Y:\\')
71
+ end
72
+
73
+ def test_tail_absolute_cases_3
74
+
75
+ assert_equal 'X:\\', F.combine_paths('a', 'X:', '\\')
76
+ assert_equal 'X:\\', F.combine_paths('a', '\\', 'X:')
77
+ assert_equal 'X:\\', F.combine_paths('X:', 'a', '\\')
78
+
79
+ assert_equal '\\\\?\\X:\\', F.combine_paths('a', '\\\\?\\X:', '\\')
80
+ assert_equal '\\\\?\\X:\\', F.combine_paths('a', '\\', '\\\\?\\X:')
81
+ assert_equal '\\\\?\\X:\\', F.combine_paths('\\\\?\\X:', 'a', '\\')
82
+ end
83
+
84
+ def test_tail_absolute_cases_4
85
+
86
+ assert_equal 'Z:\\', F.combine_paths('a', 'X:/', '\\', 'Z:')
87
+
88
+ assert_equal '\\\\?\\Z:\\', F.combine_paths('a', '\\\\?\\X:/', '\\', '\\\\?\\Z:')
89
+
90
+ assert_equal '\\\\?\\UNC\\server\\share/abc', F.combine_paths('a', '\\\\?\\X:/', '/abc', '\\\\?\\UNC\\server\\share')
91
+ end
92
+
93
+ def test_tail_absolute_cases_5
94
+
95
+ assert_equal 'Z:\\dir\\a\\b', F.combine_paths('a', 'X:/y', '\\dir', 'Z:', 'a', 'b')
96
+
97
+ assert_equal 'Z:\\dir\\a\\b', F.combine_paths('a', '\\\\?\\X:/y', '\\dir', 'Z:', 'a', 'b')
98
+
99
+ assert_equal '\\\\?\\Z:\\dir\\a\\b', F.combine_paths('a', 'X:/y', '\\dir', '\\\\?\\Z:', 'a', 'b')
100
+ end
101
+
102
+ def test_tail_absolute_cases_6
103
+
104
+ assert_equal 'Z:\\b', F.combine_paths('a', 'X:/', 'Z:', 'a', '\\', 'b')
105
+ end
106
+
107
+ def test_tail_absolute_cases_7
108
+
109
+ assert_equal 'Z:\\a\\c\\b', F.combine_paths('a', 'X:/', '\\a', 'c', 'Z:', 'b')
110
+ end
111
+
112
+ def test_tail_absolute_cases_8
113
+
114
+ assert_equal 'X:/y\\b', F.combine_paths('a', '\\a', 'c', 'Z:', 'X:/y', 'b')
115
+ end
116
+
117
+ def test_tail_absolute_cases_9
118
+
119
+ assert_equal 'Z:\\y\\b', F.combine_paths('a', '\\a', 'c', 'X:\\y', 'Z:', 'b')
120
+ assert_equal 'Z:/y\\b', F.combine_paths('a', '\\a', 'c', 'X:/y', 'Z:', 'b')
121
+ end
122
+ end
123
+
124
+ def test_tail_absolute_cases_10
125
+
126
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
127
+
128
+ assert_equal 'X:\\dir-1\\dir-2\\b', F.combine_paths('a', '\\a', 'c', 'X:/y', '\\dir-1\\dir-2', 'b')
129
+ assert_equal 'X:\\dir-1/dir-2\\b', F.combine_paths('a', '\\a', 'c', 'X:/y', '\\dir-1/dir-2', 'b')
130
+ end
131
+
132
+ assert_equal '/', F.combine_paths('a', '/')
133
+
134
+ assert_equal '/', F.combine_paths('a/b/c/d', '/')
135
+
136
+ assert_equal '/', F.combine_paths('a', 'b', '/')
137
+ end
138
+
139
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
140
+
141
+ def test_drive_only
142
+
143
+ assert_equal 'D:', F.combine_paths('D:')
144
+ assert_equal 'D:dir-1\\dir-2', F.combine_paths('D:', 'dir-1\\dir-2')
145
+
146
+ assert_equal '\\\\?\\D:', F.combine_paths('\\\\?\\D:')
147
+ assert_equal '\\\\?\\D:dir-1\\dir-2', F.combine_paths('\\\\?\\D:', 'dir-1\\dir-2')
148
+ end
149
+ end
150
+
151
+ def test_embedded_absolute_cases
152
+
153
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
154
+
155
+ assert_equal '/a\\b\\c/d', F.combine_paths('x/y/z', 'z', '/a', 'b', 'c/d')
156
+ assert_equal '\\a\\b\\c/d', F.combine_paths('x/y/z', 'z', '\\a', 'b', 'c/d')
157
+ else
158
+
159
+ assert_equal '/a/b/c/d', F.combine_paths('x/y/z', 'z', '/a', 'b', 'c/d')
160
+ assert_equal '/a/b/c/d', F.combine_paths('x/y/z', 'z', '/a', 'b', 'c/d')
161
+ end
162
+ end
163
+
164
+ def test_multiple_embedded_absolute_cases
165
+
166
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
167
+
168
+ assert_equal '/a\\b\\c/d', F.combine_paths('x/y/z', '/z', '/a', 'b', 'c/d')
169
+
170
+ assert_equal '/a\\b\\c/d', F.combine_paths('x/y/z', '/z', '/a', 'b', 'c/d')
171
+ else
172
+
173
+ assert_equal '/a/b/c/d', F.combine_paths('x/y/z', '/z', '/a', 'b', 'c/d')
174
+
175
+ assert_equal '/a/b/c/d', F.combine_paths('x/y/z', '/z', '/a', 'b', 'c/d')
176
+ end
177
+ end
178
+ end
179
+
@@ -0,0 +1,19 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 3), 'lib')
4
+
5
+ require 'libpath/util'
6
+
7
+ require 'test/unit'
8
+
9
+ require 'libpath/internal_/platform'
10
+
11
+ class Test_LibPath_Util_derive_relative_path < Test::Unit::TestCase
12
+
13
+ F = ::LibPath::Util
14
+
15
+ def test_nils
16
+
17
+ end
18
+ end
19
+
@@ -0,0 +1,228 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 3), 'lib')
4
+
5
+ require 'libpath/util'
6
+
7
+ require 'test/unit'
8
+
9
+ require 'libpath/internal_/platform'
10
+
11
+ class Test_LibPath_Util_make_path_canonical_via_extend < Test::Unit::TestCase
12
+
13
+ F = ::LibPath::Util
14
+
15
+ def test_empty
16
+
17
+ assert_equal '', F.make_path_canonical('')
18
+ end
19
+
20
+ def test_root
21
+
22
+ assert_equal '/', F.make_path_canonical('/')
23
+
24
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
25
+
26
+ assert_equal '\\', F.make_path_canonical('//')
27
+ else
28
+
29
+ assert_equal '/', F.make_path_canonical('//')
30
+ end
31
+ end
32
+
33
+ def test_one_dot
34
+
35
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
36
+
37
+ assert_equal '.\\', F.make_path_canonical('.')
38
+
39
+ assert_equal '.\\', F.make_path_canonical('.\\')
40
+ assert_equal '.\\', F.make_path_canonical('.\\', make_slashes_canonical: true)
41
+
42
+ assert_equal './', F.make_path_canonical('./')
43
+ assert_equal '.\\', F.make_path_canonical('.\\', make_slashes_canonical: true)
44
+ else
45
+
46
+ assert_equal './', F.make_path_canonical('.')
47
+
48
+ assert_equal './', F.make_path_canonical('./')
49
+ assert_equal './', F.make_path_canonical('./', make_slashes_canonical: true)
50
+ end
51
+ end
52
+
53
+ def test_two_dots
54
+
55
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
56
+
57
+ assert_equal '..\\', F.make_path_canonical('..')
58
+ assert_equal '..\\', F.make_path_canonical('..//')
59
+ assert_equal '../', F.make_path_canonical('../')
60
+
61
+ assert_equal '/dir.14/', F.make_path_canonical('/dir.14/dir.2/..')
62
+ assert_equal 'dir.14/', F.make_path_canonical('dir.14/dir.2/..')
63
+
64
+ assert_equal '/', F.make_path_canonical('/dir.14/dir.2/../..')
65
+ assert_equal '/', F.make_path_canonical('/dir.14/dir.2/../../..')
66
+ assert_equal '.\\', F.make_path_canonical('dir.14/dir.2/../..')
67
+
68
+ assert_equal '\\', F.make_path_canonical('\\dir.14\\dir.2\\..\\..')
69
+ assert_equal '\\', F.make_path_canonical('\\dir.14\\dir.2\\..\\..\\..')
70
+ assert_equal '.\\', F.make_path_canonical('dir.14\\dir.2\\..\\..')
71
+ else
72
+
73
+ assert_equal '../', F.make_path_canonical('..')
74
+ assert_equal '../', F.make_path_canonical('../')
75
+
76
+ assert_equal '/dir.14/', F.make_path_canonical('/dir.14/dir.2/..')
77
+ assert_equal 'dir.14/', F.make_path_canonical('dir.14/dir.2/..')
78
+
79
+ assert_equal '/', F.make_path_canonical('/dir.14/dir.2/../..')
80
+ assert_equal '/', F.make_path_canonical('/dir.14/dir.2/../../..')
81
+ assert_equal './', F.make_path_canonical('dir.14/dir.2/../..')
82
+ end
83
+
84
+ end
85
+
86
+ def test_redundant_slashes
87
+
88
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
89
+
90
+ assert_equal '.\\', F.make_path_canonical('.//')
91
+ assert_equal '.\\', F.make_path_canonical('.\\\\')
92
+
93
+ assert_equal '..\\', F.make_path_canonical('..//')
94
+ else
95
+
96
+ assert_equal './', F.make_path_canonical('.//')
97
+
98
+ assert_equal '../', F.make_path_canonical('..//')
99
+ end
100
+ end
101
+
102
+ def test_basenames
103
+
104
+ assert_equal 'a', F.make_path_canonical('a')
105
+
106
+ assert_equal 'file.ext', F.make_path_canonical('file.ext')
107
+ end
108
+
109
+ def test_trailing_dots
110
+
111
+ assert_equal 'a.', F.make_path_canonical('a.')
112
+ assert_equal 'a.', F.make_path_canonical('./a.')
113
+ assert_equal 'a.', F.make_path_canonical('././././a.')
114
+ assert_equal 'a.', F.make_path_canonical('abc/../a.')
115
+
116
+ assert_equal 'a..', F.make_path_canonical('a..')
117
+ assert_equal 'a..', F.make_path_canonical('./a..')
118
+ assert_equal 'a..', F.make_path_canonical('././././a..')
119
+ assert_equal 'a..', F.make_path_canonical('abc/../a..')
120
+ assert_equal 'a..', F.make_path_canonical('abc//../a..')
121
+
122
+ assert_equal 'a...', F.make_path_canonical('a...')
123
+ assert_equal 'a...', F.make_path_canonical('./a...')
124
+ assert_equal 'a...', F.make_path_canonical('././././a...')
125
+ assert_equal 'a...', F.make_path_canonical('abc/../a...')
126
+
127
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
128
+
129
+ assert_equal 'a.', F.make_path_canonical('a.')
130
+ assert_equal 'a.', F.make_path_canonical('.\\a.')
131
+ assert_equal 'a.', F.make_path_canonical('.\\.\\.\\.\\a.')
132
+ assert_equal 'a.', F.make_path_canonical('abc\\..\\a.')
133
+
134
+ assert_equal 'a..', F.make_path_canonical('a..')
135
+ assert_equal 'a..', F.make_path_canonical('.\\a..')
136
+ assert_equal 'a..', F.make_path_canonical('.\\.\\.\\.\\a..')
137
+ assert_equal 'a..', F.make_path_canonical('abc\\..\\a..')
138
+
139
+ assert_equal 'a...', F.make_path_canonical('a...')
140
+ assert_equal 'a...', F.make_path_canonical('.\\a...')
141
+ assert_equal 'a...', F.make_path_canonical('.\\.\\.\\.\\a...')
142
+ assert_equal 'a...', F.make_path_canonical('abc\\..\\a...')
143
+ end
144
+ end
145
+
146
+ def test_one_dots_directory
147
+
148
+ assert_equal 'abc', F.make_path_canonical('./abc')
149
+
150
+ assert_equal 'abc', F.make_path_canonical('././abc')
151
+ assert_equal 'abc', F.make_path_canonical('././/abc')
152
+ assert_equal 'abc', F.make_path_canonical('././//////////////////abc')
153
+
154
+ assert_equal 'abc', F.make_path_canonical('./././././././././abc')
155
+
156
+ assert_equal 'abc/', F.make_path_canonical('abc/./')
157
+
158
+ assert_equal 'abc/', F.make_path_canonical('./abc/./')
159
+
160
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
161
+
162
+ assert_equal 'abc', F.make_path_canonical('.\\abc')
163
+
164
+ assert_equal 'abc', F.make_path_canonical('.\\.\\abc')
165
+
166
+ assert_equal 'abc', F.make_path_canonical('.\\.\\.\\.\\.\\.\\.\\.\\.\\abc')
167
+
168
+ assert_equal 'abc\\', F.make_path_canonical('abc/./', make_slashes_canonical: true)
169
+
170
+ assert_equal 'abc\\', F.make_path_canonical('abc\\.\\')
171
+
172
+ assert_equal 'abc\\', F.make_path_canonical('.\\abc\\.\\')
173
+
174
+ assert_equal 'abc\\', F.make_path_canonical('./abc/./', make_slashes_canonical: true)
175
+ end
176
+ end
177
+
178
+ def test_two_dots_directories
179
+
180
+ assert_equal '../', F.make_path_canonical('../')
181
+
182
+ assert_equal '../abc', F.make_path_canonical('../abc')
183
+
184
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
185
+
186
+ assert_equal '.\\', F.make_path_canonical('abc/..')
187
+ else
188
+
189
+ assert_equal './', F.make_path_canonical('abc/..')
190
+ end
191
+
192
+ assert_equal './', F.make_path_canonical('abc/../')
193
+
194
+ assert_equal 'def', F.make_path_canonical('abc/../def')
195
+
196
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
197
+
198
+ assert_equal '.\\', F.make_path_canonical('abc/../def/..')
199
+ else
200
+
201
+ assert_equal './', F.make_path_canonical('abc/../def/..')
202
+ end
203
+
204
+ assert_equal './', F.make_path_canonical('abc/../def/../')
205
+
206
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
207
+
208
+ assert_equal '..\\', F.make_path_canonical('..\\')
209
+
210
+ assert_equal '..\\abc', F.make_path_canonical('..\\abc')
211
+
212
+ assert_equal '.\\', F.make_path_canonical('abc\\..')
213
+
214
+ assert_equal '.\\', F.make_path_canonical('abc\\..\\')
215
+
216
+ assert_equal 'def', F.make_path_canonical('abc\\..\\def')
217
+ assert_equal 'def', F.make_path_canonical('abc\\\\..\\def')
218
+
219
+ assert_equal '.\\', F.make_path_canonical('abc\\..\\def\\..')
220
+
221
+ assert_equal '.\\', F.make_path_canonical('abc\\..\\def\\..\\')
222
+ assert_equal '.\\', F.make_path_canonical('abc\\\\..\\def\\..\\')
223
+ assert_equal '.\\', F.make_path_canonical('abc\\..\\\\def\\..\\')
224
+ end
225
+ end
226
+ end
227
+
228
+