File: bitwise_operation.rb

package info (click to toggle)
ruby-fakeredis 0.8.0-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 628 kB
  • sloc: ruby: 4,868; makefile: 2
file content (59 lines) | stat: -rw-r--r-- 1,967 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
shared_examples_for "a bitwise operation" do |operator|
  it 'raises an argument error when not passed any source keys' do
    expect { @client.bitop(operator, "destkey") }.to raise_error(Redis::CommandError)
  end

  it "should not create destination key if nothing found" do
    expect(@client.bitop(operator, "dest1", "nothing_here1")).to eq(0)
    expect(@client.exists("dest1")).to eq(0)
  end

  it "should accept operator as a case-insensitive symbol" do
    @client.set("key1", "foobar")
    @client.bitop(operator.to_s.downcase.to_sym, "dest1", "key1")
    @client.bitop(operator.to_s.upcase.to_sym, "dest2", "key1")

    expect(@client.get("dest1")).to eq("foobar")
    expect(@client.get("dest2")).to eq("foobar")
  end

  it "should accept operator as a case-insensitive string" do
    @client.set("key1", "foobar")
    @client.bitop(operator.to_s.downcase, "dest1", "key1")
    @client.bitop(operator.to_s.upcase, "dest2", "key1")

    expect(@client.get("dest1")).to eq("foobar")
    expect(@client.get("dest2")).to eq("foobar")
  end

  it "should copy original string for single key" do
    @client.set("key1", "foobar")
    @client.bitop(operator, "dest1", "key1")

    expect(@client.get("dest1")).to eq("foobar")
  end

  it "should copy original string for single key" do
    @client.set("key1", "foobar")
    @client.bitop(operator, "dest1", "key1")

    expect(@client.get("dest1")).to eq("foobar")
  end

  it "should return length of the string stored in the destination key" do
    @client.set("key1", "foobar")
    @client.set("key2", "baz")

    expect(@client.bitop(operator, "dest1", "key1")).to eq(6)
    expect(@client.bitop(operator, "dest2", "key2")).to eq(3)
  end

  it "should overwrite previous value with new one" do
    @client.set("key1", "foobar")
    @client.set("key2", "baz")
    @client.bitop(operator, "dest1", "key1")
    @client.bitop(operator, "dest1", "key2")

    expect(@client.get("dest1")).to eq("baz")
  end
end