new tester; all tests categorized

This commit is contained in:
Araq 2014-01-13 02:10:03 +01:00
commit 20b5f31c03
481 changed files with 794 additions and 2506 deletions

16
tests/gensym/tgensym.nim Normal file
View file

@ -0,0 +1,16 @@
discard """
output: "123100"
"""
template hygienic(val: expr) =
var x = val
stdout.write x
var x = 100
hygienic 1
hygienic 2
hygienic 3
echo x

View file

@ -0,0 +1,31 @@
# We need to open the gensym'ed symbol again so that the instantiation
# creates a fresh copy; but this is wrong the very first reason for gensym
# is that scope rules cannot be used! So simply removing 'sfGenSym' does
# not work. Copying the symbol does not work either because we're already
# the owner of the symbol! What we need to do is to copy the symbol
# in the generic instantiation process...
type
TA = object
x: int
TB = object
x: string
template genImpl() =
var gensymed: T
when T is TB:
gensymed.x = "abc"
else:
gensymed.x = 123
shallowCopy(result, gensymed)
proc gen[T](x: T): T =
genImpl()
var
a: TA
b: TB
let x = gen(a)
let y = gen(b)
echo x.x, " ", y.x