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.
- checksums.yaml +7 -0
- data/README.md +61 -0
- data/examples/path_from_arg0.md +99 -0
- data/examples/path_from_arg0.rb +55 -0
- data/lib/libpath.rb +12 -0
- data/lib/libpath/constants.rb +42 -0
- data/lib/libpath/constants/unix.rb +146 -0
- data/lib/libpath/constants/windows.rb +147 -0
- data/lib/libpath/diagnostics.rb +6 -0
- data/lib/libpath/diagnostics/parameter_checking.rb +46 -0
- data/lib/libpath/exceptions.rb +7 -0
- data/lib/libpath/exceptions/libpath_base_exception.rb +77 -0
- data/lib/libpath/exceptions/malformed_name_exception.rb +85 -0
- data/lib/libpath/form.rb +42 -0
- data/lib/libpath/form/unix.rb +215 -0
- data/lib/libpath/form/windows.rb +358 -0
- data/lib/libpath/internal_/array.rb +96 -0
- data/lib/libpath/internal_/platform.rb +53 -0
- data/lib/libpath/internal_/string.rb +33 -0
- data/lib/libpath/internal_/unix/form.rb +160 -0
- data/lib/libpath/internal_/windows/drive.rb +84 -0
- data/lib/libpath/internal_/windows/form.rb +281 -0
- data/lib/libpath/libpath.rb +6 -0
- data/lib/libpath/path.rb +43 -0
- data/lib/libpath/path/unix.rb +170 -0
- data/lib/libpath/path/windows.rb +176 -0
- data/lib/libpath/util.rb +42 -0
- data/lib/libpath/util/unix.rb +414 -0
- data/lib/libpath/util/windows.rb +636 -0
- data/lib/libpath/version.rb +73 -0
- data/test/performance/benchmark_drive_letter.rb +31 -0
- data/test/performance/benchmark_gsub_string_or_regex.rb +45 -0
- data/test/performance/benchmark_rindex2.rb +109 -0
- data/test/performance/benchmark_split.rb +32 -0
- data/test/unit/compare/ts_all.rb +22 -0
- data/test/unit/equate/ts_all.rb +22 -0
- data/test/unit/equate/unix/ts_all.rb +22 -0
- data/test/unit/equate/windows/ts_all.rb +22 -0
- data/test/unit/exceptions/tc_libpath_base_exception.rb +27 -0
- data/test/unit/exceptions/tc_malformed_name_exception.rb +31 -0
- data/test/unit/exceptions/ts_all.rb +22 -0
- data/test/unit/form/tc_absolute_functions.rb +369 -0
- data/test/unit/form/ts_all.rb +22 -0
- data/test/unit/form/unix/tc_absolute_functions.rb +269 -0
- data/test/unit/form/unix/ts_all.rb +22 -0
- data/test/unit/form/windows/tc_absolute_functions.rb +854 -0
- data/test/unit/form/windows/ts_all.rb +22 -0
- data/test/unit/internal_/tc_array.rb +62 -0
- data/test/unit/internal_/ts_all.rb +22 -0
- data/test/unit/internal_/unix/form/tc_slash_functions.rb +60 -0
- data/test/unit/internal_/unix/form/ts_all.rb +22 -0
- data/test/unit/internal_/unix/tc_split_path.rb +396 -0
- data/test/unit/internal_/unix/ts_all.rb +22 -0
- data/test/unit/internal_/windows/form/tc_get_windows_volume.rb +220 -0
- data/test/unit/internal_/windows/form/tc_slash_functions.rb +61 -0
- data/test/unit/internal_/windows/form/ts_all.rb +22 -0
- data/test/unit/internal_/windows/tc_split_path.rb +881 -0
- data/test/unit/internal_/windows/ts_all.rb +22 -0
- data/test/unit/parse/ts_all.rb +22 -0
- data/test/unit/path/tc_path.rb +778 -0
- data/test/unit/path/ts_all.rb +22 -0
- data/test/unit/path/unix/tc_path.rb +565 -0
- data/test/unit/path/unix/ts_all.rb +22 -0
- data/test/unit/path/windows/tc_path.rb +630 -0
- data/test/unit/path/windows/ts_all.rb +22 -0
- data/test/unit/tc_version.rb +47 -0
- data/test/unit/ts_all.rb +22 -0
- data/test/unit/util/tc_combine_paths.rb +179 -0
- data/test/unit/util/tc_derive_relative_path.rb +19 -0
- data/test/unit/util/tc_make_path_canonical.rb +228 -0
- data/test/unit/util/ts_all.rb +22 -0
- data/test/unit/util/unix/tc_combine_paths.rb +65 -0
- data/test/unit/util/unix/tc_derive_relative_path.rb +123 -0
- data/test/unit/util/unix/tc_make_path_absolute.rb +117 -0
- data/test/unit/util/unix/tc_make_path_canonical.rb +139 -0
- data/test/unit/util/unix/ts_all.rb +22 -0
- data/test/unit/util/windows/tc_combine_paths.rb +131 -0
- data/test/unit/util/windows/tc_derive_relative_path.rb +155 -0
- data/test/unit/util/windows/tc_make_path_absolute.rb +163 -0
- data/test/unit/util/windows/tc_make_path_canonical.rb +220 -0
- data/test/unit/util/windows/ts_all.rb +22 -0
- metadata +144 -0
@@ -0,0 +1,73 @@
|
|
1
|
+
|
2
|
+
# ######################################################################## #
|
3
|
+
# File: libpath/version.rb
|
4
|
+
#
|
5
|
+
# Purpose: Version for libpath.Ruby library
|
6
|
+
#
|
7
|
+
# Created: 8th January 2019
|
8
|
+
# Updated: 16th April 2019
|
9
|
+
#
|
10
|
+
# Home: http://github.com/synesissoftware/libpath.Ruby
|
11
|
+
#
|
12
|
+
# Author: Matthew Wilson
|
13
|
+
#
|
14
|
+
# Copyright (c) 2019, Matthew Wilson and Synesis Software
|
15
|
+
# All rights reserved.
|
16
|
+
#
|
17
|
+
# Redistribution and use in source and binary forms, with or without
|
18
|
+
# modification, are permitted provided that the following conditions are
|
19
|
+
# met:
|
20
|
+
#
|
21
|
+
# * Redistributions of source code must retain the above copyright
|
22
|
+
# notice, this list of conditions and the following disclaimer.
|
23
|
+
#
|
24
|
+
# * Redistributions in binary form must reproduce the above copyright
|
25
|
+
# notice, this list of conditions and the following disclaimer in the
|
26
|
+
# documentation and/or other materials provided with the distribution.
|
27
|
+
#
|
28
|
+
# * Neither the names of the copyright holder nor the names of its
|
29
|
+
# contributors may be used to endorse or promote products derived from
|
30
|
+
# this software without specific prior written permission.
|
31
|
+
#
|
32
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
33
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
34
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
35
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
36
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
37
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
38
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
39
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
40
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
41
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
42
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
43
|
+
#
|
44
|
+
# ######################################################################## #
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
=begin
|
49
|
+
=end
|
50
|
+
|
51
|
+
module LibPath # :nodoc:
|
52
|
+
|
53
|
+
# Current version of the libpath.Ruby library
|
54
|
+
VERSION = '0.2.1'
|
55
|
+
|
56
|
+
private
|
57
|
+
VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
|
58
|
+
public
|
59
|
+
# Major version of the libpath.Ruby library
|
60
|
+
VERSION_MAJOR = VERSION_PARTS_[0] # :nodoc:
|
61
|
+
# Minor version of the libpath.Ruby library
|
62
|
+
VERSION_MINOR = VERSION_PARTS_[1] # :nodoc:
|
63
|
+
# Patch version of the libpath.Ruby library
|
64
|
+
VERSION_PATCH = VERSION_PARTS_[2] # :nodoc:
|
65
|
+
# Revision version of the libpath.Ruby library
|
66
|
+
VERSION_REVISION = VERSION_PATCH # :nodoc:
|
67
|
+
# Sub-patch version of the libpath.Ruby library
|
68
|
+
VERSION_SUBPATCH = VERSION_PARTS_[3] # :nodoc:
|
69
|
+
|
70
|
+
end # module LibPath
|
71
|
+
|
72
|
+
# ############################## end of file ############################# #
|
73
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
#############################################################################
|
4
|
+
# File: test/performance/benchmark_drive_letter.rb
|
5
|
+
#
|
6
|
+
# Purpose: Determines whether it's better to use String-case of regex
|
7
|
+
# to match Windows-drive letters
|
8
|
+
#
|
9
|
+
# Created: 8th January 2019
|
10
|
+
# Updated: 9th January 2019
|
11
|
+
#
|
12
|
+
# Author: Matthew Wilson
|
13
|
+
#
|
14
|
+
#############################################################################
|
15
|
+
|
16
|
+
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 2), 'lib')
|
17
|
+
|
18
|
+
require 'libpath/internal_/windows/drive'
|
19
|
+
|
20
|
+
require 'benchmark'
|
21
|
+
|
22
|
+
ITERATIONS = 100000
|
23
|
+
|
24
|
+
ITEMS = (0...ITERATIONS).map { rand(0...100) }.map { |n| n > 51 ? ' ' : (n % 26 + (n < 26 ? 'A' : 'a').ord).chr }
|
25
|
+
|
26
|
+
Benchmark.bm(10) do |x|
|
27
|
+
|
28
|
+
x.report('Regex:') { ITEMS.each { |ch| /^[a-z]/i =~ ch } }
|
29
|
+
x.report('cidl?:') { ITEMS.each { |ch| ::LibPath::Internal_::Windows::Drive.character_is_drive_letter?(ch) } }
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
#############################################################################
|
4
|
+
# File: test/performance/benchmark_gsub_string_or_regex.rb
|
5
|
+
#
|
6
|
+
# Purpose: Determine whether gsub using a string is faster than using a
|
7
|
+
# regex
|
8
|
+
#
|
9
|
+
# Created: 27th January 2019
|
10
|
+
# Updated: 27th January 2019
|
11
|
+
#
|
12
|
+
# Author: Matthew Wilson
|
13
|
+
#
|
14
|
+
#############################################################################
|
15
|
+
|
16
|
+
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 2), 'lib')
|
17
|
+
|
18
|
+
require 'benchmark'
|
19
|
+
|
20
|
+
ITERATIONS = 100000
|
21
|
+
|
22
|
+
STRINGS = [
|
23
|
+
|
24
|
+
'abcdefghijklmnopqrstuvwxyz',
|
25
|
+
'a\\b/c\\d/e\\f/g\\h/i\\j/k\\l/m\\n/o\\p/q\\r/s\\t/u\\v/w\\x/y\\z/',
|
26
|
+
''
|
27
|
+
]
|
28
|
+
|
29
|
+
h = {
|
30
|
+
'/' => '\\'
|
31
|
+
}
|
32
|
+
|
33
|
+
Benchmark.bm(24) do |x|
|
34
|
+
|
35
|
+
x.report('gsub by str:') { (0...ITERATIONS).each { STRINGS.each { |s| s.gsub('/', '\\') }}}
|
36
|
+
x.report('gsub by str (?):') { (0...ITERATIONS).each { STRINGS.each { |s| s.gsub('/', '\\') if s.include?('/') }}}
|
37
|
+
x.report('gsub by regex:') { (0...ITERATIONS).each { STRINGS.each { |s| s.gsub(/\//, '\\') }}}
|
38
|
+
x.report('gsub by regex (?):') { (0...ITERATIONS).each { STRINGS.each { |s| s.gsub(/\//, '\\') if s.include?('/') }}}
|
39
|
+
x.report('tr:') { (0...ITERATIONS).each { STRINGS.each { |s| s.tr('/', '\\') }}}
|
40
|
+
x.report('tr (?):') { (0...ITERATIONS).each { STRINGS.each { |s| s.tr('/', '\\') if s.include?('/') }}}
|
41
|
+
x.report('tr!:') { (0...ITERATIONS).each { STRINGS.each { |s| s.tr!('/', '\\') }}}
|
42
|
+
|
43
|
+
puts
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1,109 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
#############################################################################
|
4
|
+
# File: test/performance/benchmark_rindex2.rb
|
5
|
+
#
|
6
|
+
# Purpose: Determines whether it's better to use rindex() twice for
|
7
|
+
# Windows-slashes or once with a regex
|
8
|
+
#
|
9
|
+
# Created: 8th January 2019
|
10
|
+
# Updated: 8th January 2019
|
11
|
+
#
|
12
|
+
# Author: Matthew Wilson
|
13
|
+
#
|
14
|
+
#############################################################################
|
15
|
+
|
16
|
+
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 2), 'lib')
|
17
|
+
|
18
|
+
require 'benchmark'
|
19
|
+
|
20
|
+
ITERATIONS = 100000
|
21
|
+
|
22
|
+
SMALL_STRINGS = [
|
23
|
+
|
24
|
+
'C:\dir0\dir1/dir2',
|
25
|
+
'C:\dir0\dir1/dir2\dir3\dir4/',
|
26
|
+
'C:/dir0/dir1\dir2',
|
27
|
+
]
|
28
|
+
|
29
|
+
LONG_STRINGS = [
|
30
|
+
|
31
|
+
'C:' + '\dir' * 1000,
|
32
|
+
'C:' + '/dir' * 1000,
|
33
|
+
'C:' + '\dir/dir' * 500,
|
34
|
+
]
|
35
|
+
|
36
|
+
def by_two_calls(s)
|
37
|
+
|
38
|
+
ri_backward = s.rindex('\\')
|
39
|
+
ri_forward = s.rindex('/')
|
40
|
+
|
41
|
+
if ri_backward
|
42
|
+
|
43
|
+
if ri_forward
|
44
|
+
|
45
|
+
ri_forward > ri_backward ? ri_forward : ri_backward
|
46
|
+
else
|
47
|
+
|
48
|
+
ri_backward
|
49
|
+
end
|
50
|
+
else
|
51
|
+
|
52
|
+
ri_forward
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def by_regex(s)
|
57
|
+
|
58
|
+
s.rindex(/[\\\/]/)
|
59
|
+
end
|
60
|
+
|
61
|
+
def by_manual(s)
|
62
|
+
|
63
|
+
(1..s.size).each do |ix|
|
64
|
+
|
65
|
+
ch = s[-ix]
|
66
|
+
|
67
|
+
if '/' == ch || '\\' == ch
|
68
|
+
|
69
|
+
return s.size - ix
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# check
|
75
|
+
|
76
|
+
SMALL_STRINGS.each do |ss|
|
77
|
+
|
78
|
+
r_2c = by_two_calls(ss)
|
79
|
+
r_re = by_regex(ss)
|
80
|
+
r_man = by_manual(ss)
|
81
|
+
|
82
|
+
if r_2c != r_re || r_2c != r_man
|
83
|
+
|
84
|
+
abort "For string '#{ss}' results differ: by_two_calls()=#{r_2c}; by_regex()=#{r_re}; by_manual()=#{r_man}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
LONG_STRINGS.each do |ss|
|
89
|
+
|
90
|
+
r_2c = by_two_calls(ss)
|
91
|
+
r_re = by_regex(ss)
|
92
|
+
r_man = by_manual(ss)
|
93
|
+
|
94
|
+
if r_2c != r_re || r_2c != r_man
|
95
|
+
|
96
|
+
abort "For string '#{ss}' results differ: by_two_calls()=#{r_2c}; by_regex()=#{r_re}; by_manual()=#{r_man}"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# benchmark
|
101
|
+
|
102
|
+
Benchmark.bm(12) do |x|
|
103
|
+
|
104
|
+
x.report('rindex x 2:') { (0...ITERATIONS).each { SMALL_STRINGS.each { |ss| by_two_calls(ss) } } }
|
105
|
+
x.report('Regex:') { (0...ITERATIONS).each { SMALL_STRINGS.each { |ss| by_regex(ss) } } }
|
106
|
+
x.report('manual:') { (0...ITERATIONS).each { SMALL_STRINGS.each { |ss| by_manual(ss) } } }
|
107
|
+
end
|
108
|
+
|
109
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
#############################################################################
|
4
|
+
# File: test/performance/benchmark_split.rb
|
5
|
+
#
|
6
|
+
# Purpose: Determines whether split is faster without regex
|
7
|
+
#
|
8
|
+
# Created: 15th January 2019
|
9
|
+
# Updated: 15th January 2019
|
10
|
+
#
|
11
|
+
# Author: Matthew Wilson
|
12
|
+
#
|
13
|
+
#############################################################################
|
14
|
+
|
15
|
+
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 2), 'lib')
|
16
|
+
|
17
|
+
require 'benchmark'
|
18
|
+
|
19
|
+
ITERATIONS = 10
|
20
|
+
|
21
|
+
STRINGS = (1..1000).map { |n| '/abc' * n }
|
22
|
+
|
23
|
+
# benchmark
|
24
|
+
|
25
|
+
Benchmark.bm(15) do |x|
|
26
|
+
|
27
|
+
x.report('by char:') { (0...ITERATIONS).each { STRINGS.each { |s| s.split('/') } } }
|
28
|
+
x.report('by regex:') { (0...ITERATIONS).each { STRINGS.each { |s| s.split(/\//) } } }
|
29
|
+
x.report('by regex (sl):') { (0...ITERATIONS).each { STRINGS.each { |s| s.split(/[\\\/]/) } } }
|
30
|
+
end
|
31
|
+
|
32
|
+
|
@@ -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,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,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,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,27 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 3), 'lib')
|
4
|
+
|
5
|
+
require 'libpath/exceptions/libpath_base_exception'
|
6
|
+
|
7
|
+
require 'xqsr3/extensions/test/unit'
|
8
|
+
#require 'test/unit'
|
9
|
+
|
10
|
+
class Test_LibPathBaseException < Test::Unit::TestCase
|
11
|
+
|
12
|
+
include ::LibPath::Exceptions
|
13
|
+
|
14
|
+
def test_exception_exists_and_is_a_class
|
15
|
+
|
16
|
+
assert defined?(LibPathBaseException)
|
17
|
+
|
18
|
+
assert LibPathBaseException.is_a?(::Class)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_cannot_be_initialised
|
22
|
+
|
23
|
+
assert_raise_with_message(::NoMethodError, /private.*method.*new.*LibPathBaseException/) { LibPathBaseException.new(nil) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 3), 'lib')
|
4
|
+
|
5
|
+
require 'libpath/exceptions/malformed_name_exception'
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class Test_MalformedNameException < Test::Unit::TestCase
|
10
|
+
|
11
|
+
include ::LibPath::Exceptions
|
12
|
+
|
13
|
+
def test_class_exists
|
14
|
+
|
15
|
+
assert defined?(MalformedNameException)
|
16
|
+
|
17
|
+
assert MalformedNameException.is_a?(::Class)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_can_be_initialised
|
21
|
+
|
22
|
+
mnx = MalformedNameException.new("abc\0def")
|
23
|
+
|
24
|
+
assert_not_nil mnx
|
25
|
+
assert_not_nil mnx.name
|
26
|
+
assert_match /abc.*def/, mnx.name
|
27
|
+
assert_match /malformed name 'abc.*def'/, mnx.message
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|