mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
83cf0b613e
commit
ed353ff1bb
2 changed files with 35 additions and 18 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Sat Sep 3 13:59:31 2005 Tanaka Akira <akr@m17n.org>
|
||||||
|
|
||||||
|
* lib/pathname.rb (Pathname#descend): Pathname.new("./a/b/c").descend
|
||||||
|
didn't yield "."
|
||||||
|
(Pathname#ascend): ditto.
|
||||||
|
|
||||||
Fri Sep 2 23:51:54 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Fri Sep 2 23:51:54 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* parse.y (f_arg): f_norm_arg is a VALUE in ripper, not an ID.
|
* parse.y (f_arg): f_norm_arg is a VALUE in ripper, not an ID.
|
||||||
|
|
|
@ -448,10 +448,11 @@ class Pathname
|
||||||
end
|
end
|
||||||
paths << v
|
paths << v
|
||||||
else
|
else
|
||||||
until v.to_s == '.'
|
until v.basename == v
|
||||||
paths << v
|
paths << v
|
||||||
v = v.dirname
|
v = v.dirname
|
||||||
end
|
end
|
||||||
|
paths << v
|
||||||
end
|
end
|
||||||
paths.reverse_each {|path| yield path }
|
paths.reverse_each {|path| yield path }
|
||||||
end
|
end
|
||||||
|
@ -482,10 +483,11 @@ class Pathname
|
||||||
end
|
end
|
||||||
paths << v
|
paths << v
|
||||||
else
|
else
|
||||||
until v.to_s == '.'
|
until v.basename == v
|
||||||
paths << v
|
paths << v
|
||||||
v = v.dirname
|
v = v.dirname
|
||||||
end
|
end
|
||||||
|
paths << v
|
||||||
end
|
end
|
||||||
paths.each {|path| yield path }
|
paths.each {|path| yield path }
|
||||||
end
|
end
|
||||||
|
@ -1273,31 +1275,40 @@ if $0 == __FILE__
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_descend_abs
|
def test_descend_abs
|
||||||
rs = %w[/ /a /a/b /a/b/c]
|
rs = %w[/ /a /a/b /a/b/c].map {|s| Pathname.new(s) }
|
||||||
Pathname.new("/a/b/c").descend {|v|
|
Pathname.new("/a/b/c").descend {|v| assert_equal(rs.shift, v) }
|
||||||
assert_equal(Pathname.new(rs.shift), v)
|
assert_equal([], rs)
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_descend_rel
|
def test_descend_rel
|
||||||
rs = %w[a a/b a/b/c]
|
rs = %w[a a/b a/b/c].map {|s| Pathname.new(s) }
|
||||||
Pathname.new("a/b/c").descend {|v|
|
Pathname.new("a/b/c").descend {|v| assert_equal(rs.shift, v) }
|
||||||
assert_equal(Pathname.new(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
|
end
|
||||||
|
|
||||||
def test_ascend_abs
|
def test_ascend_abs
|
||||||
rs = %w[/a/b/c /a/b /a /]
|
rs = %w[/a/b/c /a/b /a /].map {|s| Pathname.new(s) }
|
||||||
Pathname.new("/a/b/c").ascend {|v|
|
Pathname.new("/a/b/c").ascend {|v| assert_equal(rs.shift, v) }
|
||||||
assert_equal(Pathname.new(rs.shift), v)
|
assert_equal([], rs)
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ascend_rel
|
def test_ascend_rel
|
||||||
rs = %w[a/b/c a/b a]
|
rs = %w[a/b/c a/b a].map {|s| Pathname.new(s) }
|
||||||
Pathname.new("a/b/c").ascend {|v|
|
Pathname.new("a/b/c").ascend {|v| assert_equal(rs.shift, v) }
|
||||||
assert_equal(Pathname.new(rs.shift), v)
|
assert_equal([], rs)
|
||||||
}
|
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue