File: string-upcase.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 (166 lines) | stat: -rw-r--r-- 4,467 bytes parent folder | download | duplicates (6)
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
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Tue Oct  1 07:51:00 2002
;;;; Contains: Tests for STRING-UPCASE

(in-package :cl-test)

(deftest string-upcase.1
  (let ((s "a"))
    (values (string-upcase s) s))
  "A" "a")

(deftest string-upcase.2
  (let ((s "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"))
    (values (string-upcase s) s))
  "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")

(deftest string-upcase.3
  (let ((s "0123456789!@#$%^&*()_-+=|\\{}[]:\";'<>?,./ "))
    (values (string-upcase s) s))
  "0123456789!@#$%^&*()_-+=|\\{}[]:\";'<>?,./ "
  "0123456789!@#$%^&*()_-+=|\\{}[]:\";'<>?,./ ")

(deftest string-upcase.4
  (string-upcase #\a)
  "A")

(deftest string-upcase.5
  (let ((sym '|a|))
    (values (string-upcase sym) sym))
  "A" |a|)

(deftest string-upcase.6
  (let ((s (make-array 6 :element-type 'character
		       :initial-contents '(#\a #\b #\c #\d #\e #\f))))
    (values (string-upcase s) s))
  "ABCDEF"
  "abcdef")

(deftest string-upcase.7
  (let ((s (make-array 6 :element-type 'standard-char
		       :initial-contents '(#\a #\b #\7 #\d #\e #\f))))
    (values (string-upcase s) s))
  "AB7DEF"
  "ab7def")

;; Tests with :start, :end

(deftest string-upcase.8
  (let ((s "abcdef"))
    (values
     (loop for i from 0 to 6
	   collect (string-upcase s :start i))
     s))
  ("ABCDEF" "aBCDEF" "abCDEF" "abcDEF" "abcdEF" "abcdeF" "abcdef")
  "abcdef")

(deftest string-upcase.9
  (let ((s "abcdef"))
    (values
      (loop for i from 0 to 6
	    collect 
	    (string-upcase s :start i :end nil))
      s))
  ("ABCDEF" "aBCDEF" "abCDEF" "abcDEF" "abcdEF" "abcdeF" "abcdef")
  "abcdef")

(deftest string-upcase.10
  (let ((s "abcde"))
    (values
     (loop for i from 0 to 4
	   collect (loop for j from i to 5
			 collect (string-upcase s :start i :end j)))
     s))
  (("abcde" "Abcde" "ABcde" "ABCde" "ABCDe" "ABCDE")
   ("abcde" "aBcde" "aBCde" "aBCDe" "aBCDE")
   ("abcde" "abCde" "abCDe" "abCDE")
   ("abcde" "abcDe" "abcDE")
   ("abcde" "abcdE"))
  "abcde")

(deftest string-upcase.11
  :notes (:nil-vectors-are-strings)
  (string-upcase (make-array '(0) :element-type nil))
  "")

(deftest string-upcase.12
  (loop for type in '(standard-char base-char character)
	for s = (make-array '(10) :element-type type
			    :fill-pointer 5
			    :initial-contents "aB0cDefGHi")
	collect (list s (string-upcase s)))
  (("aB0cD" "AB0CD") ("aB0cD" "AB0CD") ("aB0cD" "AB0CD")))


(deftest string-upcase.13
  (loop for type in '(standard-char base-char character)
	for s0 = (make-array '(10) :element-type type
			     :initial-contents "zZaB0cDefG")
	for s = (make-array '(5) :element-type type
			    :displaced-to s0
			    :displaced-index-offset 2)
	collect (list s (string-upcase s)))
  (("aB0cD" "AB0CD") ("aB0cD" "AB0CD") ("aB0cD" "AB0CD")))

(deftest string-upcase.14
  (loop for type in '(standard-char base-char character)
	for s = (make-array '(5) :element-type type
			    :adjustable t
			    :initial-contents "aB0cD")
	collect (list s (string-upcase s)))
  (("aB0cD" "AB0CD") ("aB0cD" "AB0CD") ("aB0cD" "AB0CD")))

;;; Order of evaluation tests

(deftest string-upcase.order.1
  (let ((i 0) a b c (s (copy-seq "abcdef")))
    (values
     (string-upcase
      (progn (setf a (incf i)) s)
      :start (progn (setf b (incf i)) 1)
      :end   (progn (setf c (incf i)) 4))
     i a b c))
  "aBCDef" 3 1 2 3)

(deftest string-upcase.order.2
  (let ((i 0) a b c (s (copy-seq "abcdef")))
    (values
     (string-upcase
      (progn (setf a (incf i)) s)
      :end   (progn (setf b (incf i)) 4)
      :start (progn (setf c (incf i)) 1))
     i a b c))
  "aBCDef" 3 1 2 3)

;;; Const fold tests

(def-fold-test string-upcase.fold.1 (string-upcase "abcde"))
  
;;; Error tests

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

(deftest string-upcase.error.2
  (signals-error (string-upcase (copy-seq "abc") :bad t) program-error)
  t)

(deftest string-upcase.error.3
  (signals-error (string-upcase (copy-seq "abc") :start) program-error)
  t)

(deftest string-upcase.error.4
  (signals-error (string-upcase (copy-seq "abc") :bad t
				      :allow-other-keys nil) program-error)
  t)

(deftest string-upcase.error.5
  (signals-error (string-upcase (copy-seq "abc") :end) program-error)
  t)

(deftest string-upcase.error.6
  (signals-error (string-upcase (copy-seq "abc") 1 2) program-error)
  t)