File: functions.lisp

package info (click to toggle)
cl-metabang-bind 20200101.git9ab6e64-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 240 kB
  • sloc: lisp: 1,608; makefile: 2
file content (103 lines) | stat: -rw-r--r-- 2,178 bytes parent folder | download | duplicates (4)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
(in-package #:metabang-bind-test)

(deftestsuite test-flet (metabang-bind-test)
  ())

(addtest (test-flet)
  basic-access
  (bind (((:flet doit (x))
	  (setf x (* 2 x))
	  (setf x (+ x 3))
	  x))
    (ensure-same (doit 1) 5)
    (ensure-same (doit 2) 7)))

(addtest (test-flet)
  declarations
  (bind (((:flet doit (x))
	  (declare (type fixnum x))
	  (setf x (* 2 x))
	  (setf x (+ x 3))
	  x))
    (ensure-same (doit 1) 5)
    (ensure-same (doit 2) 7)))

(addtest (test-flet)
  docstring
  (bind (((:flet doit (x))
	  "if I knew how to get the docstring out of flet, I'd test it."
	  (setf x (* 2 x))
	  (setf x (+ x 3))
	  x))
    (ensure-same (doit 1) 5)
    (ensure-same (doit 2) 7)))

(addtest (test-flet)
  docstring-and-declarations-1
  (bind (((:flet doit (x))
	  "whatever"
	  (declare (type fixnum x))
	  (setf x (* 2 x))
	  (setf x (+ x 3))
	  x))
    (ensure-same (doit 1) 5)
    (ensure-same (doit 2) 7)))

(addtest (test-flet)
  docstring-and-declarations-2
  (bind (((:flet constant (x))
	  (declare (ignore x))
	  42))
    (ensure-same (constant 1) 42)))


(deftestsuite test-labels (metabang-bind-test)
  ())

(addtest (test-labels)
  basic-access
  (bind (((:labels my-oddp (x))
	  (cond ((<= x 0) nil)
		((= x 1) t)
		(t (my-oddp (- x 2))))))
    (ensure (my-oddp 1))
    (ensure (my-oddp 7))
    (ensure-null (my-oddp 2))))

(addtest (test-labels)
  declarations
  (bind (((:labels doit (x))
	  (declare (type fixnum x))
	  (setf x (* 2 x))
	  (setf x (+ x 3))
	  x))
    (ensure-same (doit 1) 5)
    (ensure-same (doit 2) 7)))

(addtest (test-labels)
  docstring
  (bind (((:labels doit (x))
	  "if I knew how to get the docstring out of flet, I'd test it."
	  (setf x (* 2 x))
	  (setf x (+ x 3))
	  x))
    (ensure-same (doit 1) 5)
    (ensure-same (doit 2) 7)))

(addtest (test-labels)
  docstring-and-declarations-1
  (bind (((:labels doit (x))
	  "whatever"
	  (declare (type fixnum x))
	  (setf x (* 2 x))
	  (setf x (+ x 3))
	  x))
    (ensure-same (doit 1) 5)
    (ensure-same (doit 2) 7)))

(addtest (test-labels)
  docstring-and-declarations-2
  (bind (((:labels constant (x))
	  (declare (ignore x))
	  42))
    (ensure-same (constant 1) 42)))