summaryrefslogtreecommitdiffstats
path: root/tests/unittests/command_parse/test_list_parse.py
blob: e60d7a224406038ecbe1e85681f8b741512db8f7 (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
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_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",
        },
    )