2305
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
2296
|
3 |
"{ Package: 'stx:goodies/regression' }"
|
|
4 |
|
|
5 |
"{ NameSpace: RegressionTests }"
|
|
6 |
|
|
7 |
TestCase subclass:#MutabilityTest
|
|
8 |
instanceVariableNames:''
|
|
9 |
classVariableNames:''
|
|
10 |
poolDictionaries:''
|
|
11 |
category:'tests-Regression-Numbers'
|
|
12 |
!
|
|
13 |
|
|
14 |
!MutabilityTest class methodsFor:'documentation'!
|
|
15 |
|
|
16 |
documentation
|
|
17 |
"
|
|
18 |
documentation to be added.
|
|
19 |
|
|
20 |
class:
|
|
21 |
<a short class summary here, describing what instances represent>
|
|
22 |
|
|
23 |
responsibilities:
|
|
24 |
<describing what my main role is>
|
|
25 |
|
|
26 |
collaborators:
|
|
27 |
<describing with whom and how I talk to>
|
|
28 |
|
|
29 |
API:
|
|
30 |
<public api and main messages>
|
|
31 |
|
|
32 |
example:
|
|
33 |
<a one-line examples on how to use - can also be in a separate example method>
|
|
34 |
|
|
35 |
implementation:
|
|
36 |
<implementation points>
|
|
37 |
|
|
38 |
[author:]
|
|
39 |
Claus Gittinger
|
|
40 |
|
|
41 |
[instance variables:]
|
|
42 |
|
|
43 |
[class variables:]
|
|
44 |
|
|
45 |
[see also:]
|
|
46 |
|
|
47 |
"
|
|
48 |
! !
|
|
49 |
|
|
50 |
!MutabilityTest methodsFor:'tests'!
|
|
51 |
|
|
52 |
test01_immutability
|
|
53 |
"literals are immutable - if specified so"
|
|
54 |
|
|
55 |
|arr arr2|
|
|
56 |
|
2305
|
57 |
self skipIf:(self class compiledMethodAt:#test01_immutability)
|
|
58 |
byteCode isNil
|
|
59 |
description:'skipped because stc-compiled literals are always immutable'.
|
|
60 |
|
2296
|
61 |
arr := #[1 2 3 4].
|
|
62 |
self assert:(arr isImmutable). "/ because it comes from a literal
|
|
63 |
self should:[arr at:1 put:10] raise:NoModificationError.
|
|
64 |
|
|
65 |
arr2 := arr copy.
|
|
66 |
self assert:(arr2 isImmutable not).
|
|
67 |
self shouldnt:[arr2 at:1 put:10] raise:Error.
|
|
68 |
|
|
69 |
"/ unboxed s8
|
|
70 |
arr := #s8(1 2 3 4).
|
|
71 |
self assert:(arr isImmutable). "/ because it comes from a literal
|
|
72 |
self should:[arr at:1 put:10] raise:NoModificationError.
|
|
73 |
|
|
74 |
arr2 := arr copy.
|
|
75 |
self assert:(arr2 isImmutable not).
|
|
76 |
self shouldnt:[arr2 at:1 put:10] raise:Error.
|
|
77 |
|
|
78 |
"/ unboxed s16
|
|
79 |
arr := #s16(1 2 3 4).
|
|
80 |
self assert:(arr isImmutable). "/ because it comes from a literal
|
|
81 |
self should:[arr at:1 put:10] raise:NoModificationError.
|
|
82 |
|
|
83 |
arr2 := arr copy.
|
|
84 |
self assert:(arr2 isImmutable not).
|
|
85 |
self shouldnt:[arr2 at:1 put:10] raise:Error.
|
|
86 |
|
|
87 |
"/ unboxed s32
|
2313
|
88 |
"/ arr := #s32(1 2 3 4).
|
2296
|
89 |
self assert:(arr isImmutable). "/ because it comes from a literal
|
|
90 |
self should:[arr at:1 put:10] raise:NoModificationError.
|
|
91 |
|
|
92 |
arr2 := arr copy.
|
|
93 |
self assert:(arr2 isImmutable not).
|
|
94 |
self shouldnt:[arr2 at:1 put:10] raise:Error.
|
|
95 |
|
|
96 |
"/ unboxed s64
|
|
97 |
arr := #s64(1 2 3 4).
|
|
98 |
self assert:(arr isImmutable). "/ because it comes from a literal
|
|
99 |
self should:[arr at:1 put:10] raise:NoModificationError.
|
|
100 |
|
|
101 |
arr2 := arr copy.
|
|
102 |
self assert:(arr2 isImmutable not).
|
|
103 |
self shouldnt:[arr2 at:1 put:10] raise:Error.
|
|
104 |
|
|
105 |
"/ unboxed u1
|
|
106 |
arr := #u1(0 1 1 0).
|
|
107 |
self assert:(arr isImmutable). "/ because it comes from a literal
|
|
108 |
self should:[arr at:1 put:1] raise:NoModificationError.
|
|
109 |
|
|
110 |
arr2 := arr copy.
|
|
111 |
self assert:(arr2 isImmutable not).
|
|
112 |
self shouldnt:[arr2 at:1 put:1] raise:Error.
|
|
113 |
self should:[arr2 at:1 put:2] raise:Error.
|
|
114 |
|
|
115 |
"/ unboxed u8
|
|
116 |
arr := #u8(1 2 3 4).
|
|
117 |
self assert:(arr isImmutable). "/ because it comes from a literal
|
|
118 |
self should:[arr at:1 put:10] raise:NoModificationError.
|
|
119 |
|
|
120 |
arr2 := arr copy.
|
|
121 |
self assert:(arr2 isImmutable not).
|
|
122 |
self shouldnt:[arr2 at:1 put:10] raise:Error.
|
|
123 |
|
|
124 |
"/ unboxed u16
|
|
125 |
arr := #u16(1 2 3 4).
|
|
126 |
self assert:(arr isImmutable). "/ because it comes from a literal
|
|
127 |
self should:[arr at:1 put:10] raise:NoModificationError.
|
|
128 |
|
|
129 |
arr2 := arr copy.
|
|
130 |
self assert:(arr2 isImmutable not).
|
|
131 |
self shouldnt:[arr2 at:1 put:10] raise:Error.
|
|
132 |
|
|
133 |
"/ unboxed u32
|
|
134 |
arr := #u32(1 2 3 4).
|
|
135 |
self assert:(arr isImmutable). "/ because it comes from a literal
|
|
136 |
self should:[arr at:1 put:10] raise:NoModificationError.
|
|
137 |
|
|
138 |
arr2 := arr copy.
|
|
139 |
self assert:(arr2 isImmutable not).
|
|
140 |
self shouldnt:[arr2 at:1 put:10] raise:Error.
|
|
141 |
|
|
142 |
"/ unboxed u64
|
|
143 |
arr := #s64(1 2 3 4).
|
|
144 |
self assert:(arr isImmutable). "/ because it comes from a literal
|
|
145 |
self should:[arr at:1 put:10] raise:NoModificationError.
|
|
146 |
|
|
147 |
arr2 := arr copy.
|
|
148 |
self assert:(arr2 isImmutable not).
|
|
149 |
self shouldnt:[arr2 at:1 put:10] raise:Error.
|
|
150 |
|
|
151 |
"/ unboxed f16
|
2313
|
152 |
"/arr := #f16(1 2 3 4).
|
2296
|
153 |
self assert:(arr isImmutable). "/ because it comes from a literal
|
|
154 |
self should:[arr at:1 put:10] raise:NoModificationError.
|
|
155 |
|
|
156 |
arr2 := arr copy.
|
|
157 |
self assert:(arr2 isImmutable not).
|
|
158 |
self shouldnt:[arr2 at:1 put:10] raise:Error.
|
|
159 |
|
|
160 |
"/ unboxed f32
|
2313
|
161 |
"/arr := #f32(1 2 3 4).
|
2296
|
162 |
self assert:(arr isImmutable). "/ because it comes from a literal
|
|
163 |
self should:[arr at:1 put:10] raise:NoModificationError.
|
|
164 |
|
|
165 |
arr2 := arr copy.
|
|
166 |
self assert:(arr2 isImmutable not).
|
|
167 |
self shouldnt:[arr2 at:1 put:10] raise:Error.
|
|
168 |
|
|
169 |
"/ unboxed f64
|
2313
|
170 |
"/arr := #f64(1 2 3 4).
|
2296
|
171 |
self assert:(arr isImmutable). "/ because it comes from a literal
|
|
172 |
self should:[arr at:1 put:10] raise:NoModificationError.
|
|
173 |
|
|
174 |
arr2 := arr copy.
|
|
175 |
self assert:(arr2 isImmutable not).
|
|
176 |
self shouldnt:[arr2 at:1 put:10] raise:Error.
|
|
177 |
|
|
178 |
"
|
|
179 |
self run:#test01_mutability
|
|
180 |
self new test01_mutability
|
|
181 |
"
|
|
182 |
|
|
183 |
"Created: / 09-06-2019 / 15:49:37 / Claus Gittinger"
|
2305
|
184 |
"Modified: / 10-06-2019 / 20:50:21 / Claus Gittinger"
|
2296
|
185 |
!
|
|
186 |
|
|
187 |
test02_mutability
|
|
188 |
"literals are mutable - if specified so"
|
|
189 |
|
|
190 |
|
|
191 |
|arr|
|
|
192 |
|
2313
|
193 |
"/ arr := #[1 2 3 4].
|
2296
|
194 |
self assert:(arr isImmutable not). "/ because I specifid so
|
|
195 |
self shouldnt:[arr at:1 put:10] raise:NoModificationError.
|
|
196 |
|
|
197 |
"/ unboxed s8
|
2313
|
198 |
"/ arr := #s8(1 2 3 4).
|
2296
|
199 |
self assert:(arr isImmutable not). "/ because I specifid so
|
|
200 |
self shouldnt:[arr at:1 put:10] raise:NoModificationError.
|
|
201 |
|
|
202 |
"/ unboxed s16
|
2313
|
203 |
"/arr := #s16(1 2 3 4).
|
2296
|
204 |
self assert:(arr isImmutable not). "/ because I specifid so
|
|
205 |
self shouldnt:[arr at:1 put:10] raise:NoModificationError.
|
|
206 |
|
|
207 |
"/ unboxed s32
|
2313
|
208 |
"/arr := #s32(1 2 3 4).
|
2296
|
209 |
self assert:(arr isImmutable not). "/ because I specifid so
|
|
210 |
self shouldnt:[arr at:1 put:10] raise:NoModificationError.
|
|
211 |
|
|
212 |
"/ unboxed s64
|
2313
|
213 |
"/ arr := #s64(1 2 3 4).
|
2296
|
214 |
self assert:(arr isImmutable not). "/ because I specifid so
|
|
215 |
self shouldnt:[arr at:1 put:10] raise:NoModificationError.
|
|
216 |
|
|
217 |
"/ unboxed u1
|
2313
|
218 |
"/arr := #u1(0 1 1 0).
|
2296
|
219 |
self assert:(arr isImmutable not). "/ because I specifid so
|
|
220 |
self shouldnt:[arr at:1 put:1] raise:NoModificationError.
|
|
221 |
self should:[arr at:1 put:2] raise:Error.
|
|
222 |
|
|
223 |
"/ unboxed u8
|
2313
|
224 |
"/arr := #u8(1 2 3 4).
|
2296
|
225 |
self assert:(arr isImmutable not). "/ because I specifid so
|
|
226 |
self shouldnt:[arr at:1 put:10] raise:NoModificationError.
|
|
227 |
|
|
228 |
"/ unboxed u16
|
2313
|
229 |
"/arr := #u16(1 2 3 4).
|
2296
|
230 |
self assert:(arr isImmutable not). "/ because I specifid so
|
|
231 |
self shouldnt:[arr at:1 put:10] raise:NoModificationError.
|
|
232 |
|
|
233 |
"/ unboxed u32
|
2313
|
234 |
"/arr := #u32(1 2 3 4).
|
2296
|
235 |
self assert:(arr isImmutable not). "/ because I specifid so
|
|
236 |
self shouldnt:[arr at:1 put:10] raise:NoModificationError.
|
|
237 |
|
|
238 |
"/ unboxed u64
|
2313
|
239 |
"/arr := #s64(1 2 3 4).
|
2296
|
240 |
self assert:(arr isImmutable not). "/ because I specifid so
|
|
241 |
self shouldnt:[arr at:1 put:10] raise:NoModificationError.
|
|
242 |
|
|
243 |
"/ unboxed f16
|
2313
|
244 |
"/ arr := #f16(1 2 3 4).
|
2296
|
245 |
self assert:(arr isImmutable not). "/ because I specifid so
|
|
246 |
self shouldnt:[arr at:1 put:10] raise:NoModificationError.
|
|
247 |
|
|
248 |
"/ unboxed f32
|
2313
|
249 |
"/arr := #f32(1 2 3 4).
|
2296
|
250 |
self assert:(arr isImmutable not). "/ because I specifid so
|
|
251 |
self shouldnt:[arr at:1 put:10] raise:NoModificationError.
|
|
252 |
|
|
253 |
"/ unboxed f64
|
2313
|
254 |
"/arr := #f64(1 2 3 4).
|
2296
|
255 |
self assert:(arr isImmutable not). "/ because I specifid so
|
|
256 |
self shouldnt:[arr at:1 put:10] raise:NoModificationError.
|
|
257 |
|
|
258 |
"
|
|
259 |
self run:#test01_mutability
|
|
260 |
self new test01_mutability
|
|
261 |
"
|
|
262 |
|
|
263 |
"Created: / 09-06-2019 / 15:49:46 / Claus Gittinger"
|
|
264 |
! !
|
|
265 |
|
|
266 |
!MutabilityTest class methodsFor:'documentation'!
|
|
267 |
|
|
268 |
version_CVS
|
|
269 |
^ '$Header$'
|
2313
|
270 |
! ! |