]> gitweb.factorcode.org Git - factor.git/blob - extra/redis/command-writer/command-writer-tests.factor
Merge branch 'irc' of git://www.tiodante.com/git/factor
[factor.git] / extra / redis / command-writer / command-writer-tests.factor
1 ! Copyright (C) 2009 Bruno Deferrari
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: tools.test redis.command-writer io.streams.string ;
4 IN: redis.command-writer.tests
5
6 #! Connection
7 [ "QUIT\r\n" ] [ [ quit ] with-string-writer ] unit-test
8
9 [ "PING\r\n" ] [ [ ping ] with-string-writer ] unit-test
10
11 [ "AUTH password\r\n" ] [ [ "password" auth ] with-string-writer ] unit-test
12
13 #! String values
14 [ "SET key 3\r\nfoo\r\n" ] [ [ "foo" "key" set ] with-string-writer ] unit-test
15
16 [ "GET key\r\n" ] [ [ "key" get ] with-string-writer ] unit-test
17
18 [ "GETSET key 3\r\nfoo\r\n" ] [
19     [ "foo" "key" getset ] with-string-writer
20 ] unit-test
21
22 [ "MGET key1 key2 key3\r\n" ] [
23     [ { "key1" "key2" "key3" } mget ] with-string-writer
24 ] unit-test
25
26 [ "SETNX key 3\r\nfoo\r\n" ] [
27     [ "foo" "key" setnx ] with-string-writer
28 ] unit-test
29
30 [ "INCR key\r\n" ] [ [ "key" incr ] with-string-writer ] unit-test
31
32 [ "INCRBY key 7\r\n" ] [ [ 7 "key" incrby ] with-string-writer ] unit-test
33
34 [ "DECR key\r\n" ] [ [ "key" decr ] with-string-writer ] unit-test
35
36 [ "DECRBY key 7\r\n" ] [ [ 7 "key" decrby ] with-string-writer ] unit-test
37
38 [ "EXISTS key\r\n" ] [ [ "key" exists ] with-string-writer ] unit-test
39
40 [ "DEL key\r\n" ] [ [ "key" del ] with-string-writer ] unit-test
41
42 [ "TYPE key\r\n" ] [ [ "key" type ] with-string-writer ] unit-test
43
44 #! Key space
45 [ "KEYS pat*\r\n" ] [ [ "pat*" keys ] with-string-writer ] unit-test
46
47 [ "RANDOMKEY\r\n" ] [ [ randomkey ] with-string-writer ] unit-test
48
49 [ "RENAME key newkey\r\n" ] [
50     [ "newkey" "key" rename ] with-string-writer
51 ] unit-test
52
53 [ "RENAMENX key newkey\r\n" ] [
54     [ "newkey" "key" renamenx ] with-string-writer
55 ] unit-test
56
57 [ "DBSIZE\r\n" ] [ [ dbsize ] with-string-writer ] unit-test
58
59 [ "EXPIRE key 7\r\n" ] [ [ 7 "key" expire ] with-string-writer ] unit-test
60
61 #! Lists
62 [ "RPUSH key 3\r\nfoo\r\n" ] [ [ "foo" "key" rpush ] with-string-writer ] unit-test
63
64 [ "LPUSH key 3\r\nfoo\r\n" ] [ [ "foo" "key" lpush ] with-string-writer ] unit-test
65
66 [ "LLEN key\r\n" ] [ [ "key" llen ] with-string-writer ] unit-test
67
68 [ "LRANGE key 5 9\r\n" ] [ [ 5 9 "key" lrange ] with-string-writer ] unit-test
69
70 [ "LTRIM key 5 9\r\n" ] [ [ 5 9 "key" ltrim ] with-string-writer ] unit-test
71
72 [ "LINDEX key 7\r\n" ] [ [ 7 "key" lindex ] with-string-writer ] unit-test
73
74 [ "LSET key 0 3\r\nfoo\r\n" ] [ [ "foo" 0 "key" lset ] with-string-writer ] unit-test
75
76 [ "LREM key 1 3\r\nfoo\r\n" ] [ [ "foo" 1 "key" lrem ] with-string-writer ] unit-test
77
78 [ "LPOP key\r\n" ] [ [ "key" lpop ] with-string-writer ] unit-test
79
80 [ "RPOP key\r\n" ] [ [ "key" rpop ] with-string-writer ] unit-test
81
82 #! Sets
83 [ "SADD key 3\r\nfoo\r\n" ] [ [ "foo" "key" sadd ] with-string-writer ] unit-test
84
85 [ "SREM key 3\r\nfoo\r\n" ] [ [ "foo" "key" srem ] with-string-writer ] unit-test
86
87 [ "SMOVE srckey dstkey 3\r\nfoo\r\n" ] [
88     [ "foo" "dstkey" "srckey" smove ] with-string-writer
89 ] unit-test
90
91 [ "SCARD key\r\n" ] [ [ "key" scard ] with-string-writer ] unit-test
92
93 [ "SISMEMBER key 3\r\nfoo\r\n" ] [
94     [ "foo" "key" sismember ] with-string-writer
95 ] unit-test
96
97 [ "SINTER key1 key2 key3\r\n" ] [
98     [ { "key1" "key2" "key3" } sinter ] with-string-writer
99 ] unit-test
100
101 [ "SINTERSTORE dstkey key1 key2 key3\r\n" ] [
102     [ { "key1" "key2" "key3" } "dstkey" sinterstore ] with-string-writer
103 ] unit-test
104
105 [ "SUNION key1 key2 key3\r\n" ] [
106     [ { "key1" "key2" "key3" } sunion ] with-string-writer
107 ] unit-test
108
109 [ "SUNIONSTORE dstkey key1 key2 key3\r\n" ] [
110     [ { "key1" "key2" "key3" } "dstkey" sunionstore ] with-string-writer
111 ] unit-test
112
113 [ "SMEMBERS key\r\n" ] [ [ "key" smembers ] with-string-writer ] unit-test
114
115 #! Multiple db
116 [ "SELECT 2\r\n" ] [ [ 2 select ] with-string-writer ] unit-test
117
118 [ "MOVE key 2\r\n" ] [ [ 2 "key" move ] with-string-writer ] unit-test
119
120 [ "FLUSHDB\r\n" ] [ [ flushdb ] with-string-writer ] unit-test
121
122 [ "FLUSHALL\r\n" ] [ [ flushall ] with-string-writer ] unit-test
123
124 #! Sorting
125
126 #! Persistence control
127 [ "SAVE\r\n" ] [ [ save ] with-string-writer ] unit-test
128
129 [ "BGSAVE\r\n" ] [ [ bgsave ] with-string-writer ] unit-test
130
131 [ "LASTSAVE\r\n" ] [ [ lastsave ] with-string-writer ] unit-test
132
133 [ "SHUTDOWN\r\n" ] [ [ shutdown ] with-string-writer ] unit-test
134
135 #! Remote server control
136 [ "INFO\r\n" ] [ [ info ] with-string-writer ] unit-test
137
138 [ "MONITOR\r\n" ] [ [ monitor ] with-string-writer ] unit-test