Skip to content

Commit

Permalink
Make sure that all ZnCharacterEncoders self identify correctly (see Z…
Browse files Browse the repository at this point in the history
…nCharacterEncoderTest>>#testKnownEncodingIdentifiers)
  • Loading branch information
svenvc committed Nov 4, 2023
1 parent 9ccd711 commit f90402b
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ newForEncoding: string

| encoder |
encoder := self new.
encoder identifier: string.
(string asLowercase endsWith: 'be') ifTrue: [ encoder beBigEndian ].
(string asLowercase endsWith: 'le') ifTrue: [ encoder beLittleEndian ].
^ encoder
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
comparing
= anObject
^ super = anObject and: [ self endianness == anObject endianness ]
^ super = anObject and: [ self identifier == anObject identifier ]
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
comparing
hash
^ super hash bitXor: self endianness hash
^ self identifier hash
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
identifier: anObject
identifier := anObject
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing
identifier
^ #utf16
^ identifier
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ printing
printOn: stream
super printOn: stream.
stream nextPut: $(.
stream print: self identifier asString; space.
stream nextPutAll: endianness; nextPutAll: ' endian'.
stream nextPut: $)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"pools" : [ ],
"classvars" : [ ],
"instvars" : [
"endianness"
"endianness",
"identifier"
],
"name" : "ZnEndianSensitiveUTFEncoder",
"type" : "normal"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing
identifier
^ #ascii
^ #null

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
testing
testKnownEncodingIdentifiers
| all minimal asciiString |
| all minimal asciiString notSelfIdentifying|
all := ZnCharacterEncoder knownEncodingIdentifiers asSet.
minimal := #(utf8 latin1 null ascii iso88591) asSet.
"make sure at least a minimal set is present"
Expand All @@ -12,4 +12,8 @@ testKnownEncodingIdentifiers
| encoder bytes |
encoder := ZnCharacterEncoder newForEncoding: each.
bytes := encoder encodeString: asciiString.
self assert: (encoder decodeBytes: bytes) equals: asciiString ]
self assert: (encoder decodeBytes: bytes) equals: asciiString ].
"make sure identifiers are preserved"
notSelfIdentifying := ZnCharacterEncoder knownEncodingIdentifiers reject: [ :each |
each asZnCharacterEncoder identifier = each ].
self assert: notSelfIdentifying isEmpty

0 comments on commit f90402b

Please sign in to comment.