Formatting.
[cl-mock.git] / tests / functions.lisp
1 ;; -*- mode: lisp; syntax: common-lisp; coding: utf-8-unix; package: cl-mock-tests; -*-
2
3 (in-package #:cl-mock-tests)
4 \f
5 (in-suite cl-mock)
6
7 (def-test progf.calls-binding ()
8   (progf '(foo) (list (lambda () 23))
9     (is (eql 23 (foo)))))
10
11 (def-test dflet.calls-binding ()
12   (dflet ((foo () 23))
13     (is (eql 23 (foo)))))
14
15 (def-test dflet.notinline.works ()
16   (declare (notinline foo bar))
17   (defun foo () 23)
18   (dflet ((foo () 42))
19     (is (eql 42 (foo)))))
20
21 (def-test dflet.simple-mock ()
22   (defun foo (&optional (string "Hello, World!"))
23     (1+ (bar string)))
24   (defun bar (string)
25     (length string))
26   (dflet ((bar (string)
27             (cond
28               ((equalp string "Hello, World!")
29                42))))
30     (is (eql 43 (foo)))
31     (is (eql 43 (foo "HELLO, WORLD!")))))
32
33 (def-test dflet.package-locks ()
34   "Either we can rebind LIST, or an error occurs and the binding is not
35 modified."
36   (let ((list #'list))
37     (handler-case (dflet ((list ()))
38                     (is (eql 42 (list))))
39       (error ()
40         (is (eq #'list list))))))
41
42 (def-test dflet.package-locks.order.1 ()
43   (defun foo ()
44     23)
45   (let ((list #'list)
46         (foo #'foo))
47     (handler-case (dflet
48                       ((foo () 13)
49                        (list () 42))
50                     (is (eql 42 (list)))
51                     (is (eql 13 (foo))))
52       (error ()
53         (is (eq #'list list))
54         (is (eq #'foo foo))))))
55
56 (def-test dflet.package-locks.order.2 ()
57   (defun foo ()
58     23)
59   (let ((list #'list)
60         (foo #'foo))
61     (handler-case (dflet
62                       ((list () 42)
63                        (foo () 13))
64                     (is (eql 42 (list)))
65                     (is (eql 13 (foo))))
66       (error ()
67         (is (eq #'list list))
68         (is (eq #'foo foo))))))