-
-
Notifications
You must be signed in to change notification settings - Fork 354
/
CompletionContextTest.class.st
480 lines (453 loc) · 12 KB
/
CompletionContextTest.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
Class {
#name : #CompletionContextTest,
#superclass : #TestCase,
#category : #'NECompletion-NewTests'
}
{ #category : #private }
CompletionContextTest >> checkUntypedVariablesOnly: aString [
| context model |
context := self createContextFor: aString at: aString size.
self assert: context isVariablesOnly.
model := context model.
model loadEntries.
self assert: model hasMessage not.
self denyEmpty: (model entriesOfType: #instVar).
context narrowWith: 'a'.
self assertEmpty: (model entriesOfType: #selector)
]
{ #category : #private }
CompletionContextTest >> createContextFor: aString at: anInteger [
^ NECContext
controller: NECController new
class: NECTestClass
source: aString
position: anInteger
]
{ #category : #tests }
CompletionContextTest >> testBlockTemporaries [
| text temps context |
text := 'testIt
| a b c |
a _ [ :each | |d | ^d].
^self'.
context := self
createContextFor: text
at: 39.
temps := context temporaries collect: [ :each | each contents ].
self assert: temps size = 5.
self assert: temps first = 'a'.
self assert: temps second = 'b'.
self assert: temps third = 'c'.
self assert: temps fourth = 'each'.
self assert: temps fifth = 'd'
]
{ #category : #tests }
CompletionContextTest >> testBlockTemporariesBoxed [
| text temps context |
text := 'testIt
| a b c |
a := [ :each | |d | d = a ifTrue:[ |x| ] ifFalse:[ |y|.
^self'.
context := self
createContextFor: text
at: 73.
temps := context temporaries collect: [ :each | each contents ].
self assert: temps size = 5.
self assert: temps first = 'a'.
self assert: temps second = 'b'.
self assert: temps third = 'c'.
self assert: temps fourth = 'each'.
self assert: temps fifth = 'd'.
]
{ #category : #tests }
CompletionContextTest >> testCompletionToken [
| text context |
text := 'testIt: aRectangle
| abc |
test.
abc da'.
context := self createContextFor: text at: text size.
self assert: context completionToken equals: 'da'
]
{ #category : #tests }
CompletionContextTest >> testCompletionTokenEmpty [
| text context |
text := 'testIt: aRectangle
| abc |
test.
abc daf '.
context := self createContextFor: text at: text size.
self assert: context completionToken = ''
]
{ #category : #tests }
CompletionContextTest >> testCreateModel [
| text context |
text := 'testIt: aRectangle
aRectangle printS'.
context := self createContextFor: text at: text size.
self assert: context createModel class == NECTypedModel.
text := 'testIt:'.
context := self createContextFor: text at: text size.
self assert: context createModel class = NECUntypedModel.
text := 'testIt: rect
rect is'.
context := self createContextFor: text at: text size.
self assert: context createModel class = NECUntypedModel
]
{ #category : #tests }
CompletionContextTest >> testEmpty [
self createContextFor: '' at: 0
]
{ #category : #tests }
CompletionContextTest >> testInTheMiddelOfAWord [
| text context |
text := 'hagada'.
context := self
createContextFor: text
at: 4.
self assert: context completionToken = 'haga'
]
{ #category : #tests }
CompletionContextTest >> testReceiverArgument [
| text context |
text := 'testIt: aRectangle
aRectangle printS'.
context := self
createContextFor: text
at: text size.
self assert: context receiverClass == Rectangle.
text := 'testIt: rect
rect is'.
context := self
createContextFor: text
at: text size.
self assert: context receiverClass isNil
]
{ #category : #tests }
CompletionContextTest >> testReceiverCascade [
| text context |
text := 'testIt
| b |
b _ Stream new.
b
nextPutAll: ''test'';
nextPut: $c;
s'.
context := self createContextFor: text at: text size.
self assert: context receiverClass == Stream.
text := 'testIt
| b |
b _ Stream new
nextPutAll: ''test'';
nextPut: $c with: true;
s'.
context := self createContextFor: text at: text size.
self assert: context receiverClass == Stream.
text := 'testIt: aStream
| test |
aStream
nextPutAll: ''test'';
nextPut: $c with: true;
s'.
context := self createContextFor: text at: text size.
self assert: context receiverClass == Stream.
text := 'testIt: aStream
aStream
nextPutAll: ''test'';
nextPut: $c with: true;
s'.
context := self createContextFor: text at: text size.
self assert: context receiverClass == Stream
]
{ #category : #tests }
CompletionContextTest >> testReceiverClassVar [
| text context |
text := 'testIt
ClassVar '.
context := self
createContextFor: text
at: text size.
self assert: context receiverClass == ByteString
]
{ #category : #tests }
CompletionContextTest >> testReceiverConstant [
| text context |
text := 'testIt
15r16 printS'.
context := self createContextFor: text at: text size.
self assert: context receiverClass == SmallInteger.
text := 'testIt
''test'' printS'.
context := self createContextFor: text at: text size.
self assert: context receiverClass == ByteString.
text := 'testIt
true ifTrue:'.
context := self createContextFor: text at: text size.
self assert: context receiverClass == True.
text := 'testIt
false "this is it"
printStr'.
context := self createContextFor: text at: text size.
self assert: context receiverClass == False.
text := 'testIt
a _ [ :test | test * test ]
v'.
context := self createContextFor: text at: text size.
self assert: context receiverClass == BlockClosure.
text := 'testIt
$c as'.
context := self createContextFor: text at: text size.
self assert: context receiverClass == Character.
text := 'testIt
#gaga as'.
context := self createContextFor: text at: text size.
self assert: context receiverClass == Symbol.
text := 'testIt
#( 1 2 3) as'.
context := self createContextFor: text at: text size.
self assert: context receiverClass == Array.
text:='testIt
2r1.1e2 as'.
context := self createContextFor: text at: text size.
self assert: (context receiverClass includesBehavior: Float).
text:='testIt
23s32 as'.
context := self createContextFor: text at: text size.
self assert: context receiverClass == ScaledDecimal.
]
{ #category : #tests }
CompletionContextTest >> testReceiverGlobal [
| text context |
text := 'testIt
Dictionary n'.
context := self createContextFor: text at: text size.
self assert: context receiverClass == Dictionary class.
]
{ #category : #tests }
CompletionContextTest >> testReceiverGlobalVarNew [
| text context |
text := 'testIt
Dictionary new a'.
context := self createContextFor: text at: text size.
self assert: context receiverClass == Dictionary.
]
{ #category : #tests }
CompletionContextTest >> testReceiverTempVar [
| text context |
text := 'testIt
| aha |
aha _ ''test''.
aha p'.
context := self
createContextFor: text
at: text size.
self assert: context receiverClass == ByteString.
text := 'testIt
| aha |
ah _ ''test''.
ah p'.
context := self
createContextFor: text
at: text size.
self assert: context receiverClass isNil.
text := 'testIt
| aha |
aha _ constantString.
aha p'.
context := self
createContextFor: text
at: text size.
self assert: context receiverClass == ByteString.
text := 'testIt
| aha |
aha _ constant asDate.
aha p'.
context := self
createContextFor: text
at: text size.
self assert: context receiverClass isNil.
text := 'testIt
| aha bili |
aha _ constantString.
bili _ aha.
bili p'.
context := self
createContextFor: text
at: text size.
self assert: context receiverClass == ByteString.
text := 'testIt
| aha bili |
aha _ constantString.
bili _ aha _ 15.
bili p'.
context := self
createContextFor: text
at: text size.
self assert: context receiverClass = SmallInteger.
text := 'testIt
| aha bili |
aha _ constantString.
bili _ 15.
bili _ aha.
bili p'.
context := self
createContextFor: text
at: text size.
self assert: context receiverClass == SmallInteger.
text := 'testIt
[ :each | |a| a _ 16. a print'.
context := self
createContextFor: text
at: text size.
self assert: context receiverClass == SmallInteger.
text := 'testIt
[ :each | |a| a _ Dictionary new. a print'.
context := self
createContextFor: text
at: text size.
self assert: context receiverClass == Dictionary.
text := 'testIt
[ :each | |a| a _ Dictionary. a print'.
context := self
createContextFor: text
at: text size.
self assert: context receiverClass == Dictionary class.
text := 'testIt
| aha |
aha _ constantLargeInteger.
aha p'.
context := self
createContextFor: text
at: text size.
self assert: context receiverClass = LargePositiveInteger.
]
{ #category : #tests }
CompletionContextTest >> testReceiverTempVar2 [
| text context |
text := 'openMenuFor: aParagraphEditor
| theMenu |
context := NECContext
controller: self
class: model receiverClass
source: aParagraphEditor text string
position: aParagraphEditor caret - 1.
editor := aParagraphEditor.
theMenu := NECMenuMorph
controller: self
position: (aParagraphEditor selectionPosition: context completionToken).
theMenu isClosed
ifFalse: [menuMorph := theMenu]. theMenu o'.
context := self createContextFor: text at: text size.
self assert: context receiverClass == NECMenuMorph
]
{ #category : #tests }
CompletionContextTest >> testReceiverTempVar3 [
"if tempvar assignment is from a keyword message send (case 3), the guessed type should be 'nil' as in case for simple messages. Don't move over to other var assignments (smallint for var b)"
| text context |
"case 1 guess from constant"
text := 'testIt
| a b |
a _ ''test''.
b _ 10.
a as'.
context := self
createContextFor: text
at: text size.
self assert: context receiverClass == ByteString.
"case 2 can not guess from return value of a message send"
text := 'testIt
| a b |
a _ self class.
b _ 10.
a as'.
context := self
createContextFor: text
at: text size.
self assert: context receiverClass isNil.
"case 3 can not guess from return value of a keyword message send"
text := 'testIt
| a b |
a _ self init:''test''.
b _ 10.
a as'.
context := self
createContextFor: text
at: text size.
self assert: context receiverClass isNil.
]
{ #category : #tests }
CompletionContextTest >> testTemporaries [
| text temps context |
text := 'testIt: aRectangle
| a b c |
a _ [ :each | |d | ^d].
^self'.
context := self
createContextFor: text
at: text size.
temps := context temporaries collect: [ :each | each contents ].
self assert: temps size = 4.
self assert: temps first = 'aRectangle'.
self assert: temps second = 'a'.
self assert: temps third = 'b'.
self assert: temps fourth = 'c'
]
{ #category : #tests }
CompletionContextTest >> testUnfinishedString [
| text context |
text := 'testIt: aRectangle
| a b c |
self test: ''test it and so'.
context := self
createContextFor: text
at: text size.
self assert: context completionToken = 'so'
]
{ #category : #tests }
CompletionContextTest >> testUntypedSelectorsOnly [
| text context model |
text := 'testIt: aRectangle
| ab bc bd |
ab '.
context := self createContextFor: text at: text size.
model := context model.
self assert: model hasMessage.
self assert: model message = 'press key for selectors'.
context narrowWith: 'ab'.
self denyEmpty: (model entriesOfType: #selector).
self assertEmpty: (model entriesOfType: #local).
self assertEmpty: (model entriesOfType: #instance)
]
{ #category : #tests }
CompletionContextTest >> testUntypedVarsOnly [
self checkUntypedVariablesOnly: 'testIt
'.
self checkUntypedVariablesOnly: '+ aTest
'.
self checkUntypedVariablesOnly: 'gaga: aTest
'.
self checkUntypedVariablesOnly: 'gaga
^ '.
self checkUntypedVariablesOnly: 'testIt
a ifTrue:[ '.
self checkUntypedVariablesOnly: 'testIt
a ifTrue:[ :each'.
self checkUntypedVariablesOnly: 'testIt
a ifTrue:[ :each |'.
self checkUntypedVariablesOnly: 'testIt
a ifTrue:[ :each | '.
self checkUntypedVariablesOnly: 'testIt
<primitive: 67>
'.
self checkUntypedVariablesOnly: 'testIt
ab _'.
self checkUntypedVariablesOnly: 'testIt
ab _ '.
self checkUntypedVariablesOnly: 'self compare: '.
self checkUntypedVariablesOnly: 'self compare: x caseSensitive: '.
self checkUntypedVariablesOnly: 'self gaga: x gugu: ('.
self checkUntypedVariablesOnly: 'testIt
a _ 15 + '.
self checkUntypedVariablesOnly: 'testIt
self hugatada: '
]