diff options
author | cooldome <cdome@bk.ru> | 2018-09-07 00:52:42 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-09-07 01:52:42 +0200 |
commit | c033ff990acceac6d2095242fa17501e98555973 (patch) | |
tree | 0b3d8ee51191116876de92a477b13be9b0c5fc41 /tests/macros | |
parent | 36e6ca16d1ece106d88fbb951b544b80c360d600 (diff) | |
download | Nim-c033ff990acceac6d2095242fa17501e98555973.tar.gz |
Renderer bug fixes (#8804)
Fixes #8763: render bug: pure enums not handled correctly Fixes #8762: render bug: binary operators called with quotes rendered incorrectly FIxes #8761: render bug: inversion of operator priorities
Diffstat (limited to 'tests/macros')
-rw-r--r-- | tests/macros/tmacrostmt.nim | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/tests/macros/tmacrostmt.nim b/tests/macros/tmacrostmt.nim index 9dbfbce43..c1f26e626 100644 --- a/tests/macros/tmacrostmt.nim +++ b/tests/macros/tmacrostmt.nim @@ -43,6 +43,10 @@ macro repr_and_parse(fn: typed): typed = echo fn_impl.repr result = parseStmt(fn_impl.repr) +macro repr_to_string(fn: typed): string = + let fn_impl = fn.getImpl + result = newStrLitNode(fn_impl.repr) + repr_and_parse(f) @@ -70,8 +74,49 @@ proc test_cond_stmtlist(x, y: int): int = result = x +#------------------------------------ +# bug #8762 +proc t2(a, b: int): int = + `+`(a, b) + + +#------------------------------------ +# bug #8761 + +proc fn1(x, y: int):int = + 2 * (x + y) + +proc fn2(x, y: float): float = + (y + 2 * x) / (x - y) + +proc fn3(x, y: int): bool = + (((x and 3) div 4) or (x mod (y xor -1))) == 0 or y notin [1,2] + +static: + let fn1s = "proc fn1(x, y: int): int =\n result = 2 * (x + y)\n" + let fn2s = "proc fn2(x, y: float): float =\n result = (y + 2.0 * x) / (x - y)\n" + let fn3s = "proc fn3(x, y: int): bool =\n result = ((x and 3) div 4 or x mod (y xor -1)) == 0 or not contains([1, 2], y)\n" + doAssert fn1.repr_to_string == fn1s + doAssert fn2.repr_to_string == fn2s + doAssert fn3.repr_to_string == fn3s + +#------------------------------------ +# bug #8763 + +type + A {.pure.} = enum + X, Y + B {.pure.} = enum + X, Y + +proc test_pure_enums(a: B) = + case a + of B.X: echo B.X + of B.Y: echo B.Y + repr_and_parse(one_if_proc) repr_and_parse(test_block) repr_and_parse(test_cond_stmtlist) - +repr_and_parse(t2) +repr_and_parse(test_pure_enums) |