From 773e515c583a7707319459390f61a0fa1db06eea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sat, 23 May 2020 12:55:30 +0200 Subject: Add tests for with-replaced-attrs. --- module/vcomponent/control.scm | 2 -- tests/vcomponent-control.scm | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 tests/vcomponent-control.scm diff --git a/module/vcomponent/control.scm b/module/vcomponent/control.scm index 3bdecc5a..34a2cf95 100644 --- a/module/vcomponent/control.scm +++ b/module/vcomponent/control.scm @@ -35,5 +35,3 @@ (lambda () body ...) (lambda () (restore-values! htable component (quote (key ...))))))])) ; Out guard -;;; TODO test that restore works, at all -;;; Test that non-local exit and return works diff --git a/tests/vcomponent-control.scm b/tests/vcomponent-control.scm new file mode 100644 index 00000000..318c4335 --- /dev/null +++ b/tests/vcomponent-control.scm @@ -0,0 +1,25 @@ +(((vcomponent control) with-replaced-attrs) + ((vcomponent) parse-calendar) + ((vcomponent base) attr)) + + + +(define ev (call-with-input-string + "BEGIN:DUMMY +KEY:value +END:DUMMY" + parse-calendar)) + +;; Test that temoraries are set and restored +(test-equal "value" (attr ev 'KEY)) +(with-replaced-attrs (ev (KEY "other")) + (test-equal "other" (attr ev 'KEY))) +(test-equal "value" (attr ev 'KEY)) + +;; Test that they are restored on non-local exit +(catch #t + (lambda () + (with-replaced-attrs (ev (KEY "other")) + (throw 'any))) + (lambda _ + (test-equal "value" (attr ev 'KEY)))) -- cgit v1.2.3