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

test[S8Ref] reinterpretUntilZeros

"should return a new Buffer instance up until the first 0"
| buf buf2 |
buf := NodeBuffer string: 'hello' ,0 asCharacter ,'world'.
buf2 := buf reinterpretUntilZeros: 1.
buf2 size = #hello size ifFalse: [ ^self error: 'Invalid size (',buf size,')' ].
buf2 handle toString = #hello ifFalse: [ ^self error: 'Invalid contents' ].


"should return a new Buffer instance up until the first 0 starting from offset"
| buf buf2 |
buf := NodeBuffer string: 'hello' ,0 asCharacter ,'world'.
buf2 := buf reinterpretUntilZeros: 1 offset: 3.
buf2 size = #lo size ifFalse: [ ^self error: 'Invalid size(',buf size,')' ].
buf2 handle toString = #lo ifFalse: [ ^self error: 'Invalid contents' ].


"should return a new Buffer instance up until the first 2-byte sequence of 0s"
| str buf len buf2 |
str := 'hello world'.
buf := NodeBuffer size: 50.
len := buf write: str offset: #ucs2.
buf writeInt16LE: 0 offset: len.
buf2 := buf reinterpretUntilZeros: 2.
buf2 size / 2 = str size ifFalse: [ ^self error: 'Invalid size(',(buf size / 2),')' ].
(buf2 handle #toString: #ucs2) = str ifFalse: [ ^self error: 'Invalid contents' ].