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