summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-17 04:58:49 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-17 04:58:49 +0000
commit990c8759dbb85961b7cc9d4496d04a053e784570 (patch)
treef89982236847e0dcc0f4c7ad93a2bb961f23e4aa /test
parent7d4bfb5308a9c81ce20a4927f7fb0edef80b94d0 (diff)
Split test_expand_path, test_basename, test_dirname
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66425 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_file_exhaustive.rb45
1 files changed, 36 insertions, 9 deletions
diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb
index 28a3007fe58..a65d859600c 100644
--- a/test/ruby/test_file_exhaustive.rb
+++ b/test/ruby/test_file_exhaustive.rb
@@ -781,7 +781,10 @@ class TestFileExhaustive < Test::Unit::TestCase
def test_expand_path
assert_equal(regular_file, File.expand_path(File.basename(regular_file), File.dirname(regular_file)))
assert_equal(utf8_file, File.expand_path(File.basename(utf8_file), File.dirname(utf8_file)))
- if NTFS
+ end
+
+ if NTFS
+ def test_expand_path_ntfs
[regular_file, utf8_file].each do |file|
assert_equal(file, File.expand_path(file + " "))
assert_equal(file, File.expand_path(file + "."))
@@ -792,8 +795,11 @@ class TestFileExhaustive < Test::Unit::TestCase
assert_match(/\Ae:\//i, File.expand_path('e:foo', 'd:/bar'))
assert_match(%r'\Ac:/bar/foo\z'i, File.expand_path('c:foo', 'c:/bar'))
end
- case RUBY_PLATFORM
- when /darwin/
+ end
+
+ case RUBY_PLATFORM
+ when /darwin/
+ def test_expand_path_hfs
["\u{feff}", *"\u{2000}"..."\u{2100}"].each do |c|
file = regular_file + c
full_path = File.expand_path(file)
@@ -809,11 +815,16 @@ class TestFileExhaustive < Test::Unit::TestCase
end
end
end
- if DRIVE
+ end
+
+ if DRIVE
+ def test_expand_path_absolute
assert_match(%r"\Az:/foo\z"i, File.expand_path('/foo', "z:/bar"))
assert_match(%r"\A//host/share/foo\z"i, File.expand_path('/foo', "//host/share/bar"))
assert_match(%r"\A#{DRIVE}/foo\z"i, File.expand_path('/foo'))
- else
+ end
+ else
+ def test_expand_path_absolute
assert_equal("/foo", File.expand_path('/foo'))
end
end
@@ -1183,7 +1194,10 @@ class TestFileExhaustive < Test::Unit::TestCase
assert_equal("foo", File.basename("foo", ".ext"))
assert_equal("foo", File.basename("foo.ext", ".ext"))
assert_equal("foo", File.basename("foo.ext", ".*"))
- if NTFS
+ end
+
+ if NTFS
+ def test_basename_strip
[regular_file, utf8_file].each do |file|
basename = File.basename(file)
assert_equal(basename, File.basename(file + " "))
@@ -1197,7 +1211,9 @@ class TestFileExhaustive < Test::Unit::TestCase
assert_equal(basename, File.basename(file + ".", ".*"))
assert_equal(basename, File.basename(file + "::$DATA", ".*"))
end
- else
+ end
+ else
+ def test_basename_strip
[regular_file, utf8_file].each do |file|
basename = File.basename(file)
assert_equal(basename + " ", File.basename(file + " "))
@@ -1212,13 +1228,18 @@ class TestFileExhaustive < Test::Unit::TestCase
assert_equal(basename, File.basename(file + "::$DATA", ".*"))
end
end
- if File::ALT_SEPARATOR == '\\'
+ end
+
+ if File::ALT_SEPARATOR == '\\'
+ def test_basename_backslash
a = "foo/\225\\\\"
[%W"cp437 \225", %W"cp932 \225\\"].each do |cp, expected|
assert_equal(expected.force_encoding(cp), File.basename(a.dup.force_encoding(cp)), cp)
end
end
+ end
+ def test_basename_encoding
assert_incompatible_encoding {|d| File.basename(d)}
assert_incompatible_encoding {|d| File.basename(d, ".*")}
assert_raise(Encoding::CompatibilityError) {File.basename("foo.ext", ".*".encode("utf-16le"))}
@@ -1234,8 +1255,14 @@ class TestFileExhaustive < Test::Unit::TestCase
assert_equal(@dir, File.dirname(regular_file))
assert_equal(@dir, File.dirname(utf8_file))
assert_equal(".", File.dirname(""))
+ end
+
+ def test_dirname_encoding
assert_incompatible_encoding {|d| File.dirname(d)}
- if File::ALT_SEPARATOR == '\\'
+ end
+
+ if File::ALT_SEPARATOR == '\\'
+ def test_dirname_backslash
a = "\225\\\\foo"
[%W"cp437 \225", %W"cp932 \225\\"].each do |cp, expected|
assert_equal(expected.force_encoding(cp), File.dirname(a.dup.force_encoding(cp)), cp)