redislike 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +5 -0
  3. data/lib/redislike/lists.rb +2 -0
  4. data/redislike.gemspec +1 -1
  5. data/tests/compatibility/helpers/compatibility.rb +11 -0
  6. data/tests/compatibility/redislike/lists/lindex.rb +29 -0
  7. data/tests/compatibility/redislike/lists/linsert.rb +30 -0
  8. data/tests/compatibility/redislike/lists/llen.rb +24 -0
  9. data/tests/compatibility/redislike/lists/lpop.rb +24 -0
  10. data/tests/compatibility/redislike/lists/lpush.rb +23 -0
  11. data/tests/compatibility/redislike/lists/lpushx.rb +23 -0
  12. data/tests/compatibility/redislike/lists/lrange.rb +31 -0
  13. data/tests/compatibility/redislike/lists/lrem.rb +59 -0
  14. data/tests/compatibility/redislike/lists/lset.rb +20 -0
  15. data/tests/compatibility/redislike/lists/ltrim.rb +24 -0
  16. data/tests/compatibility/redislike/lists/rpop.rb +25 -0
  17. data/tests/compatibility/redislike/lists/rpoplpush.rb +24 -0
  18. data/tests/compatibility/redislike/lists/rpush.rb +24 -0
  19. data/tests/compatibility/redislike/lists/rpushx.rb +25 -0
  20. data/tests/compatibility/redislike/lists.rb +14 -0
  21. data/tests/compatibility/redislike.rb +12 -0
  22. data/tests/redislike/lists/lindex.rb +33 -0
  23. data/tests/redislike/lists/linsert.rb +38 -0
  24. data/tests/redislike/lists/llen.rb +18 -0
  25. data/tests/redislike/lists/lpop.rb +25 -0
  26. data/tests/redislike/lists/lpush.rb +28 -0
  27. data/tests/redislike/lists/lpushx.rb +28 -0
  28. data/tests/redislike/lists/lrange.rb +45 -0
  29. data/tests/redislike/lists/lset.rb +34 -0
  30. data/tests/redislike/lists/rpop.rb +25 -0
  31. data/tests/redislike/lists/rpoplpush.rb +38 -0
  32. data/tests/redislike/lists/rpush.rb +28 -0
  33. data/tests/redislike/lists/rpushx.rb +28 -0
  34. data/tests/redislike/lists.rb +12 -255
  35. data/tests/redislike.rb +1 -2
  36. metadata +31 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b32d60e77c8f6e9fc89a7df48aa4f8229564c66e
4
- data.tar.gz: ce5b4dcdafb32682ac78350970cbbedd6ccca032
3
+ metadata.gz: be9073ce31c76bc2fe4b3395ea7118953d792c7b
4
+ data.tar.gz: 83f2fb7b888471aac831d9bed7ec2ac0a040c00e
5
5
  SHA512:
6
- metadata.gz: ae5c0c559385cf9e46394631629f942b2bd4c5da4b9b9208d3d5ab13ad030b55fc65325b847cadb24cdf74d3bbc48bfbda23555dcb933e9addfbd468174b3b9a
7
- data.tar.gz: 9e0bade973bb81c47130e8ba41975b4798d9ece654d338dda1c627ef23c071aa5e946842e59776797fabc5242c51ca3b266b8ee385f54609f3ba2b18902d385e
6
+ metadata.gz: 5f208e78072393e3f78831956a921fec73994e6f1761b1043c7ae6d47d272e9d8265e568ecffb368370fa36deb6b3ca161eb7eeb990a54df4daa23a94c3cf89f
7
+ data.tar.gz: 63531c739bd0928a9e8e201147817b80014822b88a8c39e7c91bca6a5f9cc9e46247bc6de15dc10ecc1f2feb4aee4086c1f5c2bf99bcd32013c28e7260dd0f3d
data/Rakefile CHANGED
@@ -13,6 +13,11 @@ task :kintama do
13
13
  sh 'ruby tests/redislike.rb'
14
14
  end
15
15
 
16
+ desc 'Verify Compatibility with Redis'
17
+ task :compatibility do
18
+ sh 'ruby tests/compatibility/redislike.rb'
19
+ end
20
+
16
21
  task audit: [:style, :complexity, :duplication, :design, :documentation]
17
22
 
18
23
  task style: [:rubocop]
@@ -73,6 +73,8 @@ module RedisLike
73
73
  end
74
74
 
75
75
  def lset(list, index, item)
76
+ fail KeyError, 'ERR no such key' unless exists(list)
77
+ fail IndexError, 'ERR index out of range' unless lindex(list, index)
76
78
  items = fetch list, []
77
79
  items[index] = item
78
80
  'OK' if store list, items
data/redislike.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'redislike'
3
- gem.version = '0.1.0'
3
+ gem.version = '0.2.0'
4
4
  gem.licenses = 'MIT'
5
5
  gem.authors = ['Chris Olstrom']
6
6
  gem.email = 'chris@olstrom.com'
@@ -0,0 +1,11 @@
1
+ module CompatibilityTesting
2
+ def mirror(method, *arguments)
3
+ original = @original.method(method).call(*arguments)
4
+ compatible = @compatible.method(method).call(*arguments)
5
+ [original, compatible]
6
+ end
7
+
8
+ def assert_compatible(method, *arguments)
9
+ assert_equal(*mirror(method, *arguments))
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ context 'LINDEX' do
2
+ include CompatibilityTesting
3
+
4
+ setup do
5
+ @original = Redis.new
6
+ @compatible = Moneta.new :Memory
7
+ mirror :lpush, 'test:lindex', 'foo'
8
+ mirror :lpush, 'test:lindex', 'bar'
9
+ mirror :lpush, 'test:lindex', 'baz'
10
+ end
11
+
12
+ test 'when list does not exist' do
13
+ assert_compatible :lindex, 'test:nx', 1
14
+ end
15
+
16
+ test 'in range' do
17
+ assert_compatible :lindex, 'test:lindex', 1
18
+ end
19
+
20
+ test 'out of range' do
21
+ assert_compatible :lindex, 'test:lindex', 999
22
+ end
23
+
24
+ teardown do
25
+ @original.del 'test:lindex'
26
+ @original.disconnect!
27
+ @compatible.close
28
+ end
29
+ end
@@ -0,0 +1,30 @@
1
+ context 'LINSERT' do
2
+ include CompatibilityTesting
3
+
4
+ setup do
5
+ @original = Redis.new
6
+ @compatible = Moneta.new :Memory
7
+ mirror :lpush, 'test:linsert', 'foo'
8
+ end
9
+
10
+ test 'when list does not exist' do
11
+ assert_compatible :linsert, 'test:nx', :before, 'foo', 'bar'
12
+ assert_compatible :linsert, 'test:nx', :after, 'foo', 'bar'
13
+ end
14
+
15
+ test 'when list contains pivot value' do
16
+ assert_compatible :linsert, 'test:linsert', :before, 'foo', 'bar'
17
+ assert_compatible :linsert, 'test:linsert', :after, 'foo', 'bar'
18
+ end
19
+
20
+ test 'when list does not contain pivot value' do
21
+ assert_compatible :linsert, 'test:linsert', :before, 'baz', 'bar'
22
+ assert_compatible :linsert, 'test:linsert', :after, 'baz', 'bar'
23
+ end
24
+
25
+ teardown do
26
+ @original.del 'test:linsert', 'test:nx'
27
+ @original.disconnect!
28
+ @compatible.close
29
+ end
30
+ end
@@ -0,0 +1,24 @@
1
+ context 'LLEN' do
2
+ include CompatibilityTesting
3
+
4
+ setup do
5
+ @original = Redis.new
6
+ @compatible = Moneta.new :Memory
7
+ mirror :lpush, 'test:llen', 'foo'
8
+ end
9
+
10
+ test 'when list does not exist' do
11
+ assert_compatible :llen, 'test:nx'
12
+ end
13
+
14
+ test 'when list exists' do
15
+ mirror :lpush, 'test:llen', 'foo'
16
+ assert_compatible :llen, 'test:llen'
17
+ end
18
+
19
+ teardown do
20
+ @original.del 'test:llen'
21
+ @original.disconnect!
22
+ @compatible.close
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ context 'LPOP' do
2
+ include CompatibilityTesting
3
+
4
+ setup do
5
+ @original = Redis.new
6
+ @compatible = Moneta.new :Memory
7
+ mirror :lpush, 'test:lpop', 'foo'
8
+ end
9
+
10
+ test 'when list does not exist' do
11
+ assert_compatible :lpop, 'test:nx'
12
+ end
13
+
14
+ test 'when list exists' do
15
+ mirror :lpush, 'test:lpop', 'foo'
16
+ assert_compatible :lpop, 'test:nx'
17
+ end
18
+
19
+ teardown do
20
+ @original.del 'test:lpop'
21
+ @original.disconnect!
22
+ @compatible.close
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ context 'LPUSH' do
2
+ include CompatibilityTesting
3
+
4
+ setup do
5
+ @original = Redis.new
6
+ @compatible = Moneta.new :Memory
7
+ mirror :lpush, 'test:lpush', 'foo'
8
+ end
9
+
10
+ test 'when list does not exist' do
11
+ assert_compatible :lpush, 'test:nx', 'foo'
12
+ end
13
+
14
+ test 'when list has items already' do
15
+ assert_compatible :lpush, 'test:lpush', 'foo'
16
+ end
17
+
18
+ teardown do
19
+ @original.del 'test:lpush', 'test:nx'
20
+ @original.disconnect!
21
+ @compatible.close
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ context 'LPUSHX' do
2
+ include CompatibilityTesting
3
+
4
+ setup do
5
+ @original = Redis.new
6
+ @compatible = Moneta.new :Memory
7
+ mirror :lpush, 'test:lpushx', 'foo'
8
+ end
9
+
10
+ test 'when list does not exist' do
11
+ assert_compatible :lpushx, 'test:nx', 'foo'
12
+ end
13
+
14
+ test 'when list has items already' do
15
+ assert_compatible :lpushx, 'test:lpushx', 'foo'
16
+ end
17
+
18
+ teardown do
19
+ @original.del 'test:lpushx', 'test:nx'
20
+ @original.disconnect!
21
+ @compatible.close
22
+ end
23
+ end
@@ -0,0 +1,31 @@
1
+ context 'LRANGE' do
2
+ include CompatibilityTesting
3
+
4
+ setup do
5
+ @original = Redis.new
6
+ @compatible = Moneta.new :Memory
7
+ mirror :lpush, 'test:lrange', 'foo'
8
+ end
9
+
10
+ test 'when list does not exist' do
11
+ assert_compatible :lrange, 'test:nx', 0, -1
12
+ end
13
+
14
+ test 'when list exists' do
15
+ assert_compatible :lrange, 'test:lrange', 0, -1
16
+ end
17
+
18
+ test 'stop beyond range' do
19
+ assert_compatible :lrange, 'test:lrange', 0, 9
20
+ end
21
+
22
+ test 'stop before start' do
23
+ assert_compatible :lrange, 'test:lrange', -1, 1
24
+ end
25
+
26
+ teardown do
27
+ @original.del 'test:lrange'
28
+ @original.disconnect!
29
+ @compatible.close
30
+ end
31
+ end
@@ -0,0 +1,59 @@
1
+ context 'LREM' do
2
+ include CompatibilityTesting
3
+
4
+ setup do
5
+ @original = Redis.new
6
+ @compatible = Moneta.new :Memory
7
+ 3.times { mirror :lpush, 'test:lrem', 'foo' }
8
+ end
9
+
10
+ test 'when list does not exist' do
11
+ assert_compatible :lrem, 'test:nx', 0, 'foo'
12
+ end
13
+
14
+ test 'all items (present)' do
15
+ assert_compatible :lrem, 'test:lrem', 0, 'foo'
16
+ end
17
+
18
+ test 'all items (when not present)' do
19
+ assert_compatible :lrem, 'test:lrem', 0, 'bar'
20
+ end
21
+
22
+ test 'one from head (present)' do
23
+ assert_compatible :lrem, 'test:lrem', 1, 'foo'
24
+ end
25
+
26
+ test 'one from head (when not present)' do
27
+ assert_compatible :lrem, 'test:lrem', 1, 'bar'
28
+ end
29
+
30
+ test 'more than exists from head (present)' do
31
+ assert_compatible :lrem, 'test:lrem', 9, 'foo'
32
+ end
33
+
34
+ test 'more than exists from head (when not present)' do
35
+ assert_compatible :lrem, 'test:lrem', 9, 'bar'
36
+ end
37
+
38
+ test 'one from tail (present)' do
39
+ assert_compatible :lrem, 'test:lrem', -1, 'foo'
40
+ end
41
+
42
+ test 'one from tail (when not present)' do
43
+ assert_compatible :lrem, 'test:lrem', -1, 'bar'
44
+ end
45
+
46
+ test 'more than exists from tail (present)' do
47
+ assert_compatible :lrem, 'test:lrem', -9, 'foo'
48
+ end
49
+
50
+ test 'more than exists from tail (when not present)' do
51
+ assert_compatible :lrem, 'test:lrem', -9, 'bar'
52
+ end
53
+
54
+ teardown do
55
+ @original.del 'test:lrem'
56
+ @original.disconnect!
57
+ @compatible.close
58
+ end
59
+ end
@@ -0,0 +1,20 @@
1
+ context 'LSET' do
2
+ include CompatibilityTesting
3
+
4
+ setup do
5
+ @original = Redis.new
6
+ @compatible = Moneta.new :Memory
7
+ 3.times { mirror :lpush, 'test:lset', 'foo' }
8
+ end
9
+
10
+ test 'in range' do
11
+ assert_compatible :lset, 'test:lset', 1, 'bar'
12
+ assert_equal mirror(:lindex, 'test:lset', 1).uniq, ['bar']
13
+ end
14
+
15
+ teardown do
16
+ @original.del 'test:lset'
17
+ @original.disconnect!
18
+ @compatible.close
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ context 'LTRIM' do
2
+ include CompatibilityTesting
3
+
4
+ setup do
5
+ @original = Redis.new
6
+ @compatible = Moneta.new :Memory
7
+ 100.times { mirror :lpush, 'test:ltrim', 'foo' }
8
+ end
9
+
10
+ test 'when list does not exist' do
11
+ assert_compatible :ltrim, 'test:nx', 0, 10
12
+ end
13
+
14
+ test 'when range is larger than list length' do
15
+ assert_compatible :ltrim, 'test:ltrim', 0, 200
16
+ assert_equal mirror(:lrange, 'test:ltrim', 0, -1).uniq.flatten.size, 100
17
+ end
18
+
19
+ teardown do
20
+ @original.del 'test:ltrim'
21
+ @original.disconnect!
22
+ @compatible.close
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ context 'RPOP' do
2
+ include CompatibilityTesting
3
+
4
+ setup do
5
+ @original = Redis.new
6
+ @compatible = Moneta.new :Memory
7
+ mirror :lpush, 'test:rpop', 'foo'
8
+ end
9
+
10
+ test 'when list does not exist' do
11
+ assert_compatible :rpop, 'test:nx'
12
+ end
13
+
14
+ test 'when list exists' do
15
+ mirror :rpush, 'test', 'foo'
16
+ assert_compatible :rpop, 'test:rpop'
17
+ end
18
+
19
+
20
+ teardown do
21
+ @original.del 'test:rpop'
22
+ @original.disconnect!
23
+ @compatible.close
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ context 'RPOPLPUSH' do
2
+ include CompatibilityTesting
3
+
4
+ setup do
5
+ @original = Redis.new
6
+ @compatible = Moneta.new :Memory
7
+ mirror :lpush, 'test:rpoplpush', 'foo'
8
+ end
9
+
10
+ test 'when source list does not exist' do
11
+ assert_compatible :rpoplpush, 'test:nx', 'test:rpoplpush:a'
12
+ end
13
+
14
+ test 'when list exists' do
15
+ 3.times { mirror :lpush, 'test:rpoplpush:a', 'foo' }
16
+ assert_compatible :rpoplpush, 'test:rpoplpush:a', 'test:rpoplpush:b'
17
+ end
18
+
19
+ teardown do
20
+ @original.del 'test:rpoplpush:a', 'test:rpoplpush:b'
21
+ @original.disconnect!
22
+ @compatible.close
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ context 'RPUSH' do
2
+ include CompatibilityTesting
3
+
4
+ setup do
5
+ @original = Redis.new
6
+ @compatible = Moneta.new :Memory
7
+ mirror :lpush, 'test:rpush', 'foo'
8
+ end
9
+
10
+ test 'when list does not exist' do
11
+ assert_compatible :rpush, 'test:nx', 'foo'
12
+ end
13
+
14
+ test 'when list has items already' do
15
+ mirror :lpush, 'test:rpush', 'foo'
16
+ assert_compatible :rpush, 'test:rpush', 'foo'
17
+ end
18
+
19
+ teardown do
20
+ @original.del 'test:rpush', 'test:nx'
21
+ @original.disconnect!
22
+ @compatible.close
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ context 'RPUSHX' do
2
+ include CompatibilityTesting
3
+
4
+ setup do
5
+ @original = Redis.new
6
+ @compatible = Moneta.new :Memory
7
+ mirror :lpush, 'test:rpushx', 'foo'
8
+ end
9
+
10
+ test 'when list does not exist' do
11
+ assert_compatible :rpushx, 'test:nx', 'foo'
12
+ end
13
+
14
+ test 'when list has items already' do
15
+ mirror :lpush, 'test:rpushx', 'foo'
16
+ assert_compatible :rpushx, 'test:rpushx', 'foo'
17
+ end
18
+
19
+
20
+ teardown do
21
+ @original.del 'test:rpushx', 'test:nx'
22
+ @original.disconnect!
23
+ @compatible.close
24
+ end
25
+ end
@@ -0,0 +1,14 @@
1
+ require_relative 'lists/lindex'
2
+ require_relative 'lists/linsert'
3
+ require_relative 'lists/llen'
4
+ require_relative 'lists/lpop'
5
+ require_relative 'lists/lpush'
6
+ require_relative 'lists/lpushx'
7
+ require_relative 'lists/lrange'
8
+ require_relative 'lists/lrem'
9
+ require_relative 'lists/lset'
10
+ require_relative 'lists/ltrim'
11
+ require_relative 'lists/rpop'
12
+ require_relative 'lists/rpoplpush'
13
+ require_relative 'lists/rpush'
14
+ require_relative 'lists/rpushx'
@@ -0,0 +1,12 @@
1
+
2
+ require 'bundler/setup'
3
+ require 'simplecov'
4
+ SimpleCov.command_name 'Kintama'
5
+ SimpleCov.start { add_filter '/vendor/' }
6
+ require 'redis'
7
+ require 'kintama'
8
+ require 'moneta'
9
+ require 'redislike'
10
+
11
+ require_relative 'helpers/compatibility'
12
+ require_relative 'redislike/lists'
@@ -0,0 +1,33 @@
1
+ context 'LINDEX' do
2
+ setup do
3
+ @db = Moneta.new :Memory
4
+ end
5
+
6
+ given 'an empty list' do
7
+ should 'return nothing' do
8
+ assert_equal nil, @db.lindex('test:nx', 1)
9
+ end
10
+ end
11
+
12
+ given 'a list with 3 items' do
13
+ setup do
14
+ @db.lpush 'test:lindex', 'foo'
15
+ @db.lpush 'test:lindex', 'bar'
16
+ @db.lpush 'test:lindex', 'baz'
17
+ end
18
+
19
+ context 'a request for an index within range' do
20
+ should 'return the item at that index' do
21
+ assert_equal 'bar', @db.lindex('test:lindex', 1)
22
+ end
23
+ end
24
+
25
+ context 'a request for an index out of range' do
26
+ should 'return nothing' do
27
+ assert_equal nil, @db.lindex('test:lindex', 999)
28
+ end
29
+ end
30
+ end
31
+
32
+ teardown { @db.close }
33
+ end
@@ -0,0 +1,38 @@
1
+ context 'LINSERT' do
2
+ setup do
3
+ @db = Moneta.new :Memory
4
+ @db.lpush 'test:linsert', 'foo'
5
+ end
6
+
7
+ context 'inserting before a pivot value' do
8
+ test 'when list does not exist' do
9
+ assert_equal 0, @db.linsert('test:nx', :before, 'foo', 'bar')
10
+ end
11
+
12
+ test 'when pivot is present' do
13
+ assert_equal 2, @db.linsert('test:linsert', :before, 'foo', 'bar')
14
+ assert @db.lrange('test:linsert', 0, -1).include? 'bar'
15
+ end
16
+
17
+ test 'when pivot is not present' do
18
+ assert_equal -1, @db.linsert('test:linsert', :before, 'baz', 'bar')
19
+ end
20
+ end
21
+
22
+ context 'inserting after a pivot' do
23
+ test 'when list does not exist' do
24
+ assert_equal 0, @db.linsert('test:nx', :after, 'foo', 'bar')
25
+ end
26
+
27
+ test 'when pivot is present' do
28
+ assert_equal 2, @db.linsert('test:linsert', :after, 'foo', 'bar')
29
+ assert @db.lrange('test:linsert', 0, -1).include? 'bar'
30
+ end
31
+
32
+ test 'when pivot is not present' do
33
+ assert_equal -1, @db.linsert('test:linsert', :after, 'baz', 'bar')
34
+ end
35
+ end
36
+
37
+ teardown { @db.close }
38
+ end
@@ -0,0 +1,18 @@
1
+ context 'LLEN' do
2
+ setup do
3
+ @db = Moneta.new :Memory
4
+ @db.lpush 'test:llen', 'foo'
5
+ end
6
+
7
+ test 'when list does not exist' do
8
+ assert_equal 0, @db.llen('test:nx')
9
+ end
10
+
11
+ test 'when list exists' do
12
+ assert_equal 1, @db.llen('test:llen')
13
+ @db.lpush 'test:llen', 'bar'
14
+ assert_equal 2, @db.llen('test:llen')
15
+ end
16
+
17
+ teardown { @db.close }
18
+ end
@@ -0,0 +1,25 @@
1
+ context 'LPOP' do
2
+ setup do
3
+ @db = Moneta.new :Memory
4
+ end
5
+
6
+ given 'an empty list' do
7
+ should 'should return nothing' do
8
+ assert_nil @db.lpop 'test:nx'
9
+ end
10
+ end
11
+
12
+ given 'a list with two items in it' do
13
+ setup do
14
+ @db.lpush 'test:lpop', 'foo'
15
+ @db.lpush 'test:lpop', 'bar'
16
+ end
17
+
18
+ should 'return items from the head of the list' do
19
+ values = 3.times.map { @db.lpop 'test:lpop' }
20
+ assert_equal ['bar', 'foo', nil], values
21
+ end
22
+ end
23
+
24
+ teardown { @db.close }
25
+ end
@@ -0,0 +1,28 @@
1
+ context 'LPUSH' do
2
+ setup do
3
+ @db = Moneta.new :Memory
4
+ end
5
+
6
+ given 'an empty list' do
7
+ should 'have one item when one is pushed into it' do
8
+ assert_equal 1, @db.lpush('test:nx', 'foo')
9
+ end
10
+ end
11
+
12
+ given 'a list with 2 items' do
13
+ setup { 2.times { @db.lpush 'test:lpush', 'foo' } }
14
+
15
+ context 'pushing an item into it' do
16
+ should 'have 3 items' do
17
+ assert_equal 3, @db.lpush('test:lpush', 'foo')
18
+ end
19
+
20
+ should 'have that item at the head of the list' do
21
+ @db.lpush 'test:lpush', 'bar'
22
+ assert_equal 'bar', @db.lpop('test:lpush')
23
+ end
24
+ end
25
+ end
26
+
27
+ teardown { @db.close }
28
+ end
@@ -0,0 +1,28 @@
1
+ context 'LPUSHX' do
2
+ setup do
3
+ @db = Moneta.new :Memory
4
+ end
5
+
6
+ given 'an empty list' do
7
+ should 'have one item when one is pushed into it' do
8
+ assert_equal 0, @db.lpushx('test:nx', 'foo')
9
+ end
10
+ end
11
+
12
+ given 'a list with 2 items' do
13
+ setup { 2.times { @db.lpush 'test:lpushx', 'foo' } }
14
+
15
+ context 'pushing an item into it' do
16
+ should 'have 3 items' do
17
+ assert_equal 3, @db.lpushx('test:lpushx', 'foo')
18
+ end
19
+
20
+ should 'have that item at the head of the list' do
21
+ @db.lpushx 'test:lpushx', 'bar'
22
+ assert_equal 'bar', @db.lpop('test:lpushx')
23
+ end
24
+ end
25
+ end
26
+
27
+ teardown { @db.close }
28
+ end
@@ -0,0 +1,45 @@
1
+ context 'LRANGE' do
2
+ setup do
3
+ @db = Moneta.new :Memory
4
+ end
5
+
6
+ given 'an empty list' do
7
+ should 'return an empty list' do
8
+ assert_equal [], @db.lrange('test:nx', 0, -1)
9
+ end
10
+ end
11
+
12
+ given 'a list with three items in it' do
13
+ setup do
14
+ @db.lpush 'test:lrange', 'foo'
15
+ @db.lpush 'test:lrange', 'bar'
16
+ @db.lpush 'test:lrange', 'baz'
17
+ end
18
+
19
+ context 'a range within the list' do
20
+ should 'return the items in that range' do
21
+ assert_equal %w(baz bar), @db.lrange('test:lrange', 0, 1)
22
+ end
23
+ end
24
+
25
+ context 'a range containing the whole list' do
26
+ should 'return the whole list' do
27
+ assert_equal %w(baz bar foo), @db.lrange('test:lrange', 0, -1)
28
+ end
29
+ end
30
+
31
+ context 'an out of range stop' do
32
+ should 'return the whole list' do
33
+ assert_equal %w(baz bar foo), @db.lrange('test:lrange', 0, 9)
34
+ end
35
+ end
36
+
37
+ context 'stop before stop' do
38
+ should 'return an empty list' do
39
+ assert_equal [], @db.lrange('test:lrange', -1, 1)
40
+ end
41
+ end
42
+ end
43
+
44
+ teardown { @db.close }
45
+ end
@@ -0,0 +1,34 @@
1
+ context 'LSET' do
2
+ setup do
3
+ @db = Moneta.new :Memory
4
+ end
5
+
6
+ given 'an empty list' do
7
+ should 'raise an error' do
8
+ assert_raises(KeyError) { @db.lset('test:nx', 1, 'foo') }
9
+ end
10
+ end
11
+
12
+ given 'a list with three items' do
13
+ setup { 3.times { @db.lpush 'test:lset', 'foo' } }
14
+
15
+ context 'setting an item within range' do
16
+ should 'return OK' do
17
+ assert_equal 'OK', @db.lset('test:lset', 1, 'bar')
18
+ end
19
+
20
+ should 'overwrite the previous item' do
21
+ @db.lset('test:lset', 1, 'bar')
22
+ assert_equal 'bar', @db.lindex('test:lset', 1)
23
+ end
24
+ end
25
+
26
+ context 'setting an item out of range' do
27
+ should 'raise an error' do
28
+ assert_raises(IndexError) { @db.lset('test:lset', 999, 'bar') }
29
+ end
30
+ end
31
+ end
32
+
33
+ teardown { @db.close }
34
+ end
@@ -0,0 +1,25 @@
1
+ context 'RPOP' do
2
+ setup do
3
+ @db = Moneta.new :Memory
4
+ end
5
+
6
+ given 'an empty list' do
7
+ should 'should return nothing' do
8
+ assert_nil @db.rpop 'test:nx'
9
+ end
10
+ end
11
+
12
+ given 'a list with two items in it' do
13
+ setup do
14
+ @db.lpush 'test:rpop', 'foo'
15
+ @db.lpush 'test:rpop', 'bar'
16
+ end
17
+
18
+ should 'return items from the tail of the list' do
19
+ values = 3.times.map { @db.rpop 'test:rpop' }
20
+ assert_equal ['foo', 'bar', nil], values
21
+ end
22
+ end
23
+
24
+ teardown { @db.close }
25
+ end
@@ -0,0 +1,38 @@
1
+ context 'RPOPLPUSH' do
2
+ setup do
3
+ @db = Moneta.new :Memory
4
+ end
5
+
6
+ given 'an empty list' do
7
+ should 'return nothing' do
8
+ assert_nil @db.rpoplpush 'test:nx', 'test:rpoplpush:b'
9
+ end
10
+ end
11
+
12
+ given 'a list with two items' do
13
+ setup do
14
+ @db.lpush 'test:rpoplpush:a', 'foo'
15
+ @db.lpush 'test:rpoplpush:a', 'bar'
16
+ end
17
+
18
+ should 'return the item at the tail of the list' do
19
+ assert_equal 'foo', @db.rpoplpush('test:rpoplpush:a', 'test:rpoplpush:b')
20
+ end
21
+
22
+ context 'an item has been moved' do
23
+ setup do
24
+ @db.rpoplpush 'test:rpoplpush:a', 'test:rpoplpush:b'
25
+ end
26
+
27
+ should 'be removed from the source list' do
28
+ assert !@db.lrange('test:rpoplpush:a', 0, -1).include?('foo')
29
+ end
30
+
31
+ should 'end up in the destination list' do
32
+ assert @db.lrange('test:rpoplpush:b', 0, -1).include?('foo')
33
+ end
34
+ end
35
+ end
36
+
37
+ teardown { @db.close }
38
+ end
@@ -0,0 +1,28 @@
1
+ context 'RPUSH' do
2
+ setup do
3
+ @db = Moneta.new :Memory
4
+ end
5
+
6
+ given 'an empty list' do
7
+ should 'have one item when one is pushed into it' do
8
+ assert_equal 1, @db.rpush('test:nx', 'foo')
9
+ end
10
+ end
11
+
12
+ given 'a list with 2 items' do
13
+ setup { 2.times { @db.lpush 'test:rpush', 'foo' } }
14
+
15
+ context 'pushing an item into it' do
16
+ should 'have 3 items' do
17
+ assert_equal 3, @db.rpush('test:rpush', 'foo')
18
+ end
19
+
20
+ should 'have that item at the tail of the list' do
21
+ @db.rpush 'test:rpush', 'bar'
22
+ assert_equal 'bar', @db.rpop('test:rpush')
23
+ end
24
+ end
25
+ end
26
+
27
+ teardown { @db.close }
28
+ end
@@ -0,0 +1,28 @@
1
+ context 'RPUSHX' do
2
+ setup do
3
+ @db = Moneta.new :Memory
4
+ end
5
+
6
+ given 'an empty list' do
7
+ should 'have one item when one is pushed into it' do
8
+ assert_equal 0, @db.rpushx('test:nx', 'foo')
9
+ end
10
+ end
11
+
12
+ given 'a list with 2 items' do
13
+ setup { 2.times { @db.lpush 'test:rpushx', 'foo' } }
14
+
15
+ context 'pushing an item into it' do
16
+ should 'have 3 items' do
17
+ assert_equal 3, @db.rpushx('test:rpushx', 'foo')
18
+ end
19
+
20
+ should 'have that item at the tail of the list' do
21
+ @db.rpushx 'test:rpushx', 'bar'
22
+ assert_equal 'bar', @db.rpop('test:rpushx')
23
+ end
24
+ end
25
+ end
26
+
27
+ teardown { @db.close }
28
+ end
@@ -1,255 +1,12 @@
1
- context 'List Operations' do
2
- def mirror(method, *arguments)
3
- original = @original.method(method).call(*arguments)
4
- compatible = @compatible.method(method).call(*arguments)
5
- [original, compatible]
6
- end
7
-
8
- def assert_compatible(method, *arguments)
9
- assert_equal(*mirror(method, *arguments))
10
- end
11
-
12
- setup do
13
- @original = Redis.new
14
- # @compatible = Moneta.new :Daybreak, file: '.test.db', expires: true
15
- @compatible = Moneta.new :Memory
16
-
17
- @original.del 'test', 'test:a', 'test:b', 'test:nx'
18
- end
19
-
20
- teardown do
21
- @original.disconnect!
22
- @compatible.close
23
- end
24
-
25
- context 'lindex' do
26
- setup do
27
- mirror :lpush, 'test', 'foo'
28
- mirror :lpush, 'test', 'bar'
29
- end
30
-
31
- test 'when list does not exist' do
32
- assert_compatible :lindex, 'test:nx', 1
33
- end
34
-
35
- test 'in range' do
36
- assert_compatible :lindex, 'test', 1
37
- end
38
-
39
- test 'out of range' do
40
- assert_compatible :lindex, 'test', 999
41
- end
42
- end
43
-
44
- context 'linsert' do
45
- setup do
46
- mirror :lpush, 'test', 'foo'
47
- end
48
-
49
- test 'when list does not exist' do
50
- assert_compatible :linsert, 'test:nx', :before, 'foo', 'bar'
51
- assert_compatible :linsert, 'test:nx', :after, 'foo', 'bar'
52
- end
53
-
54
- test 'when list contains pivot value' do
55
- assert_compatible :linsert, 'test', :before, 'foo', 'bar'
56
- assert_compatible :linsert, 'test', :after, 'foo', 'bar'
57
- end
58
-
59
- test 'when list does not contain pivot value' do
60
- assert_compatible :linsert, 'test', :before, 'baz', 'bar'
61
- assert_compatible :linsert, 'test', :after, 'baz', 'bar'
62
- end
63
- end
64
-
65
- context 'llen' do
66
- test 'when list does not exist' do
67
- assert_compatible :llen, 'test:nx'
68
- end
69
-
70
- test 'when list exists' do
71
- mirror :lpush, 'test', 'foo'
72
- assert_compatible :llen, 'test'
73
- end
74
- end
75
-
76
- context 'lpop' do
77
- test 'when list does not exist' do
78
- assert_compatible :lpop, 'test:nx'
79
- end
80
-
81
- test 'when list exists' do
82
- mirror :lpush, 'test', 'foo'
83
- assert_compatible :lpop, 'test:nx'
84
- end
85
- end
86
-
87
- context 'lpush' do
88
- test 'when list does not exist' do
89
- assert_compatible :lpush, 'test:nx', 'foo'
90
- end
91
-
92
- test 'when list has items already' do
93
- mirror :lpush, 'test', 'foo'
94
- assert_compatible :lpush, 'test', 'foo'
95
- end
96
- end
97
-
98
- context 'lpushx' do
99
- test 'when list does not exist' do
100
- assert_compatible :lpushx, 'test:nx', 'foo'
101
- end
102
-
103
- test 'when list has items already' do
104
- mirror :lpush, 'test', 'foo'
105
- assert_compatible :lpushx, 'test', 'foo'
106
- end
107
- end
108
-
109
- context 'lrange' do
110
- test 'when list does not exist' do
111
- assert_compatible :lrange, 'test:nx', 0, -1
112
- end
113
-
114
- test 'when list exists' do
115
- mirror :lpush, 'test', 'foo'
116
- assert_compatible :lrange, 'test', 0, -1
117
- end
118
-
119
- test 'stop beyond range' do
120
- mirror :lpush, 'test', 'foo'
121
- assert_compatible :lrange, 'test', 0, 9
122
- end
123
-
124
- test 'stop before start' do
125
- mirror :lpush, 'test', 'foo'
126
- assert_compatible :lrange, 'test', -1, 1
127
- end
128
- end
129
-
130
- context 'lrem' do
131
- setup do
132
- mirror :lpush, 'test', 'foo'
133
- mirror :lpush, 'test', 'foo'
134
- mirror :lpush, 'test', 'foo'
135
- end
136
-
137
- test 'when list does not exist' do
138
- assert_compatible :lrem, 'test:nx', 0, 'foo'
139
- end
140
-
141
- test 'all items (present)' do
142
- assert_compatible :lrem, 'test', 0, 'foo'
143
- end
144
-
145
- test 'all items (when not present)' do
146
- assert_compatible :lrem, 'test', 0, 'bar'
147
- end
148
-
149
- test 'one from head (present)' do
150
- assert_compatible :lrem, 'test', 1, 'foo'
151
- end
152
-
153
- test 'one from head (when not present)' do
154
- assert_compatible :lrem, 'test', 1, 'bar'
155
- end
156
-
157
- test 'more than exists from head (present)' do
158
- assert_compatible :lrem, 'test', 9, 'foo'
159
- end
160
-
161
- test 'more than exists from head (when not present)' do
162
- assert_compatible :lrem, 'test', 9, 'bar'
163
- end
164
-
165
- test 'one from tail (present)' do
166
- assert_compatible :lrem, 'test', -1, 'foo'
167
- end
168
-
169
- test 'one from tail (when not present)' do
170
- assert_compatible :lrem, 'test', -1, 'bar'
171
- end
172
-
173
- test 'more than exists from tail (present)' do
174
- assert_compatible :lrem, 'test', -9, 'foo'
175
- end
176
-
177
- test 'more than exists from tail (when not present)' do
178
- assert_compatible :lrem, 'test', -9, 'bar'
179
- end
180
- end
181
-
182
- context 'lset' do
183
- setup do
184
- mirror :lpush, 'test', 'foo'
185
- mirror :lpush, 'test', 'foo'
186
- mirror :lpush, 'test', 'foo'
187
- end
188
-
189
- test 'in range' do
190
- assert_compatible :lset, 'test', 1, 'bar'
191
- assert_equal mirror(:lindex, 'test', 1).uniq, ['bar']
192
- end
193
- end
194
-
195
- context 'ltrim' do
196
- setup do
197
- 100.times do
198
- mirror :lpush, 'test', 'foo'
199
- end
200
- end
201
-
202
- test 'when list does not exist' do
203
- assert_compatible :ltrim, 'test:nx', 0, 10
204
- end
205
-
206
- test 'when range is larger than list length' do
207
- assert_compatible :ltrim, 'test', 0, 200
208
- assert_equal mirror(:lrange, 'test', 0, -1).uniq.flatten.size, 100
209
- end
210
- end
211
-
212
- context 'rpop' do
213
- test 'when list does not exist' do
214
- assert_compatible :rpop, 'test:nx'
215
- end
216
-
217
- test 'when list exists' do
218
- mirror :rpush, 'test', 'foo'
219
- assert_compatible :rpop, 'test:nx'
220
- end
221
- end
222
-
223
- context 'rpoplpush' do
224
- test 'when source list does not exist' do
225
- assert_compatible :rpoplpush, 'test:nx', 'test:b'
226
- end
227
-
228
- test 'when list exists' do
229
- 3.times { mirror :lpush, 'test:a', 'foo' }
230
- assert_compatible :rpoplpush, 'test:a', 'test:b'
231
- end
232
- end
233
-
234
- context 'rpush' do
235
- test 'when list does not exist' do
236
- assert_compatible :rpush, 'test:nx', 'foo'
237
- end
238
-
239
- test 'when list has items already' do
240
- mirror :rpush, 'test', 'foo'
241
- assert_compatible :rpush, 'test', 'foo'
242
- end
243
- end
244
-
245
- context 'rpushx' do
246
- test 'when list does not exist' do
247
- assert_compatible :rpushx, 'test:nx', 'foo'
248
- end
249
-
250
- test 'when list has items already' do
251
- mirror :rpush, 'test', 'foo'
252
- assert_compatible :rpushx, 'test', 'foo'
253
- end
254
- end
255
- end
1
+ require_relative 'lists/lindex'
2
+ require_relative 'lists/linsert'
3
+ require_relative 'lists/llen'
4
+ require_relative 'lists/lpop'
5
+ require_relative 'lists/lpush'
6
+ require_relative 'lists/lpushx'
7
+ require_relative 'lists/lrange'
8
+ require_relative 'lists/lset'
9
+ require_relative 'lists/rpop'
10
+ require_relative 'lists/rpoplpush'
11
+ require_relative 'lists/rpush'
12
+ require_relative 'lists/rpushx'
data/tests/redislike.rb CHANGED
@@ -3,9 +3,8 @@ require 'bundler/setup'
3
3
  require 'simplecov'
4
4
  SimpleCov.command_name 'Kintama'
5
5
  SimpleCov.start { add_filter '/vendor/' }
6
- require 'redis'
7
6
  require 'kintama'
8
7
  require 'moneta'
8
+ require 'redislike'
9
9
 
10
- require_relative '../lib/redislike'
11
10
  require_relative 'redislike/lists'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redislike
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Olstrom
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-05 00:00:00.000000000 Z
11
+ date: 2015-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: moneta
@@ -83,8 +83,37 @@ files:
83
83
  - lib/redislike/keys.rb
84
84
  - lib/redislike/lists.rb
85
85
  - redislike.gemspec
86
+ - tests/compatibility/helpers/compatibility.rb
87
+ - tests/compatibility/redislike.rb
88
+ - tests/compatibility/redislike/lists.rb
89
+ - tests/compatibility/redislike/lists/lindex.rb
90
+ - tests/compatibility/redislike/lists/linsert.rb
91
+ - tests/compatibility/redislike/lists/llen.rb
92
+ - tests/compatibility/redislike/lists/lpop.rb
93
+ - tests/compatibility/redislike/lists/lpush.rb
94
+ - tests/compatibility/redislike/lists/lpushx.rb
95
+ - tests/compatibility/redislike/lists/lrange.rb
96
+ - tests/compatibility/redislike/lists/lrem.rb
97
+ - tests/compatibility/redislike/lists/lset.rb
98
+ - tests/compatibility/redislike/lists/ltrim.rb
99
+ - tests/compatibility/redislike/lists/rpop.rb
100
+ - tests/compatibility/redislike/lists/rpoplpush.rb
101
+ - tests/compatibility/redislike/lists/rpush.rb
102
+ - tests/compatibility/redislike/lists/rpushx.rb
86
103
  - tests/redislike.rb
87
104
  - tests/redislike/lists.rb
105
+ - tests/redislike/lists/lindex.rb
106
+ - tests/redislike/lists/linsert.rb
107
+ - tests/redislike/lists/llen.rb
108
+ - tests/redislike/lists/lpop.rb
109
+ - tests/redislike/lists/lpush.rb
110
+ - tests/redislike/lists/lpushx.rb
111
+ - tests/redislike/lists/lrange.rb
112
+ - tests/redislike/lists/lset.rb
113
+ - tests/redislike/lists/rpop.rb
114
+ - tests/redislike/lists/rpoplpush.rb
115
+ - tests/redislike/lists/rpush.rb
116
+ - tests/redislike/lists/rpushx.rb
88
117
  homepage: http://colstrom.github.io/redislike/
89
118
  licenses:
90
119
  - MIT