summaryrefslogtreecommitdiff
path: root/test/ruby/test_file_exhaustive.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-18 03:38:42 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-18 03:38:42 +0000
commit829ab73879fe7b997a295e2d4c4684fd528105dc (patch)
tree615a01104afc823373c5f5679a4bb53f26059ba6 /test/ruby/test_file_exhaustive.rb
parent5f9342fa8aec29df47604df5a149c45505783357 (diff)
* file.c (rb_file_s_extname): fix for spaces before extention.
[ruby-dev:38044] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22394 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_file_exhaustive.rb')
-rw-r--r--test/ruby/test_file_exhaustive.rb51
1 files changed, 25 insertions, 26 deletions
diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb
index 420b3d527e..af6e0e1520 100644
--- a/test/ruby/test_file_exhaustive.rb
+++ b/test/ruby/test_file_exhaustive.rb
@@ -42,7 +42,7 @@ class TestFileExhaustive < Test::Unit::TestCase
def test_path
file = @file
- assert_equal(file, File.new(file).path)
+ assert_equal(file, File.open(file) {|f| f.path})
assert_equal(file, File.path(file))
o = Object.new
class << o; self; end.class_eval do
@@ -90,9 +90,9 @@ class TestFileExhaustive < Test::Unit::TestCase
assert_kind_of(String, fs1.inspect)
end
assert_raise(Errno::ENOENT) { File.stat(@nofile) }
- assert_kind_of(File::Stat, File.new(@file).stat)
+ assert_kind_of(File::Stat, File.open(@file) {|f| f.stat})
assert_raise(Errno::ENOENT) { File.lstat(@nofile) }
- assert_kind_of(File::Stat, File.new(@file).lstat)
+ assert_kind_of(File::Stat, File.open(@file) {|f| f.lstat})
end
def test_directory_p
@@ -272,7 +272,7 @@ class TestFileExhaustive < Test::Unit::TestCase
def test_atime
t1 = File.atime(@file)
- t2 = File.new(@file).atime
+ t2 = File.open(@file) {|f| f.atime}
assert_kind_of(Time, t1)
assert_kind_of(Time, t2)
assert_equal(t1, t2)
@@ -281,7 +281,7 @@ class TestFileExhaustive < Test::Unit::TestCase
def test_mtime
t1 = File.mtime(@file)
- t2 = File.new(@file).mtime
+ t2 = File.open(@file) {|f| f.mtime}
assert_kind_of(Time, t1)
assert_kind_of(Time, t2)
assert_equal(t1, t2)
@@ -290,7 +290,7 @@ class TestFileExhaustive < Test::Unit::TestCase
def test_ctime
t1 = File.ctime(@file)
- t2 = File.new(@file).ctime
+ t2 = File.open(@file) {|f| f.ctime}
assert_kind_of(Time, t1)
assert_kind_of(Time, t2)
assert_equal(t1, t2)
@@ -301,7 +301,7 @@ class TestFileExhaustive < Test::Unit::TestCase
return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM
assert_equal(1, File.chmod(0444, @file))
assert_equal(0444, File.stat(@file).mode % 01000)
- assert_equal(0, File.new(@file).chmod(0222))
+ assert_equal(0, File.open(@file) {|f| f.chmod(0222)})
assert_equal(0222, File.stat(@file).mode % 01000)
File.chmod(0600, @file)
assert_raise(Errno::ENOENT) { File.chmod(0600, @nofile) }
@@ -412,25 +412,24 @@ class TestFileExhaustive < Test::Unit::TestCase
def test_extname
assert(".test", File.extname(@file))
- assert_equal("", File.extname("foo"))
- assert_equal("", File.extname("/foo"))
- assert_equal("", File.extname(".foo"))
- assert_equal("", File.extname("/.foo"))
- assert_equal("", File.extname("bar/.foo"))
- assert_equal("", File.extname("/bar/.foo"))
- assert_equal(".ext", File.extname("foo.ext"))
- assert_equal(".ext", File.extname("/foo.ext"))
- assert_equal(".ext", File.extname(".foo.ext"))
- assert_equal(".ext", File.extname("/.foo.ext"))
- assert_equal(".ext", File.extname("bar/.foo.ext"))
- assert_equal(".ext", File.extname("/bar/.foo.ext"))
- assert_equal("", File.extname(""))
+ prefixes = ["", "/", ".", "/.", "bar/.", "/bar/."]
+ infixes = ["", " ", "."]
+ infixes2 = infixes + [".ext "]
+ appendixes = [""]
if /cygwin|mingw|mswin|bccwin/ =~ RUBY_PLATFORM
- assert_equal("", File.extname("foo "))
- assert_equal(".ext", File.extname("foo.ext "))
- assert_equal(".ext", File.extname("foo.ext."))
- assert_equal(".ext", File.extname("foo.ext::$DATA"))
- assert_equal("", File.extname("foo::$DATA.ext"))
+ appendixes << " " << "." << "::$DATA" << "::$DATA.bar"
+ end
+ prefixes.each do |prefix|
+ appendixes.each do |appendix|
+ infixes.each do |infix|
+ path = "#{prefix}foo#{infix}#{appendix}"
+ assert_equal("", File.extname(path), "File.extname(#{path.inspect})")
+ end
+ infixes2.each do |infix|
+ path = "#{prefix}foo#{infix}.ext#{appendix}"
+ assert_equal(".ext", File.extname(path), "File.extname(#{path.inspect})")
+ end
+ end
end
end
@@ -470,7 +469,7 @@ class TestFileExhaustive < Test::Unit::TestCase
f.close
make_file("foo", @file)
- assert_raise(IOError) { File.new(@file).truncate(0) }
+ assert_raise(IOError) { File.open(@file) {|f| f.truncate(0)} }
rescue NotImplementedError
end