nstring-downcase.lsp 3.25 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Thu Oct  3 21:33:16 2002
;;;; Contains: Tests for NSTRING-DOWNCASE

(in-package :cl-test)

(deftest nstring-downcase.1
  (let* ((s (copy-seq "A"))
	 (s2 (nstring-downcase s)))
11
    (values (eqt s s2) s))
12
13
14
15
16
  t "a")

(deftest nstring-downcase.2
  (let* ((s (copy-seq "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"))
	 (s2 (nstring-downcase s)))
17
    (values (eqt s s2) s))
18
19
20
21
22
23
  t
  "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")

(deftest nstring-downcase.3
  (let* ((s (copy-seq "0123456789!@#$%^&*()_-+=|\\{}[]:\";'<>?,./ "))
	 (s2 (nstring-downcase s)))
24
    (values (eqt s s2) s))
25
26
27
28
29
30
31
  t
  "0123456789!@#$%^&*()_-+=|\\{}[]:\";'<>?,./ ")

(deftest nstring-downcase.6
  (let* ((s (make-array 6 :element-type 'character
			:initial-contents '(#\A #\B #\C #\D #\E #\F)))
	 (s2 (nstring-downcase s)))
32
    (values (eqt s s2) s))
33
34
35
36
37
38
  t "abcdef")

(deftest nstring-downcase.7
  (let* ((s (make-array 6 :element-type 'standard-char
			:initial-contents '(#\A #\B #\7 #\D #\E #\F)))
	 (s2 (nstring-downcase s)))
39
    (values (eqt s s2) s))
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
  t
  "ab7def")

;; Tests with :start, :end

(deftest nstring-downcase.8
  (let ((s "ABCDEF"))
     (loop for i from 0 to 6
	   collect (nstring-downcase (copy-seq s) :start i)))
  ("abcdef" "Abcdef" "ABcdef" "ABCdef" "ABCDef" "ABCDEf" "ABCDEF"))

(deftest nstring-downcase.9
  (let ((s "ABCDEF"))
     (loop for i from 0 to 6
	   collect (nstring-downcase (copy-seq s) :start i :end nil)))
  ("abcdef" "Abcdef" "ABcdef" "ABCdef" "ABCDef" "ABCDEf" "ABCDEF"))

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

70
(deftest nstring-downcase.11
71
  :notes (:nil-vectors-are-strings)
72
73
74
  (nstring-downcase (make-array '(0) :element-type nil))
  "")

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
(deftest nstring-downcase.order.1
  (let ((i 0) a b c (s (copy-seq "ABCDEF")))
    (values
     (nstring-downcase
      (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 nstring-downcase.order.2
  (let ((i 0) a b c (s (copy-seq "ABCDEF")))
    (values
     (nstring-downcase
      (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)

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
;;; Error cases

(deftest nstring-downcase.error.1
  (classify-error (nstring-downcase))
  program-error)

(deftest nstring-downcase.error.2
  (classify-error (nstring-downcase (copy-seq "abc") :bad t))
  program-error)

(deftest nstring-downcase.error.3
  (classify-error (nstring-downcase (copy-seq "abc") :start))
  program-error)

(deftest nstring-downcase.error.4
  (classify-error (nstring-downcase (copy-seq "abc") :bad t
				      :allow-other-keys nil))
  program-error)

(deftest nstring-downcase.error.5
  (classify-error (nstring-downcase (copy-seq "abc") :end))
  program-error)

(deftest nstring-downcase.error.6
  (classify-error (nstring-downcase (copy-seq "abc") 1 2))
  program-error)


123