summary refs log tree commit diff stats
path: root/tests/whenstmt/twhen.nim
blob: b155ddcfb3c55a4c844c691615c33a2d09a444eb (plain) (blame)
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
discard """
  nimout: '''
nimvm - when
nimvm - whenElif
nimvm - whenElse
'''
  output: '''
when
whenElif
whenElse
'''
"""

# test both when and when nimvm to ensure proper evaluation

proc compileOrRuntimeProc(s: string) =
  when nimvm:
    echo "nimvm - " & s
  else:
     echo s

template output(s: string) =
  static:
    compileOrRuntimeProc(s)
  compileOrRuntimeProc(s)

when compiles(1):
  output("when")
elif compiles(2):
  output("fail - whenElif")
else:
  output("fail - whenElse")

when compiles(nonexistent):
  output("fail - when")
elif compiles(1):
  output("whenElif")
else:
  output("fail - whenElse")

when compiles(nonexistent):
  output("fail - when")
elif compiles(nonexistent):
  output("fail - whenElif")
else:
  output("whenElse")