summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-25 02:50:21 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-25 02:50:21 +0000
commit944c455b38f85c5fa1b91390d43d89b692e4c812 (patch)
tree55ea82cf0a92a02b4aa277e6469d832ffd0fa714 /test
parent5a302b3098a1a124f8a81fcbfd40924dd862abd7 (diff)
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
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_dir.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/test/ruby/test_dir.rb b/test/ruby/test_dir.rb
index 052f67ed4b..69daa766a4 100644
--- a/test/ruby/test_dir.rb
+++ b/test/ruby/test_dir.rb
@@ -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