pathname2 1.8.2

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 (46) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +5 -0
  4. data/CHANGES +171 -0
  5. data/LICENSE +177 -0
  6. data/MANIFEST +40 -0
  7. data/README +97 -0
  8. data/Rakefile +222 -0
  9. data/benchmarks/bench_pathname.rb +127 -0
  10. data/benchmarks/bench_plus.rb +34 -0
  11. data/certs/djberg96_pub.pem +26 -0
  12. data/examples/example_pathname.rb +25 -0
  13. data/lib/pathname2.rb +1140 -0
  14. data/pathname2.gemspec +46 -0
  15. data/test/test_pathname.rb +486 -0
  16. data/test/test_version.rb +17 -0
  17. data/test/windows/test_append.rb +59 -0
  18. data/test/windows/test_aref.rb +37 -0
  19. data/test/windows/test_ascend.rb +51 -0
  20. data/test/windows/test_children.rb +42 -0
  21. data/test/windows/test_clean.rb +50 -0
  22. data/test/windows/test_clean_bang.rb +50 -0
  23. data/test/windows/test_constructor.rb +48 -0
  24. data/test/windows/test_descend.rb +51 -0
  25. data/test/windows/test_drive_number.rb +58 -0
  26. data/test/windows/test_each.rb +28 -0
  27. data/test/windows/test_facade.rb +64 -0
  28. data/test/windows/test_is_absolute.rb +47 -0
  29. data/test/windows/test_is_relative.rb +46 -0
  30. data/test/windows/test_is_root.rb +44 -0
  31. data/test/windows/test_is_unc.rb +51 -0
  32. data/test/windows/test_join.rb +52 -0
  33. data/test/windows/test_long_path.rb +41 -0
  34. data/test/windows/test_misc.rb +33 -0
  35. data/test/windows/test_parent.rb +37 -0
  36. data/test/windows/test_pstrip.rb +42 -0
  37. data/test/windows/test_pstrip_bang.rb +46 -0
  38. data/test/windows/test_realpath.rb +39 -0
  39. data/test/windows/test_relative_path_from.rb +60 -0
  40. data/test/windows/test_root.rb +59 -0
  41. data/test/windows/test_short_path.rb +41 -0
  42. data/test/windows/test_to_a.rb +46 -0
  43. data/test/windows/test_undecorate.rb +47 -0
  44. data/test/windows/test_undecorate_bang.rb +53 -0
  45. metadata +176 -0
  46. metadata.gz.sig +1 -0
@@ -0,0 +1,28 @@
1
+ ########################################################################
2
+ # test_each.rb
3
+ #
4
+ # Test suite for the Pathname#each method.
5
+ ########################################################################
6
+ require 'pathname2'
7
+ require 'test-unit'
8
+
9
+ class TC_Pathname_Each < Test::Unit::TestCase
10
+ def setup
11
+ @path = Pathname.new("C:/Users/foo/bar")
12
+ end
13
+
14
+ test "each basic functionality" do
15
+ assert_respond_to(@path, :each)
16
+ assert_nothing_raised{ @path.each{} }
17
+ end
18
+
19
+ test "each returns the expected results" do
20
+ arr = []
21
+ @path.each{ |e| arr << e }
22
+ assert_equal(['C:', 'Users', 'foo', 'bar'], arr)
23
+ end
24
+
25
+ def teardown
26
+ @path = nil
27
+ end
28
+ end
@@ -0,0 +1,64 @@
1
+ ########################################################################
2
+ # test_facade.rb
3
+ #
4
+ # Test suite for the various facade methods.
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'pathname2'
8
+
9
+ class TC_Pathname_Facade < Test::Unit::TestCase
10
+ def setup
11
+ @path = Pathname.new("C:/Program Files")
12
+ end
13
+
14
+ test "file facade methods are defined" do
15
+ File.methods(false).each{ |m| assert_respond_to(@path, m.to_sym) }
16
+ end
17
+
18
+ test "dir facade methods are defined" do
19
+ Dir.methods(false).each{ |m| assert_respond_to(@path, m.to_sym) }
20
+ end
21
+
22
+ test "fileutils facade methods are defined" do
23
+ methods = FileUtils.public_instance_methods
24
+ methods -= File.methods(false)
25
+ methods -= Dir.methods(false)
26
+
27
+ # Ruby 1.9.x and 2.0 incorrectly made some of these methods public
28
+ methods.delete_if{ |m|
29
+ m =~ /stream|^ln|identical\?|mode_to_s|^sh|ruby|safe_ln|split_all/i
30
+ }
31
+
32
+ methods.each{ |method|
33
+ assert_respond_to(@path, method.to_sym)
34
+ }
35
+ end
36
+
37
+ test "find facade works as expected" do
38
+ assert_respond_to(@path, :find)
39
+ assert_nothing_raised{ @path.find{} }
40
+
41
+ Pathname.new(Dir.pwd).find{ |f|
42
+ Find.prune if f.match("git")
43
+ assert_kind_of(Pathname, f)
44
+ }
45
+ end
46
+
47
+ test "custom io methods are defined" do
48
+ assert_respond_to(@path, :foreach)
49
+ assert_respond_to(@path, :read)
50
+ assert_respond_to(@path, :readlines)
51
+ assert_respond_to(@path, :sysopen)
52
+ end
53
+
54
+ test "exist? facade works as expected" do
55
+ assert_respond_to(@path, :exist?)
56
+ assert_nothing_raised{ @path.exist? }
57
+ assert_true(Pathname.new("C:\\").exist?)
58
+ assert_false(Pathname.new("X:\\foo\\bar\\baz").exist?)
59
+ end
60
+
61
+ def teardown
62
+ @path = nil
63
+ end
64
+ end
@@ -0,0 +1,47 @@
1
+ ########################################################################
2
+ # test_is_absolute.rb
3
+ #
4
+ # Test suite for the Pathname#absolute method
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'pathname2'
8
+
9
+ class TC_Pathname_IsAbsolute < Test::Unit::TestCase
10
+ def setup
11
+ @abs_std = Pathname.new("C:/foo/bar/baz")
12
+ @abs_unc = Pathname.new("//foo/bar/baz")
13
+ end
14
+
15
+ test "absolute? basic functionality" do
16
+ assert_respond_to(@abs_std, :absolute?)
17
+ assert_nothing_raised{ @abs_std.absolute? }
18
+ assert_boolean(@abs_std.absolute?)
19
+ end
20
+
21
+ test "absolute? method returns true for absolute paths" do
22
+ assert_true(@abs_std.absolute?)
23
+ assert_true(@abs_unc.absolute?)
24
+ end
25
+
26
+ test "absolute? method returns false for non-absolute paths" do
27
+ assert_false(Pathname.new("foo").absolute?)
28
+ assert_false(Pathname.new("foo/bar").absolute?)
29
+ end
30
+
31
+ test "absolute? method returns false for empty path" do
32
+ assert_false(Pathname.new("").absolute?)
33
+ end
34
+
35
+ test "absolute? method is not destructive" do
36
+ str = 'C:/foo'
37
+ path = Pathname.new(str)
38
+ assert_nothing_raised{ path.absolute? }
39
+ assert_equal('C:\foo', path.to_s)
40
+ assert_equal('C:/foo', str)
41
+ end
42
+
43
+ def teardown
44
+ @std_absolute = nil
45
+ @unc_absolute = nil
46
+ end
47
+ end
@@ -0,0 +1,46 @@
1
+ ########################################################################
2
+ # test_is_relative.rb
3
+ #
4
+ # Test suite for the Pathname#relative method
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'pathname2'
8
+
9
+ class TC_Pathname_IsRelative < Test::Unit::TestCase
10
+ def setup
11
+ @relative = Pathname.new("foo/bar")
12
+ @absolute = Pathname.new("C:/foo/bar")
13
+ end
14
+
15
+ test "relative? basic functionality" do
16
+ assert_respond_to(@relative, :relative?)
17
+ assert_nothing_raised{ @relative.relative? }
18
+ assert_boolean(@relative.relative?)
19
+ end
20
+
21
+ test "relative? method returns true for relative paths" do
22
+ assert_true(@relative.relative?)
23
+ end
24
+
25
+ test "relative? method returns false for non-relative paths" do
26
+ assert_false(@absolute.relative?)
27
+ assert_false(Pathname.new("//foo/bar").relative?)
28
+ end
29
+
30
+ test "relative? method returns true for empty path" do
31
+ assert_true(Pathname.new("").relative?)
32
+ end
33
+
34
+ test "relative? method is not destructive" do
35
+ str = 'C:/foo'
36
+ path = Pathname.new(str)
37
+ assert_nothing_raised{ path.relative? }
38
+ assert_equal('C:\foo', path.to_s)
39
+ assert_equal('C:/foo', str)
40
+ end
41
+
42
+ def teardown
43
+ @std_relative = nil
44
+ @unc_relative = nil
45
+ end
46
+ end
@@ -0,0 +1,44 @@
1
+ ########################################################################
2
+ # test_is_root.rb
3
+ #
4
+ # Test suite for the Pathname#root method
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'pathname2'
8
+
9
+ class TC_Pathname_IsRoot < Test::Unit::TestCase
10
+ def setup
11
+ @std_root = Pathname.new("C:\\")
12
+ @unc_root = Pathname.new("\\\\foo\\bar")
13
+ end
14
+
15
+ test "root? basic functionality" do
16
+ assert_respond_to(@std_root, :root?)
17
+ assert_nothing_raised{ @std_root.root? }
18
+ assert_boolean(@std_root.root?)
19
+ end
20
+
21
+ test "root? method returns true for root paths" do
22
+ assert_true(@std_root.root?)
23
+ assert_true(@unc_root.root?)
24
+ end
25
+
26
+ test "root? method returns false for non-root paths" do
27
+ assert_false(Pathname.new("C:/foo").root?)
28
+ assert_false(Pathname.new("//foo/bar/baz").root?)
29
+ assert_false(Pathname.new("").root?)
30
+ end
31
+
32
+ test "root? method is not destructive" do
33
+ str = 'C:/foo'
34
+ path = Pathname.new(str)
35
+ assert_nothing_raised{ path.root }
36
+ assert_equal('C:\foo', path.to_s)
37
+ assert_equal('C:/foo', str)
38
+ end
39
+
40
+ def teardown
41
+ @std_root = nil
42
+ @unc_root = nil
43
+ end
44
+ end
@@ -0,0 +1,51 @@
1
+ ########################################################################
2
+ # test_is_unc.rb
3
+ #
4
+ # Test suite for the Pathname#unc? method
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'pathname2'
8
+
9
+ class TC_Pathname_IsUNC < Test::Unit::TestCase
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")
14
+ end
15
+
16
+ test "unc? basic functionality" do
17
+ assert_respond_to(@unc_path, :unc?)
18
+ assert_nothing_raised{ @unc_path.unc? }
19
+ assert_boolean(@unc_path.unc?)
20
+ end
21
+
22
+ test "unc? method returns false for non-unc paths" do
23
+ assert_false(Pathname.new("C:\\").unc?)
24
+ assert_false(Pathname.new("C:\\Program Files").unc?)
25
+ assert_false(Pathname.new("C:\\\\Program Files").unc?)
26
+ assert_false(Pathname.new("C:/Program Files/File.txt").unc?)
27
+ assert_false(Pathname.new("C:\\Program Files\\File[12].txt").unc?)
28
+ assert_false(Pathname.new("foo\\bar").unc?)
29
+ assert_false(Pathname.new(".").unc?)
30
+ end
31
+
32
+ test "unc? method returns true for unc paths" do
33
+ assert_true(Pathname.new("\\\\foo\\bar").unc?)
34
+ assert_true(Pathname.new("//foo/bar").unc?)
35
+ assert_true(Pathname.new("\\\\foo\\bar\\baz").unc?)
36
+ assert_true(Pathname.new("\\\\foo").unc?)
37
+ assert_true(Pathname.new("\\\\").unc?)
38
+ end
39
+
40
+ test "unc? method is not destructive" do
41
+ str = '//foo/bar'
42
+ assert_nothing_raised{ Pathname.new(str).unc? }
43
+ assert_equal('//foo/bar', str)
44
+ end
45
+
46
+ def teardown
47
+ @abs_path = nil
48
+ @unc_path = nil
49
+ @rel_path = nil
50
+ end
51
+ end
@@ -0,0 +1,52 @@
1
+ ########################################################################
2
+ # test_join.rb
3
+ #
4
+ # Test suite for the Pathname#join method.
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'pathname2'
8
+
9
+ class TC_Pathname_Join < Test::Unit::TestCase
10
+ def setup
11
+ @apath = Pathname.new("C:\\foo\\bar")
12
+ @rpath = Pathname.new("foo\\bar\\baz")
13
+ end
14
+
15
+ def assert_pathname_join(final, initial, *rest)
16
+ a = Pathname.new(final)
17
+ b = Pathname.new(initial)
18
+ assert_equal(a, b.join(*rest))
19
+ end
20
+
21
+ test "join method accepts one or more arguments" do
22
+ assert_nothing_raised{ @apath.join("foo") }
23
+ assert_nothing_raised{ @apath.join("foo", "bar") }
24
+ assert_nothing_raised{ @apath.join("foo", "bar", "baz") }
25
+ end
26
+
27
+ test "join method returns expected results when joining relative paths to an absolute path" do
28
+ assert_pathname_join("C:\\foo", "C:\\", "foo")
29
+ assert_pathname_join("C:\\foo\\bar", "C:\\foo", "bar")
30
+ assert_pathname_join("C:\\foo\\bar\\baz", "C:\\foo", "bar", "baz")
31
+ end
32
+
33
+ test "join method returns expected results when joining relative paths to a relative path" do
34
+ assert_pathname_join("foo\\bar", "foo", "bar")
35
+ assert_pathname_join("foo\\bar\\baz", "foo", "bar", "baz")
36
+ end
37
+
38
+ test "join method returns expected results when joining an absolute path to an absolute path" do
39
+ assert_pathname_join("D:\\", "C:\\", "D:\\")
40
+ assert_pathname_join("D:\\foo", "C:\\", "D:\\", "foo")
41
+ assert_pathname_join("D:\\", "C:\\", "foo", "bar", "D:\\")
42
+ end
43
+
44
+ test "join returns an instance of Pathname" do
45
+ assert_kind_of(Pathname, @apath.join("foo"))
46
+ end
47
+
48
+ def teardown
49
+ @apath = nil
50
+ @rpath = nil
51
+ end
52
+ end
@@ -0,0 +1,41 @@
1
+ ########################################################################
2
+ # test_long_path.rb
3
+ #
4
+ # Test suite for the Pathname#long_path method
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'pathname2'
8
+
9
+ class TC_Pathname_LongPath < Test::Unit::TestCase
10
+ def setup
11
+ @abs_path = Pathname.new("C:\\PROGRA~1")
12
+ end
13
+
14
+ test "long_path basic functionality" do
15
+ assert_respond_to(@abs_path, :long_path)
16
+ assert_nothing_raised{ @abs_path.long_path }
17
+ assert_kind_of(String, @abs_path.long_path)
18
+ end
19
+
20
+ test "long_path returns the expected result" do
21
+ assert_equal("C:\\Program Files", @abs_path.long_path)
22
+ end
23
+
24
+ test "long_path returns the same string if it's already long" do
25
+ assert_equal("C:\\Program Files", Pathname.new("C:/Program Files").long_path)
26
+ end
27
+
28
+ test "long_path fails if the path does not exist" do
29
+ assert_raise(Errno::ESRCH){ Pathname.new("C:/Bogus/AlsoBogus").long_path }
30
+ end
31
+
32
+ test "long_path method is not destructive" do
33
+ str = 'C:/Program Files'
34
+ assert_nothing_raised{ Pathname.new(str).long_path }
35
+ assert_equal('C:/Program Files', str)
36
+ end
37
+
38
+ def teardown
39
+ @abs_path = nil
40
+ end
41
+ end
@@ -0,0 +1,33 @@
1
+ ########################################################################
2
+ # test_misc.rb
3
+ #
4
+ # Test suite for miscellaneous items that didn't warrant their own
5
+ # test file.
6
+ ########################################################################
7
+ require 'pathname2'
8
+ require 'test-unit'
9
+
10
+ class MyPathname < Pathname; end
11
+
12
+ class TC_Pathname_Misc < Test::Unit::TestCase
13
+ def setup
14
+ @mypath = MyPathname.new(Dir.pwd)
15
+ end
16
+
17
+ test "subclasses return instances of that subclass" do
18
+ assert_kind_of(MyPathname, @mypath)
19
+ assert_kind_of(MyPathname, @mypath + MyPathname.new('foo'))
20
+ assert_kind_of(MyPathname, @mypath.realpath)
21
+ end
22
+
23
+ test "custom pn method works as expected" do
24
+ assert_respond_to(Kernel, :pn)
25
+ assert_nothing_raised{ pn{'c:\foo'} }
26
+ assert_kind_of(Pathname, pn{'c:\foo'})
27
+ assert_equal('c:\foo', pn{'c:\foo'})
28
+ end
29
+
30
+ def teardown
31
+ @mypath = nil
32
+ end
33
+ end
@@ -0,0 +1,37 @@
1
+ ########################################################################
2
+ # test_parent.rb
3
+ #
4
+ # Test suite for the Pathname#parent method.
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'pathname2'
8
+
9
+ class TC_Pathname_Parent < Test::Unit::TestCase
10
+ def setup
11
+ @path = Pathname.new("C:\\foo\\bar\\baz")
12
+ end
13
+
14
+ test "parent basic functionality" do
15
+ assert_respond_to(@path, :parent)
16
+ assert_nothing_raised{ @path.parent }
17
+ assert_kind_of(Pathname, @path.parent)
18
+ end
19
+
20
+ test "parent returns expected results for an absolute path" do
21
+ assert_equal("C:\\foo\\bar", Pathname.new("C:\\foo\\bar\\baz").parent)
22
+ assert_equal("C:\\", Pathname.new("C:\\foo").parent)
23
+ end
24
+
25
+ test "parent returns expected results for a relative path" do
26
+ assert_equal("foo", Pathname.new("foo\\bar").parent)
27
+ end
28
+
29
+ test "parent method returns root if already a root path" do
30
+ assert_equal("C:\\", Pathname.new("C:\\").parent)
31
+ assert_equal("\\\\foo\\bar", Pathname.new("//foo/bar").parent)
32
+ end
33
+
34
+ def teardown
35
+ @path = nil
36
+ end
37
+ end