Skip to content

Commit 5061117

Browse files
committed
adds expression test code
1 parent 8759aa6 commit 5061117

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

compiler/icnif/nifencoder.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ proc toNif(c: var EncodeContext; n: PNode) =
190190
c.withNode n:
191191
discard
192192
else:
193-
assert n.kind in {nkArgList, nkBracket, nkRecList, nkPragma} or n.len > 0, $n.kind
193+
assert n.kind in {nkArgList, nkBracket, nkRecList, nkPragma, nkType} or n.len > 0, $n.kind
194194
c.withNode(n):
195195
for i in 0 ..< n.len:
196196
c.toNif n[i]

tests/icnif/tencode_node2node.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,4 @@ testNifEncDec(graph, "modtestpragmas.nim")
333333
testNifEncDec(graph, "modtestprocs.nim")
334334
testNifEncDec(graph, "modteststatements.nim")
335335
testNifEncDec(graph, "modtestgenerics.nim")
336+
testNifEncDec(graph, "modtestexprs.nim")
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
type
2+
FooEnum = enum
3+
X,
4+
Y,
5+
Z
6+
7+
var enumTest = X
8+
enumTest = Y
9+
assert enumTest == Y
10+
11+
var enumSet = {X, Y}
12+
enumSet.incl Z
13+
14+
var intArray = [1, 1 + 1, 1 * 2, 0]
15+
intArray[3] = intArray[1] + intArray[0] * intArray[2]
16+
var strArray = ["foo", "ba" & "r", ""]
17+
strArray[2] = $(intArray[2])
18+
var floatArray = [intArray[0].float, 1.0, 0.0]
19+
floatArray[2] = floatArray[0] + floatArray[1]
20+
var intSeq = @[3, 2]
21+
intSeq.add 1
22+
23+
var tup1 = (foo: "Foo", bar: 123)
24+
tup1.foo = "Bar"
25+
tup1.bar = 321
26+
tup1[0] = "Baz"
27+
assert tup1 is (string, int)
28+
let (tup1foo, tup1bar) = tup1
29+
let (_, tup1bar2) = tup1
30+
let (tup1foo2, _) = tup1
31+
32+
var testAddr: int
33+
var testPtr = addr testAddr
34+
testPtr[] = 123
35+
36+
var testAddr2: array[2, int]
37+
var testPtr2: ptr int
38+
testPtr2 = addr testAddr2[0]
39+
var testPointer: pointer = testPtr2
40+
testPtr2 = cast[ptr int](testPointer)
41+
42+
var stmtListExpr = (echo "foo"; "stmtListExpr")
43+
var cond1 = true
44+
var testIfExpr = if cond1: 1 else: -1
45+
const TestWhenExpr = when sizeof(int) == 8: 1 else: -1
46+
var cond2: FooEnum = X
47+
var testCaseExpr = case cond2
48+
of X:
49+
1
50+
of Y:
51+
2
52+
else:
53+
3
54+
55+
var testBlockExpr = block:
56+
var a = "test"
57+
a
58+
59+
var testTryExpr = try:
60+
if cond1:
61+
222
62+
else:
63+
raise newException(CatchableError, "test")
64+
except CatchableError:
65+
-123
66+
67+
var testTryExpr2 = try:
68+
if cond1:
69+
333
70+
else:
71+
raise newException(CatchableError, "test")
72+
except CatchableError as e:
73+
echo e.msg
74+
-1234
75+
finally:
76+
echo "finally"
77+
78+
proc getNum(a: int): int = a
79+
echo static(getNum(123))

0 commit comments

Comments
 (0)