libpath-ruby 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,131 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 4), 'lib')
4
+
5
+ require 'libpath/util/windows'
6
+
7
+ require 'test/unit'
8
+
9
+ class Test_LibPath_Util_Windows_combine_paths < Test::Unit::TestCase
10
+
11
+ F = ::LibPath::Util::Windows
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
+ end
30
+
31
+ def test_tail_absolute_cases
32
+
33
+ assert_equal 'X:/', F.combine_paths('a', 'X:/')
34
+ assert_equal 'X:\\', F.combine_paths('a', 'X:\\')
35
+ assert_equal '\\\\?\\X:\\', F.combine_paths('a', '\\\\?\\X:\\')
36
+ end
37
+
38
+ def test_tail_absolute_cases_2
39
+
40
+ assert_equal 'Y:/', F.combine_paths('a', 'X:/', 'Y:/')
41
+ assert_equal 'Y:\\', F.combine_paths('a', 'X:/', 'Y:\\')
42
+ assert_equal 'Y:\\', F.combine_paths('a', '\\\\?\\X:/', 'Y:\\')
43
+ assert_equal '\\\\?\\Y:\\', F.combine_paths('a', 'X:/', '\\\\?\\Y:\\')
44
+ end
45
+
46
+ def test_tail_absolute_cases_3
47
+
48
+ assert_equal 'X:\\', F.combine_paths('a', 'X:', '\\')
49
+ assert_equal 'X:\\', F.combine_paths('a', '\\', 'X:')
50
+ assert_equal 'X:\\', F.combine_paths('X:', 'a', '\\')
51
+
52
+ assert_equal '\\\\?\\X:\\', F.combine_paths('a', '\\\\?\\X:', '\\')
53
+ assert_equal '\\\\?\\X:\\', F.combine_paths('a', '\\', '\\\\?\\X:')
54
+ assert_equal '\\\\?\\X:\\', F.combine_paths('\\\\?\\X:', 'a', '\\')
55
+ end
56
+
57
+ def test_tail_absolute_cases_4
58
+
59
+ assert_equal 'Z:\\', F.combine_paths('a', 'X:/', '\\', 'Z:')
60
+
61
+ assert_equal '\\\\?\\Z:\\', F.combine_paths('a', '\\\\?\\X:/', '\\', '\\\\?\\Z:')
62
+
63
+ assert_equal '\\\\?\\UNC\\server\\share/abc', F.combine_paths('a', '\\\\?\\X:/', '/abc', '\\\\?\\UNC\\server\\share')
64
+
65
+ assert_equal '\\\\.\\{1234-abcd}/abc', F.combine_paths('a', '\\\\?\\X:/', '/abc', '\\\\.\\{1234-abcd}')
66
+ assert_equal '\\\\.\\{1234-abcd}/abc', F.combine_paths('a', '\\\\?\\X:/', '\\\\.\\{1234-abcd}', '/abc')
67
+ end
68
+
69
+ def test_tail_absolute_cases_5
70
+
71
+ assert_equal 'Z:\\dir\\a\\b', F.combine_paths('a', 'X:/y', '\\dir', 'Z:', 'a', 'b')
72
+
73
+ assert_equal 'Z:\\dir\\a\\b', F.combine_paths('a', '\\\\?\\X:/y', '\\dir', 'Z:', 'a', 'b')
74
+
75
+ assert_equal '\\\\?\\Z:\\dir\\a\\b', F.combine_paths('a', 'X:/y', '\\dir', '\\\\?\\Z:', 'a', 'b')
76
+ end
77
+
78
+ def test_tail_absolute_cases_6
79
+
80
+ assert_equal 'Z:\\b', F.combine_paths('a', 'X:/', 'Z:', 'a', '\\', 'b')
81
+ end
82
+
83
+ def test_tail_absolute_cases_7
84
+
85
+ assert_equal 'Z:\\a\\c\\b', F.combine_paths('a', 'X:/', '\\a', 'c', 'Z:', 'b')
86
+ end
87
+
88
+ def test_tail_absolute_cases_8
89
+
90
+ assert_equal 'X:/y\\b', F.combine_paths('a', '\\a', 'c', 'Z:', 'X:/y', 'b')
91
+ end
92
+
93
+ def test_tail_absolute_cases_9
94
+
95
+ assert_equal 'Z:\\y\\b', F.combine_paths('a', '\\a', 'c', 'X:\\y', 'Z:', 'b')
96
+ assert_equal 'Z:/y\\b', F.combine_paths('a', '\\a', 'c', 'X:/y', 'Z:', 'b')
97
+ end
98
+
99
+ def test_tail_absolute_cases_10
100
+
101
+ assert_equal 'X:\\dir-1\\dir-2\\b', F.combine_paths('a', '\\a', 'c', 'X:/y', '\\dir-1\\dir-2', 'b')
102
+ assert_equal 'X:\\dir-1/dir-2\\b', F.combine_paths('a', '\\a', 'c', 'X:/y', '\\dir-1/dir-2', 'b')
103
+
104
+ assert_equal '/', F.combine_paths('a', '/')
105
+
106
+ assert_equal '/', F.combine_paths('a/b/c/d', '/')
107
+
108
+ assert_equal '/', F.combine_paths('a', 'b', '/')
109
+ end
110
+
111
+ def test_drive_only
112
+
113
+ assert_equal 'D:', F.combine_paths('D:')
114
+ assert_equal 'D:dir-1\\dir-2', F.combine_paths('D:', 'dir-1\\dir-2')
115
+
116
+ assert_equal '\\\\?\\D:', F.combine_paths('\\\\?\\D:')
117
+ assert_equal '\\\\?\\D:dir-1\\dir-2', F.combine_paths('\\\\?\\D:', 'dir-1\\dir-2')
118
+ end
119
+
120
+ def test_embedded_absolute_cases
121
+
122
+ assert_equal '/a\\b\\c/d', F.combine_paths('x/y/z', 'z', '/a', 'b', 'c/d')
123
+ assert_equal '\\a\\b\\c/d', F.combine_paths('x/y/z', 'z', '\\a', 'b', 'c/d')
124
+ end
125
+
126
+ def test_multiple_embedded_absolute_cases
127
+
128
+ assert_equal '/a\\b\\c/d', F.combine_paths('x/y/z', '/z', '/a', 'b', 'c/d')
129
+ end
130
+ end
131
+
@@ -0,0 +1,155 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 4), 'lib')
4
+
5
+ require 'libpath/util/windows'
6
+
7
+ require 'test/unit'
8
+
9
+ class Test_LibPath_Util_Windows_derive_relative_path < Test::Unit::TestCase
10
+
11
+ M = ::LibPath::Util::Windows
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
+ end
50
+
51
+ def test_from_here
52
+
53
+ assert_equal 'abc', M.derive_relative_path('.', 'abc')
54
+ end
55
+
56
+ def test_ones_above
57
+
58
+ assert_equal '..\\', M.derive_relative_path('.', '..')
59
+
60
+ assert_equal '../', M.derive_relative_path('/abc/', '/')
61
+
62
+ assert_equal '..\\', M.derive_relative_path('abc/def', 'abc')
63
+
64
+ assert_equal '..\\', M.derive_relative_path('abc/def/ghi', 'abc/def')
65
+ assert_equal '../', M.derive_relative_path('abc/def/ghi', 'abc/def/')
66
+
67
+ assert_equal '..\\', M.derive_relative_path('abc/def/./ghi', 'abc/def')
68
+ assert_equal '..\\', M.derive_relative_path('abc/def/ghi/jkl/..', 'abc/def')
69
+
70
+ assert_equal '..\\../', M.derive_relative_path('/abc/def/', '/')
71
+ #assert_equal '..\\../', M.derive_relative_path('/abc/def/', '/', make_path_canonical: true)
72
+
73
+ assert_equal '..\\..\\', M.derive_relative_path('abc/def/ghi/jkl/', 'abc/def')
74
+
75
+ assert_equal '..\\..\\', M.derive_relative_path('C:\\dir-1\\dir-2\\', 'C:\\')
76
+
77
+ assert_equal '..\\..\\', M.derive_relative_path('\\dir1\\dir2\\dir3\\dir4', '\\dir1\\dir2')
78
+ assert_equal '..\\..\\', M.derive_relative_path('/dir1/dir2/dir3/dir4', '/dir1/dir2')
79
+ end
80
+
81
+ def test_ones_below
82
+
83
+ assert_equal 'dir-1\\', M.derive_relative_path('..', '.', pwd: '/dir-1/')
84
+
85
+ assert_equal '..\\', M.derive_relative_path('.', '..', pwd: '/dir-1/')
86
+
87
+ assert_equal 'def', M.derive_relative_path('abc', 'abc/def')
88
+ assert_equal 'def\\', M.derive_relative_path('abc', 'abc/def/')
89
+ assert_equal 'def\\', M.derive_relative_path('abc', 'abc\\def\\')
90
+
91
+ assert_equal 'def\\ghi', M.derive_relative_path('abc', 'abc/def/ghi')
92
+ assert_equal 'def\\ghi\\', M.derive_relative_path('abc', 'abc/def/ghi/')
93
+ end
94
+
95
+ def test_ones_across
96
+
97
+ assert_equal '..\\e-1', M.derive_relative_path('abc/d-1', 'abc/e-1')
98
+ assert_equal '..\\e-1', M.derive_relative_path('abc/d-1/', 'abc/e-1')
99
+
100
+ assert_equal '..\\e-1\\e-2', M.derive_relative_path('abc/d-1/', 'abc/e-1/e-2')
101
+ assert_equal '..\\..\\e-1\\e-2', M.derive_relative_path('abc/d-1/d-2/', 'abc/e-1/e-2')
102
+ end
103
+
104
+ def test_simple_cases
105
+
106
+ assert_equal 'def', M.derive_relative_path('\\abc', '\\abc\\def')
107
+ assert_equal 'def', M.derive_relative_path('/abc', '/abc/def')
108
+ end
109
+
110
+ def test_absolute_path_cases
111
+
112
+ assert_equal '..\\..\\def', M.derive_relative_path('/abc/ghi', '/def')
113
+
114
+ assert_equal '..\\..\\def', M.derive_relative_path('ghi', '/def', pwd: 'C:/abc')
115
+
116
+ assert_equal '..\\def', M.derive_relative_path('abc', '\\\\?\\C:/def', pwd: '\\\\?\\C:/')
117
+
118
+ assert_equal '..\\..\abc', M.derive_relative_path('\\\\?\\UNC\\10.11.12.13:4567\\share/def/ghi', '\\\\?\\UNC\\10.11.12.13:4567\\share\abc')
119
+ assert_equal '..\\def\\ghi', M.derive_relative_path('\\\\?\\UNC\\10.11.12.13:4567\\share\\abc', '\\\\?\\UNC\\10.11.12.13:4567\\share/def/ghi')
120
+ end
121
+
122
+ def test_mixed
123
+
124
+ assert_equal 'D:\\dir-1\\dir-3', M.derive_relative_path('C:\\dir-1\\dir-2', '/dir-1/dir-3', pwd: 'D:')
125
+
126
+ assert_equal '..\\dir-3', M.derive_relative_path('C:\\dir-1\\dir-2', '/dir-1/dir-3', pwd: 'C:')
127
+
128
+ assert_equal '..\\dir-3', M.derive_relative_path('C:\\dir-1\\dir-2', 'dir-3', pwd: 'C:\\dir-1')
129
+ end
130
+
131
+ def test_both_relative
132
+
133
+ assert_equal '..\\def', M.derive_relative_path('abc', 'def', pwd: '/')
134
+ end
135
+
136
+ def test_different_drives
137
+
138
+ assert_equal 'B:\\abc', M.derive_relative_path('A:\\abc', 'B:\\abc')
139
+ end
140
+
141
+ def test_same_drives
142
+
143
+ assert_equal '.', M.derive_relative_path('A:\\abc', 'A:\\abc')
144
+ assert_equal '.', M.derive_relative_path('A:\\.\abc', 'A:\\abc')
145
+ end
146
+
147
+ def test_cases_from_Path
148
+
149
+ srd = 'C:\\dir-1\\dir-2\\dir-C\\dir-D'
150
+ target = 'C:/dir-1/dir-2/dir-3/dir-4/./dir-5/dir-6/../file.ext'
151
+
152
+ assert_equal '..\\..\\dir-3\\dir-4\\dir-5\\file.ext', M.derive_relative_path(srd, target)
153
+ end
154
+ end
155
+
@@ -0,0 +1,163 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 4), 'lib')
4
+
5
+ require 'libpath/util/windows'
6
+
7
+ require 'test/unit'
8
+
9
+ class Test_LibPath_Util_Windows_make_path_absolute < Test::Unit::TestCase
10
+
11
+ F = ::LibPath::Util::Windows
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 'C:\\', F.make_path_absolute('\\', pwd: 'C:/Users/libpath-tester')
32
+ assert_equal 'C:\\.', F.make_path_absolute('\\.', pwd: 'C:/Users/libpath-tester')
33
+ assert_equal 'C:\\a', F.make_path_absolute('\\a', pwd: 'C:/Users/libpath-tester')
34
+ assert_equal 'C:\\a\\.', F.make_path_absolute('\\a\\.', pwd: 'C:/Users/libpath-tester')
35
+
36
+ assert_equal 'C:/', F.make_path_absolute('/', pwd: 'C:/Users/libpath-tester')
37
+ assert_equal 'C:/.', F.make_path_absolute('/.', pwd: 'C:/Users/libpath-tester')
38
+ assert_equal 'C:/a', F.make_path_absolute('/a', pwd: 'C:/Users/libpath-tester')
39
+ assert_equal 'C:/a/.', F.make_path_absolute('/a/.', pwd: 'C:/Users/libpath-tester')
40
+
41
+ assert_equal 'G:\\abc\\', F.make_path_absolute('G:\\abc\\')
42
+ assert_equal 'G:\\abc\\', F.make_path_absolute('G:\\\\abc\\\\')
43
+ assert_equal 'G:\\abc\\', F.make_path_absolute('G:\\\\abc\\\\', pwd: 'C:/Users/libpath-tester')
44
+ end
45
+
46
+ def test_absolute_paths_with_canonicalisation
47
+
48
+ pwd = 'X:\\some-dir'
49
+
50
+ options = { make_canonical: true }
51
+
52
+ assert_equal 'X:/', F.make_path_absolute('/', **options, pwd: pwd)
53
+ assert_equal 'X:/', F.make_path_absolute('/.', **options, pwd: pwd)
54
+ assert_equal 'X:/a', F.make_path_absolute('/a', **options, pwd: pwd)
55
+ assert_equal 'X:/a/', F.make_path_absolute('/a/.', **options, pwd: pwd)
56
+ end
57
+
58
+ def test_relative_path_with_fixed_pwd
59
+
60
+ pwd = 'X:\\some-path\\\\or-other'
61
+
62
+ assert_equal 'X:\\some-path\\or-other\\.', F.make_path_absolute('.', pwd: pwd)
63
+ assert_equal 'X:\\some-path\\or-other\\', F.make_path_absolute('.', pwd: pwd, make_canonical: true)
64
+
65
+ assert_equal 'X:\\some-path\\or-other\\abc', F.make_path_absolute('abc', pwd: pwd)
66
+ assert_equal 'X:\\some-path\\or-other\\abc', F.make_path_absolute('abc', pwd: pwd, make_canonical: true)
67
+
68
+ assert_equal 'X:\\some-path\\or-other\\./abc', F.make_path_absolute('./abc', pwd: pwd)
69
+ assert_equal 'X:\\some-path\\or-other\\abc', F.make_path_absolute('./abc', pwd: pwd, make_canonical: true)
70
+
71
+ assert_equal 'X:\\some-path\\or-other\\./abc/', F.make_path_absolute('./abc/', pwd: pwd)
72
+ assert_equal 'X:\\some-path\\or-other\\abc/', F.make_path_absolute('./abc/', pwd: pwd, make_canonical: true)
73
+
74
+ assert_equal 'X:\\some-path\\or-other\\def/../abc', F.make_path_absolute('def/../abc', pwd: pwd)
75
+ assert_equal 'X:\\some-path\\or-other\\abc', F.make_path_absolute('def/../abc', pwd: pwd, make_canonical: true)
76
+
77
+ assert_equal 'X:\\some-path\\or-other\\def/../abc/', F.make_path_absolute('def/../abc/', pwd: pwd)
78
+ assert_equal 'X:\\some-path\\or-other\\abc/', F.make_path_absolute('def/../abc/', pwd: pwd, make_canonical: true)
79
+ end
80
+
81
+ def test_relative_path_with_fixed_home
82
+
83
+ home = 'X:\\Documents and Settings\\libpath-tester'
84
+
85
+ assert_equal 'X:\\Documents and Settings\\libpath-tester', F.make_path_absolute('~', home: home)
86
+ assert_equal 'X:\\Documents and Settings\\libpath-tester', F.make_path_absolute('~', home: home, make_canonical: true)
87
+
88
+ assert_equal 'X:\\Documents and Settings\\libpath-tester/.', F.make_path_absolute('~/.', home: home)
89
+ assert_equal 'X:\\Documents and Settings\\libpath-tester/', F.make_path_absolute('~/.', home: home, make_canonical: true)
90
+
91
+ assert_equal 'X:\\Documents and Settings\\libpath-tester\\.', F.make_path_absolute('~\\.', home: home)
92
+ assert_equal 'X:\\Documents and Settings\\libpath-tester\\', F.make_path_absolute('~\\.', home: home, make_canonical: true)
93
+
94
+ assert_equal 'X:\\Documents and Settings\\libpath-tester/abc', F.make_path_absolute('~/abc', home: home)
95
+ assert_equal 'X:\\Documents and Settings\\libpath-tester/abc', F.make_path_absolute('~/abc', home: home, make_canonical: true)
96
+
97
+ assert_equal 'X:\\Documents and Settings\\libpath-tester/./abc', F.make_path_absolute('~/./abc', home: home)
98
+ assert_equal 'X:\\Documents and Settings\\libpath-tester/abc', F.make_path_absolute('~/./abc', home: home, make_canonical: true)
99
+
100
+ assert_equal 'X:\\Documents and Settings\\libpath-tester/./abc/', F.make_path_absolute('~/./abc/', home: home)
101
+ assert_equal 'X:\\Documents and Settings\\libpath-tester/abc/', F.make_path_absolute('~/./abc/', home: home, make_canonical: true)
102
+
103
+ assert_equal 'X:\\Documents and Settings\\libpath-tester/def/../abc', F.make_path_absolute('~/def/../abc', home: home)
104
+ assert_equal 'X:\\Documents and Settings\\libpath-tester/abc', F.make_path_absolute('~/def/../abc', home: home, make_canonical: true)
105
+
106
+ assert_equal 'X:\\Documents and Settings\\libpath-tester/def/../abc/', F.make_path_absolute('~/def/../abc/', home: home)
107
+ assert_equal 'X:\\Documents and Settings\\libpath-tester/abc/', F.make_path_absolute('~/def/../abc/', home: home, make_canonical: true)
108
+ end
109
+
110
+ def test_relative_path_with_fixed_home_2
111
+
112
+ home = 'X:\\Documents and Settings\\libpath-tester\\'
113
+
114
+ assert_equal 'X:\\Documents and Settings\\libpath-tester\\', F.make_path_absolute('~', home: home)
115
+ assert_equal 'X:\\Documents and Settings\\libpath-tester\\', F.make_path_absolute('~', home: home, make_canonical: true)
116
+
117
+ assert_equal 'X:\\Documents and Settings\\libpath-tester\\', F.make_path_absolute('~/', home: home)
118
+ assert_equal 'X:\\Documents and Settings\\libpath-tester\\', F.make_path_absolute('~/', home: home, make_canonical: true)
119
+
120
+ assert_equal 'X:\\Documents and Settings\\libpath-tester\\.', F.make_path_absolute('~/.', home: home)
121
+ assert_equal 'X:\\Documents and Settings\\libpath-tester\\', F.make_path_absolute('~/.', home: home, make_canonical: true)
122
+
123
+ assert_equal 'X:\\Documents and Settings\\libpath-tester\\abc', F.make_path_absolute('~/abc', home: home)
124
+ assert_equal 'X:\\Documents and Settings\\libpath-tester\\abc', F.make_path_absolute('~/abc', home: home, make_canonical: true)
125
+
126
+ assert_equal 'X:\\Documents and Settings\\libpath-tester\\./abc', F.make_path_absolute('~/./abc', home: home)
127
+ assert_equal 'X:\\Documents and Settings\\libpath-tester\\abc', F.make_path_absolute('~/./abc', home: home, make_canonical: true)
128
+
129
+ assert_equal 'X:\\Documents and Settings\\libpath-tester\\./abc/', F.make_path_absolute('~/./abc/', home: home)
130
+ assert_equal 'X:\\Documents and Settings\\libpath-tester\\abc/', F.make_path_absolute('~/./abc/', home: home, make_canonical: true)
131
+
132
+ assert_equal 'X:\\Documents and Settings\\libpath-tester\\def/../abc', F.make_path_absolute('~/def/../abc', home: home)
133
+ assert_equal 'X:\\Documents and Settings\\libpath-tester\\abc', F.make_path_absolute('~/def/../abc', home: home, make_canonical: true)
134
+
135
+ assert_equal 'X:\\Documents and Settings\\libpath-tester\\def/../abc/', F.make_path_absolute('~/def/../abc/', home: home)
136
+ assert_equal 'X:\\Documents and Settings\\libpath-tester\\abc/', F.make_path_absolute('~/def/../abc/', home: home, make_canonical: true)
137
+ end
138
+
139
+ def test_nonhome_tilde_with_fixed_pwd
140
+
141
+ pwd = 'X:\\some-other-path\\'
142
+
143
+ assert_equal 'X:\\some-other-path\\~.', F.make_path_absolute('~.', pwd: pwd)
144
+ assert_equal 'X:\\some-other-path\\~.', F.make_path_absolute('~.', pwd: pwd, make_canonical: true)
145
+
146
+ assert_equal 'X:\\some-other-path\\~abc', F.make_path_absolute('~abc', pwd: pwd)
147
+ assert_equal 'X:\\some-other-path\\~abc', F.make_path_absolute('~abc', pwd: pwd, make_canonical: true)
148
+
149
+ assert_equal 'X:\\some-other-path\\~./abc', F.make_path_absolute('~./abc', pwd: pwd)
150
+ assert_equal 'X:\\some-other-path\\~./abc', F.make_path_absolute('~./abc', pwd: pwd, make_canonical: true)
151
+
152
+ assert_equal 'X:\\some-other-path\\~./abc/', F.make_path_absolute('~./abc/', pwd: pwd)
153
+ assert_equal 'X:\\some-other-path\\~./abc/', F.make_path_absolute('~./abc/', pwd: pwd, make_canonical: true)
154
+
155
+ assert_equal 'X:\\some-other-path\\~def/../abc', F.make_path_absolute('~def/../abc', pwd: pwd)
156
+ assert_equal 'X:\\some-other-path\\abc', F.make_path_absolute('~def/../abc', pwd: pwd, make_canonical: true)
157
+
158
+ assert_equal 'X:\\some-other-path\\~def/../abc/', F.make_path_absolute('~def/../abc/', pwd: pwd)
159
+ assert_equal 'X:\\some-other-path\\abc/', F.make_path_absolute('~def/../abc/', pwd: pwd, make_canonical: true)
160
+ end
161
+
162
+ end
163
+