rtext 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,606 +0,0 @@
1
- $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
-
3
- require 'minitest/autorun'
4
- require 'rgen/metamodel_builder'
5
- require 'rtext/language'
6
- require 'rtext/context_builder'
7
- require 'rtext/default_completer'
8
-
9
- class CompleterTest < MiniTest::Test
10
-
11
- module TestMM
12
- extend RGen::MetamodelBuilder::ModuleExtension
13
- class TestNode2 < RGen::MetamodelBuilder::MMBase
14
- has_attr 'text', String
15
- has_attr 'unlabled', String
16
- end
17
- class TestNode3 < RGen::MetamodelBuilder::MMBase
18
- end
19
- class TestNode < RGen::MetamodelBuilder::MMBase
20
- has_attr 'text', String
21
- has_attr 'unlabled1', String
22
- has_attr 'unlabled2', Integer
23
- has_many_attr 'nums', Integer
24
- has_one 'related', TestNode
25
- has_many 'others', TestNode
26
- contains_many 'childs', TestNode, 'parent'
27
- contains_one 'child2RoleA', TestNode2, 'parentA'
28
- contains_many 'child2RoleB', TestNode2, 'parentB'
29
- contains_one_uni 'testNode3', TestNode3
30
- end
31
- SomeEnum = RGen::MetamodelBuilder::DataTypes::Enum.new(
32
- :name => "SomeEnum", :literals => [:A, :B, :'non-word*chars'])
33
- class TestNode3 < RGen::MetamodelBuilder::MMBase
34
- has_attr 'bool', Boolean
35
- has_attr 'float', Float
36
- has_attr 'enum', SomeEnum
37
- end
38
- class TextNode < RGen::MetamodelBuilder::MMBase
39
- end
40
- end
41
-
42
- def test_after_command
43
- options = complete TestMM, <<-END
44
- TestNode |
45
- END
46
- assert_options([
47
- ["\"\"", "[unlabled1] <EString>"],
48
- ["text:", "<EString>"],
49
- ["nums:", "<EInt>"],
50
- ["related:", "<TestNode>"],
51
- ["others:", "<TestNode>"]
52
- ], options)
53
- end
54
-
55
- def test_lable_prefix
56
- options = complete TestMM, <<-END
57
- TestNode t|
58
- END
59
- assert_options([
60
- ["\"\"", "[unlabled1] <EString>"],
61
- ["text:", "<EString>"],
62
- ["nums:", "<EInt>"],
63
- ["related:", "<TestNode>"],
64
- ["others:", "<TestNode>"]
65
- ], options)
66
- end
67
-
68
- def test_lable_within
69
- options = complete TestMM, <<-END
70
- TestNode t|ext
71
- END
72
- assert_options([
73
- ["\"\"", "[unlabled1] <EString>"],
74
- ["text:", "<EString>"],
75
- ["nums:", "<EInt>"],
76
- ["related:", "<TestNode>"],
77
- ["others:", "<TestNode>"]
78
- ], options)
79
- end
80
-
81
- def test_unlabled_prefix
82
- options = complete TestMM, <<-END
83
- TestNode u|
84
- END
85
- assert_options([
86
- ["\"\"", "[unlabled1] <EString>"],
87
- ["text:", "<EString>"],
88
- ["nums:", "<EInt>"],
89
- ["related:", "<TestNode>"],
90
- ["others:", "<TestNode>"]
91
- ], options)
92
- end
93
-
94
- def test_after_labled_value
95
- options = complete TestMM, <<-END
96
- TestNode nums: 1, |
97
- END
98
- assert_options([
99
- ["text:", "<EString>"],
100
- ["related:", "<TestNode>"],
101
- ["others:", "<TestNode>"]
102
- ], options)
103
- end
104
-
105
- def test_after_labled_value_directly_after_comma
106
- options = complete TestMM, <<-END
107
- TestNode nums: 1,|
108
- END
109
- assert_options([
110
- ["text:", "<EString>"],
111
- ["related:", "<TestNode>"],
112
- ["others:", "<TestNode>"]
113
- ], options)
114
- end
115
-
116
- def test_after_second_labled_value_directly_after_comma
117
- options = complete TestMM, <<-END
118
- TestNode nums: 1, text: "a",|
119
- END
120
- assert_options([
121
- ["related:", "<TestNode>"],
122
- ["others:", "<TestNode>"]
123
- ], options)
124
- end
125
-
126
- def test_after_unlabled_value
127
- options = complete TestMM, <<-END
128
- TestNode "bla", |
129
- END
130
- assert_options([
131
- ["0", "[unlabled2] <EInt>"],
132
- ["text:", "<EString>"],
133
- ["nums:", "<EInt>"],
134
- ["related:", "<TestNode>"],
135
- ["others:", "<TestNode>"]
136
- ], options)
137
- end
138
-
139
- def test_after_unlabled_value_directly_after_comma
140
- options = complete TestMM, <<-END
141
- TestNode "bla",|
142
- END
143
- assert_options([
144
- ["0", "[unlabled2] <EInt>"],
145
- ["text:", "<EString>"],
146
- ["nums:", "<EInt>"],
147
- ["related:", "<TestNode>"],
148
- ["others:", "<TestNode>"]
149
- ], options)
150
- end
151
-
152
- def test_after_unlabled_value2
153
- options = complete TestMM, <<-END
154
- TestNode "bla", 1, |
155
- END
156
- assert_options([
157
- ["text:", "<EString>"],
158
- ["nums:", "<EInt>"],
159
- ["related:", "<TestNode>"],
160
- ["others:", "<TestNode>"]
161
- ], options)
162
- end
163
-
164
- def test_after_unlabled_value3
165
- options = complete TestMM, <<-END
166
- TestNode "bla", 1,|
167
- END
168
- assert_options([
169
- ["text:", "<EString>"],
170
- ["nums:", "<EInt>"],
171
- ["related:", "<TestNode>"],
172
- ["others:", "<TestNode>"]
173
- ], options)
174
- end
175
-
176
- def test_after_array
177
- options = complete TestMM, <<-END
178
- TestNode nums: [1, 2], |
179
- END
180
- assert_options([
181
- ["text:", "<EString>"],
182
- ["related:", "<TestNode>"],
183
- ["others:", "<TestNode>"]
184
- ], options)
185
- end
186
-
187
- def test_after_array_direct
188
- options = complete TestMM, <<-END
189
- TestNode nums: [1, 2]|
190
- END
191
- assert_options([
192
- ], options)
193
- end
194
-
195
- def test_value_int
196
- options = complete TestMM, <<-END
197
- TestNode nums: |
198
- END
199
- assert_options([
200
- ["0", "<EInt>"],
201
- ], options)
202
- end
203
-
204
- def test_value_int_part
205
- options = complete TestMM, <<-END
206
- TestNode nums: 0|
207
- END
208
- assert_options([
209
- ["0", "<EInt>"]
210
- ], options)
211
- end
212
-
213
- def test_value_boolean
214
- options = complete TestMM, <<-END
215
- TestNode3 bool: |
216
- END
217
- assert_options([
218
- ["true", "<EBoolean>"],
219
- ["false", "<EBoolean>"],
220
- ], options)
221
- end
222
-
223
- def test_value_boolean_part
224
- options = complete TestMM, <<-END
225
- TestNode3 bool: t|
226
- END
227
- assert_options([
228
- ["true", "<EBoolean>"],
229
- ["false", "<EBoolean>"],
230
- ], options)
231
- end
232
-
233
- def test_value_boolean_full
234
- options = complete TestMM, <<-END
235
- TestNode3 bool: true|
236
- END
237
- assert_options([
238
- ["true", "<EBoolean>"],
239
- ["false", "<EBoolean>"],
240
- ], options)
241
- end
242
-
243
- def test_value_float
244
- options = complete TestMM, <<-END
245
- TestNode3 float: |
246
- END
247
- assert_options([
248
- ["0.0", "<EFloat>"],
249
- ], options)
250
- end
251
-
252
- def test_value_float_part
253
- options = complete TestMM, <<-END
254
- TestNode3 float: 0|
255
- END
256
- assert_options([
257
- ["0.0", "<EFloat>"],
258
- ], options)
259
- end
260
-
261
- def test_value_float_full
262
- options = complete TestMM, <<-END
263
- TestNode3 float: 0.0|
264
- END
265
- assert_options([
266
- ["0.0", "<EFloat>"],
267
- ], options)
268
- end
269
-
270
- def test_value_enum
271
- options = complete TestMM, <<-END
272
- TestNode3 enum: |
273
- END
274
- assert_options([
275
- ["A", "<SomeEnum>"],
276
- ["B", "<SomeEnum>"],
277
- ["\"non-word*chars\"", "<SomeEnum>"]
278
- ], options)
279
- end
280
-
281
- def test_value_enum_part
282
- options = complete TestMM, <<-END
283
- TestNode3 enum: A|
284
- END
285
- assert_options([
286
- ["A", "<SomeEnum>"],
287
- ["B", "<SomeEnum>"],
288
- ["\"non-word*chars\"", "<SomeEnum>"]
289
- ], options)
290
- end
291
-
292
- def test_array_value
293
- options = complete TestMM, <<-END
294
- TestNode nums: [|
295
- END
296
- assert_options([
297
- ["0", "<EInt>"],
298
- ], options)
299
- end
300
-
301
- def test_array_value2
302
- options = complete TestMM, <<-END
303
- TestNode nums: [1,|
304
- END
305
- assert_options([
306
- ["0", "<EInt>"],
307
- ], options)
308
- end
309
-
310
- def test_reference_value
311
- options = complete(TestMM, %Q(\
312
- TestNode related: |\
313
- ), lambda { |r| [
314
- RText::DefaultCompleter::CompletionOption.from_text_extra("A", "a"),
315
- RText::DefaultCompleter::CompletionOption.from_text_extra("B", "b") ] })
316
- assert_options([
317
- ["A", "a"],
318
- ["B", "b"],
319
- ], options)
320
- end
321
-
322
- def test_reference_value_part
323
- options = complete(TestMM, %Q(\
324
- TestNode related: /My/|\
325
- ), lambda { |r| [
326
- RText::DefaultCompleter::CompletionOption.from_text_extra("/My/Target", "a"),
327
- RText::DefaultCompleter::CompletionOption.from_text_extra("/MyOther/Target", "b") ] })
328
- assert_options([
329
- ["/My/Target", "a"],
330
- ["/MyOther/Target", "b"]
331
- ], options)
332
- end
333
-
334
- def test_reference_value_no_ref_completion_provider
335
- options = complete TestMM, <<-END
336
- TestNode related: |
337
- END
338
- assert_options([
339
- ], options)
340
- end
341
-
342
- def test_reference_value_in_array
343
- options = complete(TestMM, %Q(\
344
- TestNode others: |
345
- ), lambda { |r| [
346
- RText::DefaultCompleter::CompletionOption.from_text_extra("A", "a"),
347
- RText::DefaultCompleter::CompletionOption.from_text_extra("B", "b") ] })
348
- assert_options([
349
- ["A", "a"],
350
- ["B", "b"],
351
- ], options)
352
- end
353
-
354
- def test_reference_value_in_array_after_bracket
355
- options = complete(TestMM, %Q(\
356
- TestNode others: [|
357
- ), lambda { |r| [
358
- RText::DefaultCompleter::CompletionOption.from_text_extra("A", "a"),
359
- RText::DefaultCompleter::CompletionOption.from_text_extra("B", "b") ] })
360
- assert_options([
361
- ["A", "a"],
362
- ["B", "b"],
363
- ], options)
364
- end
365
-
366
- def test_reference_value_in_array_second_value
367
- options = complete(TestMM, %Q(\
368
- TestNode others: [xxx, |
369
- ), lambda { |r| [
370
- RText::DefaultCompleter::CompletionOption.from_text_extra("A", "a"),
371
- RText::DefaultCompleter::CompletionOption.from_text_extra("B", "b") ] })
372
- assert_options([
373
- ["A", "a"],
374
- ["B", "b"],
375
- ], options)
376
- end
377
-
378
- def test_reference_value_nested
379
- options = complete(TestMM, %Q(\
380
- TestNode {
381
- TestNode SimpleState, others: [|/StatemachineMM/State]
382
- ), lambda { |r| [
383
- RText::DefaultCompleter::CompletionOption.from_text_extra("A", "a"),
384
- RText::DefaultCompleter::CompletionOption.from_text_extra("B", "b") ] })
385
- assert_options([
386
- ["A", "a"],
387
- ["B", "b"],
388
- ], options)
389
- end
390
-
391
- def test_after_curly
392
- options = complete TestMM, <<-END
393
- TestNode {|
394
- END
395
- assert_options([
396
- ], options)
397
- end
398
-
399
- def test_children
400
- options = complete TestMM, <<-END
401
- TestNode {
402
- |
403
- END
404
- assert_options([
405
- ["TestNode", "<unlabled1>, <unlabled2>"],
406
- ["child2RoleA:", "<TestNode2>"],
407
- ["child2RoleB:", "<TestNode2>"],
408
- ["testNode3:", "<TestNode3>"]
409
- ], options)
410
- end
411
-
412
- def test_children_with_role
413
- options = complete TestMM, <<-END
414
- TestNode {
415
- child2RoleA:
416
- |
417
- END
418
- assert_options([
419
- ["TestNode2", "<unlabled>"],
420
- ], options)
421
- end
422
-
423
- def test_after_child_role
424
- options = complete TestMM, <<-END
425
- TestNode {
426
- child2RoleA:|
427
- END
428
- assert_options([
429
- ], options)
430
- end
431
-
432
- def test_after_child_role2
433
- options = complete TestMM, <<-END
434
- TestNode {
435
- child2RoleA: |
436
- END
437
- assert_options([
438
- ], options)
439
- end
440
-
441
- def test_after_child_role3
442
- options = complete TestMM, <<-END
443
- TestNode {
444
- child2RoleA: [|
445
- END
446
- assert_options([
447
- ], options)
448
- end
449
-
450
- def test_after_child_role4
451
- options = complete TestMM, <<-END
452
- TestNode {
453
- child2RoleA: [ |
454
- END
455
- assert_options([
456
- ], options)
457
- end
458
-
459
- def test_children_with_role_array
460
- options = complete TestMM, <<-END
461
- TestNode {
462
- child2RoleB: [
463
- |
464
- END
465
- assert_options([
466
- ["TestNode2", "<unlabled>"],
467
- ], options)
468
- end
469
-
470
- def test_children_prefix
471
- options = complete TestMM, <<-END
472
- TestNode {
473
- child2RoleB: [
474
- X|
475
- END
476
- assert_options([
477
- ["TestNode2", "<unlabled>"],
478
- ], options)
479
- end
480
-
481
- def test_children_inside_childrole
482
- options = complete TestMM, <<-END
483
- TestNode {
484
- child2RoleA:
485
- TestNode2 |
486
- END
487
- assert_options([
488
- ["unlabled", "[unlabled] <EString>"],
489
- ["text:", "<EString>"]
490
- ], options)
491
- end
492
-
493
- def test_children_inside_childrole_array
494
- options = complete TestMM, <<-END
495
- TestNode {
496
- child2RoleB: [
497
- TestNode2 |
498
- END
499
- assert_options([
500
- ["unlabled", "[unlabled] <EString>"],
501
- ["text:", "<EString>"]
502
- ], options)
503
- end
504
-
505
- def test_unquoted_argument
506
- options = complete TestMM, <<-END
507
- TestNode {
508
- child2RoleB: [
509
- TestNode2 text: |
510
- END
511
- assert_options([
512
- ["text", "<EString>"]
513
- ], options)
514
- end
515
-
516
- def test_root
517
- options = complete TestMM, <<-END
518
- |
519
- END
520
- assert_options([
521
- ["TestNode", "<unlabled1>, <unlabled2>"],
522
- ["TestNode2", "<unlabled>"],
523
- ["TestNode3", ""],
524
- ["TextNode", ""]
525
- ], options)
526
- end
527
-
528
- def test_root_no_context_lines
529
- options = complete TestMM, ""
530
- assert_options([
531
- ["TestNode", "<unlabled1>, <unlabled2>"],
532
- ["TestNode2", "<unlabled>"],
533
- ["TestNode3", ""],
534
- ["TextNode", ""]
535
- ], options)
536
- end
537
-
538
- def test_root_prefix
539
- options = complete TestMM, <<-END
540
- Text|
541
- END
542
- assert_options([
543
- ["TestNode", "<unlabled1>, <unlabled2>"],
544
- ["TestNode2", "<unlabled>"],
545
- ["TestNode3", ""],
546
- ["TextNode", ""]
547
- ], options)
548
- end
549
-
550
- def test_within_command
551
- options = complete TestMM, <<-END
552
- Text|Node
553
- END
554
- assert_options([
555
- ["TestNode", "<unlabled1>, <unlabled2>"],
556
- ["TestNode2", "<unlabled>"],
557
- ["TestNode3", ""],
558
- ["TextNode", ""]
559
- ], options)
560
- end
561
-
562
- def test_within_command2
563
- options = complete TestMM, <<-END
564
- |TextNode
565
- END
566
- assert_options([
567
- ["TestNode", "<unlabled1>, <unlabled2>"],
568
- ["TestNode2", "<unlabled>"],
569
- ["TestNode3", ""],
570
- ["TextNode", ""]
571
- ], options)
572
- end
573
-
574
- def assert_options(expected, options)
575
- assert_equal(expected, options.collect { |o| [o.insert, o.extra] })
576
- end
577
-
578
- def complete(mm, text, ref_comp_option_provider=nil)
579
- context_lines = text.split("\n")
580
- if context_lines.last
581
- pos_in_line = context_lines.last.index("|")
582
- context_lines.last.sub!("|", "")
583
- end
584
- lang = RText::Language.new(mm.ecore,
585
- :root_classes => mm.ecore.eAllClasses,
586
- :unlabled_arguments => lambda {|c| ["unlabled1", "unlabled2", "unlabled"]},
587
- :unquoted_arguments => lambda {|c| c.name == "TestNode2" ? ["text", "unlabled"] : []},
588
- :labeled_containments => lambda {|c| ["testNode3"]})
589
- context = RText::ContextBuilder.build_context(lang, context_lines, pos_in_line)
590
- completer = RText::DefaultCompleter.new(lang)
591
- class << completer
592
- attr_accessor :ref_comp_option_provider
593
- def reference_options(context)
594
- if ref_comp_option_provider
595
- ref_comp_option_provider.call(context.feature)
596
- else
597
- super
598
- end
599
- end
600
- end
601
- completer.ref_comp_option_provider = ref_comp_option_provider
602
- completer.complete(context)
603
- end
604
-
605
- end
606
-