test_utf16.rb

Akio Tajima, 04/12/2013 01:15 AM

Download (643 Bytes)

 
1
require 'test/unit'
2
require 'tempfile'
3

    
4
class TestUtf16 < Test::Unit::TestCase
5
  def setup
6
    @tempfile = Tempfile.new('utf16test')
7
    @tempname = @tempfile.path
8
    @tempfile.close!
9
    File.open(@tempname, 'wb:utf-16') do |f|
10
      f.write <<EOF
11
This is not a love song.
12
This is not a love song.
13
EOF
14
    end
15
  end
16
  
17
  def teardown
18
    File.delete(@tempname)
19
  end
20
  
21
  def test_hello
22
    file = File.open(@tempname, 'rb:UTF-16LE')
23
    begin
24
      file.each_line do |line|
25
        assert_equal 'This is not a love song.', line.rstrip.encode('utf-8')
26
      end  
27
    ensure
28
      file.close
29
    end
30
  end
31
end