49 |
47 |
50 !MutabilityTest methodsFor:'tests'! |
48 !MutabilityTest methodsFor:'tests'! |
51 |
49 |
52 test01_immutability |
50 test01_immutability |
53 "literals are immutable - if specified so" |
51 "literals are immutable - if specified so" |
|
52 |
|
53 <pragma: +STXExtendedArrayLiterals> |
|
54 <pragma: +arraysAreImmutable> |
54 |
55 |
55 |arr arr2| |
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 |
|
85 arr := #s32(1 2 3 4). |
|
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 |
|
149 arr := #f16(1 2 3 4). |
|
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 |
|
158 arr := #f32(1 2 3 4). |
|
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 |
|
167 arr := #f64(1 2 3 4). |
|
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" |
|
181 "Modified: / 10-06-2019 / 20:50:21 / Claus Gittinger" |
|
182 "Modified: / 17-06-2019 / 15:11:09 / Stefan Reise" |
|
183 ! |
|
184 |
|
185 test02_mutability |
|
186 "literals are mutable - if specified so" |
|
187 |
|
188 <pragma: +STXExtendedArrayLiterals> |
|
189 <pragma: -arraysAreImmutable> |
|
190 |
|
191 |arr| |
56 |
192 |
57 self skipIf:(self class compiledMethodAt:#test01_immutability) |
193 self skipIf:(self class compiledMethodAt:#test01_immutability) |
58 byteCode isNil |
194 byteCode isNil |
59 description:'skipped because stc-compiled literals are always immutable'. |
195 description:'skipped because stc-compiled literals are always immutable'. |
60 |
196 |
61 arr := #[1 2 3 4]. |
197 arr := #[1 2 3 4]. |
62 self assert:(arr isImmutable). "/ because it comes from a literal |
198 self assert:(arr isImmutable not). "/ because I specifid so |
63 self should:[arr at:1 put:10] raise:NoModificationError. |
199 self shouldnt:[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 |
200 |
69 "/ unboxed s8 |
201 "/ unboxed s8 |
70 arr := #s8(1 2 3 4). |
202 arr := #s8(1 2 3 4). |
71 self assert:(arr isImmutable). "/ because it comes from a literal |
203 self assert:(arr isImmutable not). "/ because I specifid so |
72 self should:[arr at:1 put:10] raise:NoModificationError. |
204 self shouldnt:[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 |
205 |
78 "/ unboxed s16 |
206 "/ unboxed s16 |
79 arr := #s16(1 2 3 4). |
207 arr := #s16(1 2 3 4). |
80 self assert:(arr isImmutable). "/ because it comes from a literal |
208 self assert:(arr isImmutable not). "/ because I specifid so |
81 self should:[arr at:1 put:10] raise:NoModificationError. |
209 self shouldnt:[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 |
210 |
87 "/ unboxed s32 |
211 "/ unboxed s32 |
88 "/ arr := #s32(1 2 3 4). |
212 arr := #s32(1 2 3 4). |
89 self assert:(arr isImmutable). "/ because it comes from a literal |
213 self assert:(arr isImmutable not). "/ because I specifid so |
90 self should:[arr at:1 put:10] raise:NoModificationError. |
214 self shouldnt:[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 |
215 |
96 "/ unboxed s64 |
216 "/ unboxed s64 |
97 arr := #s64(1 2 3 4). |
217 arr := #s64(1 2 3 4). |
98 self assert:(arr isImmutable). "/ because it comes from a literal |
218 self assert:(arr isImmutable not). "/ because I specifid so |
99 self should:[arr at:1 put:10] raise:NoModificationError. |
219 self shouldnt:[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 |
220 |
105 "/ unboxed u1 |
221 "/ unboxed u1 |
106 arr := #u1(0 1 1 0). |
222 arr := #u1(0 1 1 0). |
107 self assert:(arr isImmutable). "/ because it comes from a literal |
223 self assert:(arr isImmutable not). "/ because I specifid so |
108 self should:[arr at:1 put:1] raise:NoModificationError. |
224 self shouldnt:[arr at:1 put:1] raise:NoModificationError. |
109 |
225 self should:[arr at:1 put:2] raise:Error. |
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 |
226 |
115 "/ unboxed u8 |
227 "/ unboxed u8 |
116 arr := #u8(1 2 3 4). |
228 arr := #u8(1 2 3 4). |
117 self assert:(arr isImmutable). "/ because it comes from a literal |
229 self assert:(arr isImmutable not). "/ because I specifid so |
118 self should:[arr at:1 put:10] raise:NoModificationError. |
230 self shouldnt:[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 |
231 |
124 "/ unboxed u16 |
232 "/ unboxed u16 |
125 arr := #u16(1 2 3 4). |
233 arr := #u16(1 2 3 4). |
126 self assert:(arr isImmutable). "/ because it comes from a literal |
234 self assert:(arr isImmutable not). "/ because I specifid so |
127 self should:[arr at:1 put:10] raise:NoModificationError. |
235 self shouldnt:[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 |
236 |
133 "/ unboxed u32 |
237 "/ unboxed u32 |
134 arr := #u32(1 2 3 4). |
238 arr := #u32(1 2 3 4). |
135 self assert:(arr isImmutable). "/ because it comes from a literal |
239 self assert:(arr isImmutable not). "/ because I specifid so |
136 self should:[arr at:1 put:10] raise:NoModificationError. |
240 self shouldnt:[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 |
241 |
142 "/ unboxed u64 |
242 "/ unboxed u64 |
143 arr := #s64(1 2 3 4). |
243 arr := #s64(1 2 3 4). |
144 self assert:(arr isImmutable). "/ because it comes from a literal |
244 self assert:(arr isImmutable not). "/ because I specifid so |
145 self should:[arr at:1 put:10] raise:NoModificationError. |
245 self shouldnt:[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 |
246 |
151 "/ unboxed f16 |
247 "/ unboxed f16 |
152 "/arr := #f16(1 2 3 4). |
248 arr := #f16(1 2 3 4). |
153 self assert:(arr isImmutable). "/ because it comes from a literal |
249 self assert:(arr isImmutable not). "/ because I specifid so |
154 self should:[arr at:1 put:10] raise:NoModificationError. |
250 self shouldnt:[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 |
251 |
160 "/ unboxed f32 |
252 "/ unboxed f32 |
161 "/arr := #f32(1 2 3 4). |
253 arr := #f32(1 2 3 4). |
162 self assert:(arr isImmutable). "/ because it comes from a literal |
254 self assert:(arr isImmutable not). "/ because I specifid so |
163 self should:[arr at:1 put:10] raise:NoModificationError. |
255 self shouldnt:[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 |
256 |
169 "/ unboxed f64 |
257 "/ unboxed f64 |
170 "/arr := #f64(1 2 3 4). |
258 arr := #f64(1 2 3 4). |
171 self assert:(arr isImmutable). "/ because it comes from a literal |
259 self assert:(arr isImmutable not). "/ because I specifid so |
172 self should:[arr at:1 put:10] raise:NoModificationError. |
260 self shouldnt:[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 |
261 |
178 " |
262 " |
179 self run:#test01_mutability |
263 self run:#test01_mutability |
180 self new test01_mutability |
264 self new test01_mutability |
181 " |
265 " |
182 |
266 |
183 "Created: / 09-06-2019 / 15:49:37 / Claus Gittinger" |
|
184 "Modified: / 10-06-2019 / 20:50:21 / Claus Gittinger" |
|
185 ! |
|
186 |
|
187 test02_mutability |
|
188 "literals are mutable - if specified so" |
|
189 |
|
190 |
|
191 |arr| |
|
192 |
|
193 "/ arr := #[1 2 3 4]. |
|
194 self assert:(arr isImmutable not). "/ because I specifid so |
|
195 self shouldnt:[arr at:1 put:10] raise:NoModificationError. |
|
196 |
|
197 "/ unboxed s8 |
|
198 "/ arr := #s8(1 2 3 4). |
|
199 self assert:(arr isImmutable not). "/ because I specifid so |
|
200 self shouldnt:[arr at:1 put:10] raise:NoModificationError. |
|
201 |
|
202 "/ unboxed s16 |
|
203 "/arr := #s16(1 2 3 4). |
|
204 self assert:(arr isImmutable not). "/ because I specifid so |
|
205 self shouldnt:[arr at:1 put:10] raise:NoModificationError. |
|
206 |
|
207 "/ unboxed s32 |
|
208 "/arr := #s32(1 2 3 4). |
|
209 self assert:(arr isImmutable not). "/ because I specifid so |
|
210 self shouldnt:[arr at:1 put:10] raise:NoModificationError. |
|
211 |
|
212 "/ unboxed s64 |
|
213 "/ arr := #s64(1 2 3 4). |
|
214 self assert:(arr isImmutable not). "/ because I specifid so |
|
215 self shouldnt:[arr at:1 put:10] raise:NoModificationError. |
|
216 |
|
217 "/ unboxed u1 |
|
218 "/arr := #u1(0 1 1 0). |
|
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 |
|
224 "/arr := #u8(1 2 3 4). |
|
225 self assert:(arr isImmutable not). "/ because I specifid so |
|
226 self shouldnt:[arr at:1 put:10] raise:NoModificationError. |
|
227 |
|
228 "/ unboxed u16 |
|
229 "/arr := #u16(1 2 3 4). |
|
230 self assert:(arr isImmutable not). "/ because I specifid so |
|
231 self shouldnt:[arr at:1 put:10] raise:NoModificationError. |
|
232 |
|
233 "/ unboxed u32 |
|
234 "/arr := #u32(1 2 3 4). |
|
235 self assert:(arr isImmutable not). "/ because I specifid so |
|
236 self shouldnt:[arr at:1 put:10] raise:NoModificationError. |
|
237 |
|
238 "/ unboxed u64 |
|
239 "/arr := #s64(1 2 3 4). |
|
240 self assert:(arr isImmutable not). "/ because I specifid so |
|
241 self shouldnt:[arr at:1 put:10] raise:NoModificationError. |
|
242 |
|
243 "/ unboxed f16 |
|
244 "/ arr := #f16(1 2 3 4). |
|
245 self assert:(arr isImmutable not). "/ because I specifid so |
|
246 self shouldnt:[arr at:1 put:10] raise:NoModificationError. |
|
247 |
|
248 "/ unboxed f32 |
|
249 "/arr := #f32(1 2 3 4). |
|
250 self assert:(arr isImmutable not). "/ because I specifid so |
|
251 self shouldnt:[arr at:1 put:10] raise:NoModificationError. |
|
252 |
|
253 "/ unboxed f64 |
|
254 "/arr := #f64(1 2 3 4). |
|
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" |
267 "Created: / 09-06-2019 / 15:49:46 / Claus Gittinger" |
|
268 "Modified: / 17-06-2019 / 15:11:06 / Stefan Reise" |
264 ! ! |
269 ! ! |
265 |
270 |
266 !MutabilityTest class methodsFor:'documentation'! |
271 !MutabilityTest class methodsFor:'documentation'! |
267 |
272 |
268 version_CVS |
273 version_CVS |
269 ^ '$Header$' |
274 ^ '$Header$' |
270 ! ! |
275 ! ! |
|
276 |