new tester; all tests categorized
This commit is contained in:
parent
51ee524109
commit
20b5f31c03
481 changed files with 794 additions and 2506 deletions
23
tests/objvariant/tadrdisc.nim
Normal file
23
tests/objvariant/tadrdisc.nim
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
discard """
|
||||
file: "tadrdisc.nim"
|
||||
line: 20
|
||||
errormsg: "for a \'var\' type a variable needs to be passed"
|
||||
"""
|
||||
# Test that the address of a dicriminants cannot be taken
|
||||
|
||||
type
|
||||
TKind = enum ka, kb, kc
|
||||
TA = object
|
||||
case k: TKind
|
||||
of ka: x, y: int
|
||||
of kb: a, b: string
|
||||
of kc: c, d: float
|
||||
|
||||
proc setKind(k: var TKind) =
|
||||
k = kc
|
||||
|
||||
var a: TA
|
||||
setKind(a.k) #ERROR_MSG for a 'var' type a variable needs to be passed
|
||||
|
||||
|
||||
|
||||
60
tests/objvariant/tcheckedfield1.nim
Normal file
60
tests/objvariant/tcheckedfield1.nim
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
discard """
|
||||
errormsg: "cannot prove that field 'x.s' is accessible"
|
||||
line:51
|
||||
"""
|
||||
|
||||
import strutils
|
||||
|
||||
{.warning[ProveField]: on.}
|
||||
|
||||
type
|
||||
TNodeKind = enum
|
||||
nkBinary, nkTernary, nkStr
|
||||
PNode = ref TNode not nil
|
||||
TNode = object
|
||||
case k: TNodeKind
|
||||
of nkBinary, nkTernary: a, b: PNode
|
||||
of nkStr: s: string
|
||||
|
||||
PList = ref object
|
||||
data: string
|
||||
next: PList
|
||||
|
||||
proc getData(x: PList not nil) =
|
||||
echo x.data
|
||||
|
||||
var head: PList
|
||||
|
||||
proc processList() =
|
||||
var it = head
|
||||
while it != nil:
|
||||
getData(it)
|
||||
it = it.next
|
||||
|
||||
proc toString2(x: PNode): string =
|
||||
if x.k < nkStr:
|
||||
toString2(x.a) & " " & toString2(x.b)
|
||||
else:
|
||||
x.s
|
||||
|
||||
proc toString(x: PNode): string =
|
||||
case x.k
|
||||
of nkTernary, nkBinary:
|
||||
toString(x.a) & " " & toString(x.b)
|
||||
of nkStr:
|
||||
x.s
|
||||
|
||||
proc toString3(x: PNode): string =
|
||||
if x.k <= nkBinary:
|
||||
toString3(x.a) & " " & toString3(x.b)
|
||||
else:
|
||||
x.s # x.k in {nkStr} --> fact: not (x.k <= nkBinary)
|
||||
|
||||
proc p() =
|
||||
var x: PNode = PNode(k: nkStr, s: "abc")
|
||||
|
||||
let y = x
|
||||
if not y.isNil:
|
||||
echo toString(y), " ", toString2(y)
|
||||
|
||||
p()
|
||||
14
tests/objvariant/temptycaseobj.nim
Normal file
14
tests/objvariant/temptycaseobj.nim
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
discard """
|
||||
line: 11
|
||||
errormsg: "identifier expected, but found 'keyword of'"
|
||||
"""
|
||||
|
||||
type
|
||||
TMyEnum = enum enA, enU, enO
|
||||
TMyCase = object
|
||||
case e: TMyEnum
|
||||
of enA:
|
||||
of enU: x, y: int
|
||||
of enO: a, b: string
|
||||
|
||||
|
||||
52
tests/objvariant/tvariantstack.nim
Normal file
52
tests/objvariant/tvariantstack.nim
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
discard """
|
||||
file: "tvariantstack.nim"
|
||||
output: "came here"
|
||||
"""
|
||||
#BUG
|
||||
type
|
||||
TAnyKind = enum
|
||||
nkInt,
|
||||
nkFloat,
|
||||
nkString
|
||||
PAny = ref TAny
|
||||
TAny = object
|
||||
case kind: TAnyKind
|
||||
of nkInt: intVal: int
|
||||
of nkFloat: floatVal: float
|
||||
of nkString: strVal: string
|
||||
|
||||
TStack* = object
|
||||
list*: seq[TAny]
|
||||
|
||||
proc newStack(): TStack =
|
||||
result.list = @[]
|
||||
|
||||
proc push(Stack: var TStack, item: TAny) =
|
||||
var nSeq: seq[TAny] = @[item]
|
||||
for i in items(Stack.list):
|
||||
nSeq.add(i)
|
||||
Stack.list = nSeq
|
||||
|
||||
proc pop(Stack: var TStack): TAny =
|
||||
result = Stack.list[0]
|
||||
Stack.list.delete(0)
|
||||
|
||||
var stack = newStack()
|
||||
|
||||
var s: TAny
|
||||
s.kind = nkString
|
||||
s.strVal = "test"
|
||||
|
||||
stack.push(s)
|
||||
|
||||
var nr: TAny
|
||||
nr.kind = nkint
|
||||
nr.intVal = 78
|
||||
|
||||
stack.push(nr)
|
||||
|
||||
var t = stack.pop()
|
||||
echo "came here"
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue