[backport] fix #15064, strscans.scanf edge case for '$+' (#15223)

This commit is contained in:
Miran
2020-08-25 09:57:15 +02:00
committed by GitHub
parent 5651a2f711
commit 15ff89cec1
2 changed files with 16 additions and 2 deletions

View File

@@ -396,7 +396,7 @@ macro scanf*(input: string; pattern: static[string]; results: varargs[typed]): b
var resLen = genSym(nskLet, "resLen")
conds.add newLetStmt(resLen, newCall(bindSym"parseUntil", inp,
results[i], newLit(token), idx))
conds.add newCall(bindSym"!=", resLen, newLit min)
conds.add newCall(bindSym">=", resLen, newLit min)
conds.add resLen
else:
matchError

View File

@@ -79,8 +79,22 @@ block EmptyTuple:
block Arrow:
let text = "foo;bar;baz;"
var idx = 0
var res = ""
doAssert scanp(text, idx, +(~{';','\0'} -> (discard $_)), ';')
doAssert scanp(text, idx, +(~{';','\0'} -> (discard $_)), ';')
doAssert scanp(text, idx, +(~{';','\0'} -> (discard $_)), ';')
doAssert scanp(text, idx, +(~{';','\0'} -> (discard $_)), ';') == false
block issue15064:
var nick1, msg1: string
doAssert scanf("<abcd> a", "<$+> $+", nick1, msg1)
doAssert nick1 == "abcd"
doAssert msg1 == "a"
var nick2, msg2: string
doAssert(not scanf("<abcd> ", "<$+> $+", nick2, msg2))
var nick3, msg3: string
doAssert scanf("<abcd> ", "<$+> $*", nick3, msg3)
doAssert nick3 == "abcd"
doAssert msg3 == ""