tdo.nim 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. discard """
  2. output: '''true
  3. true
  4. true
  5. true inner B'''
  6. """
  7. template withValue(a, b, c, d, e: untyped) =
  8. if c:
  9. d
  10. else:
  11. e
  12. template withValue(a, b, c, d: untyped) =
  13. if c:
  14. d
  15. const
  16. EVENT_READ = 1
  17. EVENT_WRITE = 2
  18. FLAG_HANDLE = 3
  19. EVENT_MASK = 3
  20. var s: string
  21. proc main =
  22. var value = false
  23. var fd = 8888
  24. var event = 0
  25. s.withValue(fd, value) do:
  26. if value:
  27. var oe = (EVENT_MASK)
  28. if (oe xor event) != 0:
  29. if (oe and EVENT_READ) != 0 and (event and EVENT_READ) == 0:
  30. discard
  31. if (oe and EVENT_WRITE) != 0 and (event and EVENT_WRITE) == 0:
  32. discard
  33. if (oe and EVENT_READ) == 0 and (event and EVENT_READ) != 0:
  34. discard
  35. if (oe and EVENT_WRITE) == 0 and (event and EVENT_WRITE) != 0:
  36. discard
  37. else:
  38. raise newException(ValueError, "error")
  39. do:
  40. raise newException(ValueError, "Descriptor is not registered in queue")
  41. proc main2 =
  42. var unused = 8
  43. # test 'then' branch:
  44. s.withValue(unused, true) do:
  45. echo "true"
  46. do:
  47. echo "false"
  48. # test overloading:
  49. s.withValue(unused, false) do:
  50. echo "cannot come here"
  51. # test 'else' branch:
  52. s.withValue(unused, false) do:
  53. echo "false"
  54. do:
  55. echo "true"
  56. # test proper nesting:
  57. s.withValue(unused, false) do:
  58. echo "false"
  59. s.withValue(unused, false) do:
  60. echo "false inner A"
  61. do:
  62. echo "true inner A"
  63. do:
  64. echo "true"
  65. s.withValue(unused, false) do:
  66. echo "false inner B"
  67. do:
  68. echo "true inner B"
  69. main2()