test_io_unicode_paths.rb

new file: bootstraptest/test_io_unicode_paths.rb - B Kelly, 03/25/2010 10:13 AM

Download (925 Bytes)

 
1
# encoding: UTF-8
2

    
3
# NOTE: I've only enabled for win32 for now, but I presume
4
# these tests would also apply to other platforms with
5
# unicode paths, like Linux and OS X
6

    
7
if RUBY_PLATFORM =~ /win32/
8

    
9
assert_equal 'ok', %q{
10
  require 'tmpdir'
11
  FNAME_CHINESE = "\u52ec\u52ee\u52f1\u52f2.txt"
12
  DNAME_CHINESE = "\u52ec\u52ee\u52f1\u52f2"
13
  Dir.mkdir DNAME_CHINESE
14
  test(?d, DNAME_CHINESE) or raise "test ?d fail"
15
  fpath = File.join(DNAME_CHINESE, FNAME_CHINESE)
16
  File.open(fpath, "w") {|io| io.puts "Hello, World"}
17
  dat = File.read(fpath)
18
  ( dat == "Hello, World\n" ) or raise "fpath read fail"
19
  test(?f, fpath) or raise "test ?f fail"
20
  
21
  Dir.chdir DNAME_CHINESE
22
  cwd = Dir.pwd
23
#### FIXME: Dir.pwd is returning "Windows-1252" encoding
24
# cwd.force_encoding("UTF-8")
25
  ( cwd[(-DNAME_CHINESE.length)..-1] == DNAME_CHINESE ) or raise "cwd check fail"
26
  :ok
27
}
28

    
29
# TODO: File.unlink, File.stat, Dir.rmdir, Dir.open, ...
30

    
31
end