file-string-length.lsp 1.91 KB
Newer Older
pfdietz's avatar
pfdietz committed
1 2 3 4 5 6 7 8
;-*- 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
sds's avatar
sds committed
9
  (with-open-file
pfdietz's avatar
pfdietz committed
10 11 12
    (s "tmp.dat" :direction :output
       :if-exists :supersede)
    (loop for x across +standard-chars+
sds's avatar
sds committed
13 14 15 16 17 18 19
          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)))))))
pfdietz's avatar
pfdietz committed
20 21 22
  nil)

(deftest file-string-length.2
sds's avatar
sds committed
23
  (with-open-file
pfdietz's avatar
pfdietz committed
24 25 26
    (s "tmp.dat" :direction :output
       :if-exists :supersede)
    (loop for x across +standard-chars+
sds's avatar
sds committed
27 28 29 30 31 32 33
          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)))))))
pfdietz's avatar
pfdietz committed
34 35
  nil)

36 37 38
(deftest file-string-length.3
  (with-open-file
   (stream "tmp.dat" :direction :output
sds's avatar
sds committed
39
           :if-exists :supersede)
40
   (let* ((s1 "abcde")
sds's avatar
sds committed
41
          (n (file-string-length stream s1)))
42 43 44 45 46
     (do-special-strings
      (s2 s1 nil)
      (assert (= (file-string-length stream s2) n)))))
  nil)

pfdietz's avatar
pfdietz committed
47 48 49 50 51 52 53 54
;;; Error tests

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

(deftest file-string-length.error.2
  (signals-error
sds's avatar
sds committed
55
   (with-open-file
pfdietz's avatar
pfdietz committed
56 57 58 59 60 61 62 63
    (s "tmp.dat" :direction :output
       :if-exists :supersede)
    (file-string-length s))
   program-error)
  t)

(deftest file-string-length.error.3
  (signals-error
sds's avatar
sds committed
64
   (with-open-file
pfdietz's avatar
pfdietz committed
65 66 67 68 69 70 71
    (s "tmp.dat" :direction :output
       :if-exists :supersede)
    (file-string-length s #\x nil))
   program-error)
  t)


sds's avatar
sds committed
72

pfdietz's avatar
pfdietz committed
73