/
FLUserGuidesTest.class.st
175 lines (145 loc) · 4.64 KB
/
FLUserGuidesTest.class.st
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
"
SUnit tests to guide users with fuel serialization
"
Class {
#name : #FLUserGuidesTest,
#superclass : #FLSerializationTest,
#category : #'Fuel-Tests-Core-Base'
}
{ #category : #running }
FLUserGuidesTest >> tearDown [
#('demo.fuel' 'numbers.fuel' 'number.fuel.zip' 'example.FL' )
do: [:each | self deleteFileNamed: each ].
super tearDown
]
{ #category : #'tests-Managing Globals' }
FLUserGuidesTest >> testConsiderGlobal [
| aSerializer anArray materializedArray |
"Prepare an array whose two elements are system globals."
anArray := Array with: Set new with: Set new.
Smalltalk at: #GlobalSet1 put: anArray first.
Smalltalk at: #GlobalSet2 put: anArray second.
"Serialize considering *only first* as a global object."
FLPlatform current
fileNamed: 'demo.fuel'
writeStreamDo: [ :aStream |
aSerializer := FLSerializer newDefault.
aSerializer analyzer considerGlobal: #GlobalSet1.
aSerializer serialize: anArray on: aStream ].
"Materialize"
FLPlatform current
fileNamed: 'demo.fuel'
readStreamDo: [:aStream |
materializedArray := (FLMaterializer newDefault
materializeFrom: aStream) root].
"Check that second element is a new Set."
[ (Smalltalk at: #GlobalSet1) == materializedArray first ] assert.
[ (Smalltalk at: #GlobalSet2) ~~ materializedArray second ] assert
]
{ #category : #'tests-Getting Started' }
FLUserGuidesTest >> testDemo [
| sourceArray loadedArray |
sourceArray := Array
with: 'a string'
with: Transcript
with: [ Transcript
show: 'a string';
flush ].
"Store to the file"
FLSerializer serialize: sourceArray toFileNamed: 'example.FL'.
"Load from the file"
loadedArray := FLMaterializer materializeFromFileNamed: 'example.FL'.
"The arrays are not the same"
[ sourceArray ~~ loadedArray ] assert.
"The strings are not the same"
[ sourceArray first ~~ loadedArray first ] assert.
[ sourceArray first = loadedArray first ] assert.
"The global instance Transcript is the same"
[ sourceArray second == loadedArray second ] assert.
"Look at Transcript how the loaded block prints a string"
loadedArray third value
]
{ #category : #'tests-Getting Started' }
FLUserGuidesTest >> testFileShortcuts [
| materializedString |
FLSerializer serialize: 'stringToSerialize' toFileNamed: 'demo.fuel'.
materializedString := FLMaterializer materializeFromFileNamed: 'demo.fuel'.
]
{ #category : #'tests-Getting Started' }
FLUserGuidesTest >> testFileStream [
| materializedString |
FLPlatform current
fileNamed: 'demo.fuel'
writeStreamDo: [ :aStream |
FLSerializer newDefault
serialize: 'stringToSerialize'
on: aStream ].
FLPlatform current
fileNamed: 'demo.fuel'
readStreamDo: [ :aStream |
materializedString := (FLMaterializer newDefault
materializeFrom: aStream ) root ]
]
{ #category : #'tests-Getting Started' }
FLUserGuidesTest >> testGZip [
FLPlatform current
fileNamed: 'demo.fuel'
writeStreamDo: [ :aFileStream |
|gzip|
gzip := GZipWriteStream on: aFileStream.
FLSerializer newDefault serialize: 123 on: gzip.
gzip finish. ].
FLPlatform current
fileNamed: 'demo.fuel'
readStreamDo: [:aFileStream |
|gzip|
gzip := GZipReadStream on: aFileStream.
FLMaterializer newDefault
materializeFrom: gzip ]
]
{ #category : #'tests-Getting Started' }
FLUserGuidesTest >> testMemoryStream [
| anArray materializedString |
anArray := FLSerializer serializeToByteArray: 'stringToSerialize'.
materializedString := FLMaterializer materializeFromByteArray: anArray.
]
{ #category : #'tests-Customizing Graph' }
FLUserGuidesTest >> testPluggableSubstitution [
| objectToSerialize aSerializer |
objectToSerialize := Array with: 'hello' with: '' writeStream.
FLPlatform current
fileNamed: 'demo.fuel'
writeStreamDo: [ :aStream |
aSerializer := FLSerializer newDefault.
aSerializer analyzer when: [ :o | o isStream ] substituteBy: [ :o | nil ].
aSerializer
serialize: objectToSerialize
on: aStream ].
FLPlatform current
fileNamed: 'demo.fuel'
readStreamDo: [ :aStream |
(FLMaterializer newDefault
materializeFrom: aStream)
root ]
]
{ #category : #'tests-Getting Started' }
FLUserGuidesTest >> testShowingProgressBar [
(Smalltalk globals includesKey: #FLProgressSerialization) ifFalse: [
" Needs:
(ConfigurationOfFuel project latestVersion) load: 'FuelProgressUpdate'.
"
^self ].
FLPlatform current
fileNamed: 'numbers.fuel'
writeStreamDo: [:aStream |
FLSerializer newDefault
showProgress;
serialize: (1 to: 200000) asArray
on: aStream ].
FLPlatform current
fileNamed: 'numbers.fuel'
readStreamDo: [:aStream |
FLMaterializer newDefault
showProgress;
materializeFrom: aStream ]
]