diff options
author | rekado <rekado@elephly.net> | 2014-12-16 18:38:32 +0100 |
---|---|---|
committer | rekado <rekado@elephly.net> | 2014-12-16 18:38:32 +0100 |
commit | 71ac7c2b1cdf22e1203ce378874faec4d0edd6c4 (patch) | |
tree | 3301d229e33334880e85648b1c2288d19d088e94 | |
parent | 131d26ffeca06e98b50191703baf7683f8b47e30 (diff) |
write tests for handle-stanza
-rw-r--r-- | spec/xmpp.scm | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/spec/xmpp.scm b/spec/xmpp.scm index a5f5ed8..0b9a74b 100644 --- a/spec/xmpp.scm +++ b/spec/xmpp.scm @@ -135,7 +135,35 @@ ;; TODO (suite "next-stanza-id!" (tests)) -(suite "handle-stanza" (tests)) +(suite "handle-stanza" + (tests + (test "calls id handler first, then generic handler" e + (assert-equal + '(generic-handler id-handler) + (let ((results '())) + (register-stanza-handler + (lambda _ (set! results (cons 'generic-handler results)))) + (register-temp-stanza-handler-for-id + (stanza-id (e 'stanza)) + (lambda _ (set! results (cons 'id-handler results)))) + ((@@ (gnubba xmpp) handle-stanza) (e 'stanza)) + results))) + (test "catches 'halt" e + (assert-false + (error? + (begin + (register-stanza-handler + (lambda _ (throw 'never-executed))) + (register-temp-stanza-handler-for-id + (stanza-id (e 'stanza)) + (lambda _ (throw 'halt))) + ((@@ (gnubba xmpp) handle-stanza) (e 'stanza))))))) + (options) + (setups + (setup 'stanza (iq "payload" #:to "romeo@capulet.it" #:id "1234"))) + (teardowns + ;; always reset the internal state after each test + (teardown e (set! (@@ (gnubba xmpp) *stanza-handlers*) '())))) (suite "run-handler-loop" (tests |