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