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