Sha256: ae3b6a5effe853f678d7b8f42aa2a62315b835aee2971fefea79d4a27076671b
Contents?: true
Size: 1.14 KB
Versions: 4
Compression:
Stored size: 1.14 KB
Contents
require 'spec_helper' require 'berkeley_library/util/stringios' module BerkeleyLibrary module Util describe StringIOs do describe :getbyte do let(:s) { '祇園精舎の鐘の声、諸行無常の響きあり。' } let(:bytes) { s.bytes } let(:sio) { StringIO.new(s) } it 'gets the byte at the specified byte index' do bytes.each_with_index do |b, i| expect(StringIOs.getbyte(sio, i)).to eq(b) end end it 'reads from the end if given a negative index' do bytes.reverse.each_with_index do |b, i| end_offset = i + 1 expect(StringIOs.getbyte(sio, -end_offset)).to eq(b) end end it 'resets the current offset' do StringIOs.getbyte(sio, bytes.size / 2) expect(sio.pos).to eq(0) end it 'returns nil for a too-large positive offset' do expect(StringIOs.getbyte(s, bytes.size)).to be_nil end it 'returns nil for a too-large negative offset' do expect(StringIOs.getbyte(s, -(1 + bytes.size))).to be_nil end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems