forked from pharo-project/pharo
/
TextStreamTest.class.st
70 lines (66 loc) · 1.99 KB
/
TextStreamTest.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
"
A TextStreamTest is a test class for testing the behavior of TextStream
"
Class {
#name : #TextStreamTest,
#superclass : #TestCase,
#instVars : [
'stream'
],
#category : #'Text-Tests-Base'
}
{ #category : #running }
TextStreamTest >> setUp [
stream := TextStream on: (Text new:100)
]
{ #category : #test }
TextStreamTest >> testNextPutAll [
stream
nextPutAll: 'Pharo';
space.
self assert: stream contents isText.
self assert: stream contents string equals: 'Pharo '.
"No attribute was set"
1 to: 6 do: [:index | self assertEmpty: (stream contents runs at: index) ]
]
{ #category : #test }
TextStreamTest >> testWithAttributeDo [
| attributes |
stream
withAttribute: TextEmphasis bold
do: [stream nextPutAll: 'Pharo' ].
stream space.
stream
withAttribute: TextEmphasis underlined
do: [stream nextPutAll: 'is cool' ].
self assert: stream contents string equals: 'Pharo is cool'.
"part of the text underlined"
1 to: 5 do: [ :index |
attributes := stream contents runs at: index.
self assert: attributes isArray.
self assert: attributes first emphasisCode equals: 1].
"no attribute on this space character"
self assertEmpty: (stream contents runs at: 6).
"part of the text bold"
7 to: 13 do: [ :index |
attributes := stream contents runs at: index.
self assert: attributes isArray.
self assert: attributes first emphasisCode equals: 4].
]
{ #category : #test }
TextStreamTest >> testWithAttributesDo [
| attributes |
stream
withAttributes: {TextEmphasis bold. TextColor yellow}
do: [stream nextPutAll: 'Pharo' ].
stream nextPutAll: ' is cool'.
self assert: stream contents string equals: 'Pharo is cool'.
1 to: 5 do: [ :index |
attributes := stream contents runs at: index.
self assert: attributes size equals: 2.
self assert: attributes first emphasisCode equals: 1.
self assert: attributes second color equals: Color yellow ].
"No attribute for the remaining part of the text"
6 to: 12 do: [ :index |
self assertEmpty: (stream contents runs at: index ) ]
]