Nim/tests/stdlib/ttypetraits.nim
Timothee Cour e78ef57c93
typetraits: add toSigned, toUnsigned (#18445)
* typetraits: add toSigned, toUnsigned

* improve and add tests

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Co-authored-by: flywind <xzsflywind@gmail.com>
2022-04-07 17:38:01 -04:00

92 lines
1.3 KiB
Nim

discard """
targets: "c cpp js"
"""
# xxx merge with tests/metatype/ttypetraits.nim
import std/typetraits
macro testClosure(fn: typed, flag: static bool) =
if flag:
doAssert hasClosure(fn)
else:
doAssert not hasClosure(fn)
block:
proc h1() =
echo 1
testClosure(h1, false)
proc h2() {.nimcall.} =
echo 2
testClosure(h2, false)
block:
proc fn(): auto =
proc hello() {.nimcall.} =
echo 3
hello
let name = fn()
testClosure(name, false)
block:
proc fn(): auto =
proc hello() =
echo 3
hello
let name = fn()
testClosure(name, false)
block:
proc fn(): auto =
var x = 0
proc hello() =
echo 3
inc x
hello
let name = fn()
testClosure(name, true)
block:
proc fn(): auto =
var x = 0
proc hello() {.closure.} =
echo 3
inc x
hello
let name = fn()
testClosure(name, true)
block:
proc fn(): auto =
var x = 0
proc hello() {.closure.} =
echo 3
inc x
hello
let name = fn()
testClosure(name, true)
let name2 = name
testClosure(name2, true)
block:
iterator hello(): int =
yield 1
testClosure(hello, false)
when not defined(js):
block:
iterator hello(): int {.closure.}=
yield 1
testClosure(hello, true)