summaryrefslogtreecommitdiffstats
path: root/tests/unittests/command_parse/test_sorted_set_parse.py
blob: a0af616a0a40cd16a83d268bc4c613d5a7c130b3 (plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import pytest


def test_zcount(judge_command):
    judge_command(
        "zcount foo -10 0",
        {"command": "zcount", "key": "foo", "min": "-10", "max": "0"},
    )


def test_bzpopmax(judge_command):
    judge_command(
        "bzpopmax set set2 set3 4",
        {"command": "bzpopmax", "keys": "set set2 set3", "timeout": "4"},
    )
    judge_command(
        "bzpopmin set   4", {"command": "bzpopmin", "keys": "set", "timeout": "4"}
    )


def test_zadd(judge_command):
    judge_command(
        "zadd t 100 qewqr 23 pp 11 oo",
        {
            "command": "zadd",
            "key": "t",
            "score": "11",  # FIXME: only have last one
            "member": "oo",
        },
    )
    judge_command(
        "zadd t incr 100 foo",
        {
            "command": "zadd",
            "key": "t",
            "incr": "incr",
            "score": "100",  # FIXME: only have last one
            "member": "foo",
        },
    )
    judge_command(
        "zadd t NX CH incr 100 foo",
        {
            "command": "zadd",
            "key": "t",
            "condition": "NX",
            "changed": "CH",
            "incr": "incr",
            "score": "100",  # FIXME: only have last one
            "member": "foo",
        },
    )


def test_zincrby(judge_command):
    judge_command(
        "zincrby t 10 foo",
        {"command": "zincrby", "key": "t", "float": "10", "member": "foo"},
    )
    judge_command(
        "zincrby t 2.3 foo",
        {"command": "zincrby", "key": "t", "float": "2.3", "member": "foo"},
    )


def test_zlexcount(judge_command):
    judge_command(
        "zlexcount a - +",
        {"command": "zlexcount", "key": "a", "lexmin": "-", "lexmax": "+"},
    )
    judge_command(
        "zlexcount a (aaaa [z",
        {"command": "zlexcount", "key": "a", "lexmin": "(aaaa", "lexmax": "[z"},
    )
    judge_command(
        "ZLEXCOUNT myset - [c",
        {"command": "ZLEXCOUNT", "key": "myset", "lexmin": "-", "lexmax": "[c"},
    )
    judge_command(
        "ZLEXCOUNT myset [aaa (g",
        {"command": "ZLEXCOUNT", "key": "myset", "lexmin": "[aaa", "lexmax": "(g"},
    )


def test_zrange(judge_command):
    judge_command(
        "zrange foo -1 10",
        {"command": "zrange", "key": "foo", "start": "-1", "end": "10"},
    )
    judge_command(
        "zrange foo 0 -1",
        {"command": "zrange", "key": "foo", "start": "0", "end": "-1"},
    )
    judge_command(
        "zrange foo 0 -1 withscores",
        {
            "command": "zrange",
            "key": "foo",
            "start": "0",
            "end": "-1",
            "withscores": "withscores",
        },
    )


@pytest.mark.xfail(reason="Not implemented yet")
def test_zinterstore(judge_command):
    judge_command("ZINTERSTORE out 2 zset1 zset2 WEIGHTS 2 3", {})
    judge_command("ZINTERSTORE out 2 zset1 zset2 WEIGHTS -1 -2", {})
    judge_command("ZINTERSTORE out 2 zset1 zset2 WEIGHTS 0.2 0.3", {})


def test_zrangebylex(judge_command):
    judge_command(
        "ZRANGEBYLEX myzset [aaa (g",
        {"command": "ZRANGEBYLEX", "key": "myzset", "lexmin": "[aaa", "lexmax": "(g"},
    )
    judge_command(
        "ZRANGEBYLEX myzset - (c",
        {"command": "ZRANGEBYLEX", "key": "myzset", "lexmin": "-", "lexmax": "(c"},
    )
    judge_command(
        "ZRANGEBYLEX myzset - (c limit 10 100",
        {
            "command": "ZRANGEBYLEX",
            "key": "myzset",
            "lexmin": "-",
            "lexmax": "(c",
            "limit": "limit",
            "offset": "10",
            "count": "100",
        },
    )
    judge_command(
        "ZRANGEBYLEX myzset - (c limit 10 -1",
        {
            "command": "ZRANGEBYLEX",
            "key": "myzset",
            "lexmin": "-",
            "lexmax": "(c",
            "limit": "limit",
            "offset": "10",
            "count": "-1",
        },
    )


def test_zrangebyscore(judge_command):
    judge_command(
        "ZRANGEBYSCORE myzset -inf +inf",
        {"command": "ZRANGEBYSCORE", "key": "myzset", "min": "-inf", "max": "+inf"},
    )
    judge_command(
        "ZRANGEBYSCORE myzset 1 2",
        {"command": "ZRANGEBYSCORE", "key": "myzset", "min": "1", "max": "2"},
    )
    judge_command(
        "ZRANGEBYSCORE myzset (1 (2",
        {"command": "ZRANGEBYSCORE", "key": "myzset", "min": "(1", "max": "(2"},
    )
    judge_command(
        "ZRANGEBYSCORE myzset -inf +inf LIMIT 10 100",
        {
            "command": "ZRANGEBYSCORE",
            "key": "myzset",
            "min": "-inf",
            "max": "+inf",
            "limit": "LIMIT",
            "offset": "10",
            "count": "100",
        },
    )