diff options
author | Zahary Karadjov <zahary@gmail.com> | 2017-04-09 22:59:24 +0300 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2017-04-09 22:59:24 +0300 |
commit | 987b522071fcf35b59d633bafd7d312cdb385c1f (patch) | |
tree | 714dafe8e8fba69bbe705a6d92335e106175f960 /tests/closure | |
parent | 03172bef6f58a2176c08253de44339ad9fce15d5 (diff) | |
download | Nim-987b522071fcf35b59d633bafd7d312cdb385c1f.tar.gz |
fix the do notation when used with procs
Diffstat (limited to 'tests/closure')
-rw-r--r-- | tests/closure/tdonotation.nim | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/closure/tdonotation.nim b/tests/closure/tdonotation.nim new file mode 100644 index 000000000..795b18f86 --- /dev/null +++ b/tests/closure/tdonotation.nim @@ -0,0 +1,47 @@ +discard """ +output: ''' +click at 10,20 +lost focus 2 +registered handler for UserEvent 1 +registered handler for UserEvent 3''' +""" + +import future + +type + Button = object + Event = object + x, y: int + +proc onClick(x: Button, handler: proc(x: Event)) = + handler(Event(x: 10, y: 20)) + +proc onFocusLost(x: Button, handler: proc()) = + handler() + +proc onUserEvent(x: Button, eventName: string, handler: proc) = + echo "registered handler for ", eventName + +var b = Button() + +b.onClick do (e: Event): + echo "click at ", e.x, ",", e.y + +when false: + # this syntax doesn't work yet + b.onFocusLost: + echo "lost focus 1" + +b.onFocusLost do: + echo "lost focus 2" + +b.onUserEvent("UserEvent 1") do: + discard + +when false: + # this syntax doesn't work yet + b.onUserEvent("UserEvent 2"): + discard + +b.onUserEvent("UserEvent 3", () => echo "event 2") + |