pathname2 1.8.4 → 2.0.0

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 (45) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGES.md +7 -0
  4. data/Gemfile +2 -3
  5. data/MANIFEST.md +2 -2
  6. data/README.md +6 -0
  7. data/Rakefile +227 -222
  8. data/benchmarks/bench_pathname2.rb +127 -0
  9. data/examples/{example_pathname.rb → example_pathname2.rb} +7 -7
  10. data/lib/pathname2.rb +160 -169
  11. data/pathname2.gemspec +13 -9
  12. data/test/{test_pathname.rb → test_pathname2.rb} +67 -63
  13. data/test/test_version.rb +3 -3
  14. data/test/windows/test_append.rb +7 -7
  15. data/test/windows/test_aref.rb +3 -3
  16. data/test/windows/test_ascend.rb +5 -5
  17. data/test/windows/test_children.rb +7 -7
  18. data/test/windows/test_clean.rb +17 -17
  19. data/test/windows/test_clean_bang.rb +17 -17
  20. data/test/windows/test_constructor.rb +12 -12
  21. data/test/windows/test_descend.rb +5 -5
  22. data/test/windows/test_drive_number.rb +13 -13
  23. data/test/windows/test_each.rb +3 -3
  24. data/test/windows/test_facade.rb +6 -6
  25. data/test/windows/test_is_absolute.rb +8 -8
  26. data/test/windows/test_is_relative.rb +7 -7
  27. data/test/windows/test_is_root.rb +8 -8
  28. data/test/windows/test_is_unc.rb +18 -18
  29. data/test/windows/test_join.rb +8 -8
  30. data/test/windows/test_long_path.rb +6 -6
  31. data/test/windows/test_misc.rb +7 -7
  32. data/test/windows/test_parent.rb +9 -9
  33. data/test/windows/test_pstrip.rb +9 -9
  34. data/test/windows/test_pstrip_bang.rb +10 -10
  35. data/test/windows/test_realpath.rb +5 -5
  36. data/test/windows/test_relative_path_from.rb +4 -4
  37. data/test/windows/test_root.rb +14 -14
  38. data/test/windows/test_short_path.rb +6 -6
  39. data/test/windows/test_to_a.rb +12 -12
  40. data/test/windows/test_undecorate.rb +12 -12
  41. data/test/windows/test_undecorate_bang.rb +13 -13
  42. data.tar.gz.sig +0 -0
  43. metadata +61 -54
  44. metadata.gz.sig +0 -0
  45. data/benchmarks/bench_pathname.rb +0 -127
@@ -1,16 +1,16 @@
1
1
  ########################################################################
2
2
  # test_root.rb
3
3
  #
4
- # Test suite for the Pathname#root method
4
+ # Test suite for the Pathname2#root method
5
5
  ########################################################################
6
6
  require 'test-unit'
7
7
  require 'pathname2'
8
8
 
9
- class TC_Pathname_Root < Test::Unit::TestCase
9
+ class TC_Pathname2_Root < Test::Unit::TestCase
10
10
  def setup
11
- @abs_path = Pathname.new("C:\\Program Files")
12
- @unc_path = Pathname.new("\\\\foo\\bar\\baz")
13
- @rel_path = Pathname.new("foo\\bar\\baz")
11
+ @abs_path = Pathname2.new("C:\\Program Files")
12
+ @unc_path = Pathname2.new("\\\\foo\\bar\\baz")
13
+ @rel_path = Pathname2.new("foo\\bar\\baz")
14
14
  end
15
15
 
16
16
  test "root method returns expected results for absolute paths" do
@@ -18,13 +18,13 @@ class TC_Pathname_Root < Test::Unit::TestCase
18
18
  end
19
19
 
20
20
  test "root method returns expected results for paths with forward slashes" do
21
- assert_equal("C:\\", Pathname.new("C:/Program Files").root)
21
+ assert_equal("C:\\", Pathname2.new("C:/Program Files").root)
22
22
  end
23
23
 
24
24
  test "root method returns expected results for unc paths" do
25
25
  assert_equal("\\\\foo\\bar", @unc_path.root)
26
- assert_equal("\\\\foo", Pathname.new("\\\\foo").root)
27
- assert_equal("\\\\", Pathname.new("\\\\").root)
26
+ assert_equal("\\\\foo", Pathname2.new("\\\\foo").root)
27
+ assert_equal("\\\\", Pathname2.new("\\\\").root)
28
28
  end
29
29
 
30
30
  test "root method returns dot for relative paths" do
@@ -32,22 +32,22 @@ class TC_Pathname_Root < Test::Unit::TestCase
32
32
  end
33
33
 
34
34
  test "root method returns expected result for root path" do
35
- assert_equal("Z:\\", Pathname.new("Z:\\").root)
36
- assert_equal("\\\\foo\\bar", Pathname.new("\\\\foo\\bar").root)
35
+ assert_equal("Z:\\", Pathname2.new("Z:\\").root)
36
+ assert_equal("\\\\foo\\bar", Pathname2.new("\\\\foo\\bar").root)
37
37
  end
38
38
 
39
39
  test "root method returns expected result for empty string" do
40
- assert_equal(".", Pathname.new("").root)
40
+ assert_equal(".", Pathname2.new("").root)
41
41
  end
42
42
 
43
43
  test "root method returns expected result for dot and dotdot" do
44
- assert_equal(".", Pathname.new("..").root)
45
- assert_equal(".", Pathname.new(".").root)
44
+ assert_equal(".", Pathname2.new("..").root)
45
+ assert_equal(".", Pathname2.new(".").root)
46
46
  end
47
47
 
48
48
  test "root method is not destructive" do
49
49
  str = 'C:/Program Files'
50
- assert_nothing_raised{ Pathname.new(str).root }
50
+ assert_nothing_raised{ Pathname2.new(str).root }
51
51
  assert_equal('C:/Program Files', str)
52
52
  end
53
53
 
@@ -1,14 +1,14 @@
1
1
  ########################################################################
2
2
  # test_short_path.rb
3
3
  #
4
- # Test suite for the Pathname#short_path method
4
+ # Test suite for the Pathname2#short_path method
5
5
  ########################################################################
6
6
  require 'test-unit'
7
7
  require 'pathname2'
8
8
 
9
- class TC_Pathname_ShortPath < Test::Unit::TestCase
9
+ class TC_Pathname2_ShortPath < Test::Unit::TestCase
10
10
  def setup
11
- @abs_path = Pathname.new("C:\\Program Files")
11
+ @abs_path = Pathname2.new("C:\\Program Files")
12
12
  end
13
13
 
14
14
  test "short_path basic functionality" do
@@ -22,16 +22,16 @@ class TC_Pathname_ShortPath < Test::Unit::TestCase
22
22
  end
23
23
 
24
24
  test "short_path returns the same string if it's already short" do
25
- assert_equal("C:\\", Pathname.new("C:/").short_path)
25
+ assert_equal("C:\\", Pathname2.new("C:/").short_path)
26
26
  end
27
27
 
28
28
  test "short_path fails if the path does not exist" do
29
- assert_raise(Errno::ESRCH){ Pathname.new("C:/Bogus/AlsoBogus").short_path }
29
+ assert_raise(Errno::ESRCH){ Pathname2.new("C:/Bogus/AlsoBogus").short_path }
30
30
  end
31
31
 
32
32
  test "short_path method is not destructive" do
33
33
  str = 'C:/Program Files'
34
- assert_nothing_raised{ Pathname.new(str).short_path }
34
+ assert_nothing_raised{ Pathname2.new(str).short_path }
35
35
  assert_equal('C:/Program Files', str)
36
36
  end
37
37
 
@@ -1,14 +1,14 @@
1
1
  ########################################################################
2
2
  # test_to_a.rb
3
3
  #
4
- # Test suite for the Pathname#to_a method.
4
+ # Test suite for the Pathname2#to_a method.
5
5
  ########################################################################
6
6
  require 'test-unit'
7
7
  require 'pathname2'
8
8
 
9
- class TC_Pathname_ToA < Test::Unit::TestCase
9
+ class TC_Pathname2_ToA < Test::Unit::TestCase
10
10
  def setup
11
- @path = Pathname.new('C:/Program Files/foo')
11
+ @path = Pathname2.new('C:/Program Files/foo')
12
12
  end
13
13
 
14
14
  test "to_a basic functionality" do
@@ -18,21 +18,21 @@ class TC_Pathname_ToA < Test::Unit::TestCase
18
18
  end
19
19
 
20
20
  test "to_a returns the expected results for standard paths" do
21
- assert_equal(['C:'], Pathname.new('C:/').to_a)
22
- assert_equal(['C:', 'Program Files'], Pathname.new('C:/Program Files').to_a)
23
- assert_equal(['C:', 'Program Files', 'Stuff'], Pathname.new('C:/Program Files/Stuff').to_a)
24
- assert_equal(['C:', 'Users'], Pathname.new("C:\\Users").to_a)
21
+ assert_equal(['C:'], Pathname2.new('C:/').to_a)
22
+ assert_equal(['C:', 'Program Files'], Pathname2.new('C:/Program Files').to_a)
23
+ assert_equal(['C:', 'Program Files', 'Stuff'], Pathname2.new('C:/Program Files/Stuff').to_a)
24
+ assert_equal(['C:', 'Users'], Pathname2.new("C:\\Users").to_a)
25
25
  end
26
26
 
27
27
  test "to_a returns the expected results for unc paths" do
28
- assert_equal(['foo', 'bar', 'baz'], Pathname.new('//foo/bar/baz').to_a)
29
- assert_equal(['foo', 'bar'], Pathname.new('//foo/bar').to_a)
30
- assert_equal(['foo'], Pathname.new('//foo').to_a)
28
+ assert_equal(['foo', 'bar', 'baz'], Pathname2.new('//foo/bar/baz').to_a)
29
+ assert_equal(['foo', 'bar'], Pathname2.new('//foo/bar').to_a)
30
+ assert_equal(['foo'], Pathname2.new('//foo').to_a)
31
31
  end
32
32
 
33
33
  test "to_a returns the expected results for empty strings and empty unc paths" do
34
- assert_equal([], Pathname.new('').to_a)
35
- assert_equal([], Pathname.new('//').to_a)
34
+ assert_equal([], Pathname2.new('').to_a)
35
+ assert_equal([], Pathname2.new('//').to_a)
36
36
  end
37
37
 
38
38
  test "to_a does not modify receiver" do
@@ -1,14 +1,14 @@
1
1
  ########################################################################
2
2
  # test_undecorate.rb
3
3
  #
4
- # Test suite for the Pathname#undecorate method
4
+ # Test suite for the Pathname2#undecorate method
5
5
  ########################################################################
6
6
  require 'test-unit'
7
7
  require 'pathname2'
8
8
 
9
- class TC_Pathname_Undecorate < Test::Unit::TestCase
9
+ class TC_Pathname2_Undecorate < Test::Unit::TestCase
10
10
  def setup
11
- @std = Pathname.new('C:/Path/File.txt')
11
+ @std = Pathname2.new('C:/Path/File.txt')
12
12
  end
13
13
 
14
14
  test "undecorate basic functionality" do
@@ -16,28 +16,28 @@ class TC_Pathname_Undecorate < Test::Unit::TestCase
16
16
  assert_nothing_raised{ @std.undecorate }
17
17
  end
18
18
 
19
- test "undecorate returns a Pathname object" do
20
- assert_kind_of(Pathname, @std.undecorate)
19
+ test "undecorate returns a Pathname2 object" do
20
+ assert_kind_of(Pathname2, @std.undecorate)
21
21
  end
22
22
 
23
23
  test "undecorate method returns an already undecorated path unchanged" do
24
- assert_equal('C:\Path\File.txt', Pathname.new('C:\Path\File.txt').undecorate)
25
- assert_equal('\\foo\bar', Pathname.new('\\foo\bar').undecorate)
24
+ assert_equal('C:\Path\File.txt', Pathname2.new('C:\Path\File.txt').undecorate)
25
+ assert_equal('\\foo\bar', Pathname2.new('\\foo\bar').undecorate)
26
26
  end
27
27
 
28
28
  test "undecorate returns expected result for standard path" do
29
- assert_equal('C:\Path\File', Pathname.new('C:\Path\File[12]').undecorate)
30
- assert_equal('C:\Path\[3].txt', Pathname.new('C:\Path\[3].txt').undecorate)
29
+ assert_equal('C:\Path\File', Pathname2.new('C:\Path\File[12]').undecorate)
30
+ assert_equal('C:\Path\[3].txt', Pathname2.new('C:\Path\[3].txt').undecorate)
31
31
  end
32
32
 
33
33
  test "undecorate returns expected result for UNC path" do
34
- assert_equal('\\foo\bar.txt',Pathname.new('\\foo\bar[5].txt').undecorate)
35
- assert_equal('\\foo\bar', Pathname.new('\\foo\bar[5]').undecorate)
34
+ assert_equal('\\foo\bar.txt',Pathname2.new('\\foo\bar[5].txt').undecorate)
35
+ assert_equal('\\foo\bar', Pathname2.new('\\foo\bar[5]').undecorate)
36
36
  end
37
37
 
38
38
  test "undecorate does not modify the original string" do
39
39
  str = 'C:/Path/File.txt'
40
- assert_nothing_raised{ Pathname.new(str).undecorate }
40
+ assert_nothing_raised{ Pathname2.new(str).undecorate }
41
41
  assert_equal('C:/Path/File.txt', str)
42
42
  end
43
43
 
@@ -1,14 +1,14 @@
1
1
  ########################################################################
2
2
  # test_undecorate_bang.rb
3
3
  #
4
- # Test suite for the Pathname#undecorate! method
4
+ # Test suite for the Pathname2#undecorate! method
5
5
  ########################################################################
6
6
  require 'test-unit'
7
7
  require 'pathname2'
8
8
 
9
- class TC_Pathname_UndecorateBang < Test::Unit::TestCase
9
+ class TC_Pathname2_UndecorateBang < Test::Unit::TestCase
10
10
  def setup
11
- @std = Pathname.new('C:/Path/File.txt')
11
+ @std = Pathname2.new('C:/Path/File.txt')
12
12
  end
13
13
 
14
14
  test "undecorate! basic functionality" do
@@ -16,33 +16,33 @@ class TC_Pathname_UndecorateBang < Test::Unit::TestCase
16
16
  assert_nothing_raised{ @std.undecorate! }
17
17
  end
18
18
 
19
- test "undecorate! returns a Pathname object" do
20
- assert_kind_of(Pathname, @std.undecorate!)
19
+ test "undecorate! returns a Pathname2 object" do
20
+ assert_kind_of(Pathname2, @std.undecorate!)
21
21
  end
22
22
 
23
23
  test "undecorate! method returns an already undecorated path unchanged" do
24
- assert_equal('C:\Path\File.txt', Pathname.new('C:\Path\File.txt').undecorate!)
25
- assert_equal('\\foo\bar', Pathname.new('\\foo\bar').undecorate!)
24
+ assert_equal('C:\Path\File.txt', Pathname2.new('C:\Path\File.txt').undecorate!)
25
+ assert_equal('\\foo\bar', Pathname2.new('\\foo\bar').undecorate!)
26
26
  end
27
27
 
28
28
  test "undecorate! returns expected result for standard path" do
29
- assert_equal('C:\Path\File', Pathname.new('C:\Path\File[12]').undecorate!)
30
- assert_equal('C:\Path\[3].txt', Pathname.new('C:\Path\[3].txt').undecorate!)
29
+ assert_equal('C:\Path\File', Pathname2.new('C:\Path\File[12]').undecorate!)
30
+ assert_equal('C:\Path\[3].txt', Pathname2.new('C:\Path\[3].txt').undecorate!)
31
31
  end
32
32
 
33
33
  test "undecorate! returns expected result for UNC path" do
34
- assert_equal('\\foo\bar.txt',Pathname.new('\\foo\bar[5].txt').undecorate!)
35
- assert_equal('\\foo\bar', Pathname.new('\\foo\bar[5]').undecorate!)
34
+ assert_equal('\\foo\bar.txt',Pathname2.new('\\foo\bar[5].txt').undecorate!)
35
+ assert_equal('\\foo\bar', Pathname2.new('\\foo\bar[5]').undecorate!)
36
36
  end
37
37
 
38
38
  test "undecorate! does not modify the original string" do
39
39
  str = 'C:/Path/File.txt'
40
- assert_nothing_raised{ Pathname.new(str).undecorate }
40
+ assert_nothing_raised{ Pathname2.new(str).undecorate }
41
41
  assert_equal('C:/Path/File.txt', str)
42
42
  end
43
43
 
44
44
  test "undecorate does modify the object itself" do
45
- path = Pathname.new('C:\Path\File[12]')
45
+ path = Pathname2.new('C:\Path\File[12]')
46
46
  assert_nothing_raised{ path.undecorate! }
47
47
  assert_equal('C:\Path\File', path)
48
48
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,11 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pathname2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.4
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain:
11
10
  - |
@@ -35,36 +34,50 @@ cert_chain:
35
34
  ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
36
35
  WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
37
36
  -----END CERTIFICATE-----
38
- date:
37
+ date: 1980-01-02 00:00:00.000000000 Z
39
38
  dependencies:
40
39
  - !ruby/object:Gem::Dependency
41
40
  name: facade
42
41
  requirement: !ruby/object:Gem::Requirement
43
42
  requirements:
44
- - - ">="
43
+ - - "~>"
45
44
  - !ruby/object:Gem::Version
46
- version: '0'
45
+ version: '1.2'
47
46
  type: :runtime
48
47
  prerelease: false
49
48
  version_requirements: !ruby/object:Gem::Requirement
50
49
  requirements:
51
- - - ">="
50
+ - - "~>"
52
51
  - !ruby/object:Gem::Version
53
- version: '0'
52
+ version: '1.2'
53
+ - !ruby/object:Gem::Dependency
54
+ name: addressable
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '2.8'
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '2.8'
54
67
  - !ruby/object:Gem::Dependency
55
68
  name: test-unit
56
69
  requirement: !ruby/object:Gem::Requirement
57
70
  requirements:
58
- - - ">="
71
+ - - "~>"
59
72
  - !ruby/object:Gem::Version
60
- version: '0'
73
+ version: '3.4'
61
74
  type: :development
62
75
  prerelease: false
63
76
  version_requirements: !ruby/object:Gem::Requirement
64
77
  requirements:
65
- - - ">="
78
+ - - "~>"
66
79
  - !ruby/object:Gem::Version
67
- version: '0'
80
+ version: '3.4'
68
81
  - !ruby/object:Gem::Dependency
69
82
  name: rake
70
83
  requirement: !ruby/object:Gem::Requirement
@@ -92,65 +105,61 @@ executables: []
92
105
  extensions: []
93
106
  extra_rdoc_files: []
94
107
  files:
108
+ - CHANGES.md
109
+ - Gemfile
95
110
  - LICENSE
96
- - test
97
- - test/test_pathname.rb
98
- - test/windows
99
- - test/windows/test_long_path.rb
100
- - test/windows/test_short_path.rb
101
- - test/windows/test_parent.rb
102
- - test/windows/test_root.rb
103
- - test/windows/test_undecorate_bang.rb
111
+ - MANIFEST.md
112
+ - README.md
113
+ - Rakefile
114
+ - benchmarks/bench_pathname2.rb
115
+ - benchmarks/bench_plus.rb
116
+ - certs/djberg96_pub.pem
117
+ - examples/example_pathname2.rb
118
+ - lib/pathname2.rb
119
+ - pathname2.gemspec
120
+ - test/test_pathname2.rb
121
+ - test/test_version.rb
122
+ - test/windows/test_append.rb
123
+ - test/windows/test_aref.rb
124
+ - test/windows/test_ascend.rb
125
+ - test/windows/test_children.rb
104
126
  - test/windows/test_clean.rb
105
127
  - test/windows/test_clean_bang.rb
106
- - test/windows/test_pstrip_bang.rb
128
+ - test/windows/test_constructor.rb
129
+ - test/windows/test_descend.rb
130
+ - test/windows/test_drive_number.rb
131
+ - test/windows/test_each.rb
107
132
  - test/windows/test_facade.rb
108
133
  - test/windows/test_is_absolute.rb
109
- - test/windows/test_realpath.rb
110
- - test/windows/test_children.rb
111
- - test/windows/test_pstrip.rb
112
- - test/windows/test_relative_path_from.rb
113
- - test/windows/test_constructor.rb
114
- - test/windows/test_join.rb
115
134
  - test/windows/test_is_relative.rb
116
135
  - test/windows/test_is_root.rb
117
- - test/windows/test_append.rb
118
136
  - test/windows/test_is_unc.rb
119
- - test/windows/test_aref.rb
137
+ - test/windows/test_join.rb
138
+ - test/windows/test_long_path.rb
120
139
  - test/windows/test_misc.rb
121
- - test/windows/test_ascend.rb
122
- - test/windows/test_each.rb
123
- - test/windows/test_descend.rb
124
- - test/windows/test_undecorate.rb
125
- - test/windows/test_drive_number.rb
140
+ - test/windows/test_parent.rb
141
+ - test/windows/test_pstrip.rb
142
+ - test/windows/test_pstrip_bang.rb
143
+ - test/windows/test_realpath.rb
144
+ - test/windows/test_relative_path_from.rb
145
+ - test/windows/test_root.rb
146
+ - test/windows/test_short_path.rb
126
147
  - test/windows/test_to_a.rb
127
- - test/test_version.rb
128
- - pathname2.gemspec
129
- - README.md
130
- - Rakefile
131
- - MANIFEST.md
132
- - certs
133
- - certs/djberg96_pub.pem
134
- - examples
135
- - examples/example_pathname.rb
136
- - benchmarks
137
- - benchmarks/bench_pathname.rb
138
- - benchmarks/bench_plus.rb
139
- - lib
140
- - lib/pathname2.rb
141
- - Gemfile
142
- - CHANGES.md
148
+ - test/windows/test_undecorate.rb
149
+ - test/windows/test_undecorate_bang.rb
143
150
  homepage: https://github.com/djberg96/pathname2
144
151
  licenses:
145
152
  - Apache-2.0
146
153
  metadata:
147
154
  homepage_uri: https://github.com/djberg96/pathname2
148
155
  bug_tracker_uri: https://github.com/djberg96/pathname2/issues
149
- changelog_uri: https://github.com/djberg96/pathname2/blob/ffi/CHANGES.md
156
+ changelog_uri: https://github.com/djberg96/pathname2/blob/main/CHANGES.md
150
157
  documentation_uri: https://github.com/djberg96/pathname2/wiki
151
158
  source_code_uri: https://github.com/djberg96/pathname2
152
159
  wiki_uri: https://github.com/djberg96/pathname2/wiki
153
- post_install_message:
160
+ rubygems_mfa_required: 'true'
161
+ github_repo: https://github.com/djberg96/pathname2
162
+ funding_uri: https://github.com/sponsors/djberg96
154
163
  rdoc_options: []
155
164
  require_paths:
156
165
  - lib
@@ -165,10 +174,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
174
  - !ruby/object:Gem::Version
166
175
  version: '0'
167
176
  requirements: []
168
- rubygems_version: 3.0.3
169
- signing_key:
177
+ rubygems_version: 3.6.9
170
178
  specification_version: 4
171
179
  summary: An alternate implementation of the Pathname class
172
180
  test_files:
173
- - test/test_pathname.rb
174
181
  - test/test_version.rb
metadata.gz.sig CHANGED
Binary file
@@ -1,127 +0,0 @@
1
- #####################################################################
2
- # bench_pathname.rb
3
- #
4
- # Benchmark suite for all methods of the Pathname class, excluding
5
- # the facade methods.
6
- #
7
- # Use the Rake tasks to run this benchmark:
8
- #
9
- # => rake benchmark to run the pure Ruby benchmark.
10
- #####################################################################
11
- require 'benchmark'
12
- require 'pathname2'
13
- require 'rbconfig'
14
-
15
- if RbConfig::CONFIG['host_os'] =~ /mingw|mswin/i
16
- path1 = Pathname.new("C:\\Program Files\\Windows NT")
17
- path2 = Pathname.new("Accessories")
18
- path3 = Pathname.new("C:\\Program Files\\..\\.\\Windows NT")
19
- else
20
- path1 = Pathname.new("/usr/local")
21
- path2 = Pathname.new("bin")
22
- path3 = Pathname.new("/usr/../local/./bin")
23
- path4 = Pathname.new("/dev/stdin")
24
- end
25
-
26
- MAX = 10000
27
-
28
- Benchmark.bm(25) do |bench|
29
- bench.report("Pathname.new(path)"){
30
- MAX.times{ Pathname.new("/usr/local/bin") }
31
- }
32
-
33
- bench.report("Pathname#+(Pathname)"){
34
- MAX.times{ path1 + path2 }
35
- }
36
-
37
- bench.report("Pathname#+(String)"){
38
- MAX.times{ path1 + path2 }
39
- }
40
-
41
- bench.report("Pathname#children"){
42
- MAX.times{ path1.children }
43
- }
44
-
45
- bench.report("Pathname#pstrip"){
46
- MAX.times{ path1.pstrip }
47
- }
48
-
49
- bench.report("Pathname#pstrip!"){
50
- MAX.times{ path1.pstrip! }
51
- }
52
-
53
- bench.report("Pathname#to_a"){
54
- MAX.times{ path1.to_a }
55
- }
56
-
57
- bench.report("Pathname#descend"){
58
- MAX.times{ path1.descend{} }
59
- }
60
-
61
- bench.report("Pathname#ascend"){
62
- MAX.times{ path1.ascend{} }
63
- }
64
-
65
- bench.report("Pathname#root"){
66
- MAX.times{ path1.root }
67
- }
68
-
69
- bench.report("Pathname#root?"){
70
- MAX.times{ path1.root? }
71
- }
72
-
73
- bench.report("Pathname#<=>"){
74
- MAX.times{ path1 <=> path2 }
75
- }
76
-
77
- bench.report("Pathname#absolute?"){
78
- MAX.times{ path1.absolute? }
79
- }
80
-
81
- bench.report("Pathname#relative?"){
82
- MAX.times{ path1.relative? }
83
- }
84
-
85
- bench.report("Pathname#clean"){
86
- MAX.times{ path3.clean }
87
- }
88
-
89
- bench.report("Pathname#clean!"){
90
- MAX.times{ path3.clean! }
91
- }
92
-
93
- # Platform specific tests
94
- if RbConfig::CONFIG['host_os'] =~ /mingw|mswin/i
95
- bench.report("Pathname.new(file_url)"){
96
- MAX.times{ Pathname.new("file:///C:/usr/local/bin") }
97
- }
98
-
99
- bench.report("Pathname#drive_number"){
100
- MAX.times{ path1.drive_number }
101
- }
102
-
103
- bench.report("Pathname#unc?"){
104
- MAX.times{ path1.unc? }
105
- }
106
-
107
- bench.report("Pathname#undecorate"){
108
- MAX.times{ path1.undecorate }
109
- }
110
-
111
- bench.report("Pathname#undecorate!"){
112
- MAX.times{ path1.undecorate! }
113
- }
114
-
115
- bench.report("Pathname#short_path"){
116
- MAX.times{ path1.short_path }
117
- }
118
-
119
- bench.report("Pathname#long_path"){
120
- MAX.times{ path1.long_path }
121
- }
122
- else
123
- bench.report("Pathname#realpath"){
124
- MAX.times{ path4.realpath }
125
- }
126
- end
127
- end