recls-ruby 2.6.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # test Recls entries
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
6
+
7
+
8
+ require 'recls'
9
+
10
+ require 'test/unit'
11
+
12
+ class Test_Recls_entry < Test::Unit::TestCase
13
+
14
+ unless defined? assert_false
15
+ def assert_false arg0, *args
16
+ assert !arg0, *args
17
+ end
18
+ end
19
+
20
+ def setup
21
+
22
+ @cwd = Dir.pwd
23
+ end
24
+
25
+ def test_entry_does_not_mark_directory
26
+
27
+ cwd = Recls.stat @cwd
28
+
29
+ assert_equal @cwd, cwd.path
30
+ end
31
+
32
+ def test_entry_does_mark_directory
33
+
34
+ cwd = Recls.stat @cwd, Recls::MARK_DIRECTORIES
35
+
36
+ # assert_equal "#{@cwd}#{Recls::PATH_NAME_SEPARATOR}", cwd.path
37
+ assert_equal "#{@cwd}/", cwd.path
38
+ end
39
+ end
40
+
@@ -0,0 +1,68 @@
1
+ #! /usr/bin/ruby
2
+ #
3
+ # test Recls.FileSearch class
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
6
+
7
+
8
+ require 'recls'
9
+
10
+ require 'test/unit'
11
+
12
+ class Test_Recls_FileSearch_class < Test::Unit::TestCase
13
+
14
+ def test_construction
15
+
16
+ fs = Recls::FileSearch.new(nil, nil, 0)
17
+
18
+ assert_not_nil(fs)
19
+
20
+ end # def test_construction
21
+
22
+ def test_construction_1
23
+
24
+ fs = Recls::FileSearch.new('abc', '*c', Recls::FILES)
25
+
26
+ assert_not_nil(fs)
27
+ assert_equal('abc', fs.search_root)
28
+ assert_equal(['*c'], fs.patterns)
29
+ if not defined? RECLS_NO_OBSOLETE
30
+ assert_equal('abc', fs.searchRoot)
31
+ assert_equal(['*c'], fs.pattern)
32
+ end
33
+ assert_equal(Recls::FILES, fs.flags)
34
+
35
+ end # def test_construction_1
36
+
37
+ def test_construction_2
38
+
39
+ fs = Recls::FileSearch.new('def', '*c', 0)
40
+
41
+ assert_not_nil(fs)
42
+ assert_equal('def', fs.search_root)
43
+ assert_equal(['*c'], fs.patterns)
44
+ if not defined? RECLS_NO_OBSOLETE
45
+ assert_equal('def', fs.searchRoot)
46
+ assert_equal(['*c'], fs.pattern)
47
+ end
48
+ assert_equal(Recls::FILES, fs.flags)
49
+
50
+ end # def test_construction_2
51
+
52
+ def test_construction_3
53
+
54
+ fs = Recls::FileSearch.new('ghi', '*c', Recls::DIRECTORIES)
55
+
56
+ assert_not_nil(fs)
57
+ assert_equal('ghi', fs.search_root)
58
+ assert_equal(['*c'], fs.patterns)
59
+ if not defined? RECLS_NO_OBSOLETE
60
+ assert_equal('ghi', fs.searchRoot)
61
+ assert_equal(['*c'], fs.pattern)
62
+ end
63
+ assert_equal(Recls::DIRECTORIES, fs.flags)
64
+
65
+ end # def test_construction_3
66
+
67
+ end
68
+
@@ -0,0 +1,78 @@
1
+ #! /usr/bin/ruby
2
+ #
3
+ # test Recls constants
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
6
+
7
+
8
+ require 'recls'
9
+
10
+ require 'test/unit'
11
+
12
+ class Test_Recls_constants < Test::Unit::TestCase
13
+
14
+ private
15
+ @@OS_IS_WINDOWS = Recls::Ximpl::OS::OS_IS_WINDOWS
16
+
17
+ public
18
+
19
+
20
+ def test_PATH_NAME_SEPARATOR
21
+
22
+ expected = @@OS_IS_WINDOWS ? '\\' : '/'
23
+
24
+ assert_equal(expected, Recls::PATH_NAME_SEPARATOR)
25
+
26
+ end # def test_PATH_NAME_SEPARATOR
27
+
28
+ if not defined? RECLS_NO_OBSOLETE
29
+
30
+ def test_pathNameSeparator
31
+
32
+ assert_equal(Recls::PATH_NAME_SEPARATOR, Recls::pathNameSeparator)
33
+
34
+ end # def test_pathNameSeparator
35
+
36
+ end
37
+
38
+ def test_PATH_SEPARATOR
39
+
40
+ expected = @@OS_IS_WINDOWS ? ';' : ':'
41
+
42
+ assert_equal(expected, Recls::PATH_SEPARATOR)
43
+
44
+ end # def test_PATH_SEPARATOR
45
+
46
+ if not defined? RECLS_NO_OBSOLETE
47
+
48
+ def test_pathSeparator
49
+
50
+ assert_equal(Recls::PATH_SEPARATOR, Recls::pathSeparator)
51
+
52
+ end # def test_pathSeparator
53
+
54
+ end
55
+
56
+
57
+
58
+ def test_WILDCARDS_ALL
59
+
60
+ #expected = @@OS_IS_WINDOWS ? '*.*' : '*'
61
+
62
+ assert_equal('*', Recls::WILDCARDS_ALL)
63
+
64
+ end # def test_WILDCARDS_ALL
65
+
66
+ if not defined? RECLS_NO_OBSOLETE
67
+
68
+ def test_wildcardsAll
69
+
70
+ assert_equal(Recls::WILDCARDS_ALL, Recls::wildcardsAll)
71
+
72
+ end # def test_wildcardsAll
73
+
74
+ end
75
+
76
+ end
77
+
78
+
@@ -0,0 +1,159 @@
1
+ #! /usr/bin/ruby
2
+ #
3
+ # test Recls canonicalise_path() method
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
6
+
7
+
8
+ require 'recls/util'
9
+
10
+ require 'test/unit'
11
+
12
+ class Test_canonicalise_path < Test::Unit::TestCase
13
+
14
+ def test_nil
15
+
16
+ assert_nil(Recls::canonicalise_path(nil))
17
+
18
+ end
19
+
20
+ def test_empty
21
+
22
+ assert_equal('', Recls::canonicalise_path(''))
23
+
24
+ end
25
+
26
+ def test_dots_directories
27
+
28
+ assert_equal('.', Recls::canonicalise_path('.'))
29
+ assert_equal('./', Recls::canonicalise_path('./'))
30
+ assert_equal('.', Recls::canonicalise_path('././.'))
31
+ assert_equal('./', Recls::canonicalise_path('./././'))
32
+
33
+ assert_equal('..', Recls::canonicalise_path('..'))
34
+ assert_equal('../', Recls::canonicalise_path('../'))
35
+ assert_equal('..', Recls::canonicalise_path('../.'))
36
+ assert_equal('../', Recls::canonicalise_path('.././'))
37
+
38
+ end
39
+
40
+ def test_files_only
41
+
42
+ assert_equal('a', Recls::canonicalise_path('a'))
43
+ assert_equal('file', Recls::canonicalise_path('file'))
44
+ assert_equal('file.ext', Recls::canonicalise_path('file.ext'))
45
+
46
+ end
47
+
48
+ def test_zero_parts
49
+
50
+ if Recls::Ximpl::OS::OS_IS_WINDOWS
51
+
52
+ assert_equal('H:', Recls::canonicalise_path('H:'))
53
+
54
+ assert_equal('\\\\server', Recls::canonicalise_path('\\\\server'))
55
+ assert_equal('\\\\server\\', Recls::canonicalise_path('\\\\server\\'))
56
+ assert_equal('\\\\server\\share', Recls::canonicalise_path('\\\\server\\share'))
57
+ assert_equal('\\\\server\\share/', Recls::canonicalise_path('\\\\server\\share/'))
58
+
59
+ end
60
+
61
+ end
62
+
63
+ def test_canonicalised_directories_one_level
64
+
65
+ assert_equal('abc', Recls::canonicalise_path('abc'))
66
+ assert_equal('abc/', Recls::canonicalise_path('abc/'))
67
+ assert_equal('/abc', Recls::canonicalise_path('/abc'))
68
+ assert_equal('/abc/', Recls::canonicalise_path('/abc/'))
69
+
70
+ end # test_canonicalised_directories_one_level
71
+
72
+ def test_canonicalised_directories_two_levels
73
+
74
+ assert_equal('abc/def', Recls::canonicalise_path('abc/def'))
75
+ assert_equal('abc/def/', Recls::canonicalise_path('abc/def/'))
76
+ assert_equal('/abc/def', Recls::canonicalise_path('/abc/def'))
77
+ assert_equal('/abc/def/', Recls::canonicalise_path('/abc/def/'))
78
+
79
+ end # test_canonicalised_directories_two_levels
80
+
81
+ def test_uncanonicalised_directories_one_level
82
+
83
+ assert_equal('.', Recls::canonicalise_path('.'))
84
+ assert_equal('./', Recls::canonicalise_path('./'))
85
+ assert_equal('/', Recls::canonicalise_path('/.'))
86
+ assert_equal('/', Recls::canonicalise_path('/./'))
87
+
88
+ assert_equal('..', Recls::canonicalise_path('..'))
89
+ assert_equal('../', Recls::canonicalise_path('../'))
90
+ assert_equal('/', Recls::canonicalise_path('/..'))
91
+ assert_equal('/', Recls::canonicalise_path('/../'))
92
+
93
+ end # def test_uncanonicalised_directories_one_level
94
+
95
+ def test_single_canonicalisation
96
+
97
+ assert_equal('dir.1/', Recls::canonicalise_path('dir.1/'))
98
+ assert_equal('dir.1/', Recls::canonicalise_path('dir.1/./'))
99
+ assert_equal('dir.1/', Recls::canonicalise_path('./dir.1/./'))
100
+ assert_equal('dir.1/', Recls::canonicalise_path('./dir.1/.'))
101
+
102
+ end
103
+
104
+ def test_double_canonicalisation
105
+
106
+ assert_equal('dir.1/dir.2/', Recls::canonicalise_path('dir.1/dir.2/'))
107
+ assert_equal('dir.1/dir.2/', Recls::canonicalise_path('dir.1/dir.2/dir.3/../'))
108
+ assert_equal('dir.1/dir.2/', Recls::canonicalise_path('dir.1/dir.2/dir.3/../'))
109
+ assert_equal('dir.1/dir.2/', Recls::canonicalise_path('dir.1/dir.3/../dir.2/'))
110
+ assert_equal('dir.1/dir.2/', Recls::canonicalise_path('dir.3/../dir.1/dir.2/'))
111
+
112
+ assert_equal('../dir.1/dir.2/', Recls::canonicalise_path('../dir.1/dir.2/'))
113
+ assert_equal('../dir.4/', Recls::canonicalise_path('../dir.1/../dir.4/'))
114
+
115
+ assert_equal('/dir.1/dir.2/', Recls::canonicalise_path('/dir.1/dir.2/'))
116
+ assert_equal('/dir.1/dir.2/', Recls::canonicalise_path('/dir.1/dir.2/dir.3/../'))
117
+ assert_equal('/dir.1/dir.2/', Recls::canonicalise_path('/dir.1/dir.2/dir.3/../'))
118
+ assert_equal('/dir.1/dir.2/', Recls::canonicalise_path('/dir.1/dir.3/../dir.2/'))
119
+ assert_equal('/dir.1/dir.2/', Recls::canonicalise_path('/dir.3/../dir.1/dir.2/'))
120
+
121
+ assert_equal('/dir.1/dir.2/', Recls::canonicalise_path('/../dir.1/dir.2/'))
122
+ assert_equal('/dir.4/', Recls::canonicalise_path('/../dir.1/../dir.4/'))
123
+
124
+ assert_equal('/dir.14/', Recls::canonicalise_path('/dir.14/dir.2/..'))
125
+ assert_equal('/', Recls::canonicalise_path('/dir.14/dir.2/../..'))
126
+ assert_equal('/', Recls::canonicalise_path('/dir.14/dir.2/../../..'))
127
+ assert_equal('dir.14/', Recls::canonicalise_path('dir.14/dir.2/..'))
128
+ assert_equal('.', Recls::canonicalise_path('dir.14/dir.2/../..'))
129
+ assert_equal('..', Recls::canonicalise_path('dir.14/dir.2/../../..'))
130
+
131
+ if Recls::Ximpl::OS::OS_IS_WINDOWS
132
+
133
+ assert_equal('H:\\dir.1\\dir.2\\', Recls::canonicalise_path('H:\\dir.1\\dir.2\\'))
134
+ assert_equal('H:\\dir.1\\dir.2\\', Recls::canonicalise_path('H:\\dir.1\\dir.2\\dir.3\\..\\'))
135
+ assert_equal('H:\\dir.1\\dir.2\\', Recls::canonicalise_path('H:\\dir.1\\dir.2\\dir.3\\..\\'))
136
+ assert_equal('H:\\dir.1\\dir.2\\', Recls::canonicalise_path('H:\\dir.1\\dir.3\\..\\dir.2\\'))
137
+ assert_equal('H:\\dir.1\\dir.2\\', Recls::canonicalise_path('H:\\dir.3\\..\\dir.1\\dir.2\\'))
138
+
139
+ assert_equal('H:\\dir.43\\dir.5\\', Recls::canonicalise_path('H:\\..\\dir.43\\dir.5\\'))
140
+ assert_equal('H:\\dir.42\\', Recls::canonicalise_path('H:\\..\\dir.1\\..\\dir.42\\'))
141
+
142
+ end
143
+
144
+ end
145
+
146
+ def test_complex_examples
147
+
148
+ assert_equal('../dir.11/dir.22/dir.33/file3.', Recls::canonicalise_path('abc/.././././.././dir.1/../dir.11/dir.22/dir.33/file3.'))
149
+ assert_equal('/dir.11/dir.22/dir.33/file3.', Recls::canonicalise_path('/abc/.././././.././dir.1/../dir.11/dir.22/dir.33/file3.'))
150
+ assert_equal('../dir.11/dir.22/dir.33/file3.', Recls::canonicalise_path('./././abc/.././././.././dir.1/../dir.11/dir.22/././dir.33/././file3.'))
151
+
152
+ if Recls::Ximpl::OS::OS_IS_WINDOWS
153
+
154
+ end
155
+
156
+ end
157
+
158
+ end
159
+
@@ -0,0 +1,908 @@
1
+ #! /usr/bin/ruby
2
+ #
3
+ # test Recls::Ximpl::Util namespace
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
6
+
7
+
8
+ require 'recls'
9
+
10
+ require 'test/unit'
11
+
12
+ class Test_Recls_Ximpl_Util_get_windows_root < Test::Unit::TestCase
13
+
14
+ def test_nil
15
+
16
+ wr, rem = Recls::Ximpl::Util.get_windows_root(nil)
17
+ assert_nil(wr)
18
+ assert_nil(rem)
19
+
20
+ end
21
+
22
+ def test_empty
23
+
24
+ wr, rem = Recls::Ximpl::Util.get_windows_root('')
25
+ assert_nil(wr)
26
+ assert_equal('', rem)
27
+
28
+ end
29
+
30
+ def test_dots_directories
31
+
32
+ wr, rem = Recls::Ximpl::Util.get_windows_root('.')
33
+ assert_nil(wr)
34
+ assert_not_nil(rem)
35
+ assert_equal('.', rem)
36
+
37
+ wr, rem = Recls::Ximpl::Util.get_windows_root('..')
38
+ assert_nil(wr)
39
+ assert_not_nil(rem)
40
+ assert_equal('..', rem)
41
+
42
+ end
43
+
44
+ def test_relative_paths
45
+
46
+ wr, rem = Recls::Ximpl::Util.get_windows_root('a')
47
+ assert_nil(wr)
48
+ assert_not_nil(rem)
49
+ assert_equal('a', rem)
50
+
51
+ wr, rem = Recls::Ximpl::Util.get_windows_root('dir1')
52
+ assert_nil(wr)
53
+ assert_not_nil(rem)
54
+ assert_equal('dir1', rem)
55
+
56
+ wr, rem = Recls::Ximpl::Util.get_windows_root('dir1/dir2')
57
+ assert_nil(wr)
58
+ assert_not_nil(rem)
59
+ assert_equal('dir1/dir2', rem)
60
+
61
+ end
62
+
63
+ def test_windows_paths
64
+
65
+ if Recls::Ximpl::OS::OS_IS_WINDOWS
66
+
67
+ # drive only
68
+ wr, rem = Recls::Ximpl::Util.get_windows_root('H:')
69
+ assert_not_nil(wr)
70
+ assert_equal('H:', wr)
71
+ assert_not_nil(rem)
72
+ assert_equal('', rem)
73
+
74
+ # drive and root directory
75
+ wr, rem = Recls::Ximpl::Util.get_windows_root('H:\\')
76
+ assert_not_nil(wr)
77
+ assert_equal('H:', wr)
78
+ assert_not_nil(rem)
79
+ assert_equal('\\', rem)
80
+
81
+ # drive and rooted sub-directory
82
+ wr, rem = Recls::Ximpl::Util.get_windows_root('H:\\dir1')
83
+ assert_not_nil(wr)
84
+ assert_equal('H:', wr)
85
+ assert_not_nil(rem)
86
+ assert_equal('\\dir1', rem)
87
+
88
+ # drive and unrooted sub-directory
89
+ wr, rem = Recls::Ximpl::Util.get_windows_root('H:dir1')
90
+ assert_not_nil(wr)
91
+ assert_equal('H:', wr)
92
+ assert_not_nil(rem)
93
+ assert_equal('dir1', rem)
94
+
95
+ # UNC with server only
96
+ wr, rem = Recls::Ximpl::Util.get_windows_root('\\\\server')
97
+ assert_not_nil(wr)
98
+ assert_equal('\\\\server', wr)
99
+ assert_nil(rem)
100
+
101
+ # UNC with server and slash
102
+ wr, rem = Recls::Ximpl::Util.get_windows_root('\\\\server\\')
103
+ assert_not_nil(wr)
104
+ assert_equal('\\\\server\\', wr)
105
+ assert_nil(rem)
106
+
107
+ # UNC with server and drive only
108
+ wr, rem = Recls::Ximpl::Util.get_windows_root('\\\\server\\share')
109
+ assert_not_nil(wr)
110
+ assert_equal('\\\\server\\share', wr)
111
+ assert_nil(rem)
112
+
113
+ # UNC full drive with root directory
114
+ wr, rem = Recls::Ximpl::Util.get_windows_root('\\\\server\\share\\')
115
+ assert_not_nil(wr)
116
+ assert_equal('\\\\server\\share', wr)
117
+ assert_equal('\\', rem)
118
+
119
+ wr, rem = Recls::Ximpl::Util.get_windows_root('\\\\server\\share/')
120
+ assert_not_nil(wr)
121
+ assert_equal('\\\\server\\share', wr)
122
+ assert_equal('/', rem)
123
+
124
+ end
125
+
126
+ end
127
+
128
+ end
129
+
130
+ class Test_Recls_Ximpl_Util_split_path < Test::Unit::TestCase
131
+
132
+ def test_nil
133
+
134
+ wr, dir, bn, no, ex = Recls::Ximpl::Util::split_path(nil)
135
+ assert_nil(wr)
136
+ assert_nil(dir)
137
+ assert_nil(bn)
138
+ assert_nil(no)
139
+ assert_nil(ex)
140
+
141
+ end
142
+
143
+ def test_empty
144
+
145
+ wr, dir, bn, no, ex = Recls::Ximpl::Util::split_path('')
146
+ assert_nil(wr)
147
+ assert_nil(dir)
148
+ assert_nil(bn)
149
+ assert_nil(no)
150
+ assert_nil(ex)
151
+
152
+ end
153
+
154
+ def test_name_only
155
+
156
+ wr, dir, bn, no, ex = Recls::Ximpl::Util::split_path('a')
157
+ assert_nil(wr)
158
+ assert_nil(dir)
159
+ assert_equal('a', bn)
160
+ assert_equal('a', no)
161
+ assert_nil(ex)
162
+
163
+ wr, dir, bn, no, ex = Recls::Ximpl::Util::split_path('abc')
164
+ assert_nil(wr)
165
+ assert_nil(dir)
166
+ assert_equal('abc', bn)
167
+ assert_equal('abc', no)
168
+ assert_nil(ex)
169
+
170
+ wr, dir, bn, no, ex = Recls::Ximpl::Util::split_path('a_slightly-long_file-name')
171
+ assert_nil(wr)
172
+ assert_nil(dir)
173
+ assert_equal('a_slightly-long_file-name', bn)
174
+ assert_equal('a_slightly-long_file-name', no)
175
+ assert_nil(ex)
176
+
177
+ end
178
+
179
+ def test_name_and_extensions
180
+
181
+ wr, dir, bn, no, ex = Recls::Ximpl::Util::split_path('a.b')
182
+ assert_nil(wr)
183
+ assert_nil(dir)
184
+ assert_equal('a.b', bn)
185
+ assert_equal('a', no)
186
+ assert_equal('.b', ex)
187
+
188
+ wr, dir, bn, no, ex = Recls::Ximpl::Util::split_path('a.b.c')
189
+ assert_nil(wr)
190
+ assert_nil(dir)
191
+ assert_equal('a.b.c', bn)
192
+ assert_equal('a.b', no)
193
+ assert_equal('.c', ex)
194
+
195
+ end
196
+
197
+ def test_directory_only
198
+
199
+ wr, dir, bn, no, ex = Recls::Ximpl::Util::split_path('a.b/')
200
+ assert_nil(wr)
201
+ assert_equal('a.b/', dir)
202
+ assert_nil(bn)
203
+ assert_nil(no)
204
+ assert_nil(ex)
205
+
206
+ wr, dir, bn, no, ex = Recls::Ximpl::Util::split_path('a.b.c/')
207
+ assert_nil(wr)
208
+ assert_equal('a.b.c/', dir)
209
+ assert_nil(bn)
210
+ assert_nil(no)
211
+ assert_nil(ex)
212
+
213
+ wr, dir, bn, no, ex = Recls::Ximpl::Util::split_path('dir1/dir2/a.b/')
214
+ assert_nil(wr)
215
+ assert_equal('dir1/dir2/a.b/', dir)
216
+ assert_nil(bn)
217
+ assert_nil(no)
218
+ assert_nil(ex)
219
+
220
+ wr, dir, bn, no, ex = Recls::Ximpl::Util::split_path('/dir1/dir2/a.b/')
221
+ assert_nil(wr)
222
+ assert_equal('/dir1/dir2/a.b/', dir)
223
+ assert_nil(bn)
224
+ assert_nil(no)
225
+ assert_nil(ex)
226
+
227
+ wr, dir, bn, no, ex = Recls::Ximpl::Util::split_path('/')
228
+ assert_nil(wr)
229
+ assert_equal('/', dir)
230
+ assert_nil(bn)
231
+ assert_nil(no)
232
+ assert_nil(ex)
233
+
234
+ end
235
+
236
+ def test_directory_and_name_only
237
+
238
+ wr, dir, bn, no, ex = Recls::Ximpl::Util::split_path('dir1/dir2/file3')
239
+ assert_nil(wr)
240
+ assert_equal('dir1/dir2/', dir)
241
+ assert_equal('file3', bn)
242
+ assert_equal('file3', no)
243
+ assert_nil(ex)
244
+
245
+ wr, dir, bn, no, ex = Recls::Ximpl::Util::split_path('/dir1/dir2/file3')
246
+ assert_nil(wr)
247
+ assert_equal('/dir1/dir2/', dir)
248
+ assert_equal('file3', bn)
249
+ assert_equal('file3', no)
250
+ assert_nil(ex)
251
+
252
+ wr, dir, bn, no, ex = Recls::Ximpl::Util::split_path('/dir.1/dir.2/file.3')
253
+ assert_nil(wr)
254
+ assert_equal('/dir.1/dir.2/', dir)
255
+ assert_equal('file.3', bn)
256
+ assert_equal('file', no)
257
+ assert_equal('.3', ex)
258
+
259
+ end
260
+
261
+ if Recls::Ximpl::OS::OS_IS_WINDOWS
262
+
263
+ def test_Windows_root
264
+
265
+ wr, dir, bn, no, ex = Recls::Ximpl::Util::split_path('H:')
266
+ assert_equal('H:', wr)
267
+ assert_nil(dir)
268
+ assert_nil(bn)
269
+ assert_nil(no)
270
+ assert_nil(ex)
271
+
272
+ wr, dir, bn, no, ex = Recls::Ximpl::Util::split_path('H:\\')
273
+ assert_equal('H:', wr)
274
+ assert_equal('\\', dir)
275
+ assert_nil(bn)
276
+ assert_nil(no)
277
+ assert_nil(ex)
278
+
279
+ wr, dir, bn, no, ex = Recls::Ximpl::Util::split_path('H:/')
280
+ assert_equal('H:', wr)
281
+ assert_equal('/', dir)
282
+ assert_nil(bn)
283
+ assert_nil(no)
284
+ assert_nil(ex)
285
+
286
+ wr, dir, bn, no, ex = Recls::Ximpl::Util::split_path('H:/file.3')
287
+ assert_equal('H:', wr)
288
+ assert_equal('/', dir)
289
+ assert_equal('file.3', bn)
290
+ assert_equal('file', no)
291
+ assert_equal('.3', ex)
292
+
293
+ wr, dir, bn, no, ex = Recls::Ximpl::Util::split_path('H:file.3')
294
+ assert_equal('H:', wr)
295
+ assert_nil(dir)
296
+ assert_equal('file.3', bn)
297
+ assert_equal('file', no)
298
+ assert_equal('.3', ex)
299
+
300
+ wr, dir, bn, no, ex = Recls::Ximpl::Util::split_path('H:/dir.1\\dir.2/file.3')
301
+ assert_equal('H:', wr)
302
+ assert_equal('/dir.1\\dir.2/', dir)
303
+ assert_equal('file.3', bn)
304
+ assert_equal('file', no)
305
+ assert_equal('.3', ex)
306
+
307
+ wr, dir, bn, no, ex = Recls::Ximpl::Util::split_path('H:/dir.1\\dir.2/file.')
308
+ assert_equal('H:', wr)
309
+ assert_equal('/dir.1\\dir.2/', dir)
310
+ assert_equal('file.', bn)
311
+ assert_equal('file', no)
312
+ assert_equal('.', ex)
313
+
314
+ end
315
+
316
+ end
317
+
318
+ end
319
+
320
+ class Test_Recls_Ximpl_basename < Test::Unit::TestCase
321
+
322
+ def test_basename_with_paths_without_directories
323
+
324
+ assert_equal('a', Recls::Ximpl::basename('a'))
325
+ assert_equal('abc', Recls::Ximpl::basename('abc'))
326
+ assert_equal('abc.def', Recls::Ximpl::basename('abc.def'))
327
+
328
+ end # def test_basename_with_paths_without_directories
329
+
330
+ def test_basename_with_paths_with_only_directories
331
+
332
+ assert_equal('', Recls::Ximpl::basename('a/'))
333
+ assert_equal('', Recls::Ximpl::basename('abc/def/'))
334
+ assert_equal('', Recls::Ximpl::basename('dir.1/dir2./'))
335
+
336
+ if Recls::Ximpl::OS::OS_IS_WINDOWS
337
+
338
+ assert_equal('', Recls::Ximpl::basename('H:\\'))
339
+ assert_equal('', Recls::Ximpl::basename('H:/'))
340
+ assert_equal('', Recls::Ximpl::basename('H:\\dir1\\'))
341
+ assert_equal('', Recls::Ximpl::basename('H:/dir1/'))
342
+
343
+ assert_equal('', Recls::Ximpl::basename('\\\\server\\share\\dir1/dir2\\'))
344
+ assert_equal('', Recls::Ximpl::basename('\\\\server\\share/dir1\\dir2/'))
345
+
346
+ assert_equal('', Recls::Ximpl::basename('\\\\server\\share\\dir1/'))
347
+ assert_equal('', Recls::Ximpl::basename('\\\\server\\share/dir1\\'))
348
+
349
+ assert_equal('', Recls::Ximpl::basename('\\\\server\\share\\'))
350
+ assert_equal('', Recls::Ximpl::basename('\\\\server\\share/'))
351
+
352
+ assert_equal('', Recls::Ximpl::basename('\\\\server\\share'))
353
+ assert_equal('', Recls::Ximpl::basename('\\\\server\\share'))
354
+
355
+ assert_equal('', Recls::Ximpl::basename('\\\\server\\'))
356
+ assert_equal('', Recls::Ximpl::basename('\\\\server\\'))
357
+
358
+ assert_equal('', Recls::Ximpl::basename('\\\\server'))
359
+ assert_equal('', Recls::Ximpl::basename('\\\\server'))
360
+
361
+ end
362
+
363
+ end # def test_basename_with_paths_with_only_directories
364
+
365
+ def test_basename_with_paths_with_directories
366
+
367
+ assert_equal('file2', Recls::Ximpl::basename('dir1/file2'))
368
+ assert_equal('file.2', Recls::Ximpl::basename('dir.1/file.2'))
369
+ assert_equal('b.c', Recls::Ximpl::basename('a/b.c'))
370
+ assert_equal('ghi.jkl', Recls::Ximpl::basename('abc/def/ghi.jkl'))
371
+ assert_equal('file3.', Recls::Ximpl::basename('dir.1/dir2./file3.'))
372
+
373
+ if Recls::Ximpl::OS::OS_IS_WINDOWS
374
+
375
+ assert_equal('file1', Recls::Ximpl::basename('H:\\file1'))
376
+ assert_equal('file1', Recls::Ximpl::basename('H:/file1'))
377
+ assert_equal('file1', Recls::Ximpl::basename('H:\\dir1\\file1'))
378
+ assert_equal('file1', Recls::Ximpl::basename('H:/dir1/file1'))
379
+
380
+ assert_equal('file1', Recls::Ximpl::basename('\\\\server\\share\\dir1/dir2\\file1'))
381
+ assert_equal('file1', Recls::Ximpl::basename('\\\\server\\share/dir1\\dir2/file1'))
382
+
383
+ assert_equal('file1', Recls::Ximpl::basename('\\\\server\\share\\dir1/file1'))
384
+ assert_equal('file1', Recls::Ximpl::basename('\\\\server\\share/dir1\\file1'))
385
+
386
+ assert_equal('file1', Recls::Ximpl::basename('\\\\server\\share\\file1'))
387
+ assert_equal('file1', Recls::Ximpl::basename('\\\\server\\share/file1'))
388
+
389
+ end
390
+
391
+ end # def test_basename_with_paths_with_directories
392
+
393
+ end
394
+
395
+ class Test_Recls_Ximpl_file_ext < Test::Unit::TestCase
396
+
397
+ def test_paths_without_files
398
+
399
+ assert_equal('', Recls::Ximpl::file_ext(''))
400
+ assert_equal('', Recls::Ximpl::file_ext('/'))
401
+ assert_equal('', Recls::Ximpl::file_ext('/dir1/'))
402
+ assert_equal('', Recls::Ximpl::file_ext('/dir.1/'))
403
+ assert_equal('', Recls::Ximpl::file_ext('/dir1/dir2/'))
404
+ assert_equal('', Recls::Ximpl::file_ext('/dir.1/dir2/'))
405
+
406
+ if Recls::Ximpl::OS::OS_IS_WINDOWS
407
+
408
+ assert_equal('', Recls::Ximpl::file_ext('H:'))
409
+ assert_equal('', Recls::Ximpl::file_ext('H:/'))
410
+ assert_equal('', Recls::Ximpl::file_ext('H:\\'))
411
+
412
+ assert_equal('', Recls::Ximpl::file_ext('\\\\server\\share\\dir1/dir2\\'))
413
+ assert_equal('', Recls::Ximpl::file_ext('\\\\server\\share/dir1\\dir2/'))
414
+
415
+ end
416
+
417
+ end
418
+
419
+ def test_paths_with_files_but_no_extensions
420
+
421
+ assert_equal('', Recls::Ximpl::file_ext('file3'))
422
+ assert_equal('', Recls::Ximpl::file_ext('/file3'))
423
+ assert_equal('', Recls::Ximpl::file_ext('/dir1/file3'))
424
+ assert_equal('', Recls::Ximpl::file_ext('/dir.1/file3'))
425
+ assert_equal('', Recls::Ximpl::file_ext('/dir1/dir2/file3'))
426
+ assert_equal('', Recls::Ximpl::file_ext('/dir.1/dir2/file3'))
427
+
428
+ if Recls::Ximpl::OS::OS_IS_WINDOWS
429
+
430
+ assert_equal('', Recls::Ximpl::file_ext('H:file3'))
431
+ assert_equal('', Recls::Ximpl::file_ext('H:/file3'))
432
+ assert_equal('', Recls::Ximpl::file_ext('H:\\file3'))
433
+
434
+ assert_equal('', Recls::Ximpl::file_ext('\\\\server\\share\\dir1/dir2\\file3'))
435
+ assert_equal('', Recls::Ximpl::file_ext('\\\\server\\share/dir1\\dir2/file3'))
436
+
437
+ end
438
+
439
+ end
440
+
441
+ def test_paths_with_files_with_extensions
442
+
443
+ assert_equal('.ext', Recls::Ximpl::file_ext('file3.ext'))
444
+ assert_equal('.ext', Recls::Ximpl::file_ext('/file3.ext'))
445
+ assert_equal('.ext', Recls::Ximpl::file_ext('/dir1/file3.ext'))
446
+ assert_equal('.ext', Recls::Ximpl::file_ext('/dir.1/file3.ext'))
447
+ assert_equal('.ext', Recls::Ximpl::file_ext('/dir1/dir2/file3.ext'))
448
+ assert_equal('.ext', Recls::Ximpl::file_ext('/dir.1/dir2/file3.ext'))
449
+
450
+ if Recls::Ximpl::OS::OS_IS_WINDOWS
451
+
452
+ assert_equal('.ext', Recls::Ximpl::file_ext('H:file3.ext'))
453
+ assert_equal('.ext', Recls::Ximpl::file_ext('H:/file3.ext'))
454
+ assert_equal('.ext', Recls::Ximpl::file_ext('H:\\file3.ext'))
455
+
456
+ assert_equal('.ext', Recls::Ximpl::file_ext('\\\\server\\share\\dir1/dir2\\file3.ext'))
457
+ assert_equal('.ext', Recls::Ximpl::file_ext('\\\\server\\share/dir1\\dir2/file3.ext'))
458
+
459
+ end
460
+
461
+ end
462
+
463
+ end
464
+
465
+ class Test_Recls_Ximpl_directory_from_directory_path < Test::Unit::TestCase
466
+
467
+ def test_nil
468
+
469
+ assert_nil(Recls::Ximpl::directory_from_directory_path(nil))
470
+
471
+ end
472
+
473
+ def test_empty
474
+
475
+ assert_equal('', Recls::Ximpl::directory_from_directory_path(''))
476
+
477
+ end
478
+
479
+ def test_dots
480
+
481
+ assert_equal('.', Recls::Ximpl::directory_from_directory_path('.'))
482
+
483
+ end
484
+
485
+ def test_leaf_dir_only
486
+
487
+ assert_equal('dir', Recls::Ximpl::directory_from_directory_path('dir'))
488
+ assert_equal('dir.ext', Recls::Ximpl::directory_from_directory_path('dir.ext'))
489
+ assert_equal('dir.', Recls::Ximpl::directory_from_directory_path('dir.'))
490
+
491
+ end
492
+
493
+ def test_roots_only
494
+
495
+ assert_equal('/', Recls::Ximpl::directory_from_directory_path('/'))
496
+
497
+ if Recls::Ximpl::OS::OS_IS_WINDOWS
498
+
499
+ assert_equal('\\', Recls::Ximpl::directory_from_directory_path('H:\\'))
500
+ assert_equal('\\', Recls::Ximpl::directory_from_directory_path('\\\\server\\share\\'))
501
+ assert_equal('/', Recls::Ximpl::directory_from_directory_path('H:/'))
502
+ assert_equal('/', Recls::Ximpl::directory_from_directory_path('\\\\server\\share/'))
503
+
504
+ end
505
+
506
+ end
507
+
508
+ def test_rooted_paths
509
+
510
+ if Recls::Ximpl::OS::OS_IS_WINDOWS
511
+
512
+ assert_equal('\\dir.1\\dir.2', Recls::Ximpl::directory_from_directory_path('H:\\dir.1\\dir.2'))
513
+ assert_equal('\\dir.1\\dir.2\\', Recls::Ximpl::directory_from_directory_path('H:\\dir.1\\dir.2\\'))
514
+
515
+ end
516
+
517
+ end
518
+
519
+ end
520
+
521
+ class Test_Recls_Ximpl_canonicalise_path < Test::Unit::TestCase
522
+
523
+ def test_nil
524
+
525
+ assert_nil(Recls::Ximpl::canonicalise_path(nil))
526
+
527
+ end
528
+
529
+ def test_empty
530
+
531
+ assert_equal('', Recls::Ximpl::canonicalise_path(''))
532
+
533
+ end
534
+
535
+ def test_dots_directories
536
+
537
+ assert_equal('.', Recls::Ximpl::canonicalise_path('.'))
538
+ assert_equal('./', Recls::Ximpl::canonicalise_path('./'))
539
+ assert_equal('.', Recls::Ximpl::canonicalise_path('././.'))
540
+ assert_equal('./', Recls::Ximpl::canonicalise_path('./././'))
541
+
542
+ assert_equal('..', Recls::Ximpl::canonicalise_path('..'))
543
+ assert_equal('../', Recls::Ximpl::canonicalise_path('../'))
544
+ assert_equal('..', Recls::Ximpl::canonicalise_path('../.'))
545
+ assert_equal('../', Recls::Ximpl::canonicalise_path('.././'))
546
+
547
+ end
548
+
549
+ def test_files_only
550
+
551
+ assert_equal('a', Recls::Ximpl::canonicalise_path('a'))
552
+ assert_equal('file', Recls::Ximpl::canonicalise_path('file'))
553
+ assert_equal('file.ext', Recls::Ximpl::canonicalise_path('file.ext'))
554
+
555
+ end
556
+
557
+ def test_zero_parts
558
+
559
+ if Recls::Ximpl::OS::OS_IS_WINDOWS
560
+
561
+ assert_equal('H:', Recls::Ximpl::canonicalise_path('H:'))
562
+
563
+ assert_equal('\\\\server', Recls::Ximpl::canonicalise_path('\\\\server'))
564
+ assert_equal('\\\\server\\', Recls::Ximpl::canonicalise_path('\\\\server\\'))
565
+ assert_equal('\\\\server\\share', Recls::Ximpl::canonicalise_path('\\\\server\\share'))
566
+ assert_equal('\\\\server\\share/', Recls::Ximpl::canonicalise_path('\\\\server\\share/'))
567
+
568
+ end
569
+
570
+ end
571
+
572
+ def test_single_canonicalisation
573
+
574
+ assert_equal('dir.1/', Recls::Ximpl::canonicalise_path('dir.1/'))
575
+ assert_equal('dir.1/', Recls::Ximpl::canonicalise_path('dir.1/./'))
576
+ assert_equal('dir.1/', Recls::Ximpl::canonicalise_path('./dir.1/./'))
577
+ assert_equal('dir.1/', Recls::Ximpl::canonicalise_path('./dir.1/.'))
578
+
579
+ end
580
+
581
+ def test_double_canonicalisation
582
+
583
+ assert_equal('dir.1/dir.2/', Recls::Ximpl::canonicalise_path('dir.1/dir.2/'))
584
+ assert_equal('dir.1/dir.2/', Recls::Ximpl::canonicalise_path('dir.1/dir.2/dir.3/../'))
585
+ assert_equal('dir.1/dir.2/', Recls::Ximpl::canonicalise_path('dir.1/dir.2/dir.3/../'))
586
+ assert_equal('dir.1/dir.2/', Recls::Ximpl::canonicalise_path('dir.1/dir.3/../dir.2/'))
587
+ assert_equal('dir.1/dir.2/', Recls::Ximpl::canonicalise_path('dir.3/../dir.1/dir.2/'))
588
+
589
+ assert_equal('../dir.1/dir.2/', Recls::Ximpl::canonicalise_path('../dir.1/dir.2/'))
590
+ assert_equal('../dir.4/', Recls::Ximpl::canonicalise_path('../dir.1/../dir.4/'))
591
+
592
+ assert_equal('/dir.1/dir.2/', Recls::Ximpl::canonicalise_path('/dir.1/dir.2/'))
593
+ assert_equal('/dir.1/dir.2/', Recls::Ximpl::canonicalise_path('/dir.1/dir.2/dir.3/../'))
594
+ assert_equal('/dir.1/dir.2/', Recls::Ximpl::canonicalise_path('/dir.1/dir.2/dir.3/../'))
595
+ assert_equal('/dir.1/dir.2/', Recls::Ximpl::canonicalise_path('/dir.1/dir.3/../dir.2/'))
596
+ assert_equal('/dir.1/dir.2/', Recls::Ximpl::canonicalise_path('/dir.3/../dir.1/dir.2/'))
597
+
598
+ assert_equal('/dir.1/dir.2/', Recls::Ximpl::canonicalise_path('/../dir.1/dir.2/'))
599
+ assert_equal('/dir.4/', Recls::Ximpl::canonicalise_path('/../dir.1/../dir.4/'))
600
+
601
+ assert_equal('/dir.14/', Recls::Ximpl::canonicalise_path('/dir.14/dir.2/..'))
602
+ assert_equal('dir.14/', Recls::Ximpl::canonicalise_path('dir.14/dir.2/..'))
603
+
604
+ assert_equal('/', Recls::Ximpl::canonicalise_path('/dir.14/dir.2/../..'))
605
+ assert_equal('.', Recls::Ximpl::canonicalise_path('dir.14/dir.2/../..'))
606
+
607
+ if Recls::Ximpl::OS::OS_IS_WINDOWS
608
+
609
+ assert_equal('H:\\dir.1\\dir.2\\', Recls::Ximpl::canonicalise_path('H:\\dir.1\\dir.2\\'))
610
+ assert_equal('H:\\dir.1\\dir.2\\', Recls::Ximpl::canonicalise_path('H:\\dir.1\\dir.2\\dir.3\\..\\'))
611
+ assert_equal('H:\\dir.1\\dir.2\\', Recls::Ximpl::canonicalise_path('H:\\dir.1\\dir.2\\dir.3\\..\\'))
612
+ assert_equal('H:\\dir.1\\dir.2\\', Recls::Ximpl::canonicalise_path('H:\\dir.1\\dir.3\\..\\dir.2\\'))
613
+ assert_equal('H:\\dir.1\\dir.2\\', Recls::Ximpl::canonicalise_path('H:\\dir.3\\..\\dir.1\\dir.2\\'))
614
+
615
+ assert_equal('H:\\dir.43\\dir.5\\', Recls::Ximpl::canonicalise_path('H:\\..\\dir.43\\dir.5\\'))
616
+ assert_equal('H:\\dir.42\\', Recls::Ximpl::canonicalise_path('H:\\..\\dir.1\\..\\dir.42\\'))
617
+
618
+ end
619
+
620
+ end
621
+
622
+ def test_complex_examples
623
+
624
+ assert_equal('../dir.11/dir.22/dir.33/file3.', Recls::Ximpl::canonicalise_path('abc/.././././.././dir.1/../dir.11/dir.22/dir.33/file3.'))
625
+ assert_equal('/dir.11/dir.22/dir.33/file3.', Recls::Ximpl::canonicalise_path('/abc/.././././.././dir.1/../dir.11/dir.22/dir.33/file3.'))
626
+ assert_equal('../dir.11/dir.22/dir.33/file3.', Recls::Ximpl::canonicalise_path('./././abc/.././././.././dir.1/../dir.11/dir.22/././dir.33/././file3.'))
627
+
628
+ if Recls::Ximpl::OS::OS_IS_WINDOWS
629
+
630
+ end
631
+
632
+ end
633
+
634
+ end
635
+
636
+ class Test_Recls_Ximpl_absolute_path < Test::Unit::TestCase
637
+
638
+ private
639
+ attr_reader :cwd
640
+ public
641
+
642
+ def setup
643
+
644
+ @cwd = Dir.getwd
645
+
646
+ end
647
+
648
+ def test_nil
649
+
650
+ assert_nil(Recls::Ximpl::absolute_path(nil))
651
+
652
+ assert_nil(Recls::Ximpl::absolute_path(nil, cwd))
653
+
654
+ end
655
+
656
+ def test_empty_path
657
+
658
+ assert_equal('', Recls::Ximpl::absolute_path(''))
659
+
660
+ assert_equal('', Recls::Ximpl::absolute_path('', cwd))
661
+
662
+ end
663
+
664
+ def test_rooted_paths
665
+
666
+ assert_equal('/', Recls::Ximpl::absolute_path('/'))
667
+ assert_equal('/abc', Recls::Ximpl::absolute_path('/abc'))
668
+ assert_equal('/abc/def', Recls::Ximpl::absolute_path('/abc/def'))
669
+ assert_equal('/abc/def/', Recls::Ximpl::absolute_path('/abc/def/'))
670
+ assert_equal('/abc/def/file.ext', Recls::Ximpl::absolute_path('/abc/def/file.ext'))
671
+
672
+ assert_equal('/', Recls::Ximpl::absolute_path('/', cwd))
673
+ assert_equal('/abc', Recls::Ximpl::absolute_path('/abc', cwd))
674
+ assert_equal('/abc/def', Recls::Ximpl::absolute_path('/abc/def', cwd))
675
+ assert_equal('/abc/def/', Recls::Ximpl::absolute_path('/abc/def/', cwd))
676
+ assert_equal('/abc/def/file.ext', Recls::Ximpl::absolute_path('/abc/def/file.ext', cwd))
677
+
678
+ end
679
+
680
+ def test_single_dot
681
+
682
+ assert_equal("#{cwd}", Recls::Ximpl::absolute_path('.'))
683
+ assert_equal("#{cwd}/", Recls::Ximpl::absolute_path('./'))
684
+
685
+ assert_equal("/dir.1/dir.2", Recls::Ximpl::absolute_path('.', "/dir.1/dir.2"))
686
+ assert_equal("/dir.1/dir.2/", Recls::Ximpl::absolute_path('./', "/dir.1/dir.2"))
687
+
688
+ assert_equal("/dir.1/dir.2", Recls::Ximpl::absolute_path('.', "/dir.1/dir.2/"))
689
+ assert_equal("/dir.1/dir.2/", Recls::Ximpl::absolute_path('./', "/dir.1/dir.2/"))
690
+
691
+ end
692
+
693
+ def test_double_dots
694
+
695
+ assert_equal("/dir.13", Recls::Ximpl::absolute_path('..', "/dir.13/dir.2"))
696
+ assert_equal("/dir.13/", Recls::Ximpl::absolute_path('../', "/dir.13/dir.2"))
697
+
698
+ assert_equal("/dir.1/", Recls::Ximpl::absolute_path('../', "/dir.1/dir.2"))
699
+
700
+ end
701
+ end
702
+
703
+ class Test_Recls_Ximpl_derive_relative_path < Test::Unit::TestCase
704
+
705
+ private
706
+ attr_reader :cwd
707
+ public
708
+
709
+ def setup
710
+
711
+ @cwd = Dir.getwd
712
+
713
+ end
714
+
715
+ def test_absolute_proper_subset
716
+
717
+ assert_equal('abc', Recls::Ximpl::derive_relative_path('/dir1/dir2', '/dir1/dir2/abc'))
718
+ assert_equal('abc', Recls::Ximpl::derive_relative_path('/dir1/dir2/', '/dir1/dir2/abc'))
719
+ assert_equal('abc/', Recls::Ximpl::derive_relative_path('/dir1/dir2', '/dir1/dir2/abc/'))
720
+ assert_equal('abc/', Recls::Ximpl::derive_relative_path('/dir1/dir2/', '/dir1/dir2/abc/'))
721
+
722
+ assert_equal('abc', Recls::Ximpl::derive_relative_path('dir1/dir2', 'dir1/dir2/abc'))
723
+ assert_equal('abc', Recls::Ximpl::derive_relative_path('dir1/dir2/', 'dir1/dir2/abc'))
724
+ assert_equal('abc/', Recls::Ximpl::derive_relative_path('dir1/dir2', 'dir1/dir2/abc/'))
725
+ assert_equal('abc/', Recls::Ximpl::derive_relative_path('dir1/dir2/', 'dir1/dir2/abc/'))
726
+
727
+ # assert_equal('/dir/dir2/abc', Recls::Ximpl::derive_relative_path('/dir1/dir2/abc', 'dir1/dir2'))
728
+ # assert_equal('/dir/dir2/abc', Recls::Ximpl::derive_relative_path('/dir1/dir2/abc', 'dir1/dir2/'))
729
+
730
+ end
731
+
732
+ def test_absolute_proper_subset_2
733
+
734
+ assert_equal('c++', Recls::Ximpl::derive_relative_path('/dir1/dir2', '/dir1/dir2/c++'))
735
+ assert_equal('c++', Recls::Ximpl::derive_relative_path('/dir1/dir2/', '/dir1/dir2/c++'))
736
+
737
+ assert_equal('c++', Recls::Ximpl::derive_relative_path('dir1/dir2', 'dir1/dir2/c++'))
738
+ assert_equal('c++', Recls::Ximpl::derive_relative_path('dir1/dir2/', 'dir1/dir2/c++'))
739
+
740
+ end
741
+
742
+ def test_absolute_same_1
743
+
744
+ assert_equal('.', Recls::Ximpl::derive_relative_path('/dir1/dir2/abc', '/dir1/dir2/abc'))
745
+ assert_equal('./', Recls::Ximpl::derive_relative_path('/dir1/dir2/abc', '/dir1/dir2/abc/'))
746
+ assert_equal('.', Recls::Ximpl::derive_relative_path('/dir1/dir2/abc/', '/dir1/dir2/abc'))
747
+ assert_equal('./', Recls::Ximpl::derive_relative_path('/dir1/dir2/abc/', '/dir1/dir2/abc/'))
748
+
749
+ assert_equal('.', Recls::Ximpl::derive_relative_path('dir1/dir2/abc', 'dir1/dir2/abc'))
750
+ assert_equal('./', Recls::Ximpl::derive_relative_path('dir1/dir2/abc', 'dir1/dir2/abc/'))
751
+ assert_equal('.', Recls::Ximpl::derive_relative_path('dir1/dir2/abc/', 'dir1/dir2/abc'))
752
+ assert_equal('./', Recls::Ximpl::derive_relative_path('dir1/dir2/abc/', 'dir1/dir2/abc/'))
753
+
754
+ end
755
+
756
+ def test_absolute_same_2
757
+
758
+ assert_equal('.', Recls::Ximpl::derive_relative_path('/dir1', '/dir1'))
759
+ assert_equal('.', Recls::Ximpl::derive_relative_path('/dir1/', '/dir1'))
760
+
761
+ end
762
+
763
+ def test_absolute_same_3
764
+
765
+ assert_equal('./', Recls::Ximpl::derive_relative_path('/', '/'))
766
+
767
+ end
768
+
769
+ def test_different_sub_trees_1
770
+
771
+ assert_equal('../abc', Recls::Ximpl::derive_relative_path('/dir1/dir2/ref', '/dir1/dir2/abc'))
772
+ assert_equal('../abc/', Recls::Ximpl::derive_relative_path('/dir1/dir2/ref', '/dir1/dir2/abc/'))
773
+ assert_equal('../abc', Recls::Ximpl::derive_relative_path('/dir1/dir2/ref/', '/dir1/dir2/abc'))
774
+ assert_equal('../abc/', Recls::Ximpl::derive_relative_path('/dir1/dir2/ref/', '/dir1/dir2/abc/'))
775
+
776
+ end
777
+
778
+ def test_different_sub_trees_2
779
+
780
+ assert_equal('../abc', Recls::Ximpl::derive_relative_path('/ref', '/abc'))
781
+ assert_equal('../abc/', Recls::Ximpl::derive_relative_path('/ref', '/abc/'))
782
+ assert_equal('../abc', Recls::Ximpl::derive_relative_path('/ref/', '/abc'))
783
+ assert_equal('../abc/', Recls::Ximpl::derive_relative_path('/ref/', '/abc/'))
784
+
785
+ end
786
+
787
+ def test_different_sub_trees_3
788
+
789
+ assert_equal('../../dir3/abc', Recls::Ximpl::derive_relative_path('/dir1/dir2/ref', '/dir1/dir3/abc'))
790
+ assert_equal('../../dir3/abc/', Recls::Ximpl::derive_relative_path('/dir1/dir2/ref', '/dir1/dir3/abc/'))
791
+ assert_equal('../../dir3/abc', Recls::Ximpl::derive_relative_path('/dir1/dir2/ref/', '/dir1/dir3/abc'))
792
+ assert_equal('../../dir3/abc/', Recls::Ximpl::derive_relative_path('/dir1/dir2/ref/', '/dir1/dir3/abc/'))
793
+
794
+ end
795
+
796
+ def test_different_sub_trees_4
797
+
798
+ assert_equal('..', Recls::Ximpl::derive_relative_path('/dir1/dir2/ref', '/dir1/dir2'))
799
+ assert_equal('..', Recls::Ximpl::derive_relative_path('/dir1/dir2/ref/', '/dir1/dir2'))
800
+ assert_equal('..', Recls::Ximpl::derive_relative_path('/dir1/dir2/ref', '/dir1/dir2/'))
801
+ assert_equal('..', Recls::Ximpl::derive_relative_path('/dir1/dir2/ref/', '/dir1/dir2/'))
802
+
803
+ end
804
+
805
+ def test_different_sub_trees_5
806
+
807
+ assert_equal('../..', Recls::Ximpl::derive_relative_path('/dir1/dir2/dir3/dir4', '/dir1/dir2'))
808
+ assert_equal('../..', Recls::Ximpl::derive_relative_path('/dir1/dir2/dir3/dir4/', '/dir1/dir2'))
809
+ assert_equal('../..', Recls::Ximpl::derive_relative_path('/dir1/dir2/dir3/dir4', '/dir1/dir2/'))
810
+ assert_equal('../..', Recls::Ximpl::derive_relative_path('/dir1/dir2/dir3/dir4/', '/dir1/dir2/'))
811
+
812
+ end
813
+
814
+ def test_embedded_dots_1
815
+
816
+ assert_equal('.', Recls::Ximpl::derive_relative_path('./dir1/dir2', 'dir1/dir2'))
817
+ assert_equal('./', Recls::Ximpl::derive_relative_path('./dir1/dir2', 'dir1/dir2/'))
818
+ assert_equal('.', Recls::Ximpl::derive_relative_path('./dir1/dir2/', 'dir1/dir2'))
819
+ assert_equal('./', Recls::Ximpl::derive_relative_path('./dir1/dir2/', 'dir1/dir2/'))
820
+
821
+ assert_equal('.', Recls::Ximpl::derive_relative_path('./dir1/dir2', './dir1/dir2'))
822
+ assert_equal('./', Recls::Ximpl::derive_relative_path('./dir1/dir2', './dir1/dir2/'))
823
+ assert_equal('.', Recls::Ximpl::derive_relative_path('./dir1/dir2/', './dir1/dir2'))
824
+ assert_equal('./', Recls::Ximpl::derive_relative_path('./dir1/dir2/', './dir1/dir2/'))
825
+
826
+ end
827
+
828
+ def test_embedded_dots_2
829
+
830
+ assert_equal('.', Recls::Ximpl::derive_relative_path('dir1/./dir2', 'dir1/dir2'))
831
+ assert_equal('./', Recls::Ximpl::derive_relative_path('dir1/./dir2', 'dir1/dir2/'))
832
+ assert_equal('.', Recls::Ximpl::derive_relative_path('dir1/./dir2/', 'dir1/dir2'))
833
+ assert_equal('./', Recls::Ximpl::derive_relative_path('dir1/./dir2/', 'dir1/dir2/'))
834
+ assert_equal('.', Recls::Ximpl::derive_relative_path('dir1/./dir2', './dir1/dir2'))
835
+ assert_equal('./', Recls::Ximpl::derive_relative_path('dir1/./dir2', './dir1/dir2/'))
836
+ assert_equal('.', Recls::Ximpl::derive_relative_path('dir1/./dir2/', './dir1/dir2'))
837
+ assert_equal('./', Recls::Ximpl::derive_relative_path('dir1/./dir2/', './dir1/dir2/'))
838
+
839
+ end
840
+
841
+ def test_embedded_dots_3
842
+
843
+ assert_equal('.', Recls::Ximpl::derive_relative_path('dir1/dir2/.', 'dir1/dir2'))
844
+ assert_equal('./', Recls::Ximpl::derive_relative_path('dir1/dir2/.', 'dir1/dir2/'))
845
+ assert_equal('.', Recls::Ximpl::derive_relative_path('dir1/dir2/./', 'dir1/dir2'))
846
+ assert_equal('./', Recls::Ximpl::derive_relative_path('dir1/dir2/./', 'dir1/dir2/'))
847
+ assert_equal('.', Recls::Ximpl::derive_relative_path('dir1/dir2/.', './dir1/dir2'))
848
+ assert_equal('./', Recls::Ximpl::derive_relative_path('dir1/dir2/.', './dir1/dir2/'))
849
+ assert_equal('.', Recls::Ximpl::derive_relative_path('dir1/dir2/./', './dir1/dir2'))
850
+ assert_equal('./', Recls::Ximpl::derive_relative_path('dir1/dir2/./', './dir1/dir2/'))
851
+
852
+ end
853
+
854
+ def test_embedded_dots_4
855
+
856
+ assert_equal('.', Recls::Ximpl::derive_relative_path('dir1/./dir2/.', 'dir1/dir2'))
857
+ assert_equal('./', Recls::Ximpl::derive_relative_path('dir1/./dir2/.', 'dir1/dir2/'))
858
+ assert_equal('.', Recls::Ximpl::derive_relative_path('dir1/./dir2/./', 'dir1/dir2'))
859
+ assert_equal('./', Recls::Ximpl::derive_relative_path('dir1/./dir2/./', 'dir1/dir2/'))
860
+ assert_equal('.', Recls::Ximpl::derive_relative_path('dir1/./dir2/.', './dir1/dir2'))
861
+ assert_equal('./', Recls::Ximpl::derive_relative_path('dir1/./dir2/.', './dir1/dir2/'))
862
+ assert_equal('.', Recls::Ximpl::derive_relative_path('dir1/./dir2/./', './dir1/dir2'))
863
+ assert_equal('./', Recls::Ximpl::derive_relative_path('dir1/./dir2/./', './dir1/dir2/'))
864
+
865
+ end
866
+
867
+ def test_embedded_dots_5
868
+
869
+ assert_equal('.', Recls::Ximpl::derive_relative_path('./dir1/./dir2/.', 'dir1/dir2'))
870
+ assert_equal('./', Recls::Ximpl::derive_relative_path('./dir1/./dir2/.', 'dir1/dir2/'))
871
+ assert_equal('.', Recls::Ximpl::derive_relative_path('./dir1/./dir2/./', 'dir1/dir2'))
872
+ assert_equal('./', Recls::Ximpl::derive_relative_path('./dir1/./dir2/./', 'dir1/dir2/'))
873
+ assert_equal('.', Recls::Ximpl::derive_relative_path('./dir1/./dir2/.', './dir1/dir2'))
874
+ assert_equal('./', Recls::Ximpl::derive_relative_path('./dir1/./dir2/.', './dir1/dir2/'))
875
+ assert_equal('.', Recls::Ximpl::derive_relative_path('./dir1/./dir2/./', './dir1/dir2'))
876
+ assert_equal('./', Recls::Ximpl::derive_relative_path('./dir1/./dir2/./', './dir1/dir2/'))
877
+
878
+ end
879
+
880
+ def test_embedded_dots_6
881
+
882
+ assert_equal('.', Recls::Ximpl::derive_relative_path('./dir1/././././dir2/.', 'dir1/dir2'))
883
+ assert_equal('./', Recls::Ximpl::derive_relative_path('./dir1/././././dir2/.', 'dir1/dir2/'))
884
+ assert_equal('.', Recls::Ximpl::derive_relative_path('./dir1/././././dir2/./', 'dir1/dir2'))
885
+ assert_equal('./', Recls::Ximpl::derive_relative_path('./dir1/././././dir2/./', 'dir1/dir2/'))
886
+ assert_equal('.', Recls::Ximpl::derive_relative_path('./dir1/././././dir2/.', './dir1/dir2'))
887
+ assert_equal('./', Recls::Ximpl::derive_relative_path('./dir1/././././dir2/.', './dir1/dir2/'))
888
+ assert_equal('.', Recls::Ximpl::derive_relative_path('./dir1/././././dir2/./', './dir1/dir2'))
889
+ assert_equal('./', Recls::Ximpl::derive_relative_path('./dir1/././././dir2/./', './dir1/dir2/'))
890
+
891
+ end
892
+
893
+ def test_embedded_dots_7
894
+
895
+ assert_equal('.', Recls::Ximpl::derive_relative_path('./dir1/././././dir2/.', 'dir1/././dir2'))
896
+ assert_equal('./', Recls::Ximpl::derive_relative_path('./dir1/././././dir2/.', 'dir1/././dir2/'))
897
+ assert_equal('.', Recls::Ximpl::derive_relative_path('./dir1/././././dir2/./', 'dir1/././dir2'))
898
+ assert_equal('./', Recls::Ximpl::derive_relative_path('./dir1/././././dir2/./', 'dir1/././dir2/'))
899
+ assert_equal('.', Recls::Ximpl::derive_relative_path('./dir1/././././dir2/.', './dir1/././dir2'))
900
+ assert_equal('./', Recls::Ximpl::derive_relative_path('./dir1/././././dir2/.', './dir1/././dir2/'))
901
+ assert_equal('.', Recls::Ximpl::derive_relative_path('./dir1/././././dir2/./', './dir1/././dir2'))
902
+ assert_equal('./', Recls::Ximpl::derive_relative_path('./dir1/././././dir2/./', './dir1/././dir2/'))
903
+
904
+ end
905
+
906
+ end
907
+
908
+