Skip to content

Commit 1274c02

Browse files
committed
Move spec to shared spec since it applies for StringIO#{write_nonblock,syswrite} too
1 parent 7c3e302 commit 1274c02

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

spec/ruby/library/stringio/shared/write.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,25 @@
8888
@io.write "fghi"
8989
@io.string.should == "12fghi"
9090
end
91+
92+
describe "transcoding" do
93+
describe "when UTF-16 encoding is set" do
94+
it "accepts a UTF-8-encoded string and transcodes it" do
95+
io = StringIO.new.set_encoding(Encoding::UTF_16BE)
96+
utf8_str = "hello"
97+
98+
io.send(@method, utf8_str)
99+
100+
result = io.string
101+
expected = [
102+
0, 104, 0, 101, 0, 108, 0, 108, 0, 111, # double-width "hello"
103+
]
104+
105+
io.external_encoding.should == Encoding::UTF_16BE
106+
result.bytes.should == expected
107+
end
108+
end
109+
end
91110
end
92111

93112
describe :stringio_write_not_writable, shared: true do

spec/ruby/library/stringio/write_spec.rb

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,3 @@
1717
describe "StringIO#write when in append mode" do
1818
it_behaves_like :stringio_write_append, :write
1919
end
20-
21-
describe "StringIO#write transcoding" do
22-
describe "when UTF-16 encoding is set" do
23-
it "accepts a UTF-8-encoded string and transcodes it" do
24-
io = StringIO.new.set_encoding(Encoding::UTF_16BE)
25-
utf8_str = "hello"
26-
27-
io.write(utf8_str)
28-
29-
result = io.string
30-
expected = [
31-
0, 104, 0, 101, 0, 108, 0, 108, 0, 111, # double-width "hello"
32-
]
33-
34-
io.external_encoding.should == Encoding::UTF_16BE
35-
result.bytes.should == expected
36-
end
37-
end
38-
end

0 commit comments

Comments
 (0)