PageRenderTime 44ms CodeModel.GetById 6ms app.highlight 35ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/bundle/jruby/2.1/gems/redis-3.0.7/test/commands_on_strings_test.rb

https://github.com/delowong/logstash
Ruby | 101 lines | 77 code | 23 blank | 1 comment | 0 complexity | 24f46faa9959d569278373a1cc344c3c MD5 | raw file
  1# encoding: UTF-8
  2
  3require File.expand_path("helper", File.dirname(__FILE__))
  4require "lint/strings"
  5
  6class TestCommandsOnStrings < Test::Unit::TestCase
  7
  8  include Helper::Client
  9  include Lint::Strings
 10
 11  def test_mget
 12    r.set("foo", "s1")
 13    r.set("bar", "s2")
 14
 15    assert_equal ["s1", "s2"]     , r.mget("foo", "bar")
 16    assert_equal ["s1", "s2", nil], r.mget("foo", "bar", "baz")
 17  end
 18
 19  def test_mget_mapped
 20    r.set("foo", "s1")
 21    r.set("bar", "s2")
 22
 23    response = r.mapped_mget("foo", "bar")
 24
 25    assert_equal "s1", response["foo"]
 26    assert_equal "s2", response["bar"]
 27
 28    response = r.mapped_mget("foo", "bar", "baz")
 29
 30    assert_equal "s1", response["foo"]
 31    assert_equal "s2", response["bar"]
 32    assert_equal nil , response["baz"]
 33  end
 34
 35  def test_mapped_mget_in_a_pipeline_returns_hash
 36    r.set("foo", "s1")
 37    r.set("bar", "s2")
 38
 39    result = r.pipelined do
 40      r.mapped_mget("foo", "bar")
 41    end
 42
 43    assert_equal result[0], { "foo" => "s1", "bar" => "s2" }
 44  end
 45
 46  def test_mset
 47    r.mset(:foo, "s1", :bar, "s2")
 48
 49    assert_equal "s1", r.get("foo")
 50    assert_equal "s2", r.get("bar")
 51  end
 52
 53  def test_mset_mapped
 54    r.mapped_mset(:foo => "s1", :bar => "s2")
 55
 56    assert_equal "s1", r.get("foo")
 57    assert_equal "s2", r.get("bar")
 58  end
 59
 60  def test_msetnx
 61    r.set("foo", "s1")
 62    assert_equal false, r.msetnx(:foo, "s2", :bar, "s3")
 63    assert_equal "s1", r.get("foo")
 64    assert_equal nil, r.get("bar")
 65
 66    r.del("foo")
 67    assert_equal true, r.msetnx(:foo, "s2", :bar, "s3")
 68    assert_equal "s2", r.get("foo")
 69    assert_equal "s3", r.get("bar")
 70  end
 71
 72  def test_msetnx_mapped
 73    r.set("foo", "s1")
 74    assert_equal false, r.mapped_msetnx(:foo => "s2", :bar => "s3")
 75    assert_equal "s1", r.get("foo")
 76    assert_equal nil, r.get("bar")
 77
 78    r.del("foo")
 79    assert_equal true, r.mapped_msetnx(:foo => "s2", :bar => "s3")
 80    assert_equal "s2", r.get("foo")
 81    assert_equal "s3", r.get("bar")
 82  end
 83
 84  def test_bitop
 85    try_encoding("UTF-8") do
 86      target_version "2.5.10" do
 87        r.set("foo", "a")
 88        r.set("bar", "b")
 89
 90        r.bitop(:and, "foo&bar", "foo", "bar")
 91        assert_equal "\x60", r.get("foo&bar")
 92        r.bitop(:or, "foo|bar", "foo", "bar")
 93        assert_equal "\x63", r.get("foo|bar")
 94        r.bitop(:xor, "foo^bar", "foo", "bar")
 95        assert_equal "\x03", r.get("foo^bar")
 96        r.bitop(:not, "~foo", "foo")
 97        assert_equal "\x9E", r.get("~foo")
 98      end
 99    end
100  end
101end