Sha256: e2bc2b4a00059ca5f6912b4fb0337c8b18519dfb7966b2334fd5051d6f82e30d

Contents?: true

Size: 1.46 KB

Versions: 11

Compression:

Stored size: 1.46 KB

Contents

require_relative "helper"

scope do
  setup do
    redis = Redic.new
    redis.call("FLUSHDB")

    nido = Nido.new("User:tmp")

    [1, 2, 3].each { |i| redis.call("SADD", "A", i) }
    [1, 4, 5].each { |i| redis.call("SADD", "B", i) }

    [10, 11, 12].each { |i| redis.call("SADD", "C", i) }
    [11, 12, 13].each { |i| redis.call("SADD", "D", i) }
    [12, 13, 14].each { |i| redis.call("SADD", "E", i) }

    [10, 11, 12].each { |i| redis.call("SADD", "F", i) }
    [11, 12, 13].each { |i| redis.call("SADD", "G", i) }
    [12, 13, 14].each { |i| redis.call("SADD", "H", i) }

    [redis, nido]
  end

  test "special condition: single argument returns that arg" do
    assert_equal "A", Ohm::Command[:sinterstore, "A"]
  end

  test "full stack test"  do |redis, nido|
    cmd1 = Ohm::Command[:sinterstore, "A", "B"]

    res = cmd1.call(nido, redis)
    assert_equal ["1"], redis.call("SMEMBERS", res)

    cmd1.clean
    assert_equal 0, redis.call("EXISTS", res)

    cmd2 = Ohm::Command[:sinterstore, "C", "D", "E"]
    cmd3 = Ohm::Command[:sunionstore, cmd1, cmd2]

    res = cmd3.call(nido, redis)
    assert_equal ["1", "12"], redis.call("SMEMBERS", res)

    cmd3.clean
    assert redis.call("KEYS", nido["*"]).empty?

    cmd4 = Ohm::Command[:sinterstore, "F", "G", "H"]
    cmd5 = Ohm::Command[:sdiffstore, cmd3, cmd4]

    res = cmd5.call(nido, redis)
    assert_equal ["1"], redis.call("SMEMBERS", res)

    cmd5.clean
    assert redis.call("KEYS", nido["*"]).empty?
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
sohm-0.0.1 test/command.rb
ohm-2.1.0 test/command.rb
ohm-2.0.1 test/command.rb
ohm-2.0.0 test/command.rb
ohm-2.0.0.rc2 test/command.rb
ohm-2.0.0.rc1 test/command.rb
ohm-2.0.0.alpha5 test/command.rb
ohm-2.0.0.alpha4 test/command.rb
ohm-2.0.0.alpha3 test/command.rb
ohm-2.0.0.alpha2 test/command.rb
ohm-2.0.0.alpha1 test/command.rb