diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/-ext-/test_add_suffix.rb | 47 | ||||
-rw-r--r-- | test/pathname/test_pathname.rb | 8 | ||||
-rw-r--r-- | test/ruby/test_argf.rb | 15 | ||||
-rw-r--r-- | test/ruby/test_file_exhaustive.rb | 27 |
4 files changed, 30 insertions, 67 deletions
diff --git a/test/-ext-/test_add_suffix.rb b/test/-ext-/test_add_suffix.rb deleted file mode 100644 index 0520baef8c..0000000000 --- a/test/-ext-/test_add_suffix.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'test/unit' -require_relative '../ruby/envutil' -require "-test-/add_suffix/bug" - -class Test_AddSuffix < Test::Unit::TestCase - Dir = "/dev/null/".freeze - Style_1 = (Dir+"foo").freeze - - def test_style_0 - assert_equal("a.x.y", Bug.add_suffix("a.x", ".y")) - end - - def test_style_1 - assert_equal(Style_1+".y", Bug.add_suffix(Style_1+".c", ".y")) - suffix = ".bak".freeze - assert_equal(Style_1+suffix, Bug.add_suffix(Style_1.dup, suffix)) - assert_equal(Style_1+suffix, Bug.add_suffix(Style_1+".bar", suffix)) - assert_equal(Style_1+".$$$", Bug.add_suffix(Style_1+suffix, suffix)) - assert_equal(Style_1+suffix, Bug.add_suffix(Style_1+".$$$", suffix)) - assert_equal(Style_1+".~~~", Bug.add_suffix(Style_1+".$$$", ".$$$")) - assert_equal(Dir+"makefile"+suffix, Bug.add_suffix(Dir+"makefile", suffix)) - end - - def test_style_2 - suffix = "~" - assert_equal(Style_1+"~", Bug.add_suffix(Style_1.dup, suffix)) - assert_equal(Style_1+".c~", Bug.add_suffix(Style_1+".c", suffix)) - assert_equal(Style_1+".c~~", Bug.add_suffix(Style_1+".c~", suffix)) - assert_equal(Style_1+"~.c~~", Bug.add_suffix(Style_1+".c~~", suffix)) - assert_equal(Style_1+"~~.c~~", Bug.add_suffix(Style_1+"~.c~~", suffix)) - assert_equal(Style_1+"~~~~~.cc~", Bug.add_suffix(Style_1+"~~~~~.ccc", suffix)) - assert_equal(Style_1+"~~~~~.$$$", Bug.add_suffix(Style_1+"~~~~~.c~~", suffix)) - assert_equal(Dir+"foo~.pas", Bug.add_suffix(Dir+"foo.pas", suffix)) - assert_equal(Dir+"makefile.~", Bug.add_suffix(Dir+"makefile", suffix)) - assert_equal(Dir+"longname.fi~", Bug.add_suffix(Dir+"longname.fil", suffix)) - assert_equal(Dir+"longnam~.fi~", Bug.add_suffix(Dir+"longname.fi~", suffix)) - assert_equal(Dir+"longnam~.$$$", Bug.add_suffix(Dir+"longnam~.fi~", suffix)) - end - - def test_style_3 - base = "a"*1000 - suffix = "-"+"b"*1000 - assert_equal(base+".~~~", Bug.add_suffix(base, suffix)) - assert_equal(base+".~~~", Bug.add_suffix(base+".$$$", suffix)) - assert_equal(base+".$$$", Bug.add_suffix(base+".~~~", suffix)) - end -end diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb index 8a8c0d9844..61d288d68d 100644 --- a/test/pathname/test_pathname.rb +++ b/test/pathname/test_pathname.rb @@ -1,5 +1,3 @@ -#!/usr/bin/env ruby - require 'test/unit' require 'pathname' @@ -185,10 +183,8 @@ class TestPathname < Test::Unit::TestCase if DOSISH defassert(:del_trailing_separator, "a", "a\\") - require 'Win32API' - if Win32API.new('kernel32', 'GetACP', nil, 'L').call == 932 - defassert(:del_trailing_separator, "\225\\", "\225\\\\") # SJIS - end + defassert(:del_trailing_separator, "\225\\".force_encoding("cp932"), "\225\\\\".force_encoding("cp932")) + defassert(:del_trailing_separator, "\225".force_encoding("cp437"), "\225\\\\".force_encoding("cp437")) end def test_plus 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 |