/
CollectionFormatterTest.class.st
73 lines (54 loc) · 1.88 KB
/
CollectionFormatterTest.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
"
I'm a CollectionFormatterTest, a test class for testing the behavior of CollectionFormatter
"
Class {
#name : #CollectionFormatterTest,
#superclass : #TestCase,
#category : 'Buoy-Collections-Tests'
}
{ #category : #tests }
CollectionFormatterTest >> testFormat [
| formatter |
formatter := CollectionFormatter separatingWith: ', '.
self assert: (formatter format: #(1 2 3)) equals: '1, 2, 3'
]
{ #category : #tests }
CollectionFormatterTest >> testFormatEmptyCollection [
| formatter |
formatter := CollectionFormatter separatingWith: ', ' andLastWith: ' and '.
self assert: (formatter format: #()) equals: String new
]
{ #category : #tests }
CollectionFormatterTest >> testFormatOn [
| formatter stream |
stream := WriteStream on: String new.
formatter := CollectionFormatter separatingWith: ', '.
formatter format: #(1 2 3) on: stream.
self assert: stream contents equals: '1, 2, 3'
]
{ #category : #tests }
CollectionFormatterTest >> testFormatOneElementCollection [
| formatter |
formatter := CollectionFormatter separatingWith: ', ' andLastWith: ' and '.
self assert: (formatter format: #(1)) equals: '1'
]
{ #category : #tests }
CollectionFormatterTest >> testFormatTwoElementCollectionWithLastSeparator [
| formatter |
formatter := CollectionFormatter separatingWith: ', ' andLastWith: ' and '.
self assert: (formatter format: #(1 2)) equals: '1 and 2'
]
{ #category : #tests }
CollectionFormatterTest >> testFormatWithElementFormater [
| formatter |
formatter := CollectionFormatter
separatingWith: $,
applyingToEach: [ :element | '/<1p>/' expandMacrosWith: element ].
self assert: (formatter format: #(1 2 3)) equals: '/1/,/2/,/3/'
]
{ #category : #tests }
CollectionFormatterTest >> testFormatWithLastSeparator [
| formatter |
formatter := CollectionFormatter separatingWith: ', ' andLastWith: ' and '.
self assert: (formatter format: #(1 2 3)) equals: '1, 2 and 3'
]