Commit | Line | Data |
---|---|---|
9aa2c796 JB |
1 | ;;;; strings.test --- test suite for Guile's string functions -*- scheme -*- |
2 | ;;;; Jim Blandy <jimb@red-bean.com> --- August 1999 | |
3 | ;;;; | |
1c17f6b0 | 4 | ;;;; Copyright (C) 1999, 2001, 2004 Free Software Foundation, Inc. |
9aa2c796 JB |
5 | ;;;; |
6 | ;;;; This program is free software; you can redistribute it and/or modify | |
7 | ;;;; it under the terms of the GNU General Public License as published by | |
8 | ;;;; the Free Software Foundation; either version 2, or (at your option) | |
9 | ;;;; any later version. | |
10 | ;;;; | |
11 | ;;;; This program is distributed in the hope that it will be useful, | |
12 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | ;;;; GNU General Public License for more details. | |
15 | ;;;; | |
16 | ;;;; You should have received a copy of the GNU General Public License | |
17 | ;;;; along with this software; see the file COPYING. If not, write to | |
18 | ;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330, | |
19 | ;;;; Boston, MA 02111-1307 USA | |
20 | ||
1c17f6b0 | 21 | (use-modules (test-suite lib)) |
9aa2c796 | 22 | |
d7e4c2da MV |
23 | (define exception:read-only-string |
24 | (cons 'misc-error "^string is read-only")) | |
548b9252 | 25 | |
049fa449 DH |
26 | (with-test-prefix "string=?" |
27 | ||
28 | (pass-if "respects 1st parameter's string length" | |
29 | (not (string=? "foo\0" "foo"))) | |
30 | ||
31 | (pass-if "respects 2nd paramter's string length" | |
32 | (not (string=? "foo" "foo\0"))) | |
33 | ||
34 | (with-test-prefix "wrong argument type" | |
35 | ||
36 | (pass-if-exception "1st argument symbol" | |
37 | exception:wrong-type-arg | |
38 | (string=? 'a "a")) | |
39 | ||
40 | (pass-if-exception "2nd argument symbol" | |
41 | exception:wrong-type-arg | |
42 | (string=? "a" 'b)))) | |
43 | ||
44 | (with-test-prefix "string<?" | |
45 | ||
46 | (pass-if "respects string length" | |
47 | (and (not (string<? "foo\0a" "foo\0a")) | |
48 | (string<? "foo\0a" "foo\0b"))) | |
49 | ||
50 | (with-test-prefix "wrong argument type" | |
51 | ||
52 | (pass-if-exception "1st argument symbol" | |
53 | exception:wrong-type-arg | |
54 | (string<? 'a "a")) | |
55 | ||
56 | (pass-if-exception "2nd argument symbol" | |
57 | exception:wrong-type-arg | |
58 | (string<? "a" 'b)))) | |
59 | ||
60 | (with-test-prefix "string-ci<?" | |
61 | ||
62 | (pass-if "respects string length" | |
63 | (and (not (string-ci<? "foo\0a" "foo\0a")) | |
64 | (string-ci<? "foo\0a" "foo\0b"))) | |
65 | ||
66 | (with-test-prefix "wrong argument type" | |
67 | ||
68 | (pass-if-exception "1st argument symbol" | |
69 | exception:wrong-type-arg | |
70 | (string-ci<? 'a "a")) | |
71 | ||
72 | (pass-if-exception "2nd argument symbol" | |
73 | exception:wrong-type-arg | |
74 | (string-ci<? "a" 'b)))) | |
75 | ||
76 | (with-test-prefix "string-set!" | |
77 | ||
d7e4c2da MV |
78 | (pass-if-exception "string constant" |
79 | exception:read-only-string | |
049fa449 DH |
80 | (string-set! "abc" 1 #\space))) |
81 | ||
82 | (with-test-prefix "substring-move!" | |
83 | ||
84 | (pass-if-exception "substring-move! checks start and end correctly" | |
85 | exception:out-of-range | |
86 | (substring-move! "sample" 3 0 "test" 3))) | |
1c17f6b0 MV |
87 | |
88 | (with-test-prefix "substring/shared" | |
89 | ||
90 | (pass-if "modify indirectly" | |
91 | (let ((str (string-copy "foofoofoo"))) | |
92 | (string-upcase! (substring/shared str 3 6)) | |
93 | (string=? str "fooFOOfoo"))) | |
94 | ||
95 | (pass-if "modify cow indirectly" | |
96 | (let* ((str1 (string-copy "foofoofoo")) | |
97 | (str2 (string-copy str1))) | |
98 | (string-upcase! (substring/shared str2 3 6)) | |
99 | (and (string=? str1 "foofoofoo") | |
7aa29a87 MV |
100 | (string=? str2 "fooFOOfoo")))) |
101 | ||
102 | (pass-if "modify double indirectly" | |
d7e4c2da | 103 | (let* ((str1 (string-copy "foofoofoo")) |
7aa29a87 MV |
104 | (str2 (substring/shared str1 2 7))) |
105 | (string-upcase! (substring/shared str2 1 4)) | |
106 | (string=? str1 "fooFOOfoo"))) | |
107 | ||
108 | (pass-if "modify cow double indirectly" | |
109 | (let* ((str1 "foofoofoo") | |
110 | (str2 (substring str1 2 7))) | |
111 | (string-upcase! (substring/shared str2 1 4)) | |
112 | (and (string=? str1 "foofoofoo") | |
113 | (string=? str2 "oFOOf"))))) |