tests.lisp 3.01 KB
Newer Older
Philipp Marek's avatar
Philipp Marek committed
1
2
3
4
5
6
7
8
9
(in-package :cl-user)

(defpackage :alexandria2-tests
  (:use :cl :alexandria-2 #+sbcl :sb-rt #-sbcl :rtest)
  (:import-from #+sbcl :sb-rt #-sbcl :rtest
                #:*compile-tests* #:*expected-failures*))

(in-package :alexandria2-tests)

10
11
12
13
14
15
16
17
18
(deftest delete-from-plist*.middle
    (let ((input (list 'a 1 'b 2 'c 3 'd 4 'd 5)))
      (multiple-value-list (delete-from-plist* input 'b 'c)))
  ((a 1 d 4 d 5)
   ((c . 3) (b . 2))))

(deftest delete-from-plist*.start
    (let ((input (list 'a 1 'b 2 'c 3 'd 4 'd 5)))
      (multiple-value-list (delete-from-plist* input 'a 'c)))
Philipp Marek's avatar
Philipp Marek committed
19
  ((b 2 d 4 d 5)
20
   ((c . 3) (a . 1))))
Philipp Marek's avatar
Philipp Marek committed
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

;; Control Flow tests

(deftest line-up-first.no-form
    (values
     (equal (macroexpand '(line-up-first 5))
            5)
     (equal (macroexpand '(line-up-first (+ 1 2)))
            '(+ 1 2)))
  t
  t)

(deftest line-up-first.function-names-are-threaded
    (values
     (equal (macroexpand '(line-up-first 5 -))
            '(- 5))
     (equal (macroexpand '(line-up-first (+ 1 2) -))
            '(- (+ 1 2))))
  t
  t)

(deftest line-up-first.list-promotion
    (macroexpand '(line-up-first
                   5
                   (+ 20)
                   (/ 25)
                   -
                   (+ 40)))
  (+ (- (/ (+ 5 20) 25)) 40)
  t)

(deftest line-up-first.multiple-args
    (macroexpand '(line-up-first
                   "this-is-a-string"
                   (subseq 0 4)))
  (subseq "this-is-a-string" 0 4)
  t)

(deftest line-up-first.several-examples
    (values
     (equal (line-up-first (+ 40 2)) 42)
     (equal (line-up-first
             5
             (+ 20)
             (/ 25)
             -
             (+ 40)) 39)
     (equal (line-up-first
             "this-is-a-string"
             (subseq 4 5)
             (string-trim  "--------good"))
            "good"))
  t
  t
  t)

;; Thread last tests

(deftest line-up-last.no-forms
    (values
     (equal (macroexpand '(line-up-last 5)) 5)
     (equal (macroexpand '(line-up-last (+ 1 2))) '(+ 1 2)))
  t
  t)

(deftest line-up-last.function-names-are-threaded
    (values (equal (macroexpand
                    '(line-up-last 5
                      -))
                   '(- 5))
            (equal (macroexpand
                    '(line-up-last (+ 1 2)
                      -))
                   '(- (+ 1 2))))
  t
  t)

(deftest line-up-last.lisp-promotion
    (macroexpand '(line-up-last
                   5
                   (+ 20)
                   (/ 25)
                   -
                   (+ 40)))
  (+ 40 (- (/ 25 (+ 20 5))))
  t)

(deftest line-up-last.several-examples
    (values (equal (line-up-last (+ 40 2)) 42)
            (equal (line-up-last
                    5
                    (+ 20)
                    (/ 25)
                    -
                    (+ 40))
                   39)
            (equal (line-up-last
                    (list 1 -2 3 -4 5)
                    (mapcar #'abs)
                    (reduce #'+)
                    (format nil "abs sum is: ~D"))
                   "abs sum is: 15"))
  t
  t
  t)