[View] [Edit] [Lock] [References] [Attachments] [History] [Home] [Changes] [Search] [Help]
test[S8Ref] coerce
"should return ref.types.void for #void"
(S8Ref current coerceType: #void) = (S8Ref type: #void) ifFalse: [ self error: 'Wrong type' ].
"should return a ref type when a * is present"
| type |
type := S8Ref current coerceType: 'void *'.
type = (S8Ref type: #void) ifTrue: [ self error: 'Should not be void' ].
(S8Ref type: #void) indirection + 1 = type indirection
ifFalse: [ self error: 'Wrong type(',type name,') indirection=',type indirection ]
"should coerce the type property of a Buffer"
| buffer type |
buffer := NodeBuffer size: (S8Ref type: #int) size.
buffer handle basicAt: #type put: #int.
type := S8Ref current getType: buffer.
type = (S8Ref type: #int) ifFalse: [ ^self error: 'Wrong type' ].
#int = (buffer handle basicAt: #type) ifFalse: [ ^self error: 'Should be int' ].
"should coerce Object to ref.types.Object"
(S8Ref current coerceType: #Object) = (S8Ref type: #Object) ifFalse: [ self error: 'Wrong type' ].
"should coerce the optional type in ref.get()"
| buffer |
buffer := NodeBuffer size: (S8Ref type: #int8) size.
buffer at: 1 put: 5.
5 = (S8Ref current get: buffer offset: 0 type: #int8) ifFalse: [ ^self error: 'Should be 5' ].
"should coerce the optional type in ref.set()"
| buffer |
buffer := NodeBuffer size: (S8Ref type: #int8) size.
S8Ref current set: buffer offset: 0 value: 5 type: #int8.
5 = (buffer at: 1) ifFalse: [ ^self error: 'Should be 5' ].
"should throw a TypeError if a type can not be resolved"
[ S8Ref current coerceType: 5@5
] on: Error do: [:ex|
^self print: 'Ok - Exception thrown=' ,ex toString stream nextLine
].
self error: 'Should throw a TypeError'