mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 08:33:58 +02:00
dir.c: Dir.each_child and Dir.children
* dir.c (dir_s_each_child, dir_s_children): Dir.each_child and Dir.children which are similar to Dir.foreach and Dir.entries respectively, except to exclude "." and "..". [Feature #11302] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58879 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5a302b3098
commit
944c455b38
3 changed files with 96 additions and 7 deletions
|
@ -214,9 +214,11 @@ class TestDir < Test::Unit::TestCase
|
|||
assert_equal(files, Dir.open(@root) {|d| Dir.glob("*/*.c", base: d)}.sort)
|
||||
end
|
||||
|
||||
def assert_entries(entries)
|
||||
def assert_entries(entries, children = false)
|
||||
entries.sort!
|
||||
assert_equal(%w(. ..) + ("a".."z").to_a, entries)
|
||||
expected = ("a".."z").to_a
|
||||
expected = %w(. ..) + expected unless children
|
||||
assert_equal(expected, entries)
|
||||
end
|
||||
|
||||
def test_entries
|
||||
|
@ -228,6 +230,14 @@ class TestDir < Test::Unit::TestCase
|
|||
assert_entries(Dir.foreach(@root).to_a)
|
||||
end
|
||||
|
||||
def test_children
|
||||
assert_entries(Dir.children(@root), true)
|
||||
end
|
||||
|
||||
def test_each_child
|
||||
assert_entries(Dir.each_child(@root).to_a, true)
|
||||
end
|
||||
|
||||
def test_dir_enc
|
||||
dir = Dir.open(@root, encoding: "UTF-8")
|
||||
begin
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue