From c79df2fb6abb5663505de13c0ae5995d72ae71a8 Mon Sep 17 00:00:00 2001 From: cooldome Date: Fri, 28 Feb 2020 09:55:06 +0000 Subject: EndsInNoReturn in expressions extension, fixes #13490 (#13520) * fix #13490 --- tests/casestmt/tcasestmt.nim | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests/casestmt') diff --git a/tests/casestmt/tcasestmt.nim b/tests/casestmt/tcasestmt.nim index b7454ef99..6abea53bc 100644 --- a/tests/casestmt/tcasestmt.nim +++ b/tests/casestmt/tcasestmt.nim @@ -250,3 +250,40 @@ proc negativeOrNot(num: int): string = doAssert negativeOrNot(-1) == "negative" doAssert negativeOrNot(10000000) == "zero or positive" doAssert negativeOrNot(0) == "zero or positive" + +######################################################## +# issue #13490 +import strutils +func foo(input: string): int = + try: + parseInt(input) + except: + return + +func foo2(b, input: string): int = + case b: + of "Y": + for c in input: + result = if c in '0'..'9': parseInt($c) + else: break + of "N": + for c in input: + result = if c in '0'..'9': parseInt($c) + else: continue + else: return + + +static: + doAssert(foo("3") == 3) + doAssert(foo("a") == 0) + doAssert(foo2("Y", "a2") == 0) + doAssert(foo2("Y", "2a") == 2) + doAssert(foo2("N", "a3") == 3) + doAssert(foo2("z", "2") == 0) + +doAssert(foo("3") == 3) +doAssert(foo("a") == 0) +doAssert(foo2("Y", "a2") == 0) +doAssert(foo2("Y", "2a") == 2) +doAssert(foo2("N", "a3") == 3) +doAssert(foo2("z", "2") == 0) -- cgit 1.4.1-2-gfad0