make tests green again

This commit is contained in:
Araq 2019-05-27 15:57:20 +02:00 • committed by Andreas Rumpf
commit 795044ed2b
10 changed files with 18 additions and 36 deletions

View file

@ -15,12 +15,10 @@ type
of nkString: strVal: string of nkString: strVal: string
var s: TAny var s: TAny
s.kind = nkString s = TAny(kind: nkString, strVal: "test")
s.strVal = "test"
var nr: TAny var nr: TAny
nr.kind = nkint s = TAny(kind: nkInt, intVal: 78)
nr.intVal = 78
# s = nr # works # s = nr # works

View file

@ -59,7 +59,7 @@ type
of M3: c:cstring of M3: c:cstring
proc newMyObject(kind: MyKind, val: string): MyObject = proc newMyObject(kind: MyKind, val: string): MyObject =
result.kind = kind result = MyObject(kind: kind)
case kind case kind
of M1: result.a = parseInt(val) of M1: result.a = parseInt(val)
@ -67,8 +67,7 @@ proc newMyObject(kind: MyKind, val: string): MyObject =
of M3: result.c = val of M3: result.c = val
proc newMyObjectRef(kind: MyKind, val: string): MyObjectRef = proc newMyObjectRef(kind: MyKind, val: string): MyObjectRef =
new(result) result = MyObjectRef(kind: kind)
result.kind = kind
case kind case kind
of M1: result.a = parseInt(val) of M1: result.a = parseInt(val)
of M2: result.b = parseFloat(val) of M2: result.b = parseFloat(val)

View file

@ -5,6 +5,7 @@ my secret
11 11
12 12
''' '''
joinable: "false"
""" """
## Example program that demonstrates how to use the ## Example program that demonstrates how to use the

View file

@ -14,8 +14,7 @@ type
proc some*[T](val: sink T): opt[T] {.inline.} = proc some*[T](val: sink T): opt[T] {.inline.} =
## Returns an ``opt`` that has the value. ## Returns an ``opt`` that has the value.
## nil is considered as none for reference types ## nil is considered as none for reference types
result.exists = true result = opt[T](exists: true, val: val)
result.val = val
proc none*(T: typedesc): opt[T] {.inline.} = proc none*(T: typedesc): opt[T] {.inline.} =
## Returns an ``opt`` for this type that has no value. ## Returns an ``opt`` for this type that has no value.

View file

@ -13,16 +13,14 @@ type
PNode = ref TNode PNode = ref TNode
proc newLit(x: int): PNode {.exportc: "newLit", dynlib.} = proc newLit(x: int): PNode {.exportc: "newLit", dynlib.} =
new(result) result = PNode(k: nkLit, x: x)
result.x = x
proc newOp(k: TNodeKind, a, b: PNode): PNode {.exportc: "newOp", dynlib.} = proc newOp(k: TNodeKind, a, b: PNode): PNode {.exportc: "newOp", dynlib.} =
assert a != nil assert a != nil
assert b != nil assert b != nil
new(result) result = PNode(k: nkSub, a: a, b: b)
# now overwrite with the real value:
result.k = k result.k = k
result.a = a
result.b = b
proc buildTree(x: int): PNode {.exportc: "buildTree", dynlib.} = proc buildTree(x: int): PNode {.exportc: "buildTree", dynlib.} =
result = newOp(nkMul, newOp(nkAdd, newLit(x), newLit(x)), newLit(x)) result = newOp(nkMul, newOp(nkAdd, newLit(x), newLit(x)), newLit(x))

View file

@ -104,9 +104,7 @@ block titerator2:
for key, val in fieldPairs(x): for key, val in fieldPairs(x):
echo key, ": ", val echo key, ": ", val
var co: TMyCaseObj var co = TMyCaseObj(myDisc: enC, c: 'Z')
co.myDisc = enC
co.c = 'Z'
for key, val in fieldPairs(co): for key, val in fieldPairs(co):
echo key, ": ", val echo key, ": ", val

View file

@ -45,19 +45,14 @@ var
flip: int flip: int
proc newCaseNode(data: string): PCaseNode = proc newCaseNode(data: string): PCaseNode =
new(result)
if flip == 0: if flip == 0:
result.kind = nkStr result = PCaseNode(kind: nkStr, data: data)
result.data = data
else: else:
result.kind = nkWhole result = PCaseNode(kind: nkWhole, unused: @["", "abc", "abdc"])
result.unused = @["", "abc", "abdc"]
flip = 1 - flip flip = 1 - flip
proc newCaseNode(a, b: PCaseNode): PCaseNode = proc newCaseNode(a, b: PCaseNode): PCaseNode =
new(result) result = PCaseNode(kind: nkList, sons: @[a, b])
result.kind = nkList
result.sons = @[a, b]
proc caseTree(lvl: int = 0): PCaseNode = proc caseTree(lvl: int = 0): PCaseNode =
if lvl == 3: result = newCaseNode("data item") if lvl == 3: result = newCaseNode("data item")

View file

@ -21,9 +21,7 @@ proc seq*() =
discard discard
proc lrange*(key: string): TRedisList = proc lrange*(key: string): TRedisList =
var foo: TListItem var foo = TListItem(kind: RedisString, str: key)
foo.kind = RedisString
foo.str = key
result = @[foo] result = @[foo]
var p = lrange("mylist") var p = lrange("mylist")

View file

@ -32,15 +32,11 @@ proc pop(Stack: var TStack): TAny =
var stack = newStack() var stack = newStack()
var s: TAny var s = TAny(kind: nkString, strVal: "test")
s.kind = nkString
s.strVal = "test"
stack.push(s) stack.push(s)
var nr: TAny var nr = TAny(kind: nkInt, intVal: 78)
nr.kind = nkint
nr.intVal = 78
stack.push(nr) stack.push(nr)

View file

@ -34,7 +34,7 @@ proc produce() {.thread.} =
m.data = line m.data = line
chan.send(m) chan.send(m)
close(input) close(input)
m.k = mEof m = TMsg(k: mEof)
chan.send(m) chan.send(m)
open(chan) open(chan)