File tree Expand file tree Collapse file tree 2 files changed +34
-5
lines changed
spec/ruby/library/stringio Expand file tree Collapse file tree 2 files changed +34
-5
lines changed Original file line number Diff line number Diff line change 167
167
io . should equal ( ret )
168
168
end
169
169
170
- it "sets the mode to read-write" do
170
+ it "sets the mode to read-write (r+) " do
171
171
io = StringIO . open ( "example" )
172
172
io . closed_read? . should be_false
173
173
io . closed_write? . should be_false
174
+
175
+ io = StringIO . new ( "example" )
176
+ io . printf ( "%d" , 123 )
177
+ io . string . should == "123mple"
174
178
end
175
179
176
180
it "tries to convert the passed Object to a String using #to_str" do
195
199
io . should equal ( ret )
196
200
end
197
201
198
- it "sets the mode to read-write" do
202
+ it "sets the mode to read-write (r+) " do
199
203
io = StringIO . open
200
204
io . closed_read? . should be_false
201
205
io . closed_write? . should be_false
206
+
207
+ io = StringIO . new ( "example" )
208
+ io . printf ( "%d" , 123 )
209
+ io . string . should == "123mple"
202
210
end
203
211
204
212
it "uses an empty String as the StringIO backend" do
Original file line number Diff line number Diff line change 4
4
5
5
describe "StringIO#printf" do
6
6
before :each do
7
- @io = StringIO . new ( 'example' )
7
+ @io = StringIO . new ( )
8
8
end
9
9
10
10
it "returns nil" do
11
11
@io . printf ( "%d %04x" , 123 , 123 ) . should be_nil
12
12
end
13
13
14
14
it "pads self with \\ 000 when the current position is after the end" do
15
- @io . pos = 10
15
+ @io . pos = 3
16
16
@io . printf ( "%d" , 123 )
17
- @io . string . should == "example \000 \000 \000 123"
17
+ @io . string . should == "\000 \000 \000 123"
18
18
end
19
19
20
20
it "performs format conversion" do
39
39
end
40
40
end
41
41
42
+ describe "StringIO#printf when in read-write mode" do
43
+ before :each do
44
+ @io = StringIO . new ( "example" , "r+" )
45
+ end
46
+
47
+ it "starts from the beginning" do
48
+ @io . printf ( "%s" , "abcdefghijk" )
49
+ @io . string . should == "abcdefghijk"
50
+ end
51
+
52
+ it "does not truncate existing string" do
53
+ @io . printf ( "%s" , "abc" )
54
+ @io . string . should == "abcmple"
55
+ end
56
+
57
+ it "correctly updates self's position" do
58
+ @io . printf ( "%s" , "abc" )
59
+ @io . pos . should eql ( 3 )
60
+ end
61
+ end
62
+
42
63
describe "StringIO#printf when in append mode" do
43
64
before :each do
44
65
@io = StringIO . new ( "example" , "a" )
You can’t perform that action at this time.
0 commit comments