* file.c (rb_file_s_basename): skip slashes just after UNC top slashes.

* test/ruby/test_path.rb (test_dirname, test_basename): follow new
  spec. and add new tests.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2005-11-22 05:39:50 +00:00
Родитель 886f33e199
Коммит 333e8b294d
3 изменённых файлов: 124 добавлений и 16 удалений

Просмотреть файл

@ -1,3 +1,10 @@
Tue Nov 22 14:36:54 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* file.c (rb_file_s_basename): skip slashes just after UNC top slashes.
* test/ruby/test_path.rb (test_dirname, test_basename): follow new
spec. and add new tests.
Tue Nov 22 13:30:15 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* win32/win32.c (rb_w32_stat): Dir.chdir('//server/shared');

4
file.c
Просмотреть файл

@ -2225,7 +2225,9 @@ rb_path_skip_prefix(const char *path)
#if defined(DOSISH_UNC) || defined(DOSISH_DRIVE_LETTER)
#ifdef DOSISH_UNC
if (isdirsep(path[0]) && isdirsep(path[1])) {
if (*(path = nextdirsep(path + 2)) && path[1] && !isdirsep(path[1]))
path += 2;
while (isdirsep(*path)) path++;
if (*(path = nextdirsep(path)) && path[1] && !isdirsep(path[1]))
path = nextdirsep(path + 1);
return (char *)path;
}

Просмотреть файл

@ -51,17 +51,20 @@ class TestPath < Test::Unit::TestCase
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:/', 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:///a'))
assert_equal('C:/', File.dirname('C:///a/'))
assert_equal('C:/a', File.dirname('C:///a/b'))
else
# others
@ -69,18 +72,22 @@ class TestPath < Test::Unit::TestCase
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('.', File.dirname('C://'))
assert_equal('C:', File.dirname('C://a'))
assert_equal('C:', File.dirname('C://a/'))
# not spec.
#assert_equal('C://a', File.dirname('C://a/b'))
assert_equal('.', File.dirname('C:///'))
assert_equal('C:', File.dirname('C:///a'))
assert_equal('C:', File.dirname('C:///a/'))
# not spec.
#assert_equal('C:///a', File.dirname('C:///a/b'))
end
@ -88,21 +95,24 @@ class TestPath < Test::Unit::TestCase
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('//a', File.dirname('//a'))
assert_equal('//a/', File.dirname('//a/'))
assert_equal('//a', File.dirname('//a/'))
assert_equal('//a/b', File.dirname('//a/b'))
assert_equal('//a/b', File.dirname('//a/b/'))
assert_equal('//a/b', File.dirname('//a/b/c'))
assert_equal('//', File.dirname('///'))
assert_equal('//a', File.dirname('///a'))
assert_equal('//a/', File.dirname('///a/'))
assert_equal('//a', File.dirname('///a/'))
assert_equal('//a/b', File.dirname('///a/b'))
assert_equal('//a/b', File.dirname('///a/b/'))
assert_equal('//a/b', File.dirname('///a/b/c'))
@ -114,6 +124,7 @@ class TestPath < Test::Unit::TestCase
assert_equal('/a', File.dirname('//a/b'))
assert_equal('/a', File.dirname('//a/b/'))
assert_equal('/a/b', File.dirname('//a/b/c'))
assert_equal('/', File.dirname('///'))
assert_equal('/', File.dirname('///a'))
assert_equal('/', File.dirname('///a/'))
@ -122,4 +133,92 @@ class TestPath < Test::Unit::TestCase
assert_equal('/a/b', File.dirname('///a/b/c'))
end
end
def test_basename # [ruby-dev:27766]
if /(bcc|ms)win\d|mingw|cygwin|djgpp|human|emx/ =~ RUBY_PLATFORM
# DOSISH_DRIVE_LETTER
assert_equal('', File.basename('C:'))
assert_equal('a', File.basename('C:a'))
assert_equal('a', File.basename('C:a/'))
assert_equal('b', File.basename('C:a/b'))
assert_equal('/', File.basename('C:/'))
assert_equal('a', File.basename('C:/a'))
assert_equal('a', File.basename('C:/a/'))
assert_equal('b', File.basename('C:/a/b'))
assert_equal('/', File.basename('C://'))
assert_equal('a', File.basename('C://a'))
assert_equal('a', File.basename('C://a/'))
assert_equal('b', File.basename('C://a/b'))
assert_equal('/', File.basename('C:///'))
assert_equal('a', File.basename('C:///a'))
assert_equal('a', File.basename('C:///a/'))
assert_equal('b', File.basename('C:///a/b'))
else
# others
assert_equal('C:', File.basename('C:'))
assert_equal('C:a', File.basename('C:a'))
assert_equal('C:a', File.basename('C:a/'))
assert_equal('b', File.basename('C:a/b'))
assert_equal('C:', File.basename('C:/'))
assert_equal('a', File.basename('C:/a'))
assert_equal('a', File.basename('C:/a/'))
assert_equal('b', File.basename('C:/a/b'))
assert_equal('C:', File.basename('C://'))
assert_equal('a', File.basename('C://a'))
assert_equal('a', File.basename('C://a/'))
assert_equal('b', File.basename('C://a/b'))
assert_equal('C:', File.basename('C:///'))
assert_equal('a', File.basename('C:///a'))
assert_equal('a', File.basename('C:///a/'))
assert_equal('b', File.basename('C:///a/b'))
end
assert_equal('', File.basename(''))
assert_equal('a', File.basename('a'))
assert_equal('a', File.basename('a/'))
assert_equal('b', File.basename('a/b'))
assert_equal('/', File.basename('/'))
assert_equal('a', File.basename('/a'))
assert_equal('a', File.basename('/a/'))
assert_equal('b', File.basename('/a/b'))
if /(bcc|ms|cyg)win|mingw|djgpp|human|emx/ =~ RUBY_PLATFORM
# DOSISH_UNC
assert_equal('/', File.basename('//'))
assert_equal('/', File.basename('//a'))
assert_equal('/', File.basename('//a/'))
assert_equal('/', File.basename('//a/b'))
assert_equal('/', File.basename('//a/b/'))
assert_equal('c', File.basename('//a/b/c'))
assert_equal('/', File.basename('///'))
assert_equal('/', File.basename('///a'))
assert_equal('/', File.basename('///a/'))
assert_equal('/', File.basename('///a/b'))
assert_equal('/', File.basename('///a/b/'))
assert_equal('c', File.basename('///a/b/c'))
else
# others
assert_equal('/', File.basename('//'))
assert_equal('a', File.basename('//a'))
assert_equal('a', File.basename('//a/'))
assert_equal('b', File.basename('//a/b'))
assert_equal('b', File.basename('//a/b/'))
assert_equal('c', File.basename('//a/b/c'))
assert_equal('/', File.basename('///'))
assert_equal('a', File.basename('///a'))
assert_equal('a', File.basename('///a/'))
assert_equal('b', File.basename('///a/b'))
assert_equal('b', File.basename('///a/b/'))
assert_equal('c', File.basename('///a/b/c'))
end
end
end