mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* file.c (file_s_dirname): added checks for some patterns with drive
letter. fixed: [ruby-dev:27738] * test/ruby/test_path.rb (test_dirname): added tests for above patterns. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9559 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4378916e95
commit
7b692e55cd
3 changed files with 87 additions and 1 deletions
|
@ -1,3 +1,11 @@
|
|||
Fri Nov 18 16:47:33 2005 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||
|
||||
* file.c (file_s_dirname): added checks for some patterns with drive
|
||||
letter. fixed: [ruby-dev:27738]
|
||||
|
||||
* test/ruby/test_path.rb (test_dirname): added tests for above
|
||||
patterns.
|
||||
|
||||
Fri Nov 18 12:19:16 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
||||
|
||||
* win32/win32.h (S_IFIFO): r,w = IO.pipe; r.stat.pipe? now
|
||||
|
|
9
file.c
9
file.c
|
@ -2638,9 +2638,16 @@ rb_file_s_dirname(VALUE klass, VALUE fname)
|
|||
}
|
||||
if (p == name)
|
||||
return rb_str_new2(".");
|
||||
#ifdef DOSISH_DRIVE_LETTER
|
||||
if (has_drive_letter(name) && isdirsep(*(name + 2))) {
|
||||
dirname = rb_str_new(name, 3);
|
||||
rb_str_cat(dirname, skiproot(name + 2), p - skiproot(name + 2));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
dirname = rb_str_new(name, p - name);
|
||||
#ifdef DOSISH_DRIVE_LETTER
|
||||
if (root == name + 2 && name[1] == ':')
|
||||
if (has_drive_letter(name) && root == name + 2 && p - name == 2)
|
||||
rb_str_cat(dirname, ".", 1);
|
||||
#endif
|
||||
OBJ_INFECT(dirname, fname);
|
||||
|
|
|
@ -43,4 +43,75 @@ class TestPath < Test::Unit::TestCase
|
|||
assert_equal("//", File.expand_path(".", "//"))
|
||||
assert_equal("//sub", File.expand_path("sub", "//"))
|
||||
end
|
||||
|
||||
def test_dirname_special # [ruby-dev:27738]
|
||||
if /(bcc|ms)win\d|mingw|cygwin|djgpp|human|emx/ =~ RUBY_PLATFORM
|
||||
# DOSISH_DRIVE_LETTER
|
||||
assert_equal('C:.', File.dirname('C:'))
|
||||
assert_equal('C:.', File.dirname('C:a'))
|
||||
assert_equal('C:.', File.dirname('C:a/'))
|
||||
assert_equal('C:a', File.dirname('C:a/b'))
|
||||
assert_equal('C:/', File.dirname('C:/'))
|
||||
assert_equal('C:/', File.dirname('C://'))
|
||||
assert_equal('C:/', File.dirname('C:///'))
|
||||
assert_equal('C:/', File.dirname('C:/a'))
|
||||
assert_equal('C:/', File.dirname('C://a'))
|
||||
assert_equal('C:/', File.dirname('C:///a'))
|
||||
assert_equal('C:/', File.dirname('C:/a/'))
|
||||
assert_equal('C:/', File.dirname('C://a/'))
|
||||
assert_equal('C:/', File.dirname('C:///a/'))
|
||||
assert_equal('C:/a', File.dirname('C:/a/b'))
|
||||
assert_equal('C:/a', File.dirname('C://a/b'))
|
||||
assert_equal('C:/a', File.dirname('C:///a/b'))
|
||||
else
|
||||
# others
|
||||
assert_equal('.', File.dirname('C:'))
|
||||
assert_equal('.', File.dirname('C:a'))
|
||||
assert_equal('.', File.dirname('C:a/'))
|
||||
assert_equal('C:a', File.dirname('C:a/b'))
|
||||
assert_equal('.', File.dirname('C:/'))
|
||||
assert_equal('.', File.dirname('C://'))
|
||||
assert_equal('.', File.dirname('C:///'))
|
||||
assert_equal('C:', File.dirname('C:/a'))
|
||||
assert_equal('C:', File.dirname('C://a'))
|
||||
assert_equal('C:', File.dirname('C:///a'))
|
||||
assert_equal('C:', File.dirname('C:/a/'))
|
||||
assert_equal('C:', File.dirname('C://a/'))
|
||||
assert_equal('C:', File.dirname('C:///a/'))
|
||||
assert_equal('C:/a', File.dirname('C:/a/b'))
|
||||
# these show current implementation, but they are not spec.
|
||||
#assert_equal('C://a', File.dirname('C://a/b'))
|
||||
#assert_equal('C:///a', File.dirname('C:///a/b'))
|
||||
end
|
||||
|
||||
assert_equal('.', File.dirname(''))
|
||||
assert_equal('.', File.dirname('a'))
|
||||
assert_equal('.', File.dirname('a/'))
|
||||
assert_equal('a', File.dirname('a/b'))
|
||||
assert_equal('/', File.dirname('/'))
|
||||
assert_equal('/', File.dirname('/a'))
|
||||
assert_equal('/', File.dirname('/a/'))
|
||||
assert_equal('/a', File.dirname('/a/b'))
|
||||
if /(bcc|ms|cyg)win|mingw|djgpp|human|emx/ =~ RUBY_PLATFORM
|
||||
# DOSISH_UNC
|
||||
assert_equal('//', File.dirname('//'))
|
||||
assert_equal('//', File.dirname('//a'))
|
||||
assert_equal('//', File.dirname('//a/'))
|
||||
assert_equal('//a', File.dirname('//a/b'))
|
||||
assert_equal('//', File.dirname('///'))
|
||||
assert_equal('//', File.dirname('///a'))
|
||||
assert_equal('//', File.dirname('///a/'))
|
||||
assert_equal('//a', File.dirname('///a/b'))
|
||||
else
|
||||
# others
|
||||
assert_equal('/', File.dirname('//'))
|
||||
assert_equal('/', File.dirname('//a'))
|
||||
assert_equal('/', File.dirname('//a/'))
|
||||
assert_equal('/a', File.dirname('//a/b'))
|
||||
assert_equal('/', File.dirname('///'))
|
||||
assert_equal('/', File.dirname('///a'))
|
||||
assert_equal('/', File.dirname('///a/'))
|
||||
assert_equal('/a', File.dirname('///a/b'))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue