diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-11-18 08:27:52 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-11-18 08:27:52 +0000 |
commit | 147dcb2236416f0d40497caf2cc5eba754bbbefb (patch) | |
tree | 8117fbcddd482f273eecb1a45fde7a5865fbb13e | |
parent | 8f8d046b1fa27cc84a5de7b0367c3326b02050b2 (diff) |
* 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/branches/ruby_1_8@9561 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | file.c | 11 | ||||
-rw-r--r-- | test/ruby/test_path.rb | 71 |
3 files changed, 88 insertions, 2 deletions
@@ -1,3 +1,11 @@ +Fri Nov 18 17:26:06 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:18:02 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp> * win32/win32.h (S_IFIFO): r,w = IO.pipe; r.stat.pipe? now @@ -2689,7 +2689,7 @@ rb_file_s_dirname(klass, fname) root = skiproot(name); #ifdef DOSISH_UNC if (root > name + 1 && isdirsep(*name)) - root = skipprefix(name = root - 2); + name = root - 2; #else if (root > name + 1) name = root - 1; @@ -2700,9 +2700,16 @@ rb_file_s_dirname(klass, 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); diff --git a/test/ruby/test_path.rb b/test/ruby/test_path.rb index 95a5d5b1d1..4b9365508a 100644 --- a/test/ruby/test_path.rb +++ b/test/ruby/test_path.rb @@ -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 # [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 |