Skip to content

Commit

Permalink
Merge pull request #2 from svenvc/master
Browse files Browse the repository at this point in the history
Update zinc version
  • Loading branch information
chisandrei authored Mar 29, 2022
2 parents 3a69f72 + ce95eb0 commit ad8f96c
Show file tree
Hide file tree
Showing 334 changed files with 997 additions and 770 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
smalltalk: [ Pharo64-9.0, Pharo64-8.0, Pharo64-7.0 ]
smalltalk: [ Pharo64-10 , Pharo64-9.0 , Pharo64-8.0 , Pharo64-7.0 ]
name: ${{ matrix.smalltalk }}
steps:
- uses: actions/checkout@v2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing-bytes
accessing - bytes
int16
^ self nextIntegerOfSize: 2 signed: true bigEndian: true
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing-bytes
accessing - bytes
int32
^ self nextIntegerOfSize: 4 signed: true bigEndian: true
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing-bytes
accessing - bytes
int8
^ self nextIntegerOfSize: 1 signed: true bigEndian: true
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing-bytes
accessing - bytes
nextInt32
^ self nextIntegerOfSize: 4 signed: true bigEndian: true
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
accessing-bytes
accessing - bytes
nextIntegerOfSize: numberOfBytes signed: signed bigEndian: bigEndian
"Assuming the receiver is a stream of bytes, read the next integer of size numberOfBytes.
If bigEndian is true, use network byte order, most significant byte first,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing-bytes
accessing - bytes
nextLittleEndianNumber: numberOfBytes
^ self nextIntegerOfSize: numberOfBytes signed: false bigEndian: false
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing-bytes
accessing - bytes
nextNumber: numberOfBytes
^ self nextIntegerOfSize: numberOfBytes signed: false bigEndian: true
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing-bytes
accessing - bytes
nextWord
^ self nextIntegerOfSize: 2 signed: false bigEndian: true
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
accessing
setToEnd

stream setToEnd
self position: stream size
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing-bytes
accessing - bytes
uint16
^ self nextIntegerOfSize: 2 signed: false bigEndian: true
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing-bytes
accessing - bytes
uint32
^ self nextIntegerOfSize: 4 signed: false bigEndian: true
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing-bytes
accessing - bytes
uint8
^ self nextIntegerOfSize: 1 signed: false bigEndian: true
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@ upToEnd
"Read elements until the stream is atEnd and return them as a collection."

| streamSize result remaining |

"If the stream knows its size we can reduce overhead by allocating a buffer of the correct size.
If the size is an over-estimate, #next: will copy the results in to a buffer of the correct size."
streamSize := [ self size ]
on: Error
do: [ 0 ].
streamSize > 0 ifTrue:
[ result := self next: (streamSize - self position) ].
streamSize := [ self size ] on: Error do: [ 0 ].
result := streamSize > 0
ifTrue: [ self next: (streamSize - self position) ]
ifFalse: [ self collectionSpecies new ].
"If the size is an under-estimate we're not at the end, get the rest and append to the result"
self atEnd ifFalse:
[ remaining := self collectionSpecies streamContents: [ :out |
[ self atEnd ] whileFalse: [
position > limit
ifTrue: [ self nextBuffer ].
out next: limit - position + 1 putAll: buffer startingAt: position.
position := limit + 1 ] ].
result := result
ifNil: [ remaining ]
ifNotNil: [ result, remaining ] ].
^result
^ self atEnd
ifTrue: [ result ]
ifFalse: [
remaining := self collectionSpecies streamContents: [ :out |
[ self atEnd ] whileFalse: [
position > limit
ifTrue: [ self nextBuffer ].
out next: limit - position + 1 putAll: buffer startingAt: position.
position := limit + 1 ] ].
result := result , remaining ]
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing-bytes
accessing - bytes
int16: integer
^ self nextIntegerOfSize: 2 signed: true bigEndian: true put: integer
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing-bytes
accessing - bytes
int32: integer
^ self nextIntegerOfSize: 4 signed: true bigEndian: true put: integer
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing-bytes
accessing - bytes
int8: integer
^ self nextIntegerOfSize: 1 signed: true bigEndian: true put: integer
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing-bytes
accessing - bytes
nextInt32Put: integer
^ self nextIntegerOfSize: 4 signed: true bigEndian: true put: integer
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
accessing-bytes
accessing - bytes
nextIntegerOfSize: numberOfBytes signed: signed bigEndian: bigEndian put: value
"Assuming the receiver is a stream of bytes, write value as the next integer of size numberOfBytes.
If bigEndian is true, use network byte order, most significant byte first,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing-bytes
accessing - bytes
nextLittleEndianNumber: numberOfBytes put: integer
^ self nextIntegerOfSize: numberOfBytes signed: false bigEndian: false put: integer
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing-bytes
accessing - bytes
nextNumber: numberOfBytes put: integer
^ self nextIntegerOfSize: numberOfBytes signed: false bigEndian: true put: integer
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing-bytes
accessing - bytes
nextWordPut: integer
^ self nextIntegerOfSize: 2 signed: false bigEndian: true put: integer
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing-bytes
accessing - bytes
uint16: integer
^ self nextIntegerOfSize: 2 signed: false bigEndian: true put: integer
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing-bytes
accessing - bytes
uint32: integer
^ self nextIntegerOfSize: 4 signed: false bigEndian: true put: integer
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing-bytes
accessing - bytes
uint8: integer
^ self nextIntegerOfSize: 1 signed: false bigEndian: true put: integer

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing
flushing
flush
^ stream flush
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ readInto: collection startingAt: offset count: requestedCount
"Read requestedCount elements into collection starting at offset,
returning the number of elements read, there could be less elements available."

0 to: requestedCount - 1 do: [ :count | | object |
(object := self next) ifNil: [ ^ count ].
collection at: offset + count put: object ].
0 to: requestedCount - 1 do: [ :aCount | | object |
(object := self next) ifNil: [ ^ aCount ].
collection at: offset + aCount put: object ].
^ requestedCount
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
error handling
errorIncomplete
self error: 'Incomplete utf-16 encoding'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
error handling
errorIncomplete
self error: 'Incomplete utf-32 encoding'
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ testReadUpToEnd
stream sizeBuffer: 4.
stream next: 2.
self assert: stream upToEnd equals: '23456789'.
self assert: stream atEnd
self assert: stream atEnd.
stream := ZnBufferedReadStream on: #[] readStream.
self assert: stream upToEnd equals: #[].
self assert: stream atEnd.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
tests
testSetToEnd
| stream source |
source := '0123456789'.
stream := ZnBufferedReadStream on: source readStream.
stream sizeBuffer: source size.

"Call setToEnd on new stream"
self assert: stream position equals: 0.
stream setToEnd.
self assert: stream position equals: source size.

"Call setToEnd without after reading some elements"
stream position: 2.
self assert: (stream next: 4) equals: '2345'.
stream setToEnd.
self assert: stream position equals: source size.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ testWriting
bufferedStream := ZnBufferedReadWriteStream on: stringStream.
0 to: 9 do: [ :each | bufferedStream nextPut: (Character digitValue: each) ].
bufferedStream flush ].
self assert: string = '0123456789'
self assert: string equals: '0123456789'
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ testWritingOverflow
bufferedStream nextPutAll: '0123'; nextPutAll: '4567'; nextPutAll: '89'.
bufferedStream nextPutAll: '0123456789'; nextPutAll: '0123456789'.
bufferedStream flush ].
self assert: string = '0123456789012345678901234567890123456789'
self assert: string equals: '0123456789012345678901234567890123456789'
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ testInt8
self assert: readStream int8 equals: 123.
self assert: readStream peek equals: 123.
self assert: readStream uint8 equals: 123.
self deny: readStream peek = 123.
self deny: readStream peek = -123.
self deny: readStream peek equals: 123.
self deny: readStream peek equals: -123.
self assert: readStream int8 equals: -123
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"commentStamp" : "SvenVanCaekenberghe 4/19/2018 14:14",
"commentStamp" : "",
"super" : "TestCase",
"category" : "Zinc-Character-Encoding-Tests",
"classinstvars" : [ ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ testWriting
bufferedStream := ZnBufferedWriteStream on: stringStream.
0 to: 9 do: [ :each | bufferedStream nextPut: (Character digitValue: each) ].
bufferedStream flush ].
self assert: string = '0123456789'
self assert: string equals: '0123456789'
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ testWritingOverflow
bufferedStream nextPutAll: '0123'; nextPutAll: '4567'; nextPutAll: '89'.
bufferedStream nextPutAll: '0123456789'; nextPutAll: '0123456789'.
bufferedStream flush ].
self assert: string = '0123456789012345678901234567890123456789'
self assert: string equals: '0123456789012345678901234567890123456789'
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ testConvencienceMethods
encoder := ZnUTF8Encoder new.
string := 'élève en Français'.
self assert: (encoder decodeBytes: (encoder encodeString: string)) equals: string.
self assert: (encoder encodedByteCountForString: string) = 20.
self assert: (encoder encodedByteCountForString: string) equals: 20.

#( 'ccc' 'ççç' 'c' 'ç' 'çc' 'cç' ) do: [ :each |
self assert: (encoder decodeBytes: (encoder encodeString: each)) equals: each ]
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
testing
testLatin2Encoder
"Example characters taken from http://en.wikipedia.org/wiki/Latin2"

| encoder inputBytes outputBytes inputString outputString |
encoder := ZnCharacterEncoder newForEncoding: 'latin2'.
inputString := String
with: (16r0154 asCharacter) with: (16r0110 asCharacter)
with: ( 16r0155 asCharacter) with: (16r0111 asCharacter).
inputBytes := #(192 208 224 240) asByteArray.
inputString := String
with: 16r0154 asCharacter
with: 16r0110 asCharacter
with: 16r0155 asCharacter
with: 16r0111 asCharacter.
inputBytes := #( 192 208 224 240 ) asByteArray.
outputBytes := self encodeString: inputString with: encoder.
self assert: outputBytes = inputBytes.
self assert: outputBytes equals: inputBytes.
outputString := self decodeBytes: inputBytes with: encoder.
self assert: outputString = inputString
self assert: outputString equals: inputString
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
testing
testNullEncoder

| encoder bytes string |
encoder := ZnNullEncoder new.
bytes := self encodeString: 'abc' with: encoder.
self assert: bytes = #(97 98 99) asByteArray.
string := self decodeBytes: #(65 66 67) asByteArray with: encoder.
self assert: string = 'ABC'
self assert: bytes equals: #( 97 98 99 ) asByteArray.
string := self decodeBytes: #( 65 66 67 ) asByteArray with: encoder.
self assert: string equals: 'ABC'
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
testing
testUTF8Encoder

"The examples are taken from http://en.wikipedia.org/wiki/UTF-8#Description"

| encoder inputBytes outputBytes inputString outputString |
encoder := ZnUTF8Encoder new.
inputString := String with: $$ with: (16r00A2 asCharacter) with: (16r20AC asCharacter) with: (16r024B62 asCharacter).
inputBytes := #(16r24 16rC2 16rA2 16rE2 16r82 16rAC 16rF0 16rA4 16rAD 16rA2) asByteArray.
inputString := String
with: $$
with: 16r00A2 asCharacter
with: 16r20AC asCharacter
with: 16r024B62 asCharacter.
inputBytes := #( 16r24 16rC2 16rA2 16rE2 16r82 16rAC 16rF0 16rA4
16rAD 16rA2 ) asByteArray.
outputBytes := self encodeString: inputString with: encoder.
self assert: outputBytes = inputBytes.
self assert: outputBytes equals: inputBytes.
outputString := self decodeBytes: inputBytes with: encoder.
self assert: outputString = inputString
self assert: outputString equals: inputString
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
testing
testUTF8EncoderAuto

| encoder inputString bytes outputString |
encoder := ZnUTF8Encoder new.
inputString := String withAll: ((1 to: 3072) collect: [ :each | Character value: each ]).
bytes := self encodeString: inputString with: encoder.
inputString := String withAll:
((1 to: 3072) collect: [ :each |
Character value: each ]).
bytes := self encodeString: inputString with: encoder.
outputString := self decodeBytes: bytes with: encoder.
self assert: inputString = outputString
self assert: inputString equals: outputString
Loading

0 comments on commit ad8f96c

Please sign in to comment.