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.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +33 -0
  3. data/README.md +25 -8
  4. data/examples/path_from_arg0.md +43 -43
  5. data/examples/path_from_arg0.rb +25 -23
  6. data/lib/libpath/constants/unix.rb +71 -71
  7. data/lib/libpath/constants/windows.rb +72 -72
  8. data/lib/libpath/constants.rb +18 -19
  9. data/lib/libpath/diagnostics/parameter_checking.rb +25 -25
  10. data/lib/libpath/diagnostics.rb +1 -1
  11. data/lib/libpath/exceptions/libpath_base_exception.rb +13 -13
  12. data/lib/libpath/exceptions/malformed_name_exception.rb +23 -22
  13. data/lib/libpath/exceptions.rb +1 -1
  14. data/lib/libpath/form/unix.rb +104 -103
  15. data/lib/libpath/form/windows.rb +200 -199
  16. data/lib/libpath/form.rb +18 -18
  17. data/lib/libpath/internal_/array.rb +53 -53
  18. data/lib/libpath/internal_/platform.rb +24 -24
  19. data/lib/libpath/internal_/string.rb +18 -18
  20. data/lib/libpath/internal_/unix/form.rb +116 -116
  21. data/lib/libpath/internal_/windows/drive.rb +59 -59
  22. data/lib/libpath/internal_/windows/form.rb +189 -189
  23. data/lib/libpath/libpath.rb +3 -0
  24. data/lib/libpath/path/unix.rb +114 -112
  25. data/lib/libpath/path/windows.rb +120 -118
  26. data/lib/libpath/path.rb +18 -20
  27. data/lib/libpath/util/unix.rb +258 -258
  28. data/lib/libpath/util/windows.rb +400 -400
  29. data/lib/libpath/util.rb +18 -19
  30. data/lib/libpath/version.rb +23 -24
  31. data/lib/libpath.rb +1 -1
  32. data/test/performance/benchmark_drive_letter.rb +50 -10
  33. data/test/performance/benchmark_gsub_string_or_regex.rb +27 -23
  34. data/test/performance/benchmark_rindex2.rb +56 -48
  35. data/test/performance/benchmark_split.rb +16 -10
  36. data/test/unit/compare/ts_all.rb +4 -4
  37. data/test/unit/equate/ts_all.rb +4 -4
  38. data/test/unit/equate/unix/ts_all.rb +4 -4
  39. data/test/unit/equate/windows/ts_all.rb +4 -4
  40. data/test/unit/exceptions/tc_libpath_base_exception.rb +10 -8
  41. data/test/unit/exceptions/tc_malformed_name_exception.rb +14 -12
  42. data/test/unit/exceptions/ts_all.rb +4 -4
  43. data/test/unit/form/tc_absolute_functions.rb +242 -240
  44. data/test/unit/form/ts_all.rb +4 -4
  45. data/test/unit/form/unix/tc_absolute_functions.rb +158 -155
  46. data/test/unit/form/unix/ts_all.rb +4 -4
  47. data/test/unit/form/windows/tc_absolute_functions.rb +628 -625
  48. data/test/unit/form/windows/ts_all.rb +4 -4
  49. data/test/unit/internal_/tc_array.rb +36 -32
  50. data/test/unit/internal_/ts_all.rb +4 -4
  51. data/test/unit/internal_/unix/form/tc_slash_functions.rb +38 -35
  52. data/test/unit/internal_/unix/form/ts_all.rb +4 -4
  53. data/test/unit/internal_/unix/tc_split_path.rb +387 -384
  54. data/test/unit/internal_/unix/ts_all.rb +4 -4
  55. data/test/unit/internal_/windows/form/tc_get_windows_volume.rb +157 -153
  56. data/test/unit/internal_/windows/form/tc_slash_functions.rb +39 -35
  57. data/test/unit/internal_/windows/form/ts_all.rb +4 -4
  58. data/test/unit/internal_/windows/tc_split_path.rb +874 -869
  59. data/test/unit/internal_/windows/ts_all.rb +4 -4
  60. data/test/unit/parse/ts_all.rb +4 -4
  61. data/test/unit/path/tc_path.rb +732 -732
  62. data/test/unit/path/ts_all.rb +4 -4
  63. data/test/unit/path/unix/tc_path.rb +544 -540
  64. data/test/unit/path/unix/ts_all.rb +4 -4
  65. data/test/unit/path/windows/tc_path.rb +608 -603
  66. data/test/unit/path/windows/ts_all.rb +4 -4
  67. data/test/unit/tc_version.rb +25 -22
  68. data/test/unit/ts_all.rb +4 -4
  69. data/test/unit/util/tc_combine_paths.rb +110 -105
  70. data/test/unit/util/tc_derive_relative_path.rb +8 -3
  71. data/test/unit/util/tc_make_path_canonical.rb +142 -138
  72. data/test/unit/util/ts_all.rb +4 -4
  73. data/test/unit/util/unix/tc_combine_paths.rb +38 -34
  74. data/test/unit/util/unix/tc_derive_relative_path.rb +80 -75
  75. data/test/unit/util/unix/tc_make_path_absolute.rb +74 -70
  76. data/test/unit/util/unix/tc_make_path_canonical.rb +95 -90
  77. data/test/unit/util/unix/ts_all.rb +4 -4
  78. data/test/unit/util/windows/tc_combine_paths.rb +82 -77
  79. data/test/unit/util/windows/tc_derive_relative_path.rb +98 -93
  80. data/test/unit/util/windows/tc_make_path_absolute.rb +105 -101
  81. data/test/unit/util/windows/tc_make_path_canonical.rb +158 -153
  82. data/test/unit/util/windows/ts_all.rb +4 -4
  83. 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
- require 'libpath/util/windows'
6
+ require 'libpath/util/windows'
7
7
  else
8
8
 
9
- require 'libpath/util/unix'
9
+ require 'libpath/util/unix'
10
10
  end
11
11
 
12
12
  module LibPath # :nodoc:
13
13
  module Util # :nodoc:
14
14
 
15
- if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
15
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
16
16
 
17
- extend ::LibPath::Util::Windows
18
- include ::LibPath::Util::Windows
19
- else
17
+ extend ::LibPath::Util::Windows
18
+ include ::LibPath::Util::Windows
19
+ else
20
20
 
21
- extend ::LibPath::Util::Unix
22
- include ::LibPath::Util::Unix
23
- end
21
+ extend ::LibPath::Util::Unix
22
+ include ::LibPath::Util::Unix
23
+ end
24
24
 
25
- # @!visibility private
26
- def self.extended receiver # :nodoc:
25
+ # @!visibility private
26
+ def self.extended receiver # :nodoc:
27
27
 
28
- $stderr.puts "#{receiver} extended by #{self}" if $DEBUG
29
- end
28
+ $stderr.puts "#{receiver} extended by #{self}" if $DEBUG
29
+ end
30
30
 
31
- # @!visibility private
32
- def self.included receiver # :nodoc:
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
 
@@ -1,16 +1,16 @@
1
-
2
1
  # ######################################################################## #
3
- # File: libpath/version.rb
2
+ # File: libpath/version.rb
4
3
  #
5
- # Purpose: Version for libpath.Ruby library
4
+ # Purpose: Version for libpath.Ruby library
6
5
  #
7
- # Created: 8th January 2019
8
- # Updated: 18th May 2019
6
+ # Created: 8th January 2019
7
+ # Updated: 6th April 2024
9
8
  #
10
- # Home: http://github.com/synesissoftware/libpath.Ruby
9
+ # Home: http://github.com/synesissoftware/libpath.Ruby
11
10
  #
12
- # Author: Matthew Wilson
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
- # Current version of the libpath.Ruby library
54
- VERSION = '0.2.2'
52
+ # Current version of the libpath.Ruby library
53
+ VERSION = '0.2.2.1'
55
54
 
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:
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
@@ -7,6 +7,6 @@ require 'libpath/util'
7
7
 
8
8
  require 'libpath/version'
9
9
 
10
- # ############################## end of file ############################# #
11
10
 
11
+ # ############################## end of file ############################# #
12
12
 
@@ -1,31 +1,71 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
3
  #############################################################################
4
- # File: test/performance/benchmark_drive_letter.rb
4
+ # File: test/performance/benchmark_drive_letter.rb
5
5
  #
6
- # Purpose: Determines whether it's better to use String-case of regex
7
- # to match Windows-drive letters
6
+ # Purpose: Determines whether it's better to use String-case of regex to
7
+ # match Windows-drive letters
8
8
  #
9
- # Created: 8th January 2019
10
- # Updated: 9th January 2019
9
+ # Created: 8th January 2019
10
+ # Updated: 6th April 2024
11
11
  #
12
- # Author: Matthew Wilson
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
- ITEMS = (0...ITERATIONS).map { rand(0...100) }.map { |n| n > 51 ? ' ' : (n % 26 + (n < 26 ? 'A' : 'a').ord).chr }
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
- 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) } }
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: test/performance/benchmark_gsub_string_or_regex.rb
4
+ # File: test/performance/benchmark_gsub_string_or_regex.rb
5
5
  #
6
- # Purpose: Determine whether gsub using a string is faster than using a
7
- # regex
6
+ # Purpose: Determine whether gsub using a string is faster than using regex
8
7
  #
9
- # Created: 27th January 2019
10
- # Updated: 27th January 2019
8
+ # Created: 27th January 2019
9
+ # Updated: 6th April 2024
11
10
  #
12
- # Author: Matthew Wilson
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
- STRINGS = [
22
+ ITERATIONS = 100000
23
+
24
+ STRINGS = [
23
25
 
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
- ''
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
- Benchmark.bm(24) do |x|
32
+ # benchmark
34
33
 
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!('/', '\\') }}}
34
+ Benchmark.bm(20) do |x|
42
35
 
43
- puts
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: test/performance/benchmark_rindex2.rb
4
+ # File: test/performance/benchmark_rindex2.rb
5
5
  #
6
- # Purpose: Determines whether it's better to use rindex() twice for
7
- # Windows-slashes or once with a regex
6
+ # Purpose: Determines whether it's better to use rindex() twice for
7
+ # Windows-slashes or once with a regex
8
8
  #
9
- # Created: 8th January 2019
10
- # Updated: 8th January 2019
9
+ # Created: 8th January 2019
10
+ # Updated: 6th April 2024
11
11
  #
12
- # Author: Matthew Wilson
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
- SMALL_STRINGS = [
23
+ ITERATIONS = 100000
23
24
 
24
- 'C:\dir0\dir1/dir2',
25
- 'C:\dir0\dir1/dir2\dir3\dir4/',
26
- 'C:/dir0/dir1\dir2',
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
- 'C:' + '\dir' * 1000,
32
- 'C:' + '/dir' * 1000,
33
- 'C:' + '\dir/dir' * 500,
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
- ri_backward = s.rindex('\\')
39
- ri_forward = s.rindex('/')
42
+ ri_backward = s.rindex('\\')
43
+ ri_forward = s.rindex('/')
40
44
 
41
- if ri_backward
45
+ if ri_backward
42
46
 
43
- if ri_forward
47
+ if ri_forward
44
48
 
45
- ri_forward > ri_backward ? ri_forward : ri_backward
46
- else
49
+ ri_forward > ri_backward ? ri_forward : ri_backward
50
+ else
47
51
 
48
- ri_backward
49
- end
50
- else
52
+ ri_backward
53
+ end
54
+ else
51
55
 
52
- ri_forward
53
- end
56
+ ri_forward
57
+ end
54
58
  end
55
59
 
56
60
  def by_regex(s)
57
61
 
58
- s.rindex(/[\\\/]/)
62
+ s.rindex(/[\\\/]/)
59
63
  end
60
64
 
61
65
  def by_manual(s)
62
66
 
63
- (1..s.size).each do |ix|
67
+ (1..s.size).each do |ix|
64
68
 
65
- ch = s[-ix]
69
+ ch = s[-ix]
66
70
 
67
- if '/' == ch || '\\' == ch
71
+ if '/' == ch || '\\' == ch
68
72
 
69
- return s.size - ix
70
- end
71
- end
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
- r_2c = by_two_calls(ss)
79
- r_re = by_regex(ss)
80
- r_man = by_manual(ss)
83
+ r_2c = by_two_calls(ss)
84
+ r_re = by_regex(ss)
85
+ r_man = by_manual(ss)
81
86
 
82
- if r_2c != r_re || r_2c != r_man
87
+ if r_2c != r_re || r_2c != r_man
83
88
 
84
- abort "For string '#{ss}' results differ: by_two_calls()=#{r_2c}; by_regex()=#{r_re}; by_manual()=#{r_man}"
85
- end
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
- r_2c = by_two_calls(ss)
91
- r_re = by_regex(ss)
92
- r_man = by_manual(ss)
95
+ r_2c = by_two_calls(ss)
96
+ r_re = by_regex(ss)
97
+ r_man = by_manual(ss)
93
98
 
94
- if r_2c != r_re || r_2c != r_man
99
+ if r_2c != r_re || r_2c != r_man
95
100
 
96
- abort "For string '#{ss}' results differ: by_two_calls()=#{r_2c}; by_regex()=#{r_re}; by_manual()=#{r_man}"
97
- end
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
- 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) } } }
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: test/performance/benchmark_split.rb
4
+ # File: test/performance/benchmark_split.rb
5
5
  #
6
- # Purpose: Determines whether split is faster without regex
6
+ # Purpose: Determines whether split is faster without regex
7
7
  #
8
- # Created: 15th January 2019
9
- # Updated: 15th January 2019
8
+ # Created: 15th January 2019
9
+ # Updated: 6th April 2024
10
10
  #
11
- # Author: Matthew Wilson
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
- STRINGS = (1..1000).map { |n| '/abc' * n }
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
- 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(/[\\\/]/) } } }
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
+
@@ -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
- $stderr.puts "requiring file '#{file}'" if $DEBUG
10
+ $stderr.puts "requiring file '#{file}'" if $DEBUG
11
11
 
12
- require file
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
- $stderr.puts "requiring file '#{file}'" if $DEBUG
18
+ $stderr.puts "requiring file '#{file}'" if $DEBUG
19
19
 
20
- require file
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
- $stderr.puts "requiring file '#{file}'" if $DEBUG
10
+ $stderr.puts "requiring file '#{file}'" if $DEBUG
11
11
 
12
- require file
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
- $stderr.puts "requiring file '#{file}'" if $DEBUG
18
+ $stderr.puts "requiring file '#{file}'" if $DEBUG
19
19
 
20
- require file
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
- $stderr.puts "requiring file '#{file}'" if $DEBUG
10
+ $stderr.puts "requiring file '#{file}'" if $DEBUG
11
11
 
12
- require file
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
- $stderr.puts "requiring file '#{file}'" if $DEBUG
18
+ $stderr.puts "requiring file '#{file}'" if $DEBUG
19
19
 
20
- require file
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
- $stderr.puts "requiring file '#{file}'" if $DEBUG
10
+ $stderr.puts "requiring file '#{file}'" if $DEBUG
11
11
 
12
- require file
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
- $stderr.puts "requiring file '#{file}'" if $DEBUG
18
+ $stderr.puts "requiring file '#{file}'" if $DEBUG
19
19
 
20
- require file
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
- include ::LibPath::Exceptions
12
+ include ::LibPath::Exceptions
13
13
 
14
- def test_exception_exists_and_is_a_class
14
+ def test_exception_exists_and_is_a_class
15
15
 
16
- assert defined?(LibPathBaseException)
16
+ assert defined?(LibPathBaseException)
17
17
 
18
- assert LibPathBaseException.is_a?(::Class)
19
- end
18
+ assert LibPathBaseException.is_a?(::Class)
19
+ end
20
20
 
21
- def test_cannot_be_initialised
21
+ def test_cannot_be_initialised
22
22
 
23
- assert_raise_with_message(::NoMethodError, /private.*method.*new.*LibPathBaseException/) { LibPathBaseException.new(nil) }
24
- end
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
- include ::LibPath::Exceptions
11
+ include ::LibPath::Exceptions
12
12
 
13
- def test_class_exists
13
+ def test_class_exists
14
14
 
15
- assert defined?(MalformedNameException)
15
+ assert defined?(MalformedNameException)
16
16
 
17
- assert MalformedNameException.is_a?(::Class)
18
- end
17
+ assert MalformedNameException.is_a?(::Class)
18
+ end
19
19
 
20
- def test_can_be_initialised
20
+ def test_can_be_initialised
21
21
 
22
- mnx = MalformedNameException.new("abc\0def")
22
+ mnx = MalformedNameException.new("abc\0def")
23
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
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
+