This repository has been archived by the owner on Jul 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.nim
79 lines (69 loc) 路 2.07 KB
/
tests.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import
unittest,
macros, # for eyeballing `expandMacros` results
unrolled
suite "Simple for-loops over slices":
test "unroll works over slices such as 1.3":
expandMacros:
var total: int
unroll for i in 1..3:
total += i
check total == 1 + 2 + 3
test "unroll works over slices such as 1.<3":
expandMacros:
var total: int
unroll for i in 1..<3:
total += i
check total == 1 + 2
# BUG: !!!
# test "unroll works when variables are defined within the loop":
# expandMacros:
# var x: int
# unroll for i in 1..3:
# var j = i + 1
# x += j
# check x == (1 + 1) + (2 + 1) + (3 + 1)
suite "Simple for-loops over arrays":
test "unroll works over 'direct' arrays":
expandMacros:
var total: int
unroll for i in [1, 2, 3]:
total += i
check total == 1 + 2 + 3
test "unroll works over 'indirect' arrays":
expandMacros:
let args = [1, 2, 3]
var total: int
unroll for i in args:
total += i
check total == 1 + 2 + 3
# BUG: !!!
# suite "Nested for-loops over slices":
# test "unroll works in inner nested loops":
# expandMacros:
# var total: int
# for i in 1..3:
# unroll for j in 1..3:
# total += i + j
# check total == (1 + 1) + (1 + 2) + (1 + 3) +
# (2 + 1) + (2 + 2) + (2 + 3) +
# (3 + 1) + (3 + 2) + (3 + 3)
# test "unroll works in outer nested loops":
# expandMacros:
# var total: int
# unroll for i in 1..3:
# for j in 1..3:
# total += i + j
# check total == (1 + 1) + (1 + 2) + (1 + 3) +
# (2 + 1) + (2 + 2) + (2 + 3) +
# (3 + 1) + (3 + 2) + (3 + 3)
# test "unroll works with multiple nested loops":
# expandMacros:
# var total: int
# unroll:
# for i in 1..3:
# for j in 1..3:
# total += i + j
# check total == (1 + 1) + (1 + 2) + (1 + 3) +
# (2 + 1) + (2 + 2) + (2 + 3) +
# (3 + 1) + (3 + 2) + (3 + 3)