131
|
1 |
"{ Package: 'exept:regression' }"
|
|
2 |
|
|
3 |
"{ NameSpace: RegressionTests }"
|
|
4 |
|
|
5 |
TestCase subclass:#ReadStreamTest
|
|
6 |
instanceVariableNames:'startPosition streamClass'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'Tests-Regression'
|
|
10 |
!
|
|
11 |
|
|
12 |
!ReadStreamTest class methodsFor:'documentation'!
|
|
13 |
|
|
14 |
documentation
|
|
15 |
"
|
|
16 |
documentation to be added.
|
|
17 |
|
|
18 |
[author:]
|
|
19 |
Stefan Vogel (stefan@zwerg)
|
|
20 |
|
|
21 |
[see also:]
|
|
22 |
|
|
23 |
[instance variables:]
|
|
24 |
|
|
25 |
[class variables:]
|
|
26 |
"
|
|
27 |
!
|
|
28 |
|
|
29 |
history
|
|
30 |
"Created: / 13.12.2001 / 17:13:17 / stefan"
|
|
31 |
! !
|
|
32 |
|
|
33 |
!ReadStreamTest methodsFor:'accessing'!
|
|
34 |
|
|
35 |
streamClass
|
|
36 |
^ streamClass
|
|
37 |
! !
|
|
38 |
|
|
39 |
!ReadStreamTest methodsFor:'helpers'!
|
|
40 |
|
|
41 |
checkPositionFor:testCollection
|
|
42 |
"check for correct common behavior of Stream reading"
|
|
43 |
|
|
44 |
|stream|
|
|
45 |
|
|
46 |
stream := self streamClass on:testCollection.
|
|
47 |
self assert:(stream size == testCollection size).
|
|
48 |
testCollection size to:1 by:-1 do:[:pos |
|
|
49 |
stream position:(pos + startPosition - 1).
|
|
50 |
self assert:(stream atEnd not).
|
|
51 |
self assert:(stream peek == (testCollection at:pos)).
|
|
52 |
self assert:(stream position == (pos + startPosition - 1)).
|
|
53 |
self assert:(stream next == (testCollection at:pos)).
|
|
54 |
self assert:(stream position == (pos + startPosition))
|
|
55 |
]
|
|
56 |
!
|
|
57 |
|
|
58 |
checkReadStreamFor:testCollection
|
|
59 |
"check for correct common behavior of Stream reading"
|
|
60 |
|
|
61 |
|stream|
|
|
62 |
|
|
63 |
stream := self streamClass on:testCollection.
|
|
64 |
stream reset. "for ReadWriteStreams"
|
|
65 |
self assert:(stream size == testCollection size).
|
|
66 |
self assert:(stream isEmpty not).
|
|
67 |
testCollection
|
|
68 |
keysAndValuesDo:[:pos :element |
|
|
69 |
self assert:(stream atEnd not).
|
|
70 |
self assert:(stream peek == element).
|
|
71 |
self assert:(stream position == (pos + startPosition - 1)).
|
|
72 |
self assert:(stream next == element).
|
|
73 |
self assert:(stream position == (pos + startPosition))
|
|
74 |
].
|
|
75 |
self assert:(stream atEnd).
|
|
76 |
self assert:(stream peek isNil).
|
|
77 |
self assert:(stream next isNil).
|
|
78 |
streamClass endOfStreamSignal
|
|
79 |
handle:[:ex | ex return]
|
|
80 |
do:[
|
|
81 |
self should:(stream next) raise:streamClass endOfStreamSignal.
|
|
82 |
self should:(stream peek) raise:streamClass endOfStreamSignal.
|
|
83 |
self shouldnt:(stream peekOrNil) raise:streamClass endOfStreamSignal
|
|
84 |
]
|
|
85 |
! !
|
|
86 |
|
|
87 |
!ReadStreamTest methodsFor:'setup'!
|
|
88 |
|
|
89 |
setUp
|
|
90 |
self streamClass:ReadStream
|
|
91 |
!
|
|
92 |
|
|
93 |
streamClass:aClass
|
|
94 |
streamClass := aClass.
|
|
95 |
startPosition := streamClass zeroPosition
|
|
96 |
! !
|
|
97 |
|
|
98 |
!ReadStreamTest methodsFor:'tests'!
|
|
99 |
|
|
100 |
testBasic
|
|
101 |
|stream|
|
|
102 |
|
|
103 |
stream := self streamClass on:''.
|
|
104 |
self assert:(stream isReadable).
|
|
105 |
self assert:(stream isPositionable).
|
|
106 |
self assert:(stream isWritable not).
|
|
107 |
self assert:(stream size == 0).
|
|
108 |
self assert:(stream isEmpty)
|
|
109 |
!
|
|
110 |
|
|
111 |
testPosition
|
|
112 |
|
|
113 |
self checkPositionFor:'12345'.
|
|
114 |
self checkPositionFor:'12345'asByteArray.
|
|
115 |
self checkPositionFor:#[1 2 3 4 5].
|
|
116 |
self checkPositionFor:#(1 2 3 4 5).
|
|
117 |
self checkPositionFor:#(1 2 3 4 5) asOrderedCollection.
|
|
118 |
|
|
119 |
|
|
120 |
"
|
|
121 |
(self selector:#testPosition) runCase
|
|
122 |
"
|
|
123 |
!
|
|
124 |
|
|
125 |
testReadStream
|
|
126 |
|
|
127 |
self checkReadStreamFor:'12345'.
|
|
128 |
self checkReadStreamFor:'12345'asByteArray.
|
|
129 |
self checkReadStreamFor:#[1 2 3 4 5].
|
|
130 |
self checkReadStreamFor:#(1 2 3 4 5).
|
|
131 |
self checkReadStreamFor:#(1 2 3 4 5) asOrderedCollection.
|
|
132 |
|
|
133 |
|
|
134 |
"
|
|
135 |
(self selector:#testReadStream) runCase
|
|
136 |
"
|
|
137 |
!
|
|
138 |
|
|
139 |
testSkipAny
|
|
140 |
|stream skipChars|
|
|
141 |
|
|
142 |
stream := self streamClass
|
|
143 |
on:'some numbers1234with\in other99 stuff' withCRs.
|
|
144 |
skipChars := 'abcdefghijklmnopqrstuvwxyz\ ' withCRs.
|
|
145 |
self assert:(stream skipAny:skipChars) == $1.
|
|
146 |
self assert:(Integer readFrom:stream) == 1234.
|
|
147 |
self assert:(stream skipAny:skipChars) == $9.
|
|
148 |
self assert:(Integer readFrom:stream) == 99
|
|
149 |
!
|
|
150 |
|
|
151 |
testSkipSeparators
|
|
152 |
|stream|
|
|
153 |
|
|
154 |
stream := self streamClass on:'one two\three' withCRs.
|
|
155 |
self assert:(stream skipSeparators == $o).
|
|
156 |
self assert:(stream nextWord = 'one').
|
|
157 |
self assert:(stream skipSeparators == $t).
|
|
158 |
self assert:(stream nextWord = 'two').
|
|
159 |
self assert:(stream skipSeparators == $t).
|
|
160 |
self assert:(stream nextWord = 'three').
|
|
161 |
self assert:(stream atEnd).
|
|
162 |
self assert:(stream skipSeparators isNil)
|
|
163 |
!
|
|
164 |
|
|
165 |
testSkipSeparatorsExceptCR
|
|
166 |
|stream|
|
|
167 |
|
|
168 |
stream := self streamClass on:'one two\three' withCRs.
|
|
169 |
self assert:(stream skipSeparatorsExceptCR == $o).
|
|
170 |
self assert:(stream nextWord = 'one').
|
|
171 |
self assert:(stream skipSeparatorsExceptCR == $t).
|
|
172 |
self assert:(stream nextWord = 'two').
|
|
173 |
self assert:(stream skipSeparatorsExceptCR == Character cr).
|
|
174 |
self assert:(stream next = Character cr).
|
|
175 |
self assert:(stream nextWord = 'three').
|
|
176 |
self assert:(stream atEnd).
|
|
177 |
self assert:(stream skipSeparatorsExceptCR isNil)
|
|
178 |
!
|
|
179 |
|
|
180 |
testSkipSpaces
|
|
181 |
|stream|
|
|
182 |
|
|
183 |
stream := self streamClass on:'one two\three' withCRs.
|
|
184 |
self assert:(stream skipSpaces == $o).
|
|
185 |
self assert:(stream nextWord = 'one').
|
|
186 |
self assert:(stream skipSpaces == $t).
|
|
187 |
self assert:(stream nextWord = 'two').
|
|
188 |
self assert:(stream skipSpaces == Character cr).
|
|
189 |
self assert:(stream next = Character cr).
|
|
190 |
self assert:(stream nextWord = 'three').
|
|
191 |
self assert:(stream atEnd).
|
|
192 |
self assert:(stream skipSpaces isNil)
|
|
193 |
! !
|
|
194 |
|
|
195 |
!ReadStreamTest class methodsFor:'documentation'!
|
|
196 |
|
|
197 |
version
|
|
198 |
^ '$Header$'
|
|
199 |
! !
|