summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_argf.rb15
-rw-r--r--test/ruby/test_file_exhaustive.rb27
2 files changed, 28 insertions, 14 deletions
diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb
index bf6996f0de..2f1ddf5391 100644
--- a/test/ruby/test_argf.rb
+++ b/test/ruby/test_argf.rb
@@ -201,21 +201,14 @@ class TestArgf < Test::Unit::TestCase
t = make_tempfile
assert_in_out_err(["-", t.path], <<-INPUT) do |r, e|
- ARGF.inplace_mode = '/\\\\'
+ ARGF.inplace_mode = '/\\\\:'
while line = ARGF.gets
puts line.chomp + '.new'
end
INPUT
- if no_safe_rename
- assert_equal([], e)
- assert_equal([], r)
- assert_equal("foo.new\nbar.new\nbaz.new\n", File.read(t.path))
- File.unlink(t.path + ".~~~") rescue nil
- else
- assert_match(/Can't rename .* to .*: .*. skipping file/, e.first) #'
- assert_equal([], r)
- assert_equal("foo\nbar\nbaz\n", File.read(t.path))
- end
+ assert_match(/Can't rename .* to .*: .*. skipping file/, e.first) #'
+ assert_equal([], r)
+ assert_equal("foo\nbar\nbaz\n", File.read(t.path))
end
end
diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb
index 02a4730ba2..44b454a773 100644
--- a/test/ruby/test_file_exhaustive.rb
+++ b/test/ruby/test_file_exhaustive.rb
@@ -403,10 +403,10 @@ class TestFileExhaustive < Test::Unit::TestCase
assert_match(/\Ac:\//i, File.expand_path('c:foo', 'd:/bar'))
assert_match(%r'\Ac:/bar/foo\z'i, File.expand_path('c:foo', 'c:/bar'))
end
- if drive = Dir.pwd[%r'\A(?:[a-z]:|//[^/]+/[^/]+)'i]
+ if DRIVE
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'))
+ assert_match(%r"\A#{DRIVE}/foo\z"i, File.expand_path('/foo'))
else
assert_equal("/foo", File.expand_path('/foo'))
end
@@ -477,7 +477,6 @@ class TestFileExhaustive < Test::Unit::TestCase
ENV["HOMEPATH"] = home_path
ENV["USERPROFILE"] = user_profile
end
- assert_incompatible_encoding {|d| File.expand_path(d)}
end
def test_expand_path_remove_trailing_alternative_data
@@ -683,16 +682,31 @@ class TestFileExhaustive < Test::Unit::TestCase
assert_equal(basename, File.basename(@file + ".", ".*"))
assert_equal(basename, File.basename(@file + "::$DATA", ".*"))
end
+ if File::ALT_SEPARATOR == '\\'
+ 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
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"))}
+
+ s = "foo\x93_a".force_encoding("cp932")
+ assert_equal(s, File.basename(s, "_a"))
end
def test_dirname
assert(@file.start_with?(File.dirname(@file)))
assert_equal(".", File.dirname(""))
assert_incompatible_encoding {|d| File.dirname(d)}
+ if File::ALT_SEPARATOR == '\\'
+ 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)
+ end
+ end
end
def test_extname
@@ -736,6 +750,13 @@ class TestFileExhaustive < Test::Unit::TestCase
def o.to_path; "foo"; end
assert_equal(s, File.join(o, "bar", "baz"))
assert_equal(s, File.join("foo" + File::SEPARATOR, "bar", File::SEPARATOR + "baz"))
+ if File::ALT_SEPARATOR == '\\'
+ a = "\225\\"
+ b = "foo"
+ [%W"cp437 \225\\foo", %W"cp932 \225\\/foo"].each do |cp, expected|
+ assert_equal(expected.force_encoding(cp), File.join(a.dup.force_encoding(cp), b.dup.force_encoding(cp)), cp)
+ end
+ end
end
def test_truncate