This file is indexed.

/usr/share/scheme48-1.9/big/queue-check.scm is in scheme48 1.9-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
; Part of Scheme 48 1.9.  See file COPYING for notices and license.

; Authors: Robert Ransom

(define-test-suite queues-tests)

(define-syntax with-queue
  (syntax-rules ()
    ((with-queue (?var) . ?body)
     (let ((?var (make-queue))) . ?body))))

;;; TODO? - move to utility package?
(define-syntax list*
  (syntax-rules (skip)
    ((list* (skip ?expr) . ?rest)
     (begin ?expr
            (list* . ?rest)))
    ((list* ?expr . ?rest)
     (let ((x ?expr))
       (cons x (list* . ?rest))))
    ((list*)
     '())))

;;; TODO? - rename to PROVISIONAL-CELL-PUSH! and move to utility package?
(define (prov-cell-push! c x)
  (ensure-atomicity!
   (provisional-cell-set! c (cons x (provisional-cell-ref c)))))

;; Test wrapper for ENQUEUE!.  Real applications should use
;; ENQUEUE-MANY!, which is faster.
(define (stuff-queue! q xs)
  (ensure-atomicity!
   (for-each (lambda (x) (enqueue! q x)) xs)))

(define (devour-queue! q)
  (ensure-atomicity
   (let loop ((acc '()))
     (if (queue-empty? q)
	 (reverse acc)
	 (loop (cons (dequeue! q) acc))))))

(define (suck-queue! q n)
  (ensure-atomicity
   (let loop ((acc '())
	      (n n))
     (if (or (queue-empty? q)
	     (<= n 0))
	 (reverse acc)
	 (loop (cons (dequeue! q) acc)
	       (- n 1))))))

;;; Tests for utility functions used by the queues package.

(define-test-case list->queue-list queues-tests
  (for-each
   (lambda (xs)
     (check (receive (head tail) (list->queue-list xs)
		     (list xs (cdr head)))
	    => (list xs xs))
     (if (not (null? xs))
	 (check (receive (head tail) (list->queue-list xs)
			 (list xs tail))
		=> (list xs (srfi-1:last-pair xs))))
     (check (receive (head tail) (list->queue-list xs)
		     (list xs (eq? (srfi-1:last-pair head) tail)))
	    => (list xs #t)))
   '(() (foo) (foo bar) (foo bar baz) (foo bar baz quux))))

;;; Tests for the queue operations we plan to keep.

(define (do-basic-tests!)
  (check (with-queue (q)
                     (enqueue! q 'a)
                     (dequeue! q))
         => 'a)
  (check (with-queue (q)
                     (stuff-queue! q '(a b c a b c))
                     (devour-queue! q))
         => '(a b c a b c))
  (check (with-queue (q)
                     (stuff-queue! q '(a b c a b c))
                     (list* (suck-queue! q 3)
                            (skip (stuff-queue! q '(d e f)))
                            (devour-queue! q)))
         => '((a b c) (a b c d e f)))
  (check (with-queue (q)
                     (stuff-queue! q '(a b c a b c))
                     (list* (suck-queue! q 3)
                            (skip (enqueue-many! q '(d e f)))
                            (devour-queue! q)))
         => '((a b c) (a b c d e f)))
  (check (with-queue (q)
                     (stuff-queue! q '(a b c a b c))
                     (list* (devour-queue! q)
                            (maybe-dequeue! q)
                            (skip (stuff-queue! q '(d e f)))
                            (maybe-dequeue! q)
                            (devour-queue! q)))
         => '((a b c a b c)
              #f
              d
              (e f))))

(define-test-case basics queues-tests
  (do-basic-tests!))
(define-test-case basics-in-big-transaction queues-tests
  (ensure-atomicity!
   ;; Calling CHECK inside a transaction is normally a *bad* idea, but
   ;; this transaction should not need to be restarted.
   (do-basic-tests!)))

(define-test-case basics-comment-tests queues-tests
  (check (let ((q (make-queue))
	       (c (make-cell '())))
	   (enqueue! q 'a)
	   (ensure-atomicity!
	    (enqueue! q 'b)
	    (prov-cell-push! c (maybe-dequeue! q)))
	   (prov-cell-push! c (maybe-dequeue! q))
	   (cell-ref c))
	 => '(b a)))

(define-test-case queue-head queues-tests
  (check-exception (with-queue (q) (queue-head q)))
  (check (with-queue (q)
                     (stuff-queue! q '(a b c))
                     (queue-head q))
         => 'a))

(define-test-case list->queue queues-tests
  (check (let ((q (list->queue '(a b c d))))
           (list* (suck-queue! q 2)
                  (skip (stuff-queue! q '(e f g)))
                  (devour-queue! q)))
         => '((a b)
              (c d e f g))))

;;; Delenda.

(define-test-case delenda-comment-tests queues-tests
  (check (let ((q (make-queue))
	       (c (make-cell 'OOPS)))
	   (enqueue! q 'a)
	   (ensure-atomicity!
	    (enqueue! q 'b)
	    (provisional-cell-set! c (queue->list q)))
	   (cell-ref c))
	 => '(a b))
  (check (let ((q (make-queue))
	       (c (make-cell 'OOPS)))
	   (enqueue! q 'a)
	   (ensure-atomicity!
	    (enqueue! q 'b)
	    (provisional-cell-set! c (queue-length q)))
	   (cell-ref c))
	 => 2)
  (check (let ((q (make-queue))
	       (c (make-cell 'OOPS)))
	   (enqueue! q 'a)
	   (ensure-atomicity!
	    (enqueue! q 'b)
	    (provisional-cell-set! c (on-queue? q 'b)))
	   (cell-ref c))
	 => #t)
  ;; The following test is no longer in a comment, but might as well
  ;; stay here.
  (check (let ((q (make-queue))
	       (c (make-cell '())))
	   (enqueue! q 'a)
	   (ensure-atomicity!
	    (enqueue! q 'b)
	    (prov-cell-push! c (delete-from-queue! q 'b))
	    (prov-cell-push! c (maybe-dequeue! q))
	    (prov-cell-push! c (maybe-dequeue! q)))
	   (cell-ref c))
	 => '(#f a #t)))

(define-test-case queue-length queues-tests
  (for-each
   (lambda (n)
     (check (with-queue (q)
                        (stuff-queue! q (srfi-1:iota n))
                        (queue-length q))
            => n))
   '(0 1 2 3 4 5 6 7 8 9 10)))

(define-test-case delete-from-queue! queues-tests
  (for-each
   (lambda (x)
     (check (with-queue (q)
                        (stuff-queue! q '(a b c a b c))
                        (list* x
                               (delete-from-queue! q x)
                               (devour-queue! q)))
            => (list x
                     (x->boolean (memq x '(a b c)))
                     (append (delq x '(a b c))
                             '(a b c)))))
   '(a b c d))
  (for-each
   (lambda (x)
     (check (with-queue (q)
                        (stuff-queue! q '(a b c a b c))
                        (list* x
                               (delete-from-queue! q x)
                               (skip (stuff-queue! q '(d e f)))
                               (devour-queue! q)))
            => (list x
                     (x->boolean (memq x '(a b c)))
                     (append (delq x '(a b c))
                             '(a b c d e f)))))
   '(a b c d)))

(define-test-case on-queue? queues-tests
  (check
   (map (lambda (x)
          (with-queue (q)
                      (stuff-queue! q '(a b c))
                      (on-queue? q x)))
        '(a b c d))
   => '(#t #t #t #f))
  (check
   (map (lambda (x)
          (with-queue (q)
                      (on-queue? q x)))
        '(a b c d))
   => '(#f #f #f #f)))

(define-test-case queue->list queues-tests
  (check (with-queue (q)
                     (stuff-queue! q '(a b c d e f))
                     (list* (queue->list q)
                            (suck-queue! q 2)
                            (skip (stuff-queue! q '(g h)))
                            (queue->list q)
                            (devour-queue! q)))
         => '((a b c d e f)
              (a b)
              (c d e f g h)
              (c d e f g h))))