Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
On TextColor
  • Loading branch information
hilaire committed Sep 26, 2019
1 parent c56f5f0 commit beb2724
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Text-Core/TextColor.class.st
Expand Up @@ -99,6 +99,7 @@ TextColor >> color: aColor [

{ #category : #scanning }
TextColor >> dominates: other [
"Only one color attribute on a same portion of text."
^ other class == self class
]

Expand Down
35 changes: 35 additions & 0 deletions src/Text-Tests/TextColorTest.class.st
@@ -0,0 +1,35 @@
Class {
#name : #TextColorTest,
#superclass : #TestCase,
#category : #'Text-Tests-Base'
}

{ #category : #tests }
TextColorTest >> testColor [
| textColor |
textColor := TextColor new color: Color red.
self assert: textColor color equals: Color red.
self assert: textColor asColor equals: Color red.

]

{ #category : #tests }
TextColorTest >> testDominates [
| text |
self assert: (TextColor red dominates: TextColor yellow).
self assert: (TextColor red dominates: TextColor red).
self deny: (TextColor red dominates: TextEmphasis bold).
self deny: (TextColor red dominates: TextFontChange font2).
"In action"
text := 'Pharo is cool' asText.
text addAttribute: TextColor red.
"Only one color at time, the last added color win"
text addAttribute: TextColor yellow.
self assert: (text attributesAt: 1) size equals: 1.
self assert: (text attributesAt: 1) first color equals: Color yellow.
"Can be both colored and bold"
text addAttribute: TextEmphasis bold.
self assert: (text attributesAt: 1) size equals: 2.
self assert: (text attributesAt: 1) first color equals: Color yellow.
self assert: (text attributesAt: 2) second emphasisCode equals: 1
]
14 changes: 14 additions & 0 deletions src/Text-Tests/TextStreamTest.class.st
Expand Up @@ -15,6 +15,20 @@ TextStreamTest >> setUp [
stream := TextStream on: (Text new:100)
]

{ #category : #test }
TextStreamTest >> testApplyAttributeBeginningAt [
| attributes |
stream nextPutAll: 'Pharo is cool'.
stream applyAttribute: TextEmphasis underlined beginningAt: 10.
1 to: 9 do: [ :index |
attributes := stream contents runs at: index.
self assertEmpty: attributes].
10 to: 14 do: [ :index |
attributes := stream contents runs at: index.
self assert: attributes isArray.
self assert: attributes first emphasisCode equals: 4].
]

{ #category : #test }
TextStreamTest >> testNextPutAll [
stream
Expand Down

0 comments on commit beb2724

Please sign in to comment.