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

31
tests/assign/tassign.nim Normal file
View file

@ -0,0 +1,31 @@
# Test the assignment operator for complex types which need RTTI
type
TRec = object
x, y: int
s: string
seq: seq[string]
arr: seq[seq[array[0..3, string]]]
TRecSeq = seq[TRec]
proc test() =
var
a, b: TRec
a.x = 1
a.y = 2
a.s = "Hallo!"
a.seq = @["abc", "def", "ghi", "jkl"]
a.arr = @[]
setLen(a.arr, 4)
a.arr[0] = @[]
a.arr[1] = @[]
b = a # perform a deep copy here!
b.seq = @["xyz", "huch", "was", "soll"]
writeln(stdout, len(a.seq))
writeln(stdout, a.seq[3])
writeln(stdout, len(b.seq))
writeln(stdout, b.seq[3])
writeln(stdout, b.y)
test()

25
tests/assign/tcopy.nim Normal file
View file

@ -0,0 +1,25 @@
discard """
file: "tcopy.nim"
output: "TEMP=C:\\Programs\\xyz\\bin"
"""
# tests the substr proc
import
strutils
proc main() =
const
example = r"TEMP=C:\Programs\xyz\bin"
var
a, b: string
p: int
p = find(example, "=")
a = substr(example, 0, p-1)
b = substr(example, p+1)
writeln(stdout, a & '=' & b)
#writeln(stdout, b)
main()
#OUT TEMP=C:\Programs\xyz\bin

View file

@ -0,0 +1,24 @@
discard """
output: '''came here'''
"""
type
TAny* = object {.pure.}
value*: pointer
rawType: pointer
proc newAny(value, rawType: pointer): TAny =
result.value = value
result.rawType = rawType
var name: cstring = "example"
var ret: seq[tuple[name: string, a: TAny]] = @[]
for i in 0..8000:
var tup = ($name, newAny(nil, nil))
assert(tup[0] == "example")
ret.add(tup)
assert(ret[ret.len()-1][0] == "example")
echo "came here"

View file

@ -0,0 +1,16 @@
discard """
output: '''abc232'''
"""
var t, s: tuple[x: string, c: int]
proc ugh: seq[tuple[x: string, c: int]] =
result = @[("abc", 232)]
t = ugh()[0]
s = t
s = ugh()[0]
echo s[0], t[1]

39
tests/assign/tobjasgn.nim Normal file
View file

@ -0,0 +1,39 @@
discard """
output: '''0
pre test a:test b:1 c:2 haha:3
assignment test a:test b:1 c:2 haha:3
'''
"""
type TSomeObj = object of TObject
Variable: int
var a = TSomeObj()
echo a.Variable.`$`
# bug #575
type
Something = object of Tobject
a: string
b, c: int32
type
Other = object of Something
haha: int
proc `$`(x: Other): string =
result = "a:" & x.a & " b:" & $x.b & " c:" & $x.c & " haha:" & $x.haha
var
t: Other
t.a = "test"
t.b = 1
t.c = 2
t.haha = 3
echo "pre test ", $t
var x = t
echo "assignment test ", x

View file

@ -0,0 +1,30 @@
discard """
file: "tvariantasgn.nim"
output: "came here"
"""
#BUG
type
TAnyKind = enum
nkInt,
nkFloat,
nkString
TAny = object
case kind: TAnyKind
of nkInt: intVal: int
of nkFloat: floatVal: float
of nkString: strVal: string
var s: TAny
s.kind = nkString
s.strVal = "test"
var nr: TAny
nr.kind = nkint
nr.intVal = 78
# s = nr # works
nr = s # fails!
echo "came here"