File: string.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 (154 lines) | stat: -rw-r--r-- 3,154 bytes parent folder | download | duplicates (3)
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
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Mon Sep 30 19:16:59 2002
;;;; Contains: Tests for string related functions and classes

(in-package :cl-test)

(deftest string.1
  (subtypep* 'string 'array)
  t t)

(deftest string.2
  (subtypep* 'string 'vector)
  t t)

(deftest string.3
  (subtypep* 'string 'sequence)
  t t)

(deftest string.4
  (let ((s (string #\a)))
    (values (notnot (stringp s)) s))
  t "a")

(deftest string.5
  (let ((s (string "")))
    (values (notnot (stringp s)) s))
  t "")

(deftest string.6
  (let ((s (string '|FOO|)))
    (values (notnot (stringp s)) s))
  t "FOO")

(deftest string.7
  (check-predicate
   #'(lambda (x)
       (handler-case (stringp (string x))
		     (type-error () :caught))))
  nil)

(deftest string.8 
  :notes (:allow-nil-arrays :nil-vectors-are-strings)
  (subtypep* '(array nil (*)) 'string)
  t t)

(deftest string.9
  :notes (:allow-nil-arrays :nil-vectors-are-strings)
  (subtypep* '(array nil 1) 'string)
  t t)

(deftest string.10
  :notes (:allow-nil-arrays :nil-vectors-are-strings)
  (string (make-array '(0) :element-type nil))
  "")

(deftest string.11
  (typep* "abcd" 'string)
  t)

(deftest string.12
  :notes (:allow-nil-arrays :nil-vectors-are-strings)
  (typep* (make-array '(17) :element-type nil) 'string)
  t)

(deftest string.13
  :notes (:allow-nil-arrays :nil-vectors-are-strings)
  (typep* (make-array '(0) :element-type nil) 'string)
  t)

(deftest string.14
  (let ((count 0))
    (loop for i below (min char-code-limit 65536)
	  for c = (code-char i)
	  for s = (and c (string c))
	  when (and c
		    (or (not (stringp s))
			(not (= (length s) 1))
			(not (eql c (char s 0)))))
	  collect (progn (incf count) (list i c s))
	  until (>= count 100)))
  nil)

(deftest string.15
  (when (> char-code-limit 65536)
    (loop for i = (random char-code-limit)
	  for c = (code-char i)
	  for s = (and c (string c))
	  repeat 2000
	  when (and c
		    (or (not (stringp s))
			(not (= (length s) 1))
			(not (eql c (char s 0)))))
	  collect (list i c s)))
  nil)

(deftest string.16
  (check-predicate #'(lambda (s) (or (not (stringp s)) (eq s (string s)))))
  nil)

(deftest string.17
  (typep* "abc" '(string))
  t)

(deftest string.18
  (typep* "abc" '(string *))
  t)

(deftest string.19
  (typep* "abc" '(string 3))
  t)

(deftest string.20
  (typep* "abc" '(string 2))
  nil)

(deftest string.21
  (typep* "abc" '(string 4))
  nil)

(deftest string.22
  (do-special-strings (s "X") (assert (typep s 'string)))
  nil)
		     
(deftest string.23
  (do-special-strings (s "X") (assert (typep s '(string))))
  nil)
		     
(deftest string.24
  (do-special-strings (s "X") (assert (typep s '(string *))))
  nil)
		     
(deftest string.25
  (do-special-strings (s "X")
		      (or (array-has-fill-pointer-p s)
			  (assert (typep s '(string 1)))))
  nil)

(deftest string.26
  (let ((i 0))
    (values (string (progn (incf i) "")) i))
  "" 1)

(def-fold-test string.fold.1 (string #\A))

;;; Error tests

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

(deftest string.error.2
  (signals-error (string nil nil) program-error)
  t)