Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4712-Text-Core-package-documentation-and-test #4715

Merged
merged 19 commits into from
Oct 3, 2019
2 changes: 2 additions & 0 deletions src/Text-Core/TextStream.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ TextStream >> nextPutAll: aCollection [

{ #category : #private }
TextStream >> withAttribute: att do: strmBlock [
"Add text to the stream with a block and apply its text attribute"
| pos1 val |
pos1 := self position.
val := strmBlock value.
Expand All @@ -51,6 +52,7 @@ TextStream >> withAttribute: att do: strmBlock [

{ #category : #private }
TextStream >> withAttributes: attributes do: streamBlock [
"Add text to the stream with a block and apply its text attributes (in collection)"
| pos1 val |
pos1 := self position.
val := streamBlock value.
Expand Down
70 changes: 70 additions & 0 deletions src/Text-Tests/TextStreamTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 assert: (stream contents runs at: index) isEmpty]
]

{ #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 assert: (stream contents runs at: 6) isEmpty.
"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 assert: (stream contents runs at: index ) isEmpty]
]