Project

General

Profile

Backport #7294 ยป 0001-backport-bug-6765.diff

luislavena (Luis Lavena), 11/07/2012 04:55 AM

View differences:

ChangeLog
1
Tue Jul 24 12:13:26 2012  NAKAMURA Usaku  <usa@ruby-lang.org>
2

  
3
	* test/ruby/test_dir_m17n.rb: refactoring. RE should be in the left side
4
	  of the =~ operator, and compare the result with nil is meaningless.
5

  
6
Tue Jul 24 08:30:15 2012  Luis Lavena  <luislavena@gmail.com>
7

  
8
	* test/ruby/test_dir_m17n.rb (create_and_check_raw_file_name): add new
9
	  helper method to ease encoding testing. Patch by Oleg Sukhodolsky.
10
	  [ruby-core:46589][Bug #6765]
11

  
12
	* test/ruby/test_dir_m17n.rb (test_filename_extutf8): use filesystem
13
	  encoding when reading entries and comparing.
14

  
15
	* test/ruby/test_dir_m17n.rb (test_filename_utf8_raw_name): removed.
16

  
17
	* test/ruby/test_dir_m17n.rb (test_filename_utf8_raw_jp_name): split test.
18

  
1 19
Fri Oct 26 17:22:18 2012  NAKAMURA Usaku  <usa@ruby-lang.org>
2 20

  
3 21
	* file.c (append_fspath): need to set the encoding to result always.
test/ruby/test_dir_m17n.rb
11 11
    }
12 12
  end
13 13

  
14
  def create_and_check_raw_file_name(code, encoding)
15
    with_tmpdir { |dir|
16
      create_file_program = %Q[
17
        filename = #{code}.chr('UTF-8').force_encoding("#{encoding}")
18
        File.open(filename, "w") {}
19
        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
20
        ents = Dir.entries(".", opts)
21
        exit ents.include?(filename)
22
      ]
23
      assert_ruby_status(["-E#{encoding}"], create_file_program, nil, :chdir=>dir)
24

  
25
      test_file_program = %Q[
26
        filename = #{code}.chr('UTF-8').force_encoding("ASCII-8BIT")
27
        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
28
        ents = Dir.entries(".", opts)
29
        expected_filename = #{code}.chr('UTF-8').encode(Encoding.find("filesystem")) rescue expected_filename = "?"
30
        expected_filename = expected_filename.force_encoding("ASCII-8BIT")
31
        result = ents.include?(filename) || (/mswin|mingw/ =~ RUBY_PLATFORM && ents.include?(expected_filename))
32
        if !result && /mswin|mingw/ =~ RUBY_PLATFORM
33
          exit Dir.entries(".", {:encoding => Encoding.find("filesystem")}).include?(expected_filename)
34
        end
35
        exit result
36
      ]
37
      assert_ruby_status(%w[-EASCII-8BIT], test_file_program, nil, :chdir=>dir)
38
    }
39
  end
40

  
14 41
  ## UTF-8 default_external, no default_internal
15 42

  
16 43
  def test_filename_extutf8
......
32 59
        File.open(filename, "w") {}
33 60
        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
34 61
        ents = Dir.entries(".", opts)
35
        exit ents.include?(filename) || ((RUBY_PLATFORM =~ /darwin/) != nil && ents.include?("%FF"))
62
        exit ents.include?(filename) || (/darwin/ =~ RUBY_PLATFORM && ents.include?("%FF"))
36 63
      EOS
37 64
      assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d)
38 65
        filename = "\xff".force_encoding("UTF-8") # invalid byte sequence as UTF-8
39 66
        File.open(filename, "w") {}
40 67
        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
41 68
        ents = Dir.entries(".", opts)
42
        exit ents.include?(filename) || ((RUBY_PLATFORM =~ /darwin/) != nil && ents.include?("%FF"))
69
        exit ents.include?(filename) || (/darwin/ =~ RUBY_PLATFORM && ents.include?("%FF"))
43 70
      EOS
44 71
    }
45 72
  end unless /mswin|mingw/ =~ RUBY_PLATFORM
......
153 180
        ents = Dir.entries(".", opts)
154 181
        ents.each {|e| e.force_encoding("ASCII-8BIT") }
155 182
        exit ents.include?(filename.force_encoding("ASCII-8BIT")) ||
156
               ((RUBY_PLATFORM =~ /darwin/) != nil && ents.include?("%A4%A2".force_encoding("ASCII-8BIT")))
183
               (/darwin/ =~ RUBY_PLATFORM && ents.include?("%A4%A2".force_encoding("ASCII-8BIT")))
157 184
      EOS
158 185
    }
159 186
  end
......
165 192
        File.open(filename, "w") {}
166 193
        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
167 194
        ents = Dir.entries(".", opts)
168
        exit ents.include?(filename) || ((RUBY_PLATFORM =~ /darwin/) != nil && ents.include?("%A4%A2".force_encoding("euc-jp")))
195
        exit ents.include?(filename) || (/darwin/ =~ RUBY_PLATFORM && ents.include?("%A4%A2".force_encoding("euc-jp")))
169 196
      EOS
170 197
      assert_ruby_status(%w[-EASCII-8BIT], <<-'EOS', nil, :chdir=>d)
171
        filename = "\xA4\xA2"
198
        filename = "\xA4\xA2".force_encoding('ASCII-8BIT')
199
        win_expected_filename = filename.encode(Encoding.find("filesystem")) rescue "?"
172 200
        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
173 201
        ents = Dir.entries(".", opts)
174
        exit ents.include?(filename) ||
175
               ((RUBY_PLATFORM =~ /darwin/) != nil && ents.include?("%A4%A2".force_encoding("ASCII-8BIT"))) ||
176
               ((RUBY_PLATFORM =~ /mswin|mingw/) != nil && ents.include?("\x82\xA0".force_encoding("ASCII-8BIT")))
202
        p ents
203
        result = ents.include?(filename) ||
204
               (/darwin/ =~ RUBY_PLATFORM =~ /darwin/ && ents.include?("%A4%A2".force_encoding("ASCII-8BIT"))) ||
205
               (/mswin|mingw/ =~ RUBY_PLATFORM && ents.include?(win_expected_filename.force_encoding("ASCII-8BIT")))
206
        if !result && /mswin|mingw/ =~ RUBY_PLATFORM
207
          exit Dir.entries(".", {:encoding => Encoding.find("filesystem")}).include?(win_expected_filename)
208
        end
209
        exit result
177 210
      EOS
178 211
    }
179 212
  end
180 213

  
181
  def test_filename_utf8_raw_name
182
    with_tmpdir {|d|
183
      assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d)
184
        filename = "\u3042".force_encoding("utf-8")
185
        File.open(filename, "w") {}
186
        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
187
        ents = Dir.entries(".", opts)
188
        exit ents.include?(filename)
189
      EOS
190
      assert_ruby_status(%w[-EASCII-8BIT], <<-'EOS', nil, :chdir=>d)
191
        filename = "\u3042".force_encoding("ASCII-8BIT")
192
        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
193
        ents = Dir.entries(".", opts)
194
        exit ents.include?(filename) || ((RUBY_PLATFORM =~ /mswin|mingw/) != nil && ents.include?("\x82\xA0".force_encoding("ASCII-8BIT")))
195
      EOS
196
    }
214
  def test_filename_utf8_raw_jp_name
215
    create_and_check_raw_file_name(0x3042, "UTF-8")
216
  end
217

  
218
  def test_filename_utf8_raw_windows_1251_name
219
    create_and_check_raw_file_name(0x0424, "UTF-8")
220
  end
221

  
222
  def test_filename_utf8_raw_windows_1252_name
223
    create_and_check_raw_file_name(0x00c7, "UTF-8")
197 224
  end
198 225

  
199 226
  def test_filename_ext_euc_jp_and_int_utf_8
......
203 230
        File.open(filename, "w") {}
204 231
        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
205 232
        ents = Dir.entries(".", opts)
206
        exit ents.include?(filename) || ((RUBY_PLATFORM =~ /darwin/) != nil && ents.include?("%A4%A2".force_encoding("euc-jp")))
233
        exit ents.include?(filename) || (/darwin/ =~ RUBY_PLATFORM && ents.include?("%A4%A2".force_encoding("euc-jp")))
207 234
      EOS
208 235
      assert_ruby_status(%w[-EEUC-JP:UTF-8], <<-'EOS', nil, :chdir=>d)
209 236
        filename = "\u3042"
210 237
        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
211 238
        ents = Dir.entries(".", opts)
212
        exit ents.include?(filename) || ((RUBY_PLATFORM =~ /darwin/) != nil && ents.include?("%A4%A2"))
239
        exit ents.include?(filename) || (/darwin/ =~ RUBY_PLATFORM && ents.include?("%A4%A2"))
213 240
      EOS
214 241
    }
215 242
  end