tdefine.nim 738 B

123456789101112131415161718192021222324252627282930
  1. discard """
  2. joinable: false
  3. cmd: "nim c -d:booldef -d:booldef2=false -d:intdef=2 -d:strdef=foobar -r $file"
  4. """
  5. const booldef {.booldefine.} = false
  6. const booldef2 {.booldefine.} = true
  7. const intdef {.intdefine.} = 0
  8. const strdef {.strdefine.} = ""
  9. doAssert defined(booldef)
  10. doAssert defined(booldef2)
  11. doAssert defined(intdef)
  12. doAssert defined(strdef)
  13. doAssert booldef
  14. doAssert not booldef2
  15. doAssert intdef == 2
  16. doAssert strdef == "foobar"
  17. # Intentionally not defined from command line
  18. const booldef3 {.booldefine.} = true
  19. const intdef2 {.intdefine.} = 1
  20. const strdef2 {.strdefine.} = "abc"
  21. type T = object
  22. when booldef3:
  23. field1: int
  24. when intdef2 == 1:
  25. field2: int
  26. when strdef2 == "abc":
  27. field3: int