mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-09 22:43:34 +00:00
make tests green again
This commit is contained in:
@@ -15,12 +15,10 @@ type
|
||||
of nkString: strVal: string
|
||||
|
||||
var s: TAny
|
||||
s.kind = nkString
|
||||
s.strVal = "test"
|
||||
s = TAny(kind: nkString, strVal: "test")
|
||||
|
||||
var nr: TAny
|
||||
nr.kind = nkint
|
||||
nr.intVal = 78
|
||||
s = TAny(kind: nkInt, intVal: 78)
|
||||
|
||||
|
||||
# s = nr # works
|
||||
|
||||
@@ -59,7 +59,7 @@ type
|
||||
of M3: c:cstring
|
||||
|
||||
proc newMyObject(kind: MyKind, val: string): MyObject =
|
||||
result.kind = kind
|
||||
result = MyObject(kind: kind)
|
||||
|
||||
case kind
|
||||
of M1: result.a = parseInt(val)
|
||||
@@ -67,8 +67,7 @@ proc newMyObject(kind: MyKind, val: string): MyObject =
|
||||
of M3: result.c = val
|
||||
|
||||
proc newMyObjectRef(kind: MyKind, val: string): MyObjectRef =
|
||||
new(result)
|
||||
result.kind = kind
|
||||
result = MyObjectRef(kind: kind)
|
||||
case kind
|
||||
of M1: result.a = parseInt(val)
|
||||
of M2: result.b = parseFloat(val)
|
||||
|
||||
@@ -5,6 +5,7 @@ my secret
|
||||
11
|
||||
12
|
||||
'''
|
||||
joinable: "false"
|
||||
"""
|
||||
|
||||
## Example program that demonstrates how to use the
|
||||
|
||||
@@ -14,8 +14,7 @@ type
|
||||
proc some*[T](val: sink T): opt[T] {.inline.} =
|
||||
## Returns an ``opt`` that has the value.
|
||||
## nil is considered as none for reference types
|
||||
result.exists = true
|
||||
result.val = val
|
||||
result = opt[T](exists: true, val: val)
|
||||
|
||||
proc none*(T: typedesc): opt[T] {.inline.} =
|
||||
## Returns an ``opt`` for this type that has no value.
|
||||
@@ -32,7 +31,7 @@ proc unsafeGet*[T](self: opt[T]): lent T {.inline.} =
|
||||
|
||||
type
|
||||
VSeq*[T] = object
|
||||
len: int
|
||||
len: int
|
||||
data: ptr UncheckedArray[T]
|
||||
|
||||
proc `=destroy`*[T](m: var VSeq[T]) {.inline.} =
|
||||
|
||||
@@ -13,16 +13,14 @@ type
|
||||
PNode = ref TNode
|
||||
|
||||
proc newLit(x: int): PNode {.exportc: "newLit", dynlib.} =
|
||||
new(result)
|
||||
result.x = x
|
||||
result = PNode(k: nkLit, x: x)
|
||||
|
||||
proc newOp(k: TNodeKind, a, b: PNode): PNode {.exportc: "newOp", dynlib.} =
|
||||
assert a != nil
|
||||
assert b != nil
|
||||
new(result)
|
||||
result = PNode(k: nkSub, a: a, b: b)
|
||||
# now overwrite with the real value:
|
||||
result.k = k
|
||||
result.a = a
|
||||
result.b = b
|
||||
|
||||
proc buildTree(x: int): PNode {.exportc: "buildTree", dynlib.} =
|
||||
result = newOp(nkMul, newOp(nkAdd, newLit(x), newLit(x)), newLit(x))
|
||||
|
||||
@@ -104,9 +104,7 @@ block titerator2:
|
||||
for key, val in fieldPairs(x):
|
||||
echo key, ": ", val
|
||||
|
||||
var co: TMyCaseObj
|
||||
co.myDisc = enC
|
||||
co.c = 'Z'
|
||||
var co = TMyCaseObj(myDisc: enC, c: 'Z')
|
||||
for key, val in fieldPairs(co):
|
||||
echo key, ": ", val
|
||||
|
||||
|
||||
@@ -45,19 +45,14 @@ var
|
||||
flip: int
|
||||
|
||||
proc newCaseNode(data: string): PCaseNode =
|
||||
new(result)
|
||||
if flip == 0:
|
||||
result.kind = nkStr
|
||||
result.data = data
|
||||
result = PCaseNode(kind: nkStr, data: data)
|
||||
else:
|
||||
result.kind = nkWhole
|
||||
result.unused = @["", "abc", "abdc"]
|
||||
result = PCaseNode(kind: nkWhole, unused: @["", "abc", "abdc"])
|
||||
flip = 1 - flip
|
||||
|
||||
proc newCaseNode(a, b: PCaseNode): PCaseNode =
|
||||
new(result)
|
||||
result.kind = nkList
|
||||
result.sons = @[a, b]
|
||||
result = PCaseNode(kind: nkList, sons: @[a, b])
|
||||
|
||||
proc caseTree(lvl: int = 0): PCaseNode =
|
||||
if lvl == 3: result = newCaseNode("data item")
|
||||
|
||||
@@ -21,9 +21,7 @@ proc seq*() =
|
||||
discard
|
||||
|
||||
proc lrange*(key: string): TRedisList =
|
||||
var foo: TListItem
|
||||
foo.kind = RedisString
|
||||
foo.str = key
|
||||
var foo = TListItem(kind: RedisString, str: key)
|
||||
result = @[foo]
|
||||
|
||||
var p = lrange("mylist")
|
||||
|
||||
@@ -32,15 +32,11 @@ proc pop(Stack: var TStack): TAny =
|
||||
|
||||
var stack = newStack()
|
||||
|
||||
var s: TAny
|
||||
s.kind = nkString
|
||||
s.strVal = "test"
|
||||
var s = TAny(kind: nkString, strVal: "test")
|
||||
|
||||
stack.push(s)
|
||||
|
||||
var nr: TAny
|
||||
nr.kind = nkint
|
||||
nr.intVal = 78
|
||||
var nr = TAny(kind: nkInt, intVal: 78)
|
||||
|
||||
stack.push(nr)
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ proc produce() {.thread.} =
|
||||
m.data = line
|
||||
chan.send(m)
|
||||
close(input)
|
||||
m.k = mEof
|
||||
m = TMsg(k: mEof)
|
||||
chan.send(m)
|
||||
|
||||
open(chan)
|
||||
|
||||
Reference in New Issue
Block a user