mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
5f9342fa8a
commit
829ab73879
1 changed files with 25 additions and 26 deletions
|
@ -42,7 +42,7 @@ class TestFileExhaustive < Test::Unit::TestCase
|
||||||
def test_path
|
def test_path
|
||||||
file = @file
|
file = @file
|
||||||
|
|
||||||
assert_equal(file, File.new(file).path)
|
assert_equal(file, File.open(file) {|f| f.path})
|
||||||
assert_equal(file, File.path(file))
|
assert_equal(file, File.path(file))
|
||||||
o = Object.new
|
o = Object.new
|
||||||
class << o; self; end.class_eval do
|
class << o; self; end.class_eval do
|
||||||
|
@ -90,9 +90,9 @@ class TestFileExhaustive < Test::Unit::TestCase
|
||||||
assert_kind_of(String, fs1.inspect)
|
assert_kind_of(String, fs1.inspect)
|
||||||
end
|
end
|
||||||
assert_raise(Errno::ENOENT) { File.stat(@nofile) }
|
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_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
|
end
|
||||||
|
|
||||||
def test_directory_p
|
def test_directory_p
|
||||||
|
@ -272,7 +272,7 @@ class TestFileExhaustive < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_atime
|
def test_atime
|
||||||
t1 = File.atime(@file)
|
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, t1)
|
||||||
assert_kind_of(Time, t2)
|
assert_kind_of(Time, t2)
|
||||||
assert_equal(t1, t2)
|
assert_equal(t1, t2)
|
||||||
|
@ -281,7 +281,7 @@ class TestFileExhaustive < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_mtime
|
def test_mtime
|
||||||
t1 = File.mtime(@file)
|
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, t1)
|
||||||
assert_kind_of(Time, t2)
|
assert_kind_of(Time, t2)
|
||||||
assert_equal(t1, t2)
|
assert_equal(t1, t2)
|
||||||
|
@ -290,7 +290,7 @@ class TestFileExhaustive < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_ctime
|
def test_ctime
|
||||||
t1 = File.ctime(@file)
|
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, t1)
|
||||||
assert_kind_of(Time, t2)
|
assert_kind_of(Time, t2)
|
||||||
assert_equal(t1, t2)
|
assert_equal(t1, t2)
|
||||||
|
@ -301,7 +301,7 @@ class TestFileExhaustive < Test::Unit::TestCase
|
||||||
return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM
|
return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM
|
||||||
assert_equal(1, File.chmod(0444, @file))
|
assert_equal(1, File.chmod(0444, @file))
|
||||||
assert_equal(0444, File.stat(@file).mode % 01000)
|
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)
|
assert_equal(0222, File.stat(@file).mode % 01000)
|
||||||
File.chmod(0600, @file)
|
File.chmod(0600, @file)
|
||||||
assert_raise(Errno::ENOENT) { File.chmod(0600, @nofile) }
|
assert_raise(Errno::ENOENT) { File.chmod(0600, @nofile) }
|
||||||
|
@ -412,25 +412,24 @@ class TestFileExhaustive < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_extname
|
def test_extname
|
||||||
assert(".test", File.extname(@file))
|
assert(".test", File.extname(@file))
|
||||||
assert_equal("", File.extname("foo"))
|
prefixes = ["", "/", ".", "/.", "bar/.", "/bar/."]
|
||||||
assert_equal("", File.extname("/foo"))
|
infixes = ["", " ", "."]
|
||||||
assert_equal("", File.extname(".foo"))
|
infixes2 = infixes + [".ext "]
|
||||||
assert_equal("", File.extname("/.foo"))
|
appendixes = [""]
|
||||||
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(""))
|
|
||||||
if /cygwin|mingw|mswin|bccwin/ =~ RUBY_PLATFORM
|
if /cygwin|mingw|mswin|bccwin/ =~ RUBY_PLATFORM
|
||||||
assert_equal("", File.extname("foo "))
|
appendixes << " " << "." << "::$DATA" << "::$DATA.bar"
|
||||||
assert_equal(".ext", File.extname("foo.ext "))
|
end
|
||||||
assert_equal(".ext", File.extname("foo.ext."))
|
prefixes.each do |prefix|
|
||||||
assert_equal(".ext", File.extname("foo.ext::$DATA"))
|
appendixes.each do |appendix|
|
||||||
assert_equal("", File.extname("foo::$DATA.ext"))
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -470,7 +469,7 @@ class TestFileExhaustive < Test::Unit::TestCase
|
||||||
f.close
|
f.close
|
||||||
make_file("foo", @file)
|
make_file("foo", @file)
|
||||||
|
|
||||||
assert_raise(IOError) { File.new(@file).truncate(0) }
|
assert_raise(IOError) { File.open(@file) {|f| f.truncate(0)} }
|
||||||
rescue NotImplementedError
|
rescue NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue