forked from SeasideSt/Grease
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGRCodecTest.class.st
More file actions
123 lines (108 loc) · 3.54 KB
/
GRCodecTest.class.st
File metadata and controls
123 lines (108 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
Class {
#name : #GRCodecTest,
#superclass : #TestCase,
#category : #'Grease-Tests-Core'
}
{ #category : #private }
GRCodecTest >> asString: aCollectionOfIntegers [
^ String streamContents: [ :stream |
aCollectionOfIntegers do: [ :each |
stream nextPut: (Character codePoint: each) ] ]
]
{ #category : #accessing }
GRCodecTest >> decodedString [
^ 'Übèrstrîñgé'
]
{ #category : #accessing }
GRCodecTest >> latin1String [
^ self asString: #(220 98 232 114 115 116 114 238 241 103 233)
]
{ #category : #accessing }
GRCodecTest >> macromanString [
^ self asString: #(134 98 143 114 115 116 114 148 150 103 142)
]
{ #category : #private }
GRCodecTest >> seasideByteArray [
^ #(83 101 97 115 105 100 101) "Seaside" asByteArray
]
{ #category : #tests }
GRCodecTest >> testAllCodecs [
self assert: GRCodec allCodecs notEmpty.
GRCodec allCodecs do: [ :codec |
self deny: codec class = GRCodec.
self assert: (codec isKindOf: GRCodec) ]
]
{ #category : #tests }
GRCodecTest >> testCodecLatin1 [
#('iso-8859-1' 'ISO-8859-1' ) do: [ :each |
| codec |
codec := GRCodec forEncoding: each.
self assert: codec name = each.
self assert: codec url name = each.
"Dialects may not guarantee anything about the comparability of
encoded strings. Convert to Strings for simplicity."
self assert: (codec encode: self decodedString) greaseString = self latin1String greaseString.
self assert: (codec url encode: self decodedString) greaseString = self latin1String greaseString.
self assert: (codec decode: self latin1String) = self decodedString.
self assert: (codec url decode: self latin1String) = self decodedString ]
]
{ #category : #tests }
GRCodecTest >> testCodecLatin1BorderLineString [
#('iso-8859-1' 'ISO-8859-1' ) do: [ :each |
| codec writeStream |
codec := GRCodec forEncoding: each.
writeStream := codec encoderFor: GRPlatform current readWriteCharacterStream.
writeStream nextPut: (Character codePoint: 0).
writeStream nextPut: (Character codePoint: 255).
self assert: writeStream contents = (String with: (Character codePoint: 0) with: (Character codePoint: 255)) ]
]
{ #category : #tests }
GRCodecTest >> testNext [
#('iso-8859-1' 'ISO-8859-1' ) do: [ :each |
| stream |
stream := (GRCodec forEncoding: each)
encoderFor: self seasideByteArray readStream.
self assert: stream next = $S.
self assert: (stream next: 1) = 'e' ]
]
{ #category : #tests }
GRCodecTest >> testNullCodec [
| codec strings |
codec := GRNullCodec new.
strings := OrderedCollection new
add: self latin1String;
add: self utf8String;
add: self utf16leString;
add: self utf16beString;
add: self macromanString;
yourself.
strings do: [ :string |
self assert: (codec encode: string) = string.
self assert: (codec url encode: string) = string.
self assert: (codec decode: string) = string.
self assert: (codec url decode: string) = string ]
]
{ #category : #tests }
GRCodecTest >> testReset [
| contents |
contents := String streamContents: [ :s |
| stream |
stream := (GRCodec forEncoding: 'ISO-8859-1') encoderFor: s.
stream
nextPutAll: 'abc';
reset;
nextPut: $d ].
self assert: contents = 'd'
]
{ #category : #accessing }
GRCodecTest >> utf16beString [
^ self asString: #(0 220 0 98 0 232 0 114 0 115 0 116 0 114 0 238 0 241 0 103 0 233)
]
{ #category : #accessing }
GRCodecTest >> utf16leString [
^ self asString: #(220 0 98 0 232 0 114 0 115 0 116 0 114 0 238 0 241 0 103 0 233 0)
]
{ #category : #accessing }
GRCodecTest >> utf8String [
^ self asString: #(195 156 98 195 168 114 115 116 114 195 174 195 177 103 195 169)
]