Debian Codegraph @

src/old-tests/tests-3.3-req.scm

raw
1
2 (add-tests-with-string-output "string-set! errors"
3 ; first with a fixed index
4 ;
5 [(let ((t 1))
6 (and (begin (set! t (fxadd1 t)) t)
7 t)) => "2\n"]
8
9 [(let ((f (if (boolean? (lambda () 12))
10 (lambda () 13)
11 (lambda () 14))))
12 (f)) => "14\n"]
13
14 [(let ([f 12])
15 (let ([g (lambda () f)])
16 (g))) => "12\n"]
17 [(fx< 1 2) => "#t\n"]
18 [(let ([f (lambda (x y) (fx< x y))])
19 (f 10 10)) => "#f\n"]
20 [(fx< 10 10) => "#f\n"]
21 [(fx< 10 2) => "#f\n"]
22 [(fx<= 1 2) => "#t\n"]
23 [(fx<= 10 10) => "#t\n"]
24 [(fx<= 10 2) => "#f\n"]
25 #;[(let ([f
26 (lambda (s i c)
27 (unless (string? s)
28 (error 'string-set!1 "not a string ~s" s))
29 (unless (fixnum? i)
30 (error 'string-set!2 "invalid index ~s" i))
31 (if (fx< i ($string-length s))
32 #f
33 (error 's1 ""))
34 (unless (fx>= i 0)
35 (error 'string-set!3 "index ~s is out of range for ~s" i s))
36 (unless (and (fx< i (string-length s))
37 (fx>= i 0))
38 (error 'string-set!3 "index ~s is out of range for ~s" i s))
39 (unless (char? c)
40 (error 'string-set!4 "not a char ~s" c))
41 ($string-set! s i c) 12)])
42 (let ([x ($string #\a #\b #\c)]
43 [y #\a])
44 (f x 8 y))) => ""]
45
46 [(let ([x 12])
47 (string-set! x 0 #\a)) => ""]
48 [(let ([x (string #\a #\b #\c)]
49 [y 12])
50 (string-set! x 0 y)) => ""]
51 [(let ([x (string #\a #\b #\c)]
52 [y 12])
53 (string-set! x 8 y)) => ""]
54 [(let ([x (string #\a #\b #\c)]
55 [y #\a])
56 (string-set! x 8 y)) => ""]
57 [(let ([x (string #\a #\b #\c)])
58 (string-set! x 8 #\a)) => ""]
59 [(let ([x (string #\a #\b #\c)]
60 [y #\a])
61 (string-set! x -1 y)) => ""]
62 ; next the general case
63 ;;; 6 kinds of errors:
64 ;;; string is either:
65 ;;; lex-non-string, run-non-string, lex-string, valid
66 ;;; index is either:
67 ;;; lex-invalid, runtime-non-fixnum, runtime-above, runtime-below, valid
68 ;;; char is either:
69 ;;; lex-invalid, runtime-non-char, valid.
70 ;;; that's 4x5x3 = 60 tests!
71 ;;; If we skip over the lexical string check, (since I don't do it),
72 ;;; we have: 2x5x3 = 30 tests.
73
74 [(let ([s (string #\a #\b #\c)] [i 1] [c #\X]) (string-set! s i c) s)
75 => "\"aXc\"\n"]
76 [(let ([s (string #\a #\b #\c)] [i 1]) (string-set! s i #\X) s)
77 => "\"aXc\"\n"]
78 [(let ([s (string #\a #\b #\c)] [i 1] [c 'X]) (string-set! s i c) s)
79 => ""]
80
81 [(let ([s (string #\a #\b #\c)] [i 1] [c #\X]) (string-set! s 1 c) s)
82 => "\"aXc\"\n"]
83 [(let ([s (string #\a #\b #\c)] [i 1]) (string-set! s 1 #\X) s)
84 => "\"aXc\"\n"]
85 [(let ([s (string #\a #\b #\c)] [i 1] [c 'X]) (string-set! s 1 c) s)
86 => ""]
87
88 [(let ([s (string #\a #\b #\c)] [i 3] [c #\X]) (string-set! s i c) s)
89 => ""]
90 [(let ([s (string #\a #\b #\c)] [i 3]) (string-set! s i #\X) s)
91 => ""]
92 [(let ([s (string #\a #\b #\c)] [i 3] [c 'X]) (string-set! s i c) s)
93 => ""]
94
95 [(let ([s (string #\a #\b #\c)] [i -10] [c #\X]) (string-set! s i c) s)
96 => ""]
97 [(let ([s (string #\a #\b #\c)] [i -11]) (string-set! s i #\X) s)
98 => ""]
99 [(let ([s (string #\a #\b #\c)] [i -1] [c 'X]) (string-set! s i c) s)
100 => ""]
101
102 [(let ([s (string #\a #\b #\c)] [i 'foo] [c #\X]) (string-set! s i c) s)
103 => ""]
104 [(let ([s (string #\a #\b #\c)] [i 'foo]) (string-set! s i #\X) s)
105 => ""]
106 [(let ([s (string #\a #\b #\c)] [i 'foo] [c 'X]) (string-set! s i c) s)
107 => ""]
108
109
110
111 [(let ([s '(string #\a #\b #\c)] [i 1] [c #\X]) (string-set! s i c) s)
112 => ""]
113 [(let ([s '(string #\a #\b #\c)] [i 1]) (string-set! s i #\X) s)
114 => ""]
115 [(let ([s '(string #\a #\b #\c)] [i 1] [c 'X]) (string-set! s i c) s)
116 => ""]
117
118 [(let ([s '(string #\a #\b #\c)] [i 1] [c #\X]) (string-set! s 1 c) s)
119 => ""]
120 [(let ([s '(string #\a #\b #\c)] [i 1]) (string-set! s 1 #\X) s)
121 => ""]
122 [(let ([s '(string #\a #\b #\c)] [i 1] [c 'X]) (string-set! s 1 c) s)
123 => ""]
124
125 [(let ([s '(string #\a #\b #\c)] [i 3] [c #\X]) (string-set! s i c) s)
126 => ""]
127 [(let ([s '(string #\a #\b #\c)] [i 3]) (string-set! s i #\X) s)
128 => ""]
129 [(let ([s '(string #\a #\b #\c)] [i 3] [c 'X]) (string-set! s i c) s)
130 => ""]
131
132 [(let ([s '(string #\a #\b #\c)] [i -10] [c #\X]) (string-set! s i c) s)
133 => ""]
134 [(let ([s '(string #\a #\b #\c)] [i -11]) (string-set! s i #\X) s)
135 => ""]
136 [(let ([s '(string #\a #\b #\c)] [i -1] [c 'X]) (string-set! s i c) s)
137 => ""]
138
139 [(let ([s '(string #\a #\b #\c)] [i 'foo] [c #\X]) (string-set! s i c) s)
140 => ""]
141 [(let ([s '(string #\a #\b #\c)] [i 'foo]) (string-set! s i #\X) s)
142 => ""]
143 [(let ([s '(string #\a #\b #\c)] [i 'foo] [c 'X]) (string-set! s i c) s)
144 => ""]
145 )
146
147 #!eof
148
149 (add-tests-with-string-output "string errors"
150 [(let ([f (lambda (a b c) (string a b c))])
151 (f #\a #\b #\c)) => "\"abc\"\n"]
152 [(let ([f (lambda (a b c) (string a b c))])
153 (f #\a 12 #\c)) => ""]
154 [(let ([f string])
155 (f #\a #\b #\c)) => "\"abc\"\n"]
156 [(let ([f string])
157 (f #\a #\b 'x)) => ""]
158 [(string #\a #\b #\c) => "\"abc\"\n"]
159 [(string #\a #\b #t) => ""]
160 )