test_utf16.rb

Akio Tajima, 04/11/2013 10:11 PM

Download (746 Bytes)

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

    
4
class TestUtf16 < Test::Unit::TestCase
5
  def setup
6
    p 'setup'
7
    @tempfile = Tempfile.new('utf16test')
8
    @tempname = @tempfile.path
9
    @tempfile.close!
10
    File.open(@tempname, 'wb:utf-16') do |f|
11
      f.write <<EOF
12
This is not a love song.
13
This is not a love song.
14
EOF
15
    end
16
  end
17
  
18
  def teardown
19
    p 'teardown'
20
    File.delete(@tempname)
21
  end
22
  
23
  def test_hello
24
    no_exception = true
25
    File.open(@tempname, 'rb:utf-16').each_line do |line|
26
      begin
27
        assert_equals 'This is not a love song.', line.rstrip
28
      rescue Encoding::CompatibilityError => e
29
        no_exception = false
30
      end  
31
    end.close
32
    assert no_exception
33
  end
34
end