summaryrefslogtreecommitdiff
path: root/lib/pathname.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-09-03 05:02:13 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-09-03 05:02:13 +0000
commited353ff1bb6df83138ba33b083bc2d258ad75cfe (patch)
tree47d6247caa38c63f915ac4d148d93a1704b3de76 /lib/pathname.rb
parent83cf0b613efc099fe8c90ff0161843b785bdfe4a (diff)
* lib/pathname.rb (Pathname#descend): Pathname.new("./a/b/c").descend
didn't yield "." (Pathname#ascend): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9073 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/pathname.rb')
-rw-r--r--lib/pathname.rb47
1 files changed, 29 insertions, 18 deletions
diff --git a/lib/pathname.rb b/lib/pathname.rb
index d9dabd0ca0..7b371def2b 100644
--- a/lib/pathname.rb
+++ b/lib/pathname.rb
@@ -448,10 +448,11 @@ class Pathname
end
paths << v
else
- until v.to_s == '.'
+ until v.basename == v
paths << v
v = v.dirname
end
+ paths << v
end
paths.reverse_each {|path| yield path }
end
@@ -482,10 +483,11 @@ class Pathname
end
paths << v
else
- until v.to_s == '.'
+ until v.basename == v
paths << v
v = v.dirname
end
+ paths << v
end
paths.each {|path| yield path }
end
@@ -1273,31 +1275,40 @@ if $0 == __FILE__
end
def test_descend_abs
- rs = %w[/ /a /a/b /a/b/c]
- Pathname.new("/a/b/c").descend {|v|
- assert_equal(Pathname.new(rs.shift), v)
- }
+ rs = %w[/ /a /a/b /a/b/c].map {|s| Pathname.new(s) }
+ Pathname.new("/a/b/c").descend {|v| assert_equal(rs.shift, v) }
+ assert_equal([], rs)
end
def test_descend_rel
- rs = %w[a a/b a/b/c]
- Pathname.new("a/b/c").descend {|v|
- assert_equal(Pathname.new(rs.shift), v)
- }
+ rs = %w[a a/b a/b/c].map {|s| Pathname.new(s) }
+ Pathname.new("a/b/c").descend {|v| assert_equal(rs.shift, v) }
+ assert_equal([], rs)
+ end
+
+ def test_descend_rel_with_current_dir
+ rs = %w[. ./a ./a/b ./a/b/c].map {|s| Pathname.new(s) }
+ Pathname.new("./a/b/c").descend {|v| assert_equal(rs.shift, v) }
+ assert_equal([], rs)
end
def test_ascend_abs
- rs = %w[/a/b/c /a/b /a /]
- Pathname.new("/a/b/c").ascend {|v|
- assert_equal(Pathname.new(rs.shift), v)
- }
+ rs = %w[/a/b/c /a/b /a /].map {|s| Pathname.new(s) }
+ Pathname.new("/a/b/c").ascend {|v| assert_equal(rs.shift, v) }
+ assert_equal([], rs)
end
def test_ascend_rel
- rs = %w[a/b/c a/b a]
- Pathname.new("a/b/c").ascend {|v|
- assert_equal(Pathname.new(rs.shift), v)
- }
+ rs = %w[a/b/c a/b a].map {|s| Pathname.new(s) }
+ Pathname.new("a/b/c").ascend {|v| assert_equal(rs.shift, v) }
+ assert_equal([], rs)
end
+
+ def test_ascend_rel_with_current_dir
+ rs = %w[./a/b/c ./a/b ./a .].map {|s| Pathname.new(s) }
+ Pathname.new("./a/b/c").ascend {|v| assert_equal(rs.shift, v) }
+ assert_equal([], rs)
+ end
+
end
end