pathname2 1.6.5-universal-mingw32 → 1.7.1-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -0,0 +1,42 @@
1
+ ########################################################################
2
+ # test_pstrip.rb
3
+ #
4
+ # Test suite for the Pathname#pstrip method
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'pathname2'
8
+
9
+ class TC_Pathname_Pstrip < Test::Unit::TestCase
10
+ def setup
11
+ @path = Pathname.new("C:/Program Files////")
12
+ end
13
+
14
+ test "pstrip basic functionality" do
15
+ assert_respond_to(@path, :pstrip)
16
+ assert_nothing_raised{ @path.pstrip }
17
+ assert_kind_of(Pathname, @path.pstrip)
18
+ end
19
+
20
+ test "pstrip returns expected result for path with trailing slashes" do
21
+ assert_equal("C:\\Program Files", @path.pstrip)
22
+ assert_equal("C:\\Program Files", Pathname.new("C:\\Program Files\\\\").pstrip)
23
+ assert_equal("C:\\Program Files", Pathname.new("C:\\Program Files//\\").pstrip)
24
+ end
25
+
26
+ test "pstrip returns the path as is if it does not contain a trailing slash" do
27
+ assert_equal("C:\\Program Files", Pathname.new("C:\\Program Files").pstrip)
28
+ assert_equal("", Pathname.new("").pstrip)
29
+ end
30
+
31
+ test "pstrip method is not destructive" do
32
+ str = 'C:/Program Files////'
33
+ assert_nothing_raised{ Pathname.new(str).pstrip }
34
+ assert_equal('C:/Program Files////', str)
35
+ end
36
+
37
+ def teardown
38
+ @abs_path = nil
39
+ @unc_path = nil
40
+ @rel_path = nil
41
+ end
42
+ end
@@ -0,0 +1,46 @@
1
+ ########################################################################
2
+ # test_pstrip_bang.rb
3
+ #
4
+ # Test suite for the Pathname#pstrip! method
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'pathname2'
8
+
9
+ class TC_Pathname_PstripBang < Test::Unit::TestCase
10
+ def setup
11
+ @path = Pathname.new("C:/Program Files////")
12
+ end
13
+
14
+ test "pstrip! basic functionality" do
15
+ assert_respond_to(@path, :pstrip!)
16
+ assert_nothing_raised{ @path.pstrip! }
17
+ assert_kind_of(Pathname, @path.pstrip!)
18
+ end
19
+
20
+ test "pstrip! returns expected result for path with trailing slashes" do
21
+ assert_equal("C:\\Program Files", @path.pstrip!)
22
+ assert_equal("C:\\Program Files", Pathname.new("C:\\Program Files\\\\").pstrip!)
23
+ assert_equal("C:\\Program Files", Pathname.new("C:\\Program Files//\\").pstrip!)
24
+ end
25
+
26
+ test "pstrip! returns the path as is if it does not contain a trailing slash" do
27
+ assert_equal("C:\\Program Files", Pathname.new("C:\\Program Files").pstrip!)
28
+ assert_equal("", Pathname.new("").pstrip!)
29
+ end
30
+
31
+ test "pstrip! alters pathname object" do
32
+ path = Pathname.new('C:/Program Files////')
33
+ assert_nothing_raised{ path.pstrip! }
34
+ assert_equal('C:\Program Files', path.to_s)
35
+ end
36
+
37
+ test "pstrip! method does not modify original constructor argument" do
38
+ str = 'C:/Program Files////'
39
+ assert_nothing_raised{ Pathname.new(str).pstrip! }
40
+ assert_equal('C:/Program Files////', str)
41
+ end
42
+
43
+ def teardown
44
+ @path = nil
45
+ end
46
+ end
@@ -0,0 +1,39 @@
1
+ ########################################################################
2
+ # test_realpath.rb
3
+ #
4
+ # Test suite for the Pathname#realpath method
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'pathname2'
8
+
9
+ class TC_Pathname_Realpath < Test::Unit::TestCase
10
+ def setup
11
+ @cwd = Dir.pwd.tr('/', "\\")
12
+ @path = Pathname.new(Dir.pwd)
13
+ end
14
+
15
+ test "realpath basic functionality" do
16
+ assert_respond_to(@path, :realpath)
17
+ assert_nothing_raised{ @path.realpath }
18
+ assert_kind_of(String, @path.realpath)
19
+ end
20
+
21
+ test "realpath returns the expected result" do
22
+ assert_equal(@cwd, @path.realpath)
23
+ end
24
+
25
+ test "realpath fails if the path does not exist" do
26
+ assert_raise(Errno::ENOENT){ Pathname.new("C:/Bogus/AlsoBogus").realpath }
27
+ end
28
+
29
+ test "realpath method is not destructive" do
30
+ str = 'C:/Program Files'
31
+ assert_nothing_raised{ Pathname.new(str).realpath }
32
+ assert_equal('C:/Program Files', str)
33
+ end
34
+
35
+ def teardown
36
+ @cwd = nil
37
+ @path = nil
38
+ end
39
+ end
@@ -0,0 +1,60 @@
1
+ ########################################################################
2
+ # test_relative_path_from.rb
3
+ #
4
+ # Test suite for the Pathname#relative_path_from method.
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'pathname2'
8
+
9
+ class TC_Pathname_RelativePathFrom < Test::Unit::TestCase
10
+ def assert_relpath(result, dest, base)
11
+ assert_equal(result, Pathname.new(dest).relative_path_from(base))
12
+ end
13
+
14
+ def assert_relative_path_error(to, from)
15
+ assert_raise(ArgumentError){ Pathname.new(to).relative_path_from(from) }
16
+ end
17
+
18
+ test "relative_path_from works as expected between two relative paths" do
19
+ assert_relpath("..\\a", 'a', 'b')
20
+ assert_relpath("..\\a", 'a', 'b/')
21
+ assert_relpath("..\\a", 'a/', 'b')
22
+ assert_relpath("..\\a", 'a/', 'b/')
23
+ assert_relpath("..\\b", "a\\b", "a\\c")
24
+ assert_relpath("..\\a", "..\\a", "..\\b")
25
+ assert_relpath("..\\b\\c", "a\\b\\c", "a\\d")
26
+ assert_relpath("..", "a\\..", "a")
27
+ assert_relpath(".", "a\\..\\b", "b")
28
+ assert_relpath("a", "a", "b\\..")
29
+ assert_relpath("b\\c", "b\\c", "b\\..")
30
+ end
31
+
32
+ test "relative_path_from works as expected between two absolute paths" do
33
+ assert_relpath("..\\a", "c:\\a", "c:\\b")
34
+ assert_relpath("..\\a", "c:\\a", "c:\\b\\")
35
+ assert_relpath("..\\a", "c:\\a\\", "c:\\b")
36
+ assert_relpath("..\\a", "c:\\a\\", "c:\\b\\")
37
+ assert_relpath("c\\d", "c:\\a\\b\\c\\d", "c:\\a\\b")
38
+ assert_relpath("..\\..", "c:\\a\\b", "c:\\a\\b\\c\\d")
39
+ assert_relpath("..\\..\\..\\..\\e", "c:\\e", "c:\\a\\b\\c\\d")
40
+ assert_relpath("..\\a", "c:\\..\\a", "c:\\b")
41
+ assert_relpath(".", "c:\\a\\..\\..\\b", "c:\\b")
42
+ end
43
+
44
+ test "relative_path_from works as expected between for . and .." do
45
+ assert_relpath("a", "a", ".")
46
+ assert_relpath("..", ".", "a")
47
+ assert_relpath(".", ".", ".")
48
+ assert_relpath(".", "..", "..")
49
+ assert_relpath("..", "..", ".")
50
+ end
51
+
52
+ test "relative_path_from is not allowed between relative and absolute paths" do
53
+ assert_relative_path_error("c:\\", ".")
54
+ assert_relative_path_error(".", "c:\\")
55
+ assert_relative_path_error("a", "..")
56
+ assert_relative_path_error(".", "..")
57
+ assert_relative_path_error("C:\\Temp", "D:\\Temp")
58
+ assert_relative_path_error("\\\\Server\\Temp", "D:\\Temp")
59
+ end
60
+ end
@@ -0,0 +1,59 @@
1
+ ########################################################################
2
+ # test_root.rb
3
+ #
4
+ # Test suite for the Pathname#root method
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'pathname2'
8
+
9
+ class TC_Pathname_Root < 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 "root method returns expected results for absolute paths" do
17
+ assert_equal("C:\\", @abs_path.root)
18
+ end
19
+
20
+ test "root method returns expected results for paths with forward slashes" do
21
+ assert_equal("C:\\", Pathname.new("C:/Program Files").root)
22
+ end
23
+
24
+ test "root method returns expected results for unc paths" do
25
+ assert_equal("\\\\foo\\bar", @unc_path.root)
26
+ assert_equal("\\\\foo", Pathname.new("\\\\foo").root)
27
+ assert_equal("\\\\", Pathname.new("\\\\").root)
28
+ end
29
+
30
+ test "root method returns dot for relative paths" do
31
+ assert_equal('.', @rel_path.root)
32
+ end
33
+
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)
37
+ end
38
+
39
+ test "root method returns expected result for empty string" do
40
+ assert_equal(".", Pathname.new("").root)
41
+ end
42
+
43
+ test "root method returns expected result for dot and dotdot" do
44
+ assert_equal(".", Pathname.new("..").root)
45
+ assert_equal(".", Pathname.new(".").root)
46
+ end
47
+
48
+ test "root method is not destructive" do
49
+ str = 'C:/Program Files'
50
+ assert_nothing_raised{ Pathname.new(str).root }
51
+ assert_equal('C:/Program Files', str)
52
+ end
53
+
54
+ def teardown
55
+ @abs_path = nil
56
+ @unc_path = nil
57
+ @rel_path = nil
58
+ end
59
+ end
@@ -0,0 +1,41 @@
1
+ ########################################################################
2
+ # test_short_path.rb
3
+ #
4
+ # Test suite for the Pathname#short_path method
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'pathname2'
8
+
9
+ class TC_Pathname_ShortPath < Test::Unit::TestCase
10
+ def setup
11
+ @abs_path = Pathname.new("C:\\Program Files")
12
+ end
13
+
14
+ test "short_path basic functionality" do
15
+ assert_respond_to(@abs_path, :short_path)
16
+ assert_nothing_raised{ @abs_path.short_path }
17
+ assert_kind_of(String, @abs_path.short_path)
18
+ end
19
+
20
+ test "short_path returns the expected result" do
21
+ assert_equal("C:\\PROGRA~1", @abs_path.short_path)
22
+ end
23
+
24
+ test "short_path returns the same string if it's already short" do
25
+ assert_equal("C:\\", Pathname.new("C:/").short_path)
26
+ end
27
+
28
+ test "short_path fails if the path does not exist" do
29
+ assert_raise(Errno::ESRCH){ Pathname.new("C:/Bogus/AlsoBogus").short_path }
30
+ end
31
+
32
+ test "short_path method is not destructive" do
33
+ str = 'C:/Program Files'
34
+ assert_nothing_raised{ Pathname.new(str).short_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,46 @@
1
+ ########################################################################
2
+ # test_to_a.rb
3
+ #
4
+ # Test suite for the Pathname#to_a method.
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'pathname2'
8
+
9
+ class TC_Pathname_ToA < Test::Unit::TestCase
10
+ def setup
11
+ @path = Pathname.new('C:/Program Files/foo')
12
+ end
13
+
14
+ test "to_a basic functionality" do
15
+ assert_respond_to(@path, :to_a)
16
+ assert_nothing_raised{ @path.to_a }
17
+ assert_kind_of(Array, @path.to_a)
18
+ end
19
+
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)
25
+ end
26
+
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)
31
+ end
32
+
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)
36
+ end
37
+
38
+ test "to_a does not modify receiver" do
39
+ @path.to_a
40
+ assert_equal('C:\Program Files\foo', @path)
41
+ end
42
+
43
+ def teardown
44
+ @path = nil
45
+ end
46
+ end
@@ -0,0 +1,47 @@
1
+ ########################################################################
2
+ # test_undecorate.rb
3
+ #
4
+ # Test suite for the Pathname#undecorate method
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'pathname2'
8
+
9
+ class TC_Pathname_Undecorate < Test::Unit::TestCase
10
+ def setup
11
+ @std = Pathname.new('C:/Path/File.txt')
12
+ end
13
+
14
+ test "undecorate basic functionality" do
15
+ assert_respond_to(@std, :undecorate)
16
+ assert_nothing_raised{ @std.undecorate }
17
+ end
18
+
19
+ test "undecorate returns a Pathname object" do
20
+ assert_kind_of(Pathname, @std.undecorate)
21
+ end
22
+
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)
26
+ end
27
+
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)
31
+ end
32
+
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)
36
+ end
37
+
38
+ test "undecorate does not modify the original string" do
39
+ str = 'C:/Path/File.txt'
40
+ assert_nothing_raised{ Pathname.new(str).undecorate }
41
+ assert_equal('C:/Path/File.txt', str)
42
+ end
43
+
44
+ def teardown
45
+ @std = nil
46
+ end
47
+ end
@@ -0,0 +1,53 @@
1
+ ########################################################################
2
+ # test_undecorate_bang.rb
3
+ #
4
+ # Test suite for the Pathname#undecorate! method
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'pathname2'
8
+
9
+ class TC_Pathname_UndecorateBang < Test::Unit::TestCase
10
+ def setup
11
+ @std = Pathname.new('C:/Path/File.txt')
12
+ end
13
+
14
+ test "undecorate! basic functionality" do
15
+ assert_respond_to(@std, :undecorate!)
16
+ assert_nothing_raised{ @std.undecorate! }
17
+ end
18
+
19
+ test "undecorate! returns a Pathname object" do
20
+ assert_kind_of(Pathname, @std.undecorate!)
21
+ end
22
+
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!)
26
+ end
27
+
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!)
31
+ end
32
+
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!)
36
+ end
37
+
38
+ test "undecorate! does not modify the original string" do
39
+ str = 'C:/Path/File.txt'
40
+ assert_nothing_raised{ Pathname.new(str).undecorate }
41
+ assert_equal('C:/Path/File.txt', str)
42
+ end
43
+
44
+ test "undecorate does modify the object itself" do
45
+ path = Pathname.new('C:\Path\File[12]')
46
+ assert_nothing_raised{ path.undecorate! }
47
+ assert_equal('C:\Path\File', path)
48
+ end
49
+
50
+ def teardown
51
+ @std = nil
52
+ end
53
+ end