twhen.nim 754 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. discard """
  2. nimout: '''
  3. nimvm - when
  4. nimvm - whenElif
  5. nimvm - whenElse
  6. '''
  7. output: '''
  8. when
  9. whenElif
  10. whenElse
  11. '''
  12. """
  13. # test both when and when nimvm to ensure proper evaluation
  14. proc compileOrRuntimeProc(s: string) =
  15. when nimvm:
  16. echo "nimvm - " & s
  17. else:
  18. echo s
  19. template output(s: string) =
  20. static:
  21. compileOrRuntimeProc(s)
  22. compileOrRuntimeProc(s)
  23. when compiles(1):
  24. output("when")
  25. elif compiles(2):
  26. output("fail - whenElif")
  27. else:
  28. output("fail - whenElse")
  29. when compiles(nonexistent):
  30. output("fail - when")
  31. elif compiles(1):
  32. output("whenElif")
  33. else:
  34. output("fail - whenElse")
  35. when compiles(nonexistent):
  36. output("fail - when")
  37. elif compiles(nonexistent):
  38. output("fail - whenElif")
  39. else:
  40. output("whenElse")