Class: ZipUnicodeFileNamesAndComments

Inherits:
MiniTest::Test
  • Object
show all
Defined in:
lib/hotplate/gems/rubyzip-1.1.7/test/unicode_file_names_and_comments_test.rb

Constant Summary collapse

FILENAME =
File.join(File.dirname(__FILE__), "test1.zip")

Instance Method Summary collapse

Instance Method Details

#test_unicode_commentObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/unicode_file_names_and_comments_test.rb', line 40

def test_unicode_comment
  str = '渠道升级'
  ::Zip::File.open(FILENAME, Zip::File::CREATE) do |z|
    z.comment = str
  end

  ::Zip::File.open(FILENAME) do |z|
    assert(z.comment.force_encoding('UTF-8') == str)
  end
  ::File.unlink(FILENAME)
end

#test_unicode_file_nameObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/unicode_file_names_and_comments_test.rb', line 9

def test_unicode_file_name
  file_entrys = ["текстовыйфайл.txt", "Résumé.txt", "슬레이어스휘.txt"]
  directory_entrys = ["папка/текстовыйфайл.txt", "Résumé/Résumé.txt", "슬레이어스휘/슬레이어스휘.txt"]
  stream = ::Zip::OutputStream.open(FILENAME) do |io|
    file_entrys.each do |filename|
      io.put_next_entry(filename)
      io.write(filename)
    end
    directory_entrys.each do |filepath|
      io.put_next_entry(filepath)
      io.write(filepath)
    end
  end
  assert(!stream.nil?)
  ::Zip::InputStream.open(FILENAME) do |io|
    file_entrys.each do |filename|
      entry = io.get_next_entry
      entry_name = entry.name
      entry_name = entry_name.force_encoding("UTF-8")
      assert(filename == entry_name)
    end
    directory_entrys.each do |filepath|
      entry = io.get_next_entry
      entry_name = entry.name
      entry_name = entry_name.force_encoding("UTF-8")
      assert(filepath == entry_name)
    end
  end
  ::File.unlink(FILENAME)
end