@@ -49,6 +49,26 @@ def test_class_read_file_encoding_convert
4949 assert_equal "hi \u00e9 verybody" , contents . sub ( "\r " , '' )
5050 end
5151
52+ def test_class_read_file_encoding_fail
53+ skip "Encoding not implemented" unless Object . const_defined? :Encoding
54+
55+ @tempfile . write "# coding: utf-8\n \317 \200 " # pi
56+ @tempfile . flush
57+
58+ # FIXME 1.9 fix on windoze
59+ expected . gsub! ( "\n " , "\r \n " ) if RUBY_VERSION =~ /^1.9/ && RUBY_PLATFORM =~ /mswin|mingw/
60+
61+ contents = :junk
62+
63+ _ , err = capture_io do
64+ contents = RDoc ::Encoding . read_file @tempfile . path , Encoding ::US_ASCII
65+ end
66+
67+ assert_nil contents
68+
69+ assert_match %r%^unable to convert U\+ 03C0 from UTF-8 to US-ASCII for% , err
70+ end
71+
5272 def test_class_read_file_encoding_fancy
5373 skip "Encoding not implemented" unless Object . const_defined? :Encoding
5474
@@ -66,6 +86,21 @@ def test_class_read_file_encoding_fancy
6686 assert_equal Encoding ::UTF_8 , contents . encoding
6787 end
6888
89+ def test_class_read_file_encoding_force_transcode
90+ skip "Encoding not implemented" unless Object . const_defined? :Encoding
91+
92+ @tempfile . write "# coding: utf-8\n \317 \200 " # pi
93+ @tempfile . flush
94+
95+ # FIXME 1.9 fix on windoze
96+ expected . gsub! ( "\n " , "\r \n " ) if RUBY_VERSION =~ /^1.9/ && RUBY_PLATFORM =~ /mswin|mingw/
97+
98+ contents = RDoc ::Encoding . read_file @tempfile . path , Encoding ::US_ASCII , true
99+
100+ assert_equal '?' , contents
101+ assert_equal Encoding ::US_ASCII , contents . encoding
102+ end
103+
69104 def test_class_read_file_encoding_guess
70105 skip "Encoding not implemented" unless Object . const_defined? :Encoding
71106
0 commit comments