|
121 | 121 | expect(stream.read_partial(2)).to be == "d"
|
122 | 122 | expect(stream.read_partial(2)).to be == nil
|
123 | 123 | end
|
| 124 | + |
| 125 | + it "can read partial input with buffer" do |
| 126 | + buffer = String.new |
| 127 | + expect(stream.read_partial(2, buffer)).to be == "He" |
| 128 | + expect(buffer).to be == "He" |
| 129 | + expect(stream.read_partial(2, buffer)).to be == "ll" |
| 130 | + expect(buffer).to be == "ll" |
| 131 | + expect(stream.read_partial(2, buffer)).to be == "o" |
| 132 | + expect(buffer).to be == "o" |
| 133 | + expect(stream.read_partial(2, buffer)).to be == "Wo" |
| 134 | + expect(buffer).to be == "Wo" |
| 135 | + expect(stream.read_partial(2, buffer)).to be == "rl" |
| 136 | + expect(buffer).to be == "rl" |
| 137 | + expect(stream.read_partial(2, buffer)).to be == "d" |
| 138 | + expect(buffer).to be == "d" |
| 139 | + expect(stream.read_partial(2, buffer)).to be == nil |
| 140 | + expect(buffer).to be == "" |
| 141 | + end |
124 | 142 | end
|
125 | 143 |
|
126 | 144 | with '#readpartial' do
|
|
129 | 147 | expect(stream.readpartial(20)).to be == "World"
|
130 | 148 | expect{stream.readpartial(20)}.to raise_exception(EOFError)
|
131 | 149 | end
|
| 150 | + |
| 151 | + it "can read partial input with buffer" do |
| 152 | + buffer = String.new |
| 153 | + expect(stream.readpartial(20, buffer)).to be == "Hello" |
| 154 | + expect(buffer).to be == "Hello" |
| 155 | + expect(stream.readpartial(20, buffer)).to be == "World" |
| 156 | + expect(buffer).to be == "World" |
| 157 | + expect{stream.readpartial(20, buffer)}.to raise_exception(EOFError) |
| 158 | + expect(buffer).to be == "" |
| 159 | + end |
132 | 160 | end
|
133 | 161 |
|
134 | 162 | with '#read_until' do
|
|
224 | 252 | expect(stream).to be(:closed?)
|
225 | 253 | end
|
226 | 254 | end
|
| 255 | + |
| 256 | + with 'IO.copy_stream' do |
| 257 | + let(:output) {StringIO.new} |
| 258 | + |
| 259 | + it "can copy input to output" do |
| 260 | + ::IO.copy_stream(stream, output) |
| 261 | + |
| 262 | + expect(output.string).to be == "HelloWorld" |
| 263 | + end |
| 264 | + end |
227 | 265 | end
|
0 commit comments