From 71ac7c2b1cdf22e1203ce378874faec4d0edd6c4 Mon Sep 17 00:00:00 2001 From: rekado Date: Tue, 16 Dec 2014 18:38:32 +0100 Subject: write tests for handle-stanza --- spec/xmpp.scm | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3