rtext 0.9.0 → 0.9.2

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