This commit is contained in:
cooldome 2018-04-06 09:53:21 +01:00 • committed by Andreas Rumpf
commit c34cb101b8
2 changed files with 15 additions and 7 deletions

View file

@ -45,15 +45,24 @@ let a = case str1:
echo "no good"
quit("quiting")
let b = case str2:
of nil, "": raise newException(ValueError, "Invalid boolean")
elif str2[0] == 'Y': true
elif str2[0] == 'N': false
else: "error".quit(2)
proc toBool(s: string): bool =
case s:
of nil, "": raise newException(ValueError, "Invalid boolean")
elif s[0] == 'Y': true
elif s[0] == 'N': false
else: "error".quit(2)
let b = "NN".toBool()
doAssert(a == true)
doAssert(b == false)
static:
#bug #7407
let bstatic = "N".toBool()
doAssert(bstatic == false)
var bb: bool
doassert(not compiles(
bb = case str2: