-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_protocol.mojo
62 lines (46 loc) · 1.34 KB
/
test_protocol.mojo
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
from protocol import FiredisParser
from testing import assert_equal
from table import Table
fn test_parse_ping() raises -> Bool:
var db = Table.create()
let msg = "*1\r\n$4\r\nPING\r\n"
let resp = "+PONG\r\n"
var parser = FiredisParser(db, msg)
parser.parse()
if assert_equal(parser.result, resp):
print_no_newline(".")
else:
print_no_newline("E")
return False
return True
fn test_parse_echo() raises -> Bool:
var db = Table.create()
let msg = "*2\r\n$4\r\necho\r\n$5\r\nfirst\r\n"
let resp = "$5\r\nfirst\r\n"
var parser = FiredisParser(db, msg)
parser.parse()
if assert_equal(parser.result, resp):
print_no_newline(".")
else:
print_no_newline("E")
return False
return True
fn test_parse_long_message() raises -> Bool:
var db = Table.create()
let msg = "*3\r\n$3\r\nset\r\n$5\r\nnames\r\n$11\r\nverylong...\r\n"
let resp = "+OK\r\n"
var parser = FiredisParser(db, msg)
parser.parse()
if assert_equal(parser.result, resp):
print_no_newline(".")
else:
print_no_newline("E")
return False
var val: StringRef = ""
_ = db.get("names", val)
if assert_equal(val, "verylong..."):
print_no_newline(".")
else:
print_no_newline("E")
return False
return True