aboutsummaryrefslogtreecommitdiff
path: root/examples.lisp
blob: 831cb09f6a0b0464db988ca6b6dfb67c4e04ede1 (plain)
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
70
71
72
73
74
75
76
77
(defpackage :testiere.examples
  (:use #:cl)
  (:import-from #:testiere
                #:defun/t
                #:with-stubs))

(in-package :testiere.examples)

(defun test-fibble ()
  (assert (= 13 (fibble 1 2))))

(defun/t fibble (x y &key (z 10))
  "Hey, a docstring."
  :tests
  (:program test-fibble)
  (= (1 2) 13)
  (>= (1 2 :z 1) -5)
  (:outputp (0 10 :z 0) (lambda (result) (equalp result 10)))
  (:fails ("strings" "ain't" :z "numbers"))
  :end
  (+ x y z))


(defvar *count*)

(defun/t increment-count ()
  "Increments the *count* variable."
  :tests
  (:with-bindings ((*count* 4))
    (:afterp () (lambda () (= *count* 5)))
    (= () 6) 
    (:outputp () (lambda (x) (= x 7))))
  :end
  (incf *count*))

(defun/t other-increment-count (&optional (amount 1))
  "Also increments the *count* variable by an optional amount."
  :tests
  (:with-bindings ((*count* 10))
    (= () 11))
  (:with-bindings ((*count* 0))
    (= (10) 10)
    (:afterp (2) (lambda () (= *count* 12))))
  :end
  (incf *count* amount))


(defun just-a-function ()
  (print "Just a function."))

(defun/t call-just-a-function ()
  "Calls JUST-A-FUNCTION."
  :tests
  (:with-stubs ((just-a-function () (print "TEMP JUST-A-FUNCTION.")))
    (equal () "TEMP JUST-A-FUNCTION."))
  :end
  (just-a-function))


(defun make-drakma-request ()
  "Make an HTTP request using DRAKMA"
  ;; implemented elsewhere
  )

(defun test-url-word-counter ()
  (with-stubs
      ((make-drakma-request () "one two three four five six seven"))
    (assert (= (count-words) 7))))

(defun/t count-words ()
  "Fetches a url and counts now many words the page contains."
  :tests
  (:program test-url-word-counter)
  :end
  (let ((fetched
          (make-drakma-request)))
    (1+ (count #\space fetched))))