/
CodeAdapterTest.class.st
95 lines (74 loc) · 2.49 KB
/
CodeAdapterTest.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
Class {
#name : #CodeAdapterTest,
#superclass : #TextAdapterTest,
#category : #'Spec-BackendTests'
}
{ #category : #tests }
CodeAdapterTest >> assertText: text at: index isStyle: styleName [
| tag |
tag := CodeStyleForTest new.
text attributesAt: index do: [ :each |
self fillTag: tag withAttribute: each ].
self assert: tag equals: (self style: styleName)
]
{ #category : #tests }
CodeAdapterTest >> assertText: text atInterval: interval isStyle: styleName [
interval do: [ :index |
self assertText: text at: index isStyle: styleName ]
]
{ #category : #accessing }
CodeAdapterTest >> classToTest [
^ CodePresenter
]
{ #category : #tests }
CodeAdapterTest >> fillTag: tag withAttribute: attr [
attr class = TextColor ifTrue: [ tag foreground: attr color ].
self flag: #TODO. "Other attributes"
]
{ #category : #tests }
CodeAdapterTest >> style: aSymbol [
| tag |
tag := CodeStyleForTest new.
self styleTableAt: aSymbol do: [ :each |
self fillTag: tag withAttribute: each ].
^ tag
]
{ #category : #tests }
CodeAdapterTest >> styleTableAt: styleName do: aBlock [
| attributes |
attributes := (SHRBTextStyler initialTextAttributesForPixelHeight: 1) at: styleName.
attributes do: aBlock
]
{ #category : #tests }
CodeAdapterTest >> testTextWithStyle [
| text |
presenter
behavior: nil;
doItReceiver: Object;
type: 'self asString.'.
text := self adapter textWithStyle.
self assertText: text atInterval: "self" (1 to: 4) isStyle: #self.
self assertText: text atInterval: "asString" (6 to: 13) isStyle: #unary.
presenter type: '10 + 42.0'.
text := self adapter textWithStyle.
self assertText: text atInterval: "10" (1 to: 2) isStyle: #integer.
self assertText: text atInterval: "+" (4 to: 4) isStyle: #binary.
self assertText: text atInterval: "42.0" (6 to: 9) isStyle: #number.
presenter behavior: Object.
presenter type: 'm1 ^ "test" 42'.
text := self adapter textWithStyle.
self assertText: text atInterval: "m1" (1 to: 2) isStyle: #patternKeyword.
self assertText: text atInterval: "^" (4 to: 4) isStyle: #return.
self assertText: text atInterval: "test" (6 to: 11) isStyle: #comment.
self assertText: text atInterval: "42" (13 to: 14) isStyle: #number.
]
{ #category : #tests }
CodeAdapterTest >> testWithSyntaxHighlight [
presenter withSyntaxHighlight.
self assert: self adapter hasSyntaxHighlightEnabled
]
{ #category : #tests }
CodeAdapterTest >> testWithoutSyntaxHighlight [
presenter withoutSyntaxHighlight.
self deny: self adapter hasSyntaxHighlightEnabled
]