summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-11-22 05:48:51 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-11-22 05:48:51 +0000
commita696d9ad0cf128864b325cf020be79062cfba5b6 (patch)
tree843191b51d7e3dbf335fc52ce93c3e9776b2cf18 /test
parentbb935564fd80c64353e468bc848ade63e8bd030c (diff)
* 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/branches/ruby_1_8@9587 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_path.rb129
1 files changed, 114 insertions, 15 deletions
diff --git a/test/ruby/test_path.rb b/test/ruby/test_path.rb
index 09ab4ac677..63dbd07346 100644
--- a/test/ruby/test_path.rb
+++ b/test/ruby/test_path.rb
@@ -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