diff options
Diffstat (limited to 'tests/exprs')
-rw-r--r-- | tests/exprs/texprstmt.nim | 12 | ||||
-rw-r--r-- | tests/exprs/tstmtexp.nim | 9 | ||||
-rw-r--r-- | tests/exprs/tstmtexprs.nim | 71 |
3 files changed, 92 insertions, 0 deletions
diff --git a/tests/exprs/texprstmt.nim b/tests/exprs/texprstmt.nim new file mode 100644 index 000000000..b32394d8d --- /dev/null +++ b/tests/exprs/texprstmt.nim @@ -0,0 +1,12 @@ +discard """ + line: 10 + errormsg: "value returned by statement has to be discarded" +""" + +# bug #578 + +proc test: string = + result = "blah" + result[1 .. -1] + +echo test() diff --git a/tests/exprs/tstmtexp.nim b/tests/exprs/tstmtexp.nim new file mode 100644 index 000000000..7cbf2eb3d --- /dev/null +++ b/tests/exprs/tstmtexp.nim @@ -0,0 +1,9 @@ +discard """ + file: "tstmtexp.nim" + line: 8 + errormsg: "value returned by statement has to be discarded" +""" +# Test 3 + +1+4 #ERROR_MSG value returned by statement has to be discarded + diff --git a/tests/exprs/tstmtexprs.nim b/tests/exprs/tstmtexprs.nim new file mode 100644 index 000000000..497a2f6d0 --- /dev/null +++ b/tests/exprs/tstmtexprs.nim @@ -0,0 +1,71 @@ +discard """ + output: '''(bar: bar) +1244 +6 +abcdefghijklmnopqrstuvwxyz +145 23''' +""" + +import strutils + +when true: + proc test(foo: proc (x, y: int): bool) = + echo foo(5, 5) + + + type Foo = object + bar: string + + proc newfoo(): Foo = + result.bar = "bar" + + echo($newfoo()) + + + proc retInt(x, y: int): int = + if (var yy = 0; yy != 0): + echo yy + else: + echo(try: parseInt("1244") except EINvalidValue: -1) + result = case x + of 23: 3 + of 64: + case y + of 1: 2 + of 2: 3 + of 3: 6 + else: 8 + else: 1 + + echo retInt(64, 3) + + proc buildString(): string = + result = "" + for x in 'a'..'z': + result.add(x) + + echo buildString() + +#test( +# proc (x, y: int): bool = +# if x == 5: return true +# if x == 2: return false +# if y == 78: return true +#) + +proc q(): int {.discardable.} = 145 +proc p(): int = + q() + +proc p2(a: int): int = + # result enforces a void context: + if a == 2: + result = 23 + q() + +echo p(), " ", p2(2) + +proc semiProblem() = + if false: echo "aye"; echo "indeed" + +semiProblem() |