Sha256: 728dda37ff09ab60f6bb042352ca11a8b5391fa666371c25c6fceaeccf69db68

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

require_relative '../spec_helper'

describe ZipTricks::WriteAndTell do
  it 'maintains the count of bytes written' do
    adapter = described_class.new('')
    expect(adapter.tell).to be_zero
    
    adapter << 'hello'
    adapter << ''
    adapter << '!'
    expect(adapter.tell).to eq(6)
  end
  
  it 'is able to write frozen String objects in different encodings, converting them to binary' do
    strs = [
      [12, 123, 0, 3].pack("C*"),
      "текста кусок",
      "текста замороженный кусок".freeze,
      [12, 123, 0, 3].pack("C*"),
    ]
    
    buf = 'превед'.force_encoding(Encoding::BINARY)
    writer = described_class.new(buf)
    strs.each {|s| writer << s }
    expect(writer.tell).to eq(79)
    expect(buf.bytesize).to eq(91) # It already contained some bytes
  end
  
  it 'advances the internal pointer using advance_position_by' do
    str = ''
    
    adapter = described_class.new(str)
    expect(adapter.tell).to be_zero
    
    adapter << 'hello'
    adapter << ''
    adapter << '!'
    expect(adapter.tell).to eq(6)
    adapter.advance_position_by(128981)
    expect(adapter.tell).to eq(6 + 128981)
    expect(str).to eq('hello!')
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
zip_tricks-2.6.0 spec/zip_tricks/write_and_tell_spec.rb
zip_tricks-2.5.0 spec/zip_tricks/write_and_tell_spec.rb