• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

moosetechnology / MooseIDE / 20140417968

11 Dec 2025 04:39PM UTC coverage: 65.249% (+0.3%) from 64.99%
20140417968

push

github

web-flow
Merge pull request #1555 from moosetechnology/refactor-sourceText

Refactor sourceTextRendering

387 of 403 new or added lines in 5 files covered. (96.03%)

22 existing lines in 5 files now uncovered.

21715 of 33280 relevant lines covered (65.25%)

1.3 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.9
/src/MooseIDE-Tests/MiSourceTextRendererModelTest.class.st
1
Class {
2
        #name : 'MiSourceTextRendererModelTest',
3
        #superclass : 'TestCase',
4
        #instVars : [
5
                'rendererModel'
6
        ],
7
        #category : 'MooseIDE-Tests-Browsers',
8
        #package : 'MooseIDE-Tests',
9
        #tag : 'Browsers'
10
}
11

12
{ #category : 'running' }
NEW
13
MiSourceTextRendererModelTest >> browserClass [
×
NEW
14
        ^ MiSourceTextBrowser
×
NEW
15
]
×
16

17
{ #category : 'running' }
18
MiSourceTextRendererModelTest >> setUp [
2✔
19
        super setUp.
2✔
20

2✔
21
        rendererModel := MiSourceTextRendererModel new.
2✔
22
        rendererModel renderer: Mock new
2✔
23
]
2✔
24

25
{ #category : 'running' }
26
MiSourceTextRendererModelTest >> stubImmediateAnchorText: aString [
2✔
27
        ^FamixTest1SourceTextAnchor new
2✔
28
                source: aString 
2✔
29
                yourself.
2✔
30

2✔
31
]
2✔
32

33
{ #category : 'running' }
34
MiSourceTextRendererModelTest >> stubIndexedAnchorText: aString [
2✔
35
        ^self stubIndexedAnchorText: aString positions: 1@(aString size)
2✔
36
]
2✔
37

38
{ #category : 'running' }
39
MiSourceTextRendererModelTest >> stubIndexedAnchorText: aString positions: startEndPos [
2✔
40
        ^FamixStubIndexedFileAnchor new
2✔
41
                source: aString ;
2✔
42
                startPos: startEndPos x ;
2✔
43
                endPos: startEndPos y ;
2✔
44
                yourself.
2✔
45

2✔
46
]
2✔
47

48
{ #category : 'tests - highlighting' }
49
MiSourceTextRendererModelTest >> testDoNotHighlightChildren [
2✔
50
        | entity |
2✔
51

2✔
52
        entity := FamixStClass new
2✔
53
                name: 'aClass' ;
2✔
54
                sourceAnchor: (self stubImmediateAnchorText: 
2✔
55
'Class {
2✔
56
        #name : ''aClass'',
2✔
57
        #package : ''For-Testing''
2✔
58
}
2✔
59

2✔
60
aClass >> aMethod()
2✔
61
        "nothing"
2✔
62
').
2✔
63
        FamixStMethod new
2✔
64
                name: 'aMethod' ;
2✔
65
                parentType: entity ;
2✔
66
                sourceAnchor: (self stubImmediateAnchorText: '        code of aMethod()' ).
2✔
67

2✔
68
        rendererModel shouldHighlightChildren: false.
2✔
69
        rendererModel renderTextFor: entity.
2✔
70

2✔
71
        self assert: rendererModel highlights size equals: 0
2✔
72
]
2✔
73

74
{ #category : 'tests - highlighting' }
75
MiSourceTextRendererModelTest >> testHighlightChildWithImmediateTextAnchor [
2✔
76
        | entity |
2✔
77

2✔
78
        entity := FamixStClass new
2✔
79
                name: 'aClass' ;
2✔
80
                sourceAnchor: (self stubImmediateAnchorText: 
2✔
81
'Class {
2✔
82
        #name : ''aClass'',
2✔
83
        #package : ''For-Testing''
2✔
84
}
2✔
85

2✔
86
aClass >> aMethod()
2✔
87
        "nothing"
2✔
88
').
2✔
89
        FamixStMethod new
2✔
90
                name: 'aMethod' ;
2✔
91
                parentType: entity ;
2✔
92
                sourceAnchor: (self stubImmediateAnchorText: '        code of aMethod()' ).
2✔
93
                
2✔
94
        rendererModel renderTextFor: entity.
2✔
95

2✔
96
        self assert: rendererModel highlights size equals: 2.
2✔
97
        rendererModel highlights do: [ :highlight |
2✔
98
                self assert: highlight class equals: MiSourceTextIdentifierHighlight.
2✔
99
        ].
2✔
100

2✔
101
        self assertCollection: (rendererModel highlights collect: #from) hasSameElements: #(19 67)
2✔
102

2✔
103
]
2✔
104

105
{ #category : 'tests - highlighting' }
106
MiSourceTextRendererModelTest >> testHighlightChildWithIndexedFileAnchor [
2✔
107
        | entity |
2✔
108
        entity := FamixJavaClass new
2✔
109
                name: 'aClass' ;
2✔
110
                sourceAnchor: (self stubIndexedAnchorText: 
2✔
111
'code of aClass {
2✔
112
        code of aMethod()
2✔
113
}').
2✔
114
        FamixJavaMethod new
2✔
115
                name: 'aMethod' ;
2✔
116
                parentType: entity ;
2✔
117
                sourceAnchor: (self stubIndexedAnchorText: #whatever positions: 18@36 ).
2✔
118
                
2✔
119
        rendererModel renderTextFor: entity.
2✔
120

2✔
121
        self assert: rendererModel highlights size equals: 2.
2✔
122
        rendererModel highlights do: [ :highlight |
2✔
123
                self assert: highlight class equals: MiSourceTextIdentifierHighlight.
2✔
124
        ].
2✔
125

2✔
126
        self assertCollection: (rendererModel highlights collect: #from) hasSameElements: #(9 27)
2✔
127

2✔
128
]
2✔
129

130
{ #category : 'tests - highlighting' }
131
MiSourceTextRendererModelTest >> testHighlightChildWithNoAnchor [
2✔
132
        | entity |
2✔
133
        entity := FamixStClass new
2✔
134
                name: 'aClass' ;
2✔
135
                sourceAnchor: (self stubIndexedAnchorText: 
2✔
136
'code of aClass {
2✔
137
        code of aMethod()
2✔
138
}').
2✔
139
        FamixStMethod new
2✔
140
                name: 'aMethod' ;
2✔
141
                parentType: entity.
2✔
142

2✔
143
        rendererModel renderTextFor: entity.
2✔
144

2✔
145
        self assert: rendererModel highlights size equals: 2.
2✔
146
        rendererModel highlights do: [ :highlight |
2✔
147
                self assert: highlight class equals: MiSourceTextIdentifierHighlight
2✔
148
        ].
2✔
149

2✔
150
        "one highlight has an interval, the other not"
2✔
151
        self assert: (rendererModel highlights anySatisfy: #hasInterval).
2✔
152
        self assert: (rendererModel highlights anySatisfy: [ :highlight | highlight hasInterval not]).
2✔
153

2✔
154
]
2✔
155

156
{ #category : 'tests - highlighting' }
157
MiSourceTextRendererModelTest >> testHighlightJavaComment [
2✔
158

2✔
159
        | entity highlight |
2✔
160
        entity := FamixJavaClass new
2✔
161
                name: 'aClass';
2✔
162
                sourceAnchor: (self stubIndexedAnchorText: 'code of aClass {
2✔
163
        /* this is a Java comment */
2✔
164
}').
2✔
165
        FamixJavaComment new
2✔
166
                sourceAnchor: (self stubIndexedAnchorText: 'this is a Java comment');
2✔
167
                commentedEntity: entity;
2✔
168
                sourceAnchor:
2✔
169
                        (self stubIndexedAnchorText: #whatever positions: 19 @ 46).
2✔
170

2✔
171
        rendererModel renderTextFor: entity.
2✔
172

2✔
173
        self assert: rendererModel highlights size equals: 2.
2✔
174

2✔
175
        highlight := rendererModel highlights
2✔
176
                detect: [ :hghlght | hghlght class = MiSourceTextCommentHighlight ]
2✔
177
                ifNone: [ self fail: 'Should have one MiSourceTextCommentHighlight' ].
2✔
178

2✔
179
        self assert: highlight from equals: 19
2✔
180
]
2✔
181

182
{ #category : 'tests - highlighting' }
183
MiSourceTextRendererModelTest >> testHighlightJavaKeywords [
2✔
184

2✔
185
        | entity positions |
2✔
186
        entity := FamixJavaClass new
2✔
187
                name: 'aClass' ;
2✔
188
                mooseModel: FamixJavaModel new ;
2✔
189
                sourceAnchor: (self stubIndexedAnchorText: 'public class aClass { }').
2✔
190
        entity mooseModel sourceLanguage: FamixJavaSourceLanguage new.
2✔
191

2✔
192
        rendererModel renderTextFor: entity.
2✔
193

2✔
194
        self assert: rendererModel highlights size equals: 3.
2✔
195

2✔
196
        self assert: (rendererModel highlights count: [ :hghlght | hghlght class = MiSourceTextKeywordHighlight ]) equals: 2.
2✔
197

2✔
198
        positions := rendererModel highlights
2✔
199
                select: [ :hghlght | hghlght class = MiSourceTextKeywordHighlight ]
2✔
200
                thenCollect: [ :hghlght | hghlght from ].
2✔
201
        
2✔
202
        self assertCollection: positions hasSameElements: #(1 8)
2✔
203
]
2✔
204

205
{ #category : 'tests - highlighting' }
206
MiSourceTextRendererModelTest >> testHighlightNoAnchor [
2✔
207
        | entity |
2✔
208
        entity := FamixStClass new
2✔
209
                name: 'aClass'.
2✔
210
        FamixStMethod new
2✔
211
                name: 'aMethod' ;
2✔
212
                parentType: entity.
2✔
213
                
2✔
214
        rendererModel renderTextFor: entity.
2✔
215

2✔
216
        self assert: rendererModel displayedText equals: 'There is no source code to show for aClass'.
2✔
217
        self assert: rendererModel highlights anyOne class equals: MiSourceTextErrorHighlight
2✔
218
]
2✔
219

220
{ #category : 'tests - highlighting' }
221
MiSourceTextRendererModelTest >> testHighlightNoChild [
2✔
222
        | entity |
2✔
223
        entity := FamixStClass new
2✔
224
                name: 'aClass' ;
2✔
225
                sourceAnchor: (self stubIndexedAnchorText: 
2✔
226
'code of aClass {
2✔
227
        code of aMethod()
2✔
228
}' ).
2✔
229
                
2✔
230
        rendererModel renderTextFor: entity.
2✔
231

2✔
232
        self assert: rendererModel highlights size equals: 1.
2✔
233
        self assert: rendererModel highlights anyOne class equals: MiSourceTextIdentifierHighlight.
2✔
234
        self assert: rendererModel highlights anyOne from equals: 9.
2✔
235
        self assert: rendererModel highlights anyOne to   equals: 14
2✔
236
]
2✔
237

238
{ #category : 'tests - highlighting' }
239
MiSourceTextRendererModelTest >> testHighlightNoKeywordInComment [
2✔
240

2✔
241
        | entity |
2✔
242
        entity := FamixJavaClass new
2✔
243
                name: 'aClass' ;
2✔
244
                mooseModel: FamixJavaModel new ;
2✔
245
                sourceAnchor: (self stubIndexedAnchorText: 'code of aClass {
2✔
246
        /* this word "class" is not a keyword */
2✔
247
}').
2✔
248
        entity mooseModel sourceLanguage: FamixJavaSourceLanguage new.
2✔
249
        FamixJavaComment new
2✔
250
                sourceAnchor: (self stubIndexedAnchorText: 'this word "class" is not a keyword');
2✔
251
                commentedEntity: entity;
2✔
252
                sourceAnchor: (self stubIndexedAnchorText: #whatever positions: 19 @ 58).
2✔
253

2✔
254
        rendererModel renderTextFor: entity.
2✔
255

2✔
256
        self assert: rendererModel highlights size equals: 2.
2✔
257
        self assert: (rendererModel highlights noneSatisfy: [ :hghlght | hghlght class = MiSourceTextKeywordHighlight ])
2✔
258
]
2✔
259

260
{ #category : 'tests - highlighting' }
261
MiSourceTextRendererModelTest >> testHighlightStComment [
2✔
262

2✔
263
        | entity highlight |
2✔
264
        entity := FamixStClass new
2✔
265
                          name: 'aClass';
2✔
266
                          sourceAnchor: (self stubIndexedAnchorText: 'code of aClass {
2✔
267
        "this is a Pharo comment"
2✔
268
}').
2✔
269
        FamixStComment new
2✔
270
                sourceAnchor: (self stubIndexedAnchorText: 'this is a Pharo comment');
2✔
271
                commentedEntity: entity.
2✔
272

2✔
273
        rendererModel renderTextFor: entity.
2✔
274

2✔
275
        self assert: rendererModel highlights size equals: 2.
2✔
276

2✔
277
        highlight := rendererModel highlights
2✔
278
                detect: [ :hghlght | hghlght class = MiSourceTextCommentHighlight ]
2✔
279
                ifNone: [ self fail: 'Should have one MiSourceTextCommentHighlight' ].
2✔
280

2✔
281
        self assert: highlight from equals: 20
2✔
282
]
2✔
283

284
{ #category : 'tests - highlighting' }
285
MiSourceTextRendererModelTest >> testHighlightStCommentForClass [
2✔
286
        "class comment appear before the class in Pharo"
2✔
287

2✔
288
        | entity highlight |
2✔
289
        entity := FamixStClass new
2✔
290
                          name: 'aClass';
2✔
291
                          sourceAnchor: (self stubIndexedAnchorText: '"this is a Pharo class comment"
2✔
292
code of aClass {
2✔
293
}').
2✔
294
        FamixStComment new
2✔
295
                sourceAnchor: (self stubIndexedAnchorText: 'this is a Pharo class comment');
2✔
296
                commentedEntity: entity.
2✔
297

2✔
298
        rendererModel renderTextFor: entity.
2✔
299

2✔
300
        self assert: rendererModel highlights size equals: 2.
2✔
301

2✔
302
        highlight := rendererModel highlights
2✔
303
                detect: [ :hghlght | hghlght class = MiSourceTextCommentHighlight ]
2✔
304
                ifNone: [ self fail: 'Should have one MiSourceTextCommentHighlight' ].
2✔
305

2✔
306
        self assert: highlight from equals: 2
2✔
307
]
2✔
308

309
{ #category : 'tests' }
310
MiSourceTextRendererModelTest >> testShowNoSourceCodeMessage [
2✔
311

2✔
312
        rendererModel renderTextFor: (FamixStClass named: 'TestClass').
2✔
313

2✔
314
        self
2✔
315
                assert: rendererModel displayedText
2✔
316
                equals: 'There is no source code to show for TestClass'.
2✔
317
]
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc