root/test/test_changing_encoding.rb

Revision 549:e07d72733cae, 1.0 kB (checked in by Sean Russell <ser@…>, 7 months ago)

Moved and renamed files to conform to Ruby's test suite.

Line 
1#!/usr/bin/ruby -Ku
2# -*- coding: utf-8 -*-
3
4require 'kconv'
5require 'iconv'
6require 'rexml/encoding'
7
8
9class ChangingEncodings < Test::Unit::TestCase
10  def initialize a
11    @u = 'テスト ほげ ふが 矎しい'
12    @e = Kconv.toeuc(@u)
13    @f = Foo.new
14    super
15  end
16
17  class Foo
18    include REXML::Encoding
19  end
20
21  # Note that these tests must be executed in order for the third one to
22  # actually test anything.
23  def test_0_euc
24    @f.encoding = 'EUC-JP'
25    assert_equal( @u, @f.decode(@e) )
26    # This doesn't happen anymore, for some reason
27    #assert_raises( Iconv::IllegalSequence, "Decoding unicode should fail" ) {
28    #  @f.decode(@u) == @u
29    #}
30  end
31
32  def test_1_utf
33    @f.encoding = 'UTF-8'
34    assert_not_equal( @u, @f.decode( @e ) )
35    assert_equal( @u, @f.decode( @u ) )
36  end
37
38  def test_2_euc
39    @f.encoding = 'EUC-JP'
40    assert_equal( @u, @f.decode(@e) )
41    # This doesn't happen anymore, for some reason
42    #assert_raises( Iconv::IllegalSequence, "Decoding unicode should fail" ) {
43    #  @f.decode(@u) == @u
44    #}
45  end
46end
Note: See TracBrowser for help on using the browser.