Sha256: 767ce4a0ee41757f55dbe9a1c942216d4edd9c34dbd4ad787bf0b40941856768

Contents?: true

Size: 1.4 KB

Versions: 10

Compression:

Stored size: 1.4 KB

Contents

# -*- coding: utf-8 -*-
require 'spec_helper'

describe '#setbit(key, offset)' do
  before do
    @key = 'mock-redis-test:setbit'
    @redises.set(@key, 'h') # ASCII 0x68
  end

  it "returns the original stored bit's value" do
    @redises.setbit(@key, 0, 1).should == 0
    @redises.setbit(@key, 1, 1).should == 1
  end

  it 'sets the bit within the string' do
    @redises.setbit(@key, 7, 1)
    @redises.get(@key).should == 'i'  # ASCII 0x69
  end

  it 'unsets the bit within the string' do
    @redises.setbit(@key, 1, 0)
    @redises.get(@key).should == '('  # ASCII 0x28
  end

  it 'does the right thing with multibyte characters' do
    @redises.set(@key, '€99.94') # the euro sign is 3 bytes wide in UTF-8
    @redises.setbit(@key, 63, 1).should == 0
    @redises.get(@key).should == '€99.95'
  end

  it 'expands the string if necessary' do
    @redises.setbit(@key, 9, 1)
    @redises.get(@key).should == 'h@'
  end

  it 'sets added bits to 0' do
    @redises.setbit(@key, 17, 1)
    @redises.get(@key).should == "h\000@"
  end

  it 'treats missing keys as empty strings' do
    @redises.del(@key)
    @redises.setbit(@key, 1, 1)
    @redises.get(@key).should == '@'
  end

  it 'sets and retrieves bits' do
    @redises.setbit(@key, 22, 1)
    @redises.getbit(@key, 22).should == 1
    @redises.setbit(@key, 23, 0)
    @redises.getbit(@key, 23).should == 0
  end

  it_should_behave_like 'a string-only command'
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mock_redis-0.18.0 spec/commands/setbit_spec.rb
mock_redis-0.17.3 spec/commands/setbit_spec.rb
mock_redis-0.17.2 spec/commands/setbit_spec.rb
mock_redis-0.17.1 spec/commands/setbit_spec.rb
mock_redis-0.17.0 spec/commands/setbit_spec.rb
mock_redis-0.16.1 spec/commands/setbit_spec.rb
mock_redis-0.16.0 spec/commands/setbit_spec.rb
mock_redis-0.15.4 spec/commands/setbit_spec.rb
mock_redis-0.15.3 spec/commands/setbit_spec.rb
mock_redis-0.15.2 spec/commands/setbit_spec.rb