test if on ParseState.Complete the whole packet was consumed

This commit is contained in:
lurchi 2018-08-21 22:21:51 +02:00
parent bc3801ed65
commit 87674ac5af
No known key found for this signature in database
GPG Key ID: 8241BE099775A097
1 changed files with 14 additions and 10 deletions

View File

@ -224,7 +224,6 @@ proc parse*(input: string,
packet.routingHeader.add(modifier)
of ParseState.RoutingModifierValue:
let (complete, value) = parseModifierSimpleValue(input, packet)
echo "parseModifierSimpleValue returned ", value
result.needMoreInput = not complete
if value.len() > 0:
if packet.routingHeader[^1].value.isNil():
@ -286,13 +285,17 @@ proc parse*(input: string,
suite "parser tests":
setup:
var packet = newPacket()
var
needMore: bool
unparsed: Slice[int]
packet = newPacket()
test "state sync":
let input = ":_target\talice\n\n?\n|\n"
while packet.state != ParseState.Complete:
let (needMore, _) = parse(input, packet)
(needMore, unparsed) = parse(input, packet)
check(not needMore)
check(unparsed == input.len()..input.high())
check(packet.routingHeader.len() == 1)
check(packet.routingHeader[0] == Modifier(op: ':',
name: "_target",
@ -303,8 +306,9 @@ suite "parser tests":
test "simple-arg":
let input = ":_target\talice\n\n:_hello\tworld\n:_hallo\twelt\n|\n"
while packet.state != ParseState.Complete:
let (needMore, _) = parse(input, packet)
(needMore, unparsed) = parse(input, packet)
check(not needMore)
check(unparsed == input.len()..input.high())
check(packet.entityHeader.len() == 2)
check(packet.entityHeader[0] == Modifier(op: ':', name: "_hello", value: "world"))
check(packet.entityHeader[1] == Modifier(op: ':', name: "_hallo", value: "welt"))
@ -312,8 +316,9 @@ suite "parser tests":
test "binary-arg":
let input = ":_target\talice\n\n:_hello 5\tworld\n:_hallo 4\twelt\n|\n"
while packet.state != ParseState.Complete:
let (needMore, _) = parse(input, packet)
(needMore, unparsed) = parse(input, packet)
check(not needMore)
check(unparsed == input.len()..input.high())
check(packet.entityHeader.len() == 2)
check(packet.entityHeader[0] == Modifier(op: ':', name: "_hello", value: "world"))
check(packet.entityHeader[1] == Modifier(op: ':', name: "_hallo", value: "welt"))
@ -321,16 +326,18 @@ suite "parser tests":
test "method/data":
let input = ":_target\talice\n\n_hello_world\nHello Alice!\n|\n"
while packet.state != ParseState.Complete:
let (needMore, _) = parse(input, packet)
(needMore, unparsed) = parse(input, packet)
check(not needMore)
check(unparsed == input.len()..input.high())
check(packet.methodName == "_hello_world")
check(packet.data == "Hello Alice!")
test "content length":
let input = ":_target\talice\n39\n:_hello\tworld\n_hello_world\nHello Alice!\n|\n"
while packet.state != ParseState.Complete:
let (needMore, _) = parse(input, packet)
(needMore, unparsed) = parse(input, packet)
check(not needMore)
check(unparsed == input.len()..input.high())
check(packet.contentLength == 39)
check(packet.data == "Hello Alice!")
@ -343,9 +350,6 @@ suite "parser tests":
input5 = "world\n"
input6 = "_hello_world\n"
input7 = "Hello Alice!\n|\n"
var
needMore: bool
unparsed: Slice[int]
(needMore, unparsed) = parse(input1[0..4], packet)
check(needMore)