diff --git a/src/Text-Core/TextColor.class.st b/src/Text-Core/TextColor.class.st index 96b15528c99..6556b253293 100644 --- a/src/Text-Core/TextColor.class.st +++ b/src/Text-Core/TextColor.class.st @@ -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 ] diff --git a/src/Text-Tests/TextColorTest.class.st b/src/Text-Tests/TextColorTest.class.st new file mode 100644 index 00000000000..1fd06137fb1 --- /dev/null +++ b/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 +] diff --git a/src/Text-Tests/TextStreamTest.class.st b/src/Text-Tests/TextStreamTest.class.st index 702999d165a..87622173881 100644 --- a/src/Text-Tests/TextStreamTest.class.st +++ b/src/Text-Tests/TextStreamTest.class.st @@ -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