[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

test[S8Ref] types

SwikiCodeRobot @> #testS8RefTypes

refType

"should find all well known types"
| types |
types := S8Ref types.
#( #CString #Object #bool #byte #char #double #float #int #int16 #int32 #int64 #int8 #long #longlong #short #sint16 #sint32 #sint64 #sint8 #size_t #uchar #uint #uint16 #uint32 #uint64 #uint8 #ulong #ulonglong #ushort #void ) do: [:key|
  (types includesKey: key) ifFalse: [ self error: 'Type not found ',key asLiteral ]
]


"should return a new type with its indirection level increased by 1"
| int ptr |
int := S8Ref type: #int.
ptr := S8Ref current refType: int.
int size = ptr size ifFalse: [ ^self error: 'Invalid size' ].
int indirection + 1 = ptr indirection ifFalse: [ ^self error: 'Invalid indirection' ].


"should coerce string types"
| int ptr |
int := S8Ref type: #int.
ptr := S8Ref current refType: #int.
int size = ptr size ifFalse: [ ^self error: 'Invalid size' ].
2 = ptr indirection ifFalse: [ ^self error: 'Invalid indirection' ].


derefType

"should throw an Error when given a type with its indirection level already at 1"
| int |
int := S8Ref type: #int.
[ S8Ref current derefType: int
] on: Error do: [:ex| ^self print: 'ok - thrown ' ,ex toString stream nextLine ].
self error: 'Should thrown an error'


"test type size&alignment"
(JS @ (S8Ref current handle basicAt: #types)) propertiesDo: [:name :type|
    name = #void ifFalse: [
      type#size >= 1 ifFalse: [ self error: 'invalid size of ',name ].
      type#alignment >= 1 ifFalse: [ self error: 'invalid alignment of ',name ].
    ]
]