libpath-ruby 0.2.2 → 0.2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +33 -0
- data/README.md +25 -8
- data/examples/path_from_arg0.md +43 -43
- data/examples/path_from_arg0.rb +25 -23
- data/lib/libpath/constants/unix.rb +71 -71
- data/lib/libpath/constants/windows.rb +72 -72
- data/lib/libpath/constants.rb +18 -19
- data/lib/libpath/diagnostics/parameter_checking.rb +25 -25
- data/lib/libpath/diagnostics.rb +1 -1
- data/lib/libpath/exceptions/libpath_base_exception.rb +13 -13
- data/lib/libpath/exceptions/malformed_name_exception.rb +23 -22
- data/lib/libpath/exceptions.rb +1 -1
- data/lib/libpath/form/unix.rb +104 -103
- data/lib/libpath/form/windows.rb +200 -199
- data/lib/libpath/form.rb +18 -18
- data/lib/libpath/internal_/array.rb +53 -53
- data/lib/libpath/internal_/platform.rb +24 -24
- data/lib/libpath/internal_/string.rb +18 -18
- data/lib/libpath/internal_/unix/form.rb +116 -116
- data/lib/libpath/internal_/windows/drive.rb +59 -59
- data/lib/libpath/internal_/windows/form.rb +189 -189
- data/lib/libpath/libpath.rb +3 -0
- data/lib/libpath/path/unix.rb +114 -112
- data/lib/libpath/path/windows.rb +120 -118
- data/lib/libpath/path.rb +18 -20
- data/lib/libpath/util/unix.rb +258 -258
- data/lib/libpath/util/windows.rb +400 -400
- data/lib/libpath/util.rb +18 -19
- data/lib/libpath/version.rb +23 -24
- data/lib/libpath.rb +1 -1
- data/test/performance/benchmark_drive_letter.rb +50 -10
- data/test/performance/benchmark_gsub_string_or_regex.rb +27 -23
- data/test/performance/benchmark_rindex2.rb +56 -48
- data/test/performance/benchmark_split.rb +16 -10
- data/test/unit/compare/ts_all.rb +4 -4
- data/test/unit/equate/ts_all.rb +4 -4
- data/test/unit/equate/unix/ts_all.rb +4 -4
- data/test/unit/equate/windows/ts_all.rb +4 -4
- data/test/unit/exceptions/tc_libpath_base_exception.rb +10 -8
- data/test/unit/exceptions/tc_malformed_name_exception.rb +14 -12
- data/test/unit/exceptions/ts_all.rb +4 -4
- data/test/unit/form/tc_absolute_functions.rb +242 -240
- data/test/unit/form/ts_all.rb +4 -4
- data/test/unit/form/unix/tc_absolute_functions.rb +158 -155
- data/test/unit/form/unix/ts_all.rb +4 -4
- data/test/unit/form/windows/tc_absolute_functions.rb +628 -625
- data/test/unit/form/windows/ts_all.rb +4 -4
- data/test/unit/internal_/tc_array.rb +36 -32
- data/test/unit/internal_/ts_all.rb +4 -4
- data/test/unit/internal_/unix/form/tc_slash_functions.rb +38 -35
- data/test/unit/internal_/unix/form/ts_all.rb +4 -4
- data/test/unit/internal_/unix/tc_split_path.rb +387 -384
- data/test/unit/internal_/unix/ts_all.rb +4 -4
- data/test/unit/internal_/windows/form/tc_get_windows_volume.rb +157 -153
- data/test/unit/internal_/windows/form/tc_slash_functions.rb +39 -35
- data/test/unit/internal_/windows/form/ts_all.rb +4 -4
- data/test/unit/internal_/windows/tc_split_path.rb +874 -869
- data/test/unit/internal_/windows/ts_all.rb +4 -4
- data/test/unit/parse/ts_all.rb +4 -4
- data/test/unit/path/tc_path.rb +732 -732
- data/test/unit/path/ts_all.rb +4 -4
- data/test/unit/path/unix/tc_path.rb +544 -540
- data/test/unit/path/unix/ts_all.rb +4 -4
- data/test/unit/path/windows/tc_path.rb +608 -603
- data/test/unit/path/windows/ts_all.rb +4 -4
- data/test/unit/tc_version.rb +25 -22
- data/test/unit/ts_all.rb +4 -4
- data/test/unit/util/tc_combine_paths.rb +110 -105
- data/test/unit/util/tc_derive_relative_path.rb +8 -3
- data/test/unit/util/tc_make_path_canonical.rb +142 -138
- data/test/unit/util/ts_all.rb +4 -4
- data/test/unit/util/unix/tc_combine_paths.rb +38 -34
- data/test/unit/util/unix/tc_derive_relative_path.rb +80 -75
- data/test/unit/util/unix/tc_make_path_absolute.rb +74 -70
- data/test/unit/util/unix/tc_make_path_canonical.rb +95 -90
- data/test/unit/util/unix/ts_all.rb +4 -4
- data/test/unit/util/windows/tc_combine_paths.rb +82 -77
- data/test/unit/util/windows/tc_derive_relative_path.rb +98 -93
- data/test/unit/util/windows/tc_make_path_absolute.rb +105 -101
- data/test/unit/util/windows/tc_make_path_canonical.rb +158 -153
- data/test/unit/util/windows/ts_all.rb +4 -4
- metadata +9 -8
data/lib/libpath/util.rb
CHANGED
@@ -3,40 +3,39 @@ require 'libpath/internal_/platform'
|
|
3
3
|
|
4
4
|
if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
|
5
5
|
|
6
|
-
|
6
|
+
require 'libpath/util/windows'
|
7
7
|
else
|
8
8
|
|
9
|
-
|
9
|
+
require 'libpath/util/unix'
|
10
10
|
end
|
11
11
|
|
12
12
|
module LibPath # :nodoc:
|
13
13
|
module Util # :nodoc:
|
14
14
|
|
15
|
-
|
15
|
+
if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
extend ::LibPath::Util::Windows
|
18
|
+
include ::LibPath::Util::Windows
|
19
|
+
else
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
extend ::LibPath::Util::Unix
|
22
|
+
include ::LibPath::Util::Unix
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
# @!visibility private
|
26
|
+
def self.extended receiver # :nodoc:
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
$stderr.puts "#{receiver} extended by #{self}" if $DEBUG
|
29
|
+
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
$stderr.puts "#{receiver} included #{self}" if $DEBUG
|
35
|
-
end
|
31
|
+
# @!visibility private
|
32
|
+
def self.included receiver # :nodoc:
|
36
33
|
|
34
|
+
$stderr.puts "#{receiver} included #{self}" if $DEBUG
|
35
|
+
end
|
37
36
|
end # module Util
|
38
37
|
end # module LibPath
|
39
38
|
|
40
|
-
# ############################## end of file ############################# #
|
41
39
|
|
40
|
+
# ############################## end of file ############################# #
|
42
41
|
|
data/lib/libpath/version.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
|
2
1
|
# ######################################################################## #
|
3
|
-
# File:
|
2
|
+
# File: libpath/version.rb
|
4
3
|
#
|
5
|
-
# Purpose:
|
4
|
+
# Purpose: Version for libpath.Ruby library
|
6
5
|
#
|
7
|
-
# Created:
|
8
|
-
# Updated:
|
6
|
+
# Created: 8th January 2019
|
7
|
+
# Updated: 6th April 2024
|
9
8
|
#
|
10
|
-
# Home:
|
9
|
+
# Home: http://github.com/synesissoftware/libpath.Ruby
|
11
10
|
#
|
12
|
-
# Author:
|
11
|
+
# Author: Matthew Wilson
|
13
12
|
#
|
13
|
+
# Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
|
14
14
|
# Copyright (c) 2019, Matthew Wilson and Synesis Software
|
15
15
|
# All rights reserved.
|
16
16
|
#
|
@@ -44,31 +44,30 @@
|
|
44
44
|
# ######################################################################## #
|
45
45
|
|
46
46
|
|
47
|
-
|
48
47
|
=begin
|
49
48
|
=end
|
50
49
|
|
51
50
|
module LibPath # :nodoc:
|
52
51
|
|
53
|
-
|
54
|
-
|
52
|
+
# Current version of the libpath.Ruby library
|
53
|
+
VERSION = '0.2.2.1'
|
55
54
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
55
|
+
private
|
56
|
+
VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
|
57
|
+
public
|
58
|
+
# Major version of the libpath.Ruby library
|
59
|
+
VERSION_MAJOR = VERSION_PARTS_[0] # :nodoc:
|
60
|
+
# Minor version of the libpath.Ruby library
|
61
|
+
VERSION_MINOR = VERSION_PARTS_[1] # :nodoc:
|
62
|
+
# Patch version of the libpath.Ruby library
|
63
|
+
VERSION_PATCH = VERSION_PARTS_[2] # :nodoc:
|
64
|
+
# Revision version of the libpath.Ruby library
|
65
|
+
VERSION_REVISION = VERSION_PATCH # :nodoc:
|
66
|
+
# Sub-patch version of the libpath.Ruby library
|
67
|
+
VERSION_SUBPATCH = VERSION_PARTS_[3] # :nodoc:
|
69
68
|
|
70
69
|
end # module LibPath
|
71
70
|
|
72
|
-
# ############################## end of file ############################# #
|
73
71
|
|
72
|
+
# ############################## end of file ############################# #
|
74
73
|
|
data/lib/libpath.rb
CHANGED
@@ -1,31 +1,71 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
|
3
3
|
#############################################################################
|
4
|
-
# File:
|
4
|
+
# File: test/performance/benchmark_drive_letter.rb
|
5
5
|
#
|
6
|
-
# Purpose:
|
7
|
-
#
|
6
|
+
# Purpose: Determines whether it's better to use String-case of regex to
|
7
|
+
# match Windows-drive letters
|
8
8
|
#
|
9
|
-
# Created:
|
10
|
-
# Updated:
|
9
|
+
# Created: 8th January 2019
|
10
|
+
# Updated: 6th April 2024
|
11
11
|
#
|
12
|
-
# Author:
|
12
|
+
# Author: Matthew Wilson
|
13
13
|
#
|
14
14
|
#############################################################################
|
15
15
|
|
16
|
+
|
16
17
|
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 2), 'lib')
|
17
18
|
|
19
|
+
|
18
20
|
require 'libpath/internal_/windows/drive'
|
19
21
|
|
20
22
|
require 'benchmark'
|
21
23
|
|
22
|
-
ITERATIONS = 100000
|
23
24
|
|
24
|
-
|
25
|
+
include ::LibPath::Internal_::Windows
|
26
|
+
|
27
|
+
|
28
|
+
ITERATIONS = 100000
|
29
|
+
|
30
|
+
ITEMS = (0...ITERATIONS).map { rand(0...100) }.map { |n| n > 51 ? ' ' : (n % 26 + (n < 26 ? 'A' : 'a').ord).chr }
|
31
|
+
|
32
|
+
def is_drive_letter_1? c
|
33
|
+
|
34
|
+
if c.valid_encoding?
|
35
|
+
|
36
|
+
co = c.ord
|
37
|
+
|
38
|
+
return true if co >= 65 && co <= 90
|
39
|
+
|
40
|
+
return true if co >= 97 && co <= 122
|
41
|
+
|
42
|
+
return false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def is_drive_letter_2? c
|
47
|
+
|
48
|
+
co = c.ord
|
49
|
+
|
50
|
+
return true if (64..90).include? co
|
51
|
+
|
52
|
+
return true if (97..122).include? co
|
53
|
+
|
54
|
+
return false
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
# benchmark
|
25
59
|
|
26
60
|
Benchmark.bm(10) do |x|
|
27
61
|
|
28
|
-
|
29
|
-
|
62
|
+
x.report('Regex:') { ITEMS.each { |ch| /^[a-zA-Z]/ =~ ch } }
|
63
|
+
x.report('Regex/i:') { ITEMS.each { |ch| /^[a-z]/i =~ ch } }
|
64
|
+
x.report('cidl?:') { ITEMS.each { |ch| Drive.character_is_drive_letter?(ch) } }
|
65
|
+
x.report('idl-1?:') { ITEMS.each { |ch| is_drive_letter_1?(ch) } }
|
66
|
+
x.report('idl-2?:') { ITEMS.each { |ch| is_drive_letter_2?(ch) } }
|
30
67
|
end
|
31
68
|
|
69
|
+
|
70
|
+
# ############################## end of file ############################# #
|
71
|
+
|
@@ -1,45 +1,49 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
|
3
3
|
#############################################################################
|
4
|
-
# File:
|
4
|
+
# File: test/performance/benchmark_gsub_string_or_regex.rb
|
5
5
|
#
|
6
|
-
# Purpose:
|
7
|
-
# regex
|
6
|
+
# Purpose: Determine whether gsub using a string is faster than using regex
|
8
7
|
#
|
9
|
-
# Created:
|
10
|
-
# Updated:
|
8
|
+
# Created: 27th January 2019
|
9
|
+
# Updated: 6th April 2024
|
11
10
|
#
|
12
|
-
# Author:
|
11
|
+
# Author: Matthew Wilson
|
13
12
|
#
|
14
13
|
#############################################################################
|
15
14
|
|
15
|
+
|
16
16
|
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 2), 'lib')
|
17
17
|
|
18
|
+
|
18
19
|
require 'benchmark'
|
19
20
|
|
20
|
-
ITERATIONS = 100000
|
21
21
|
|
22
|
-
|
22
|
+
ITERATIONS = 100000
|
23
|
+
|
24
|
+
STRINGS = [
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
'abcdefghijklmnopqrstuvwxyz',
|
27
|
+
'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/',
|
28
|
+
''
|
27
29
|
]
|
28
30
|
|
29
|
-
h = {
|
30
|
-
'/' => '\\'
|
31
|
-
}
|
32
31
|
|
33
|
-
|
32
|
+
# benchmark
|
34
33
|
|
35
|
-
|
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!('/', '\\') }}}
|
34
|
+
Benchmark.bm(20) do |x|
|
42
35
|
|
43
|
-
|
36
|
+
x.report('gsub by str:') { (0...ITERATIONS).each { STRINGS.each { |s| s.gsub('/', '\\') }}}
|
37
|
+
x.report('gsub by str (?):') { (0...ITERATIONS).each { STRINGS.each { |s| s.gsub('/', '\\') if s.include?('/') }}}
|
38
|
+
x.report('gsub by regex:') { (0...ITERATIONS).each { STRINGS.each { |s| s.gsub(/\//, '\\') }}}
|
39
|
+
x.report('gsub by regex (?):') { (0...ITERATIONS).each { STRINGS.each { |s| s.gsub(/\//, '\\') if s.include?('/') }}}
|
40
|
+
x.report('tr:') { (0...ITERATIONS).each { STRINGS.each { |s| s.tr('/', '\\') }}}
|
41
|
+
x.report('tr (?):') { (0...ITERATIONS).each { STRINGS.each { |s| s.tr('/', '\\') if s.include?('/') }}}
|
42
|
+
x.report('tr!:') { (0...ITERATIONS).each { STRINGS.each { |s| s.tr!('/', '\\') }}}
|
43
|
+
|
44
|
+
puts
|
44
45
|
end
|
45
46
|
|
47
|
+
|
48
|
+
# ############################## end of file ############################# #
|
49
|
+
|
@@ -1,109 +1,117 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
|
3
3
|
#############################################################################
|
4
|
-
# File:
|
4
|
+
# File: test/performance/benchmark_rindex2.rb
|
5
5
|
#
|
6
|
-
# Purpose:
|
7
|
-
#
|
6
|
+
# Purpose: Determines whether it's better to use rindex() twice for
|
7
|
+
# Windows-slashes or once with a regex
|
8
8
|
#
|
9
|
-
# Created:
|
10
|
-
# Updated:
|
9
|
+
# Created: 8th January 2019
|
10
|
+
# Updated: 6th April 2024
|
11
11
|
#
|
12
|
-
# Author:
|
12
|
+
# Author: Matthew Wilson
|
13
13
|
#
|
14
14
|
#############################################################################
|
15
15
|
|
16
|
+
|
16
17
|
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 2), 'lib')
|
17
18
|
|
19
|
+
|
18
20
|
require 'benchmark'
|
19
21
|
|
20
|
-
ITERATIONS = 100000
|
21
22
|
|
22
|
-
|
23
|
+
ITERATIONS = 100000
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
SMALL_STRINGS = [
|
26
|
+
|
27
|
+
'C:\dir0\dir1/dir2',
|
28
|
+
'C:\dir0\dir1/dir2\dir3\dir4/',
|
29
|
+
'C:/dir0/dir1\dir2',
|
27
30
|
]
|
28
31
|
|
29
|
-
LONG_STRINGS
|
32
|
+
LONG_STRINGS = [
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
'C:' + '\dir' * 1000,
|
35
|
+
'C:' + '/dir' * 1000,
|
36
|
+
'C:' + '\dir/dir' * 500,
|
34
37
|
]
|
35
38
|
|
39
|
+
|
36
40
|
def by_two_calls(s)
|
37
41
|
|
38
|
-
|
39
|
-
|
42
|
+
ri_backward = s.rindex('\\')
|
43
|
+
ri_forward = s.rindex('/')
|
40
44
|
|
41
|
-
|
45
|
+
if ri_backward
|
42
46
|
|
43
|
-
|
47
|
+
if ri_forward
|
44
48
|
|
45
|
-
|
46
|
-
|
49
|
+
ri_forward > ri_backward ? ri_forward : ri_backward
|
50
|
+
else
|
47
51
|
|
48
|
-
|
49
|
-
|
50
|
-
|
52
|
+
ri_backward
|
53
|
+
end
|
54
|
+
else
|
51
55
|
|
52
|
-
|
53
|
-
|
56
|
+
ri_forward
|
57
|
+
end
|
54
58
|
end
|
55
59
|
|
56
60
|
def by_regex(s)
|
57
61
|
|
58
|
-
|
62
|
+
s.rindex(/[\\\/]/)
|
59
63
|
end
|
60
64
|
|
61
65
|
def by_manual(s)
|
62
66
|
|
63
|
-
|
67
|
+
(1..s.size).each do |ix|
|
64
68
|
|
65
|
-
|
69
|
+
ch = s[-ix]
|
66
70
|
|
67
|
-
|
71
|
+
if '/' == ch || '\\' == ch
|
68
72
|
|
69
|
-
|
70
|
-
|
71
|
-
|
73
|
+
return s.size - ix
|
74
|
+
end
|
75
|
+
end
|
72
76
|
end
|
73
77
|
|
78
|
+
|
74
79
|
# check
|
75
80
|
|
76
81
|
SMALL_STRINGS.each do |ss|
|
77
82
|
|
78
|
-
|
79
|
-
|
80
|
-
|
83
|
+
r_2c = by_two_calls(ss)
|
84
|
+
r_re = by_regex(ss)
|
85
|
+
r_man = by_manual(ss)
|
81
86
|
|
82
|
-
|
87
|
+
if r_2c != r_re || r_2c != r_man
|
83
88
|
|
84
|
-
|
85
|
-
|
89
|
+
abort "For string '#{ss}' results differ: by_two_calls()=#{r_2c}; by_regex()=#{r_re}; by_manual()=#{r_man}"
|
90
|
+
end
|
86
91
|
end
|
87
92
|
|
88
93
|
LONG_STRINGS.each do |ss|
|
89
94
|
|
90
|
-
|
91
|
-
|
92
|
-
|
95
|
+
r_2c = by_two_calls(ss)
|
96
|
+
r_re = by_regex(ss)
|
97
|
+
r_man = by_manual(ss)
|
93
98
|
|
94
|
-
|
99
|
+
if r_2c != r_re || r_2c != r_man
|
95
100
|
|
96
|
-
|
97
|
-
|
101
|
+
abort "For string '#{ss}' results differ: by_two_calls()=#{r_2c}; by_regex()=#{r_re}; by_manual()=#{r_man}"
|
102
|
+
end
|
98
103
|
end
|
99
104
|
|
105
|
+
|
100
106
|
# benchmark
|
101
107
|
|
102
108
|
Benchmark.bm(12) do |x|
|
103
109
|
|
104
|
-
|
105
|
-
|
106
|
-
|
110
|
+
x.report('rindex x 2:') { (0...ITERATIONS).each { SMALL_STRINGS.each { |ss| by_two_calls(ss) } } }
|
111
|
+
x.report('Regex:') { (0...ITERATIONS).each { SMALL_STRINGS.each { |ss| by_regex(ss) } } }
|
112
|
+
x.report('manual:') { (0...ITERATIONS).each { SMALL_STRINGS.each { |ss| by_manual(ss) } } }
|
107
113
|
end
|
108
114
|
|
109
115
|
|
116
|
+
# ############################## end of file ############################# #
|
117
|
+
|
@@ -1,32 +1,38 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
|
3
3
|
#############################################################################
|
4
|
-
# File:
|
4
|
+
# File: test/performance/benchmark_split.rb
|
5
5
|
#
|
6
|
-
# Purpose:
|
6
|
+
# Purpose: Determines whether split is faster without regex
|
7
7
|
#
|
8
|
-
# Created:
|
9
|
-
# Updated:
|
8
|
+
# Created: 15th January 2019
|
9
|
+
# Updated: 6th April 2024
|
10
10
|
#
|
11
|
-
# Author:
|
11
|
+
# Author: Matthew Wilson
|
12
12
|
#
|
13
13
|
#############################################################################
|
14
14
|
|
15
|
+
|
15
16
|
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 2), 'lib')
|
16
17
|
|
18
|
+
|
17
19
|
require 'benchmark'
|
18
20
|
|
19
|
-
ITERATIONS = 10
|
20
21
|
|
21
|
-
|
22
|
+
ITERATIONS = 10
|
23
|
+
|
24
|
+
STRINGS = (1..1000).map { |n| '/abc' * n }
|
25
|
+
|
22
26
|
|
23
27
|
# benchmark
|
24
28
|
|
25
29
|
Benchmark.bm(15) do |x|
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
31
|
+
x.report('by char:') { (0...ITERATIONS).each { STRINGS.each { |s| s.split('/') } } }
|
32
|
+
x.report('by regex:') { (0...ITERATIONS).each { STRINGS.each { |s| s.split(/\//) } } }
|
33
|
+
x.report('by regex (sl):') { (0...ITERATIONS).each { STRINGS.each { |s| s.split(/[\\\/]/) } } }
|
30
34
|
end
|
31
35
|
|
32
36
|
|
37
|
+
# ############################## end of file ############################# #
|
38
|
+
|
data/test/unit/compare/ts_all.rb
CHANGED
@@ -7,16 +7,16 @@ this_dir = File.expand_path(File.dirname(__FILE__))
|
|
7
7
|
# all tc_*rb in current directory
|
8
8
|
Dir[File.join(this_dir, 'tc_*rb')].each do |file|
|
9
9
|
|
10
|
-
|
10
|
+
$stderr.puts "requiring file '#{file}'" if $DEBUG
|
11
11
|
|
12
|
-
|
12
|
+
require file
|
13
13
|
end
|
14
14
|
|
15
15
|
# all ts_*rb in immediate sub-directories
|
16
16
|
Dir[File.join(this_dir, '*', 'ts_*rb')].each do |file|
|
17
17
|
|
18
|
-
|
18
|
+
$stderr.puts "requiring file '#{file}'" if $DEBUG
|
19
19
|
|
20
|
-
|
20
|
+
require file
|
21
21
|
end
|
22
22
|
|
data/test/unit/equate/ts_all.rb
CHANGED
@@ -7,16 +7,16 @@ this_dir = File.expand_path(File.dirname(__FILE__))
|
|
7
7
|
# all tc_*rb in current directory
|
8
8
|
Dir[File.join(this_dir, 'tc_*rb')].each do |file|
|
9
9
|
|
10
|
-
|
10
|
+
$stderr.puts "requiring file '#{file}'" if $DEBUG
|
11
11
|
|
12
|
-
|
12
|
+
require file
|
13
13
|
end
|
14
14
|
|
15
15
|
# all ts_*rb in immediate sub-directories
|
16
16
|
Dir[File.join(this_dir, '*', 'ts_*rb')].each do |file|
|
17
17
|
|
18
|
-
|
18
|
+
$stderr.puts "requiring file '#{file}'" if $DEBUG
|
19
19
|
|
20
|
-
|
20
|
+
require file
|
21
21
|
end
|
22
22
|
|
@@ -7,16 +7,16 @@ this_dir = File.expand_path(File.dirname(__FILE__))
|
|
7
7
|
# all tc_*rb in current directory
|
8
8
|
Dir[File.join(this_dir, 'tc_*rb')].each do |file|
|
9
9
|
|
10
|
-
|
10
|
+
$stderr.puts "requiring file '#{file}'" if $DEBUG
|
11
11
|
|
12
|
-
|
12
|
+
require file
|
13
13
|
end
|
14
14
|
|
15
15
|
# all ts_*rb in immediate sub-directories
|
16
16
|
Dir[File.join(this_dir, '*', 'ts_*rb')].each do |file|
|
17
17
|
|
18
|
-
|
18
|
+
$stderr.puts "requiring file '#{file}'" if $DEBUG
|
19
19
|
|
20
|
-
|
20
|
+
require file
|
21
21
|
end
|
22
22
|
|
@@ -7,16 +7,16 @@ this_dir = File.expand_path(File.dirname(__FILE__))
|
|
7
7
|
# all tc_*rb in current directory
|
8
8
|
Dir[File.join(this_dir, 'tc_*rb')].each do |file|
|
9
9
|
|
10
|
-
|
10
|
+
$stderr.puts "requiring file '#{file}'" if $DEBUG
|
11
11
|
|
12
|
-
|
12
|
+
require file
|
13
13
|
end
|
14
14
|
|
15
15
|
# all ts_*rb in immediate sub-directories
|
16
16
|
Dir[File.join(this_dir, '*', 'ts_*rb')].each do |file|
|
17
17
|
|
18
|
-
|
18
|
+
$stderr.puts "requiring file '#{file}'" if $DEBUG
|
19
19
|
|
20
|
-
|
20
|
+
require file
|
21
21
|
end
|
22
22
|
|
@@ -9,19 +9,21 @@ require 'xqsr3/extensions/test/unit'
|
|
9
9
|
|
10
10
|
class Test_LibPathBaseException < Test::Unit::TestCase
|
11
11
|
|
12
|
-
|
12
|
+
include ::LibPath::Exceptions
|
13
13
|
|
14
|
-
|
14
|
+
def test_exception_exists_and_is_a_class
|
15
15
|
|
16
|
-
|
16
|
+
assert defined?(LibPathBaseException)
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
assert LibPathBaseException.is_a?(::Class)
|
19
|
+
end
|
20
20
|
|
21
|
-
|
21
|
+
def test_cannot_be_initialised
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
assert_raise_with_message(::NoMethodError, /private.*method.*new.*LibPathBaseException/) { LibPathBaseException.new(nil) }
|
24
|
+
end
|
25
25
|
end
|
26
26
|
|
27
27
|
|
28
|
+
# ############################## end of file ############################# #
|
29
|
+
|
@@ -8,24 +8,26 @@ require 'test/unit'
|
|
8
8
|
|
9
9
|
class Test_MalformedNameException < Test::Unit::TestCase
|
10
10
|
|
11
|
-
|
11
|
+
include ::LibPath::Exceptions
|
12
12
|
|
13
|
-
|
13
|
+
def test_class_exists
|
14
14
|
|
15
|
-
|
15
|
+
assert defined?(MalformedNameException)
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
assert MalformedNameException.is_a?(::Class)
|
18
|
+
end
|
19
19
|
|
20
|
-
|
20
|
+
def test_can_be_initialised
|
21
21
|
|
22
|
-
|
22
|
+
mnx = MalformedNameException.new("abc\0def")
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
29
|
end
|
30
30
|
|
31
31
|
|
32
|
+
# ############################## end of file ############################# #
|
33
|
+
|