-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwith-test.lisp
69 lines (56 loc) · 1.83 KB
/
with-test.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
;;; Copyright 2020 Google LLC
;;;
;;; Use of this source code is governed by an MIT-style
;;; license that can be found in the LICENSE file or at
;;; https://opensource.org/licenses/MIT.
;;; Test for #:ace.core.with.
(defpackage #:ace.core.with-test
(:use #:cl
#:ace.core
#:ace.core.with
#:ace.test))
(in-package #:ace.core.with-test)
(defun init (&rest args) (values-list args))
(defparameter *cleanup-done* nil)
(defcleanup init (&rest vars)
`(setf *cleanup-done* (list ,@vars)))
(deftest macroexpand-test ()
(expect (macroexpand
'(defcleanup init-one (foo)
`(setf *cleanup-done* ,foo))))
(expect (macroexpand
'(defcleanup init (&rest vars)
`(setf *cleanup-done* (list ,@vars)))))
(expect (macroexpand
'(with ((bar (init nil))
((foo baz) (init :foo)))
(setf body-executed t)))))
(deftest with-test ()
(let ((*cleanup-done* :nope))
(with ((foo (init :foo)))
(expect (eq foo :foo)))
(expect (equal *cleanup-done* '(:foo))))
(let ((*cleanup-done* :nope)
(body-executed nil))
(with ((foo (init :foo))
(bar (init nil)))
(setf body-executed t))
(expect (equal *cleanup-done* '(:foo)))
(expect (not body-executed)))
(let ((*cleanup-done* :nope)
(body-executed nil))
(with ((bar (init nil))
(foo (init :foo)))
(setf body-executed t))
(expect (eq *cleanup-done* :nope))
(expect (not body-executed)))
(let ((*cleanup-done* :baz))
(with (((foo bar) (init :foo :bar)))
(expect (eq foo :foo))
(expect (eq bar :bar)))
(expect (equal *cleanup-done* '(:foo :bar))))
(let ((*cleanup-done* :baz))
(ignore-errors
(with ((foo (init :foo)))
(error "This is ignored.")))
(expect (equal *cleanup-done* '(:foo)))))