summaryrefslogtreecommitdiffstats
path: root/tests/unittests/command_parse/test_list_parse.py
blob: 69a294e433f0bfd87869f83f5e20e6d3291c94ee (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
def test_rpush(judge_command):
    judge_command(
        "RPUSH list1 foo bar hello world",
        {"command": "RPUSH", "key": "list1", "values": "foo bar hello world"},
    )
    judge_command(
        "LPUSH list1 foo", {"command": "LPUSH", "key": "list1", "values": "foo"}
    )


def test_lindex(judge_command):
    judge_command(
        "LINDEX list1 10", {"command": "LINDEX", "key": "list1", "position": "10"}
    )
    judge_command(
        "LINDEX list1 -10", {"command": "LINDEX", "key": "list1", "position": "-10"}
    )
    judge_command("LINDEX list1 1.1", None)


def test_lset(judge_command):
    judge_command(
        "LSET list1 10 newbie",
        {"command": "LSET", "key": "list1", "position": "10", "value": "newbie"},
    )
    judge_command(
        "LSET list1 -1 newbie",
        {"command": "LSET", "key": "list1", "position": "-1", "value": "newbie"},
    )


def test_brpoplpush(judge_command):
    judge_command(
        "BRPOPLPUSH list1 list2 10",
        {"command": "BRPOPLPUSH", "key": "list1", "newkey": "list2", "timeout": "10"},
    )
    judge_command(
        "BRPOPLPUSH list1 list2 0",
        {"command": "BRPOPLPUSH", "key": "list1", "newkey": "list2", "timeout": "0"},
    )
    judge_command("BRPOPLPUSH list1 list2 -1", None)


def test_brpoplpush_with_double_timeout(judge_command):
    judge_command(
        "BRPOPLPUSH list1 list2 10.0",
        {"command": "BRPOPLPUSH", "key": "list1", "newkey": "list2", "timeout": "10.0"},
    )
    judge_command(
        "BRPOPLPUSH list1 list2 .2",
        {"command": "BRPOPLPUSH", "key": "list1", "newkey": "list2", "timeout": ".2"},
    )
    judge_command("BRPOPLPUSH list1 list2 12.", None)


def test_linsert(judge_command):
    judge_command(
        'LINSERT mylist BEFORE "World" "There"',
        {
            "command": "LINSERT",
            "key": "mylist",
            "position_choice": "BEFORE",
            "value": ['"World"', '"There"'],
        },
    )
    judge_command(
        'LINSERT mylist after "World" "There"',
        {
            "command": "LINSERT",
            "key": "mylist",
            "position_choice": "after",
            "value": ['"World"', '"There"'],
        },
    )


def test_lpos(judge_command):
    judge_command("LPOS mylist c", {"command": "LPOS", "key": "mylist", "element": "c"})
    judge_command(
        "LPOS mylist c RANK 2",
        {
            "command": "LPOS",
            "key": "mylist",
            "element": "c",
            "rank_const": "RANK",
            "rank": "2",
        },
    )
    judge_command(
        "LPOS mylist c RANK -1",
        {
            "command": "LPOS",
            "key": "mylist",
            "element": "c",
            "rank_const": "RANK",
            "rank": "-1",
        },
    )
    judge_command(
        "LPOS mylist c COUNT 2",
        {
            "command": "LPOS",
            "key": "mylist",
            "element": "c",
            "count_const": "COUNT",
            "count": "2",
        },
    )
    judge_command(
        "LPOS mylist c RANK -1 COUNT 2",
        {
            "command": "LPOS",
            "key": "mylist",
            "element": "c",
            "count_const": "COUNT",
            "count": "2",
            "rank_const": "RANK",
            "rank": "-1",
        },
    )


def test_blmove(judge_command):
    judge_command(
        "blmove list1 list2 left right 1.2",
        {
            "command": "blmove",
            "key": ["list1", "list2"],
            "lr_const": ["left", "right"],
            "timeout": "1.2",
        },
    )
    judge_command(
        "blmove list1 list2 right right .2",
        {
            "command": "blmove",
            "key": ["list1", "list2"],
            "lr_const": ["right", "right"],
            "timeout": ".2",
        },
    )
    judge_command("blmove list1 list2 right right", None)
    judge_command("blmove list1 right right 1", None)