File: file-string-length.lsp

package info (click to toggle)
cl-ansi-tests 20071218-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,000 kB
  • ctags: 22,025
  • sloc: lisp: 134,798; makefile: 144
file content (73 lines) | stat: -rw-r--r-- 1,817 bytes parent folder | download | duplicates (13)
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
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Thu Jan 22 21:34:04 2004
;;;; Contains: Tests of FILE-STRING-LENGTH

(in-package :cl-test)

(deftest file-string-length.1
  (with-open-file 
    (s "tmp.dat" :direction :output
       :if-exists :supersede)
    (loop for x across +standard-chars+
	  for len = (file-string-length s x)
	  do (assert (typep len '(or null (integer 0))))
	  do (let ((pos1 (file-position s)))
	       (write-char x s)
	       (let ((pos2 (file-position s)))
		 (when (and pos1 pos2 len)
		   (assert (= (+ pos1 len) pos2)))))))
  nil)

(deftest file-string-length.2
  (with-open-file 
    (s "tmp.dat" :direction :output
       :if-exists :supersede)
    (loop for x across +standard-chars+
	  for len = (file-string-length s (string x))
	  do (assert (typep len '(or null (integer 0))))
	  do (let ((pos1 (file-position s)))
	       (write-sequence (string x) s)
	       (let ((pos2 (file-position s)))
		 (when (and pos1 pos2 len)
		   (assert (= (+ pos1 len) pos2)))))))
  nil)

(deftest file-string-length.3
  (with-open-file
   (stream "tmp.dat" :direction :output
	   :if-exists :supersede)
   (let* ((s1 "abcde")
	  (n (file-string-length stream s1)))
     (do-special-strings
      (s2 s1 nil)
      (assert (= (file-string-length stream s2) n)))))
  nil)

;;; Error tests

(deftest file-string-length.error.1
  (signals-error (file-string-length) program-error)
  t)

(deftest file-string-length.error.2
  (signals-error
   (with-open-file 
    (s "tmp.dat" :direction :output
       :if-exists :supersede)
    (file-string-length s))
   program-error)
  t)

(deftest file-string-length.error.3
  (signals-error
   (with-open-file 
    (s "tmp.dat" :direction :output
       :if-exists :supersede)
    (file-string-length s #\x nil))
   program-error)
  t)