forked from pharo-project/pharo
/
TPrintTest.trait.st
111 lines (93 loc) · 3.4 KB
/
TPrintTest.trait.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
"
A trait for test purposes
"
Trait {
#name : #TPrintTest,
#category : #'Collections-Abstract-Tests-Traits'
}
{ #category : #requirements }
TPrintTest >> nonEmpty [
self explicitRequirement
]
{ #category : #'tests - fixture' }
TPrintTest >> test0FixturePrintTest [
self nonEmpty.
self denyEmpty: self nonEmpty
]
{ #category : #'tests - printing' }
TPrintTest >> testPrintElementsOn [
| aStream result allElementsAsString tmp |
result:=''.
aStream:= ReadWriteStream on: result.
tmp:= OrderedCollection new.
self nonEmpty do: [:each | tmp add: each asString].
self nonEmpty printElementsOn: aStream .
allElementsAsString:=(result findBetweenSubstrings: ' ' ).
1 to: allElementsAsString size do:
[:i |
self assert: (tmp occurrencesOf:(allElementsAsString at:i))=(allElementsAsString occurrencesOf:(allElementsAsString at:i)).
].
]
{ #category : #'tests - printing' }
TPrintTest >> testPrintNameOn [
| aStream result |
result:=''.
aStream:= ReadWriteStream on: result.
self nonEmpty printNameOn: aStream.
self nonEmpty class name first isVowel
ifTrue:[ self assert: aStream contents =('an ',self nonEmpty class name ) ]
ifFalse:[self assert: aStream contents =('a ',self nonEmpty class name)].
]
{ #category : #'tests - printing' }
TPrintTest >> testPrintOn [
| aStream result allElementsAsString tmp |
result:=''.
aStream:= ReadWriteStream on: result.
tmp:= OrderedCollection new.
self nonEmpty do: [:each | tmp add: each asString].
self nonEmpty printOn: aStream .
allElementsAsString:=(result findBetweenSubstrings: ' ' ).
1 to: allElementsAsString size do:
[:i |
i=1
ifTrue:[
self accessCollection class name first isVowel
ifTrue:[self assert: (allElementsAsString at:i)='an' ]
ifFalse:[self assert: (allElementsAsString at:i)='a'].].
i=2
ifTrue:[self assert: (allElementsAsString at:i)=self accessCollection class name].
i>2
ifTrue:[self assert: (tmp occurrencesOf:(allElementsAsString at:i))=(allElementsAsString occurrencesOf:(allElementsAsString at:i)).].
].
]
{ #category : #'tests - printing' }
TPrintTest >> testPrintOnDelimiter [
| result allElementsAsString tmp |
result := String streamContents: [ :aStream |
tmp := OrderedCollection new.
self nonEmpty do: [:each | tmp add: each asString].
self nonEmpty printOn: aStream delimiter: ', ' ].
allElementsAsString := (result findBetweenSubstrings: ', ').
1 to: allElementsAsString size do:
[:i |
self assert: (tmp occurrencesOf:(allElementsAsString at:i)) equals: (allElementsAsString occurrencesOf:(allElementsAsString at:i)) ].
]
{ #category : #'tests - printing' }
TPrintTest >> testPrintOnDelimiterLast [
| aStream result allElementsAsString tmp |
result:=''.
aStream:= ReadWriteStream on: result.
tmp:= OrderedCollection new.
self nonEmpty do: [:each | tmp add: each asString].
self nonEmpty printOn: aStream delimiter: ', ' last: 'and'.
allElementsAsString:=(result findBetweenSubstrings: ', ' ).
1 to: allElementsAsString size do:
[:i |
i<(allElementsAsString size-1 )
ifTrue: [self assert: (tmp occurrencesOf: (allElementsAsString at:i))=(allElementsAsString occurrencesOf: (allElementsAsString at:i))].
i=(allElementsAsString size-1)
ifTrue:[ self deny: (allElementsAsString at:i)=('and')asString].
i=(allElementsAsString size)
ifTrue: [self assert: (tmp occurrencesOf: (allElementsAsString at:i))=(allElementsAsString occurrencesOf: (allElementsAsString at:i))].
].
]