|
107 | 107 | rm_r @transcode_filename
|
108 | 108 | end
|
109 | 109 |
|
110 |
| - describe "transcoding when UTF-16 encoding is set" do |
111 |
| - it "accepts a UTF-8-encoded string and transcodes it" do |
112 |
| - utf8_str = "hello" |
| 110 | + it "transcodes the given string when the external encoding is set and neither is BINARY" do |
| 111 | + utf8_str = "hello" |
113 | 112 |
|
114 |
| - File.open(@transcode_filename, "w", external_encoding: Encoding::UTF_16BE) do |file| |
115 |
| - file.external_encoding.should == Encoding::UTF_16BE |
116 |
| - file.send(@method, utf8_str) |
117 |
| - end |
| 113 | + File.open(@transcode_filename, "w", external_encoding: Encoding::UTF_16BE) do |file| |
| 114 | + file.external_encoding.should == Encoding::UTF_16BE |
| 115 | + file.send(@method, utf8_str) |
| 116 | + end |
118 | 117 |
|
119 |
| - result = File.binread(@transcode_filename) |
120 |
| - expected = [0, 104, 0, 101, 0, 108, 0, 108, 0, 111] # double-width "hello" |
| 118 | + result = File.binread(@transcode_filename) |
| 119 | + expected = [0, 104, 0, 101, 0, 108, 0, 108, 0, 111] # UTF-16BE bytes for "hello" |
121 | 120 |
|
122 |
| - result.bytes.should == expected |
123 |
| - end |
| 121 | + result.bytes.should == expected |
124 | 122 | end
|
125 | 123 | end
|
126 | 124 |
|
|
133 | 131 | rm_r @transcode_filename
|
134 | 132 | end
|
135 | 133 |
|
136 |
| - describe "transcoding when UTF-16 encoding is set" do |
137 |
| - it "accepts a UTF-8-encoded string and transcodes it" do |
138 |
| - utf8_str = "hello" |
| 134 | + it "does not transcode the given string even when the external encoding is set" do |
| 135 | + utf8_str = "hello" |
139 | 136 |
|
140 |
| - File.open(@transcode_filename, "w", external_encoding: Encoding::UTF_16BE) do |file| |
141 |
| - file.external_encoding.should == Encoding::UTF_16BE |
142 |
| - file.send(@method, utf8_str) |
143 |
| - end |
| 137 | + File.open(@transcode_filename, "w", external_encoding: Encoding::UTF_16BE) do |file| |
| 138 | + file.external_encoding.should == Encoding::UTF_16BE |
| 139 | + file.send(@method, utf8_str) |
| 140 | + end |
144 | 141 |
|
145 |
| - result = File.binread(@transcode_filename) |
146 |
| - expected = [104, 101, 108, 108, 111] # not transcoded to UTF-16BE |
| 142 | + result = File.binread(@transcode_filename) |
| 143 | + expected = [104, 101, 108, 108, 111] # UTF-8 bytes for "hello", not transcoded to UTF-16BE |
147 | 144 |
|
148 |
| - result.bytes.should == expected |
149 |
| - end |
| 145 | + result.bytes.should == expected |
150 | 146 | end
|
151 | 147 | end
|
0 commit comments