rtext 0.9.0 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +113 -98
  3. data/Project.yaml +14 -0
  4. data/RText_Protocol +1 -1
  5. data/lib/rtext/default_completer.rb +212 -208
  6. data/lib/rtext/frontend/connector.rb +122 -55
  7. data/lib/rtext/instantiator.rb +11 -3
  8. data/lib/rtext/service.rb +264 -260
  9. metadata +18 -44
  10. data/Rakefile +0 -46
  11. data/test/completer_test.rb +0 -607
  12. data/test/context_builder_test.rb +0 -949
  13. data/test/frontend/context_test.rb +0 -302
  14. data/test/instantiator_test.rb +0 -1733
  15. data/test/integration/backend.out +0 -16
  16. data/test/integration/crash_on_request_editor.rb +0 -12
  17. data/test/integration/ecore_editor.rb +0 -50
  18. data/test/integration/frontend.log +0 -40058
  19. data/test/integration/model/invalid_encoding.invenc +0 -2
  20. data/test/integration/model/test.crash_on_request +0 -18
  21. data/test/integration/model/test.crashing_backend +0 -18
  22. data/test/integration/model/test.dont_open_socket +0 -0
  23. data/test/integration/model/test.invalid_cmd_line +0 -0
  24. data/test/integration/model/test.not_in_rtext +0 -0
  25. data/test/integration/model/test_large_with_errors.ect3 +0 -43523
  26. data/test/integration/model/test_metamodel.ect +0 -24
  27. data/test/integration/model/test_metamodel2.ect +0 -5
  28. data/test/integration/model/test_metamodel3.ect4 +0 -7
  29. data/test/integration/model/test_metamodel_error.ect2 +0 -3
  30. data/test/integration/model/test_metamodel_ok.ect2 +0 -18
  31. data/test/integration/test.rb +0 -968
  32. data/test/link_detector_test.rb +0 -288
  33. data/test/message_helper_test.rb +0 -117
  34. data/test/rtext_test.rb +0 -11
  35. data/test/serializer_test.rb +0 -1024
  36. data/test/tokenizer_test.rb +0 -174
@@ -1,968 +0,0 @@
1
- # encoding: binary
2
- $:.unshift(File.dirname(__FILE__)+"/../../lib")
3
-
4
- gem 'minitest'
5
- require 'minitest/autorun'
6
- require 'rtext/frontend/connector_manager'
7
- require 'rtext/frontend/context'
8
- require 'logger'
9
-
10
- class IntegrationTest < MiniTest::Test
11
-
12
- ModelFile = File.dirname(__FILE__)+"/model/test_metamodel.ect"
13
- ModelFile2 = File.dirname(__FILE__)+"/model/test_metamodel2.ect"
14
- ModelFile3 = File.dirname(__FILE__)+"/model/test_metamodel3.ect4"
15
- LargeWithErrorsFile = File.dirname(__FILE__)+"/model/test_large_with_errors.ect3"
16
- InvalidEncodingFile = File.dirname(__FILE__)+"/model/invalid_encoding.invenc"
17
- NotInRTextFile = File.dirname(__FILE__)+"/model/test.not_in_rtext"
18
- InvalidCmdLineFile = File.dirname(__FILE__)+"/model/test.invalid_cmd_line"
19
- CrashingBackendFile = File.dirname(__FILE__)+"/model/test.crashing_backend"
20
- DontOpenSocketFile = File.dirname(__FILE__)+"/model/test.dont_open_socket"
21
- CrashOnRequestFile = File.dirname(__FILE__)+"/model/test.crash_on_request"
22
-
23
- def setup_connector(file)
24
- @infile = file
25
- outfile = File.dirname(__FILE__)+"/backend.out"
26
- logfile = File.dirname(__FILE__)+"/frontend.log"
27
- logger = Logger.new(logfile)
28
- File.unlink(outfile) if File.exist?(outfile)
29
- @connection_timeout = false
30
- man = RText::Frontend::ConnectorManager.new(
31
- :logger => logger,
32
- :keep_outfile => true,
33
- :connection_timeout => 2,
34
- :outfile_provider => lambda { File.expand_path(outfile) },
35
- :connect_callback => lambda do |connector, state|
36
- @connection_timeout = true if state == :timeout
37
- end)
38
- @con = man.connector_for_file(@infile)
39
- end
40
-
41
- def teardown
42
- @con.stop if @con
43
- end
44
-
45
- def test_non_existing_file
46
- setup_connector("this is not a file")
47
- assert_nil @con
48
- end
49
-
50
- def test_not_in_rtext_file
51
- setup_connector(NotInRTextFile)
52
- assert_nil @con
53
- end
54
-
55
- def test_invalid_command_line
56
- setup_connector(InvalidCmdLineFile)
57
- assert @con
58
- response = load_model
59
- assert @connection_timeout
60
- end
61
-
62
- def test_crashing_backend
63
- setup_connector(CrashingBackendFile)
64
- assert @con
65
- response = load_model
66
- assert @connection_timeout
67
- end
68
-
69
- def test_backend_doesnt_open_socket
70
- setup_connector(DontOpenSocketFile)
71
- assert @con
72
- response = load_model
73
- assert @connection_timeout
74
- end
75
-
76
- def test_backend_crash_on_request
77
- setup_connector(CrashOnRequestFile)
78
- assert @con
79
- response = load_model
80
- assert_equal [], response["problems"]
81
- response = @con.execute_command({"command" => "link_targets", "context" => [], "column" => 1})
82
- assert_equal :timeout, response
83
- end
84
-
85
- # simulate external encoding utf-8 (-E in .rext) containing a iso-8859-1 character
86
- def test_invalid_encoding
87
- setup_connector(InvalidEncodingFile)
88
- response = load_model
89
- assert_equal "response", response["type"]
90
- assert_equal [], response["problems"]
91
- text = %Q(EPackage "iso-8859-1 umlaut: \xe4",| nsPrefix: "")
92
- context = build_context(text)
93
- assert_completions context, [
94
- "nsPrefix:",
95
- "nsURI:"
96
- ]
97
- end
98
-
99
- def test_loadmodel
100
- setup_connector(ModelFile)
101
- response = load_model
102
- assert_equal "response", response["type"]
103
- assert_equal [], response["problems"]
104
- end
105
-
106
- def test_loadmodel_large_with_errors
107
- setup_connector(LargeWithErrorsFile)
108
- response = load_model
109
- assert_equal "response", response["type"]
110
- assert_equal 43523, response["problems"].first["problems"].size
111
- end
112
-
113
- def test_unknown_command
114
- setup_connector(ModelFile)
115
- response = load_model
116
- response = @con.execute_command({"command" => "unknown"})
117
- assert_equal "unknown_command_error", response["type"]
118
- end
119
-
120
- #TODO: connector restart when .rtext file changes
121
-
122
- def test_complete_first_line
123
- setup_connector(ModelFile)
124
- load_model
125
- context = build_context <<-END
126
- |EPackage StatemachineMM {
127
- END
128
- assert_completions context, [
129
- "EPackage"
130
- ]
131
- context = build_context <<-END
132
- EPackage| StatemachineMM {
133
- END
134
- assert_completions context, [
135
- "EPackage"
136
- ]
137
- context = build_context <<-END
138
- EPackage |StatemachineMM {
139
- END
140
- assert_completions context, [
141
- "name",
142
- "nsPrefix:",
143
- "nsURI:"
144
- ]
145
- context = build_context <<-END
146
- EPackage S|tatemachineMM {
147
- END
148
- assert_completions context, [
149
- "name",
150
- "nsPrefix:",
151
- "nsURI:"
152
- ]
153
- context = build_context <<-END
154
- EPackage StatemachineMM| {
155
- END
156
- assert_completions context, [
157
- "name",
158
- "nsPrefix:",
159
- "nsURI:"
160
- ]
161
- context = build_context <<-END
162
- EPackage StatemachineMM |{
163
- END
164
- assert_completions context, [
165
- ]
166
- context = build_context <<-END
167
- EPackage StatemachineMM {|
168
- END
169
- # these columns don't exist
170
- assert_completions context, []
171
- context = build_context({:col => 27}, "EPackage StatemachineMM {")
172
- assert_completions context, []
173
- context = build_context({:col => 28}, "EPackage StatemachineMM {")
174
- assert_completions context, []
175
- context = build_context({:col => 100}, "EPackage StatemachineMM {")
176
- assert_completions context, []
177
- # before first column is like first column
178
- context = build_context({:col => 0}, "EPackage StatemachineMM {")
179
- assert_completions context, [
180
- "EPackage"
181
- ]
182
- context = build_context({:col => -1}, "EPackage StatemachineMM {")
183
- assert_completions context, [
184
- "EPackage"
185
- ]
186
- context = build_context({:col => -100}, "EPackage StatemachineMM {")
187
- assert_completions context, [
188
- "EPackage"
189
- ]
190
- end
191
-
192
- def test_nested_command
193
- setup_connector(ModelFile)
194
- load_model
195
- context = build_context <<-END
196
- EPackage StatemachineMM {
197
- | EClass State, abstract: true {
198
- END
199
- assert_completions context, [
200
- "EAnnotation",
201
- "EClass",
202
- "EClassifier",
203
- "EDataType",
204
- "EEnum",
205
- "EGenericType",
206
- "EPackage"
207
- ]
208
- context = build_context <<-END
209
- EPackage StatemachineMM {
210
- |EClass State, abstract: true {
211
- END
212
- assert_completions context, [
213
- "EAnnotation",
214
- "EClass",
215
- "EClassifier",
216
- "EDataType",
217
- "EEnum",
218
- "EGenericType",
219
- "EPackage"
220
- ]
221
- context = build_context <<-END
222
- EPackage StatemachineMM {
223
- EC|lass State, abstract: true {
224
- END
225
- assert_completions context, [
226
- "EAnnotation",
227
- "EClass",
228
- "EClassifier",
229
- "EDataType",
230
- "EEnum",
231
- "EGenericType",
232
- "EPackage"
233
- ]
234
- context = build_context <<-END
235
- EPackage StatemachineMM {
236
- EClass| State, abstract: true {
237
- END
238
- assert_completions context, [
239
- "EAnnotation",
240
- "EClass",
241
- "EClassifier",
242
- "EDataType",
243
- "EEnum",
244
- "EGenericType",
245
- "EPackage"
246
- ]
247
- context = build_context <<-END
248
- EPackage StatemachineMM {
249
- EClass |State, abstract: true {
250
- END
251
- assert_completions context, [
252
- "name",
253
- "abstract:",
254
- "interface:",
255
- "eSuperTypes:",
256
- "instanceClassName:"
257
- ]
258
- context = build_context <<-END
259
- EPackage StatemachineMM {
260
- EClass S|tate, abstract: true {
261
- END
262
- assert_completions context, [
263
- "name",
264
- "abstract:",
265
- "interface:",
266
- "eSuperTypes:",
267
- "instanceClassName:"
268
- ]
269
- context = build_context <<-END
270
- EPackage StatemachineMM {
271
- EClass State|, abstract: true {
272
- END
273
- assert_completions context, [
274
- "name",
275
- "abstract:",
276
- "interface:",
277
- "eSuperTypes:",
278
- "instanceClassName:"
279
- ]
280
- context = build_context <<-END
281
- EPackage StatemachineMM {
282
- EClass State,| abstract: true {
283
- END
284
- assert_completions context, [
285
- "abstract:",
286
- "interface:",
287
- "eSuperTypes:",
288
- "instanceClassName:"
289
- ]
290
- context = build_context <<-END
291
- EPackage StatemachineMM {
292
- EClass State, |abstract: true {
293
- END
294
- assert_completions context, [
295
- "abstract:",
296
- "interface:",
297
- "eSuperTypes:",
298
- "instanceClassName:"
299
- ]
300
- context = build_context <<-END
301
- EPackage StatemachineMM {
302
- EClass State, a|bstract: true {
303
- END
304
- assert_completions context, [
305
- "abstract:",
306
- "interface:",
307
- "eSuperTypes:",
308
- "instanceClassName:"
309
- ]
310
- context = build_context <<-END
311
- EPackage StatemachineMM {
312
- EClass State, abstract:| true {
313
- END
314
- assert_completions context, [
315
- "true",
316
- "false"
317
- ]
318
- context = build_context <<-END
319
- EPackage StatemachineMM {
320
- EClass State, abstract: |true {
321
- END
322
- assert_completions context, [
323
- "true",
324
- "false"
325
- ]
326
- context = build_context <<-END
327
- EPackage StatemachineMM {
328
- EClass State, abstract: t|rue {
329
- END
330
- assert_completions context, [
331
- "true",
332
- "false"
333
- ]
334
- context = build_context <<-END
335
- EPackage StatemachineMM {
336
- EClass State, abstract: true| {
337
- END
338
- assert_completions context, [
339
- "true",
340
- "false"
341
- ]
342
- context = build_context <<-END
343
- EPackage StatemachineMM {
344
- EClass State, abstract: true |{
345
- END
346
- assert_completions context, [
347
- ]
348
- context = build_context <<-END
349
- EPackage StatemachineMM {
350
- EClass State, abstract: true {|
351
- END
352
- assert_completions context, [
353
- ]
354
- end
355
-
356
- def test_complete_feature_after_linebreak
357
- setup_connector(ModelFile)
358
- load_model
359
- context = build_context <<-END
360
- EPackage StatemachineMM {
361
- EClass State, abstract: true {
362
- EAttribute name, eType: /StatemachineMM/StringType
363
- EReference parent,
364
- |eType: /StatemachineMM/CompositeState,
365
- END
366
- assert_completions context, [
367
- "containment:",
368
- "resolveProxies:",
369
- "eOpposite:",
370
- "changeable:",
371
- "defaultValueLiteral:",
372
- "derived:",
373
- "transient:",
374
- "unsettable:",
375
- "volatile:",
376
- "lowerBound:",
377
- "ordered:",
378
- "unique:",
379
- "upperBound:",
380
- "eType:"
381
- ]
382
- end
383
-
384
- def test_complete_reference_after_linebreak
385
- setup_connector(ModelFile)
386
- load_model
387
- context = build_context <<-END
388
- EPackage StatemachineMM {
389
- EClass State, abstract: true {
390
- EAttribute name, eType: /StatemachineMM/StringType
391
- EReference parent,
392
- eType: |/StatemachineMM/CompositeState,
393
- END
394
- assert_completions context, [
395
- "/StatemachineMM/CompositeState",
396
- "/StatemachineMM/SimpleState",
397
- "/StatemachineMM/State",
398
- "/StatemachineMM/StringType",
399
- "/StatemachineMM/Transition",
400
- "/StatemachineMM2/SimpleState",
401
- "/StatemachineMM2/State"
402
- ]
403
- end
404
-
405
- def test_complete_command_after_linebreak
406
- setup_connector(ModelFile)
407
- load_model
408
- context = build_context <<-END
409
- EPackage StatemachineMM {
410
- EClass State, abstract: true {
411
- EAttribute name, eType: /StatemachineMM/StringType
412
- EReference parent,
413
- eType: /StatemachineMM/CompositeState,
414
- eOpposite: /StatemachineMM/CompositeState/substates
415
- }
416
- EClass SimpleState, eSuperTypes: [/StatemachineMM/State]
417
- EClass CompositeState,
418
- eSuperTypes: [
419
- /StatemachineMM/State
420
- ],
421
- abstract: false {
422
- |EReference substates, upperBound: -1, containment: true, eType: /StatemachineMM/State, eOpposite: /StatemachineMM/State/parent
423
- END
424
- assert_completions context, [
425
- "EAnnotation",
426
- "EAttribute",
427
- "EOperation",
428
- "EReference",
429
- "EStructuralFeature"
430
- ]
431
- end
432
-
433
- def test_complete_value_after_linebreak
434
- setup_connector(ModelFile)
435
- load_model
436
- context = build_context <<-END
437
- EPackage StatemachineMM {
438
- EClass State, abstract: true {
439
- EAttribute name, eType: /StatemachineMM/StringType
440
- EReference parent,
441
- eType: /StatemachineMM/CompositeState,
442
- eOpposite: /StatemachineMM/CompositeState/substates
443
- }
444
- EClass SimpleState, eSuperTypes: [/StatemachineMM/State]
445
- EClass CompositeState,
446
- eSuperTypes: [
447
- /StatemachineMM/State
448
- ],
449
- abstract: |false {
450
- END
451
- assert_completions context, [
452
- "true",
453
- "false"
454
- ]
455
- end
456
-
457
- def test_complete_in_array_after_linebreak
458
- setup_connector(ModelFile)
459
- load_model
460
- context = build_context <<-END
461
- EPackage StatemachineMM {
462
- EClass State, abstract: true {
463
- EAttribute name, eType: /StatemachineMM/StringType
464
- EReference parent,
465
- eType: /StatemachineMM/CompositeState,
466
- eOpposite: /StatemachineMM/CompositeState/substates
467
- }
468
- EClass SimpleState, eSuperTypes: [/StatemachineMM/State]
469
- EClass CompositeState,
470
- eSuperTypes: [
471
- |/StatemachineMM/State
472
- END
473
- assert_completions context, [
474
- "/StatemachineMM/CompositeState",
475
- "/StatemachineMM/SimpleState",
476
- "/StatemachineMM/State",
477
- "/StatemachineMM/Transition",
478
- "/StatemachineMM2/SimpleState",
479
- "/StatemachineMM2/State"
480
- ]
481
- end
482
-
483
- def test_complete_in_array_after_linebreak2
484
- setup_connector(ModelFile)
485
- load_model
486
- context = build_context <<-END
487
- EPackage StatemachineMM {
488
- EClass State, abstract: true {
489
- EAttribute name, eType: /StatemachineMM/StringType
490
- EReference parent,
491
- eType: /StatemachineMM/CompositeState,
492
- eOpposite: /StatemachineMM/CompositeState/substates
493
- }
494
- EClass SimpleState, eSuperTypes: [/StatemachineMM/State]
495
- EClass CompositeState,
496
- eSuperTypes: [
497
- /StatemachineMM/State
498
- |],
499
- END
500
- assert_completions context, [
501
- ]
502
- end
503
-
504
- def test_complete_after_backslash
505
- setup_connector(ModelFile3)
506
- load_model
507
- context = build_context <<-END
508
- EPackage StatemachineMM3 {
509
- EClass State
510
- EClass \\
511
- |SimpleState,
512
- END
513
- assert_completions context, [
514
- "name",
515
- "abstract:",
516
- "interface:",
517
- "eSuperTypes:",
518
- "instanceClassName:"
519
- ]
520
- end
521
-
522
- def test_complete_after_backslash2
523
- setup_connector(ModelFile3)
524
- load_model
525
- context = build_context <<-END
526
- EPackage StatemachineMM3 {
527
- EClass State
528
- EClass \\
529
- SimpleState,
530
- |eSuperTypes: [/StatemachineMM3/State]
531
- END
532
- assert_completions context, [
533
- "abstract:",
534
- "interface:",
535
- "eSuperTypes:",
536
- "instanceClassName:"
537
- ]
538
- end
539
-
540
- def test_link_target_after_backslash
541
- setup_connector(ModelFile3)
542
- load_model
543
- context = build_context <<-END
544
- EPackage StatemachineMM3 {
545
- EClass State
546
- EClass \\
547
- SimpleState,
548
- eSuperTypes: [/S|tatemachineMM3/State]
549
- END
550
- assert_link_targets context, :file => ModelFile3, :begin => 45, :end => 66, :targets => [
551
- {"file"=> File.expand_path(ModelFile3),
552
- "line"=>2,
553
- "display"=>"/StatemachineMM3/State [EClass]"}
554
- ]
555
- end
556
-
557
- def test_reference_completion
558
- setup_connector(ModelFile)
559
- load_model
560
- context = build_context <<-END
561
- EPackage StatemachineMM {
562
- EClass State, abstract: true {
563
- EAttribute name, eType: |/StatemachineMM/StringType
564
- END
565
- assert_completions context, [
566
- "/StatemachineMM/CompositeState",
567
- "/StatemachineMM/SimpleState",
568
- "/StatemachineMM/State",
569
- "/StatemachineMM/StringType",
570
- "/StatemachineMM/Transition",
571
- "/StatemachineMM2/SimpleState",
572
- "/StatemachineMM2/State",
573
- ]
574
- context = build_context <<-END
575
- EPackage StatemachineMM {
576
- EClass State, abstract: true {
577
- EAttribute name, eType: /StatemachineMM/|StringType
578
- END
579
- assert_completions context, [
580
- "/StatemachineMM/CompositeState",
581
- "/StatemachineMM/SimpleState",
582
- "/StatemachineMM/State",
583
- "/StatemachineMM/StringType",
584
- "/StatemachineMM/Transition",
585
- "/StatemachineMM2/SimpleState",
586
- "/StatemachineMM2/State",
587
- ]
588
- context = build_context <<-END
589
- EPackage StatemachineMM {
590
- EClass State, abstract: true {
591
- EAttribute name, eType: /StatemachineMM/St|ringType
592
- END
593
- assert_completions context, [
594
- "/StatemachineMM/CompositeState",
595
- "/StatemachineMM/SimpleState",
596
- "/StatemachineMM/State",
597
- "/StatemachineMM/StringType",
598
- "/StatemachineMM/Transition",
599
- "/StatemachineMM2/SimpleState",
600
- "/StatemachineMM2/State",
601
- ]
602
- context = build_context <<-END
603
- EPackage StatemachineMM {
604
- EClass State, abstract: true {
605
- EAttribute name, eType: /StatemachineMM/StringType|
606
- END
607
- assert_completions context, [
608
- "/StatemachineMM/CompositeState",
609
- "/StatemachineMM/SimpleState",
610
- "/StatemachineMM/State",
611
- "/StatemachineMM/StringType",
612
- "/StatemachineMM/Transition",
613
- "/StatemachineMM2/SimpleState",
614
- "/StatemachineMM2/State",
615
- ]
616
- end
617
-
618
- def test_reference_completion_in_array
619
- setup_connector(ModelFile)
620
- load_model
621
- context = build_context <<-END
622
- EPackage StatemachineMM {
623
- EClass State, abstract: true {
624
- EAttribute name, eType: /StatemachineMM/StringType
625
- EReference parent,
626
- eType: /StatemachineMM/CompositeState,
627
- eOpposite: /StatemachineMM/CompositeState/substates
628
- }
629
- EClass SimpleState, eSuperTypes: [|/StatemachineMM/State]
630
- END
631
- assert_completions context, [
632
- "/StatemachineMM/CompositeState",
633
- "/StatemachineMM/SimpleState",
634
- "/StatemachineMM/State",
635
- "/StatemachineMM/Transition",
636
- "/StatemachineMM2/SimpleState",
637
- "/StatemachineMM2/State",
638
- ]
639
- context = build_context <<-END
640
- EPackage StatemachineMM {
641
- EClass State, abstract: true {
642
- EAttribute name, eType: /StatemachineMM/StringType
643
- EReference parent,
644
- eType: /StatemachineMM/CompositeState,
645
- eOpposite: /StatemachineMM/CompositeState/substates
646
- }
647
- EClass SimpleState, eSuperTypes: [/StatemachineMM/S|tate]
648
- END
649
- assert_completions context, [
650
- "/StatemachineMM/CompositeState",
651
- "/StatemachineMM/SimpleState",
652
- "/StatemachineMM/State",
653
- "/StatemachineMM/Transition",
654
- "/StatemachineMM2/SimpleState",
655
- "/StatemachineMM2/State",
656
- ]
657
- context = build_context <<-END
658
- EPackage StatemachineMM {
659
- EClass State, abstract: true {
660
- EAttribute name, eType: /StatemachineMM/StringType
661
- EReference parent,
662
- eType: /StatemachineMM/CompositeState,
663
- eOpposite: /StatemachineMM/CompositeState/substates
664
- }
665
- EClass SimpleState, eSuperTypes: [/StatemachineMM/State|]
666
- END
667
- assert_completions context, [
668
- "/StatemachineMM/CompositeState",
669
- "/StatemachineMM/SimpleState",
670
- "/StatemachineMM/State",
671
- "/StatemachineMM/Transition",
672
- "/StatemachineMM2/SimpleState",
673
- "/StatemachineMM2/State",
674
- ]
675
- context = build_context <<-END
676
- EPackage StatemachineMM {
677
- EClass State, abstract: true {
678
- EAttribute name, eType: /StatemachineMM/StringType
679
- EReference parent,
680
- eType: /StatemachineMM/CompositeState,
681
- eOpposite: /StatemachineMM/CompositeState/substates
682
- }
683
- EClass SimpleState, eSuperTypes: [/StatemachineMM/State]|
684
- END
685
- assert_completions context, [
686
- ]
687
- end
688
-
689
- def test_integer_completion
690
- setup_connector(ModelFile)
691
- load_model
692
- context = build_context <<-END
693
- EPackage StatemachineMM {
694
- EClass State, abstract: true {
695
- EAttribute name, eType: /StatemachineMM/StringType
696
- EReference parent,
697
- eType: /StatemachineMM/CompositeState,
698
- eOpposite: /StatemachineMM/CompositeState/substates
699
- }
700
- EClass SimpleState, eSuperTypes: [/StatemachineMM/State]
701
- EClass CompositeState,
702
- eSuperTypes: [
703
- /StatemachineMM/State
704
- ],
705
- abstract: false {
706
- EReference substates, upperBound: |-1, containment: true, eType: /StatemachineMM/State, eOpposite: /StatemachineMM/State/parent
707
- END
708
- assert_completions context, [
709
- "1",
710
- ]
711
- context = build_context <<-END
712
- EPackage StatemachineMM {
713
- EClass State, abstract: true {
714
- EAttribute name, eType: /StatemachineMM/StringType
715
- EReference parent,
716
- eType: /StatemachineMM/CompositeState,
717
- eOpposite: /StatemachineMM/CompositeState/substates
718
- }
719
- EClass SimpleState, eSuperTypes: [/StatemachineMM/State]
720
- EClass CompositeState,
721
- eSuperTypes: [
722
- /StatemachineMM/State
723
- ],
724
- abstract: false {
725
- EReference substates, upperBound: -1|, containment: true, eType: /StatemachineMM/State, eOpposite: /StatemachineMM/State/parent
726
- END
727
- assert_completions context, [
728
- "1",
729
- ]
730
- end
731
-
732
- def test_link_targets
733
- setup_connector(ModelFile)
734
- load_model
735
- context = build_context <<-END
736
- EPackage StatemachineMM {
737
- EClass State, abstract: true {
738
- EAttribute name, eType: /St|atemachineMM/StringType
739
- END
740
- assert_link_targets context, :begin => 29, :end => 54, :targets => [
741
- {"file"=> File.expand_path(@infile),
742
- "line"=>20,
743
- "display"=>"/StatemachineMM/StringType [EDataType]"}
744
- ]
745
- context = build_context <<-END
746
- EPackage StatemachineMM {
747
- EClass State, abstract: true {
748
- EAttribute name, eType: |/StatemachineMM/StringType
749
- END
750
- assert_link_targets context, :begin => 29, :end => 54, :targets => [
751
- {"file"=> File.expand_path(@infile),
752
- "line"=>20,
753
- "display"=>"/StatemachineMM/StringType [EDataType]"}
754
- ]
755
- context = build_context <<-END
756
- EPackage StatemachineMM {
757
- EClass State, abstract: true {
758
- EAttribute name, eType: /StatemachineMM/StringTyp|e
759
- END
760
- assert_link_targets context, :begin => 29, :end => 54, :targets => [
761
- {"file"=> File.expand_path(@infile),
762
- "line"=>20,
763
- "display"=>"/StatemachineMM/StringType [EDataType]"}
764
- ]
765
- context = build_context <<-END
766
- EPackage StatemachineMM {
767
- EClass State, abstract: true {
768
- EAttribute name, eType: /StatemachineMM/StringType|
769
- END
770
- assert_link_targets context, :begin => nil, :end => nil, :targets => []
771
- context = build_context <<-END
772
- EPackage StatemachineMM {
773
- EClass State, abstract: true {
774
- EAttribute name, eType:| /StatemachineMM/StringType
775
- END
776
- assert_link_targets context, :begin => nil, :end => nil, :targets => []
777
- # backward ref
778
- context = build_context <<-END
779
- EPackage StatemachineMM {
780
- E|Class State, abstract: true {
781
- END
782
- assert_link_targets context, :begin => 3, :end => 8, :targets => [
783
- {"file"=> File.expand_path(@infile),
784
- "line"=>8,
785
- "display"=>"/StatemachineMM/SimpleState [EClass]"},
786
- {"file"=> File.expand_path(@infile),
787
- "line"=>9,
788
- "display"=>"/StatemachineMM/CompositeState [EClass]"}
789
- ]
790
- context = build_context <<-END
791
- EPackage StatemachineMM {
792
- EClass State, abstract: true {
793
- EAttribute name, eType: /StatemachineMM/StringType
794
- EReference parent,
795
- eType: /StatemachineMM/CompositeState,
796
- eOpposite: /StatemachineMM/CompositeState/substates
797
- }
798
- |EClass SimpleState, eSuperTypes: [/StatemachineMM/State]
799
- END
800
- assert_link_targets context, :begin => 3, :end => 8, :targets => []
801
- # bad location
802
- context = build_context <<-END
803
- EPackage S|tatemachineMM {
804
- END
805
- assert_link_targets context, :begin => 10, :end => 23, :targets => []
806
- end
807
-
808
- def test_link_targets_no_text_after_name
809
- setup_connector(ModelFile)
810
- load_model
811
- context = build_context({:infile => ModelFile2}, <<-END
812
- EPackage StatemachineMM2 {
813
- ECl|ass State
814
- END
815
- )
816
- assert_link_targets context, :file => ModelFile2, :begin => 3, :end => 8, :targets => [
817
- {"file"=> File.expand_path(ModelFile2),
818
- "line"=>3,
819
- "display"=>"/StatemachineMM2/SimpleState [EClass]"}
820
- ]
821
- end
822
-
823
- def test_link_targets_after_linebreak
824
- setup_connector(ModelFile)
825
- load_model
826
- context = build_context <<-END
827
- EPackage StatemachineMM {
828
- EClass State, abstract: true {
829
- EAttribute name, eType: /StatemachineMM/StringType
830
- EReference parent,
831
- eType: /St|atemachineMM/CompositeState,
832
- END
833
- # in case of linebreaks, the begin and end column refer to the string which
834
- # was passed to the backend as the context; in this case the context extractor
835
- # appends each broken line to the previous line with all the leading whitespace removed
836
- assert_link_targets context, :begin => 37, :end => 66, :targets => [
837
- {"file"=> File.expand_path(@infile),
838
- "line"=>9,
839
- "display"=>"/StatemachineMM/CompositeState [EClass]"}
840
- ]
841
- context = build_context <<-END
842
- EPackage StatemachineMM {
843
- EClass State, abstract: true {
844
- EAttribute name, eType: /StatemachineMM/StringType
845
- EReference parent,
846
- eType: |/StatemachineMM/CompositeState,
847
- END
848
- assert_link_targets context, :begin => 37, :end => 66, :targets => [
849
- {"file"=> File.expand_path(@infile),
850
- "line"=>9,
851
- "display"=>"/StatemachineMM/CompositeState [EClass]"}
852
- ]
853
- context = build_context <<-END
854
- EPackage StatemachineMM {
855
- EClass State, abstract: true {
856
- EAttribute name, eType: /StatemachineMM/StringType
857
- EReference parent,
858
- eType: /StatemachineMM/CompositeStat|e,
859
- END
860
- assert_link_targets context, :begin => 37, :end => 66, :targets => [
861
- {"file"=> File.expand_path(@infile),
862
- "line"=>9,
863
- "display"=>"/StatemachineMM/CompositeState [EClass]"}
864
- ]
865
- context = build_context <<-END
866
- EPackage StatemachineMM {
867
- EClass State, abstract: true {
868
- EAttribute name, eType: /StatemachineMM/StringType
869
- EReference parent,
870
- eType: /StatemachineMM/CompositeState|,
871
- END
872
- assert_link_targets context, :begin => nil, :end => nil, :targets => []
873
- end
874
-
875
- def test_find_elements
876
- setup_connector(ModelFile)
877
- load_model
878
- response = @con.execute_command(
879
- {"command" => "find_elements", "search_pattern" => "Sta"})
880
- assert_equal \
881
- [{"display"=>"State [EClass] - /StatemachineMM",
882
- "file"=> File.expand_path(@infile),
883
- "line"=>2},
884
- {"display"=>"State [EClass] - /StatemachineMM2",
885
- "file"=> File.expand_path(ModelFile2),
886
- "line"=>2},
887
- {"display"=>"StatemachineMM [EPackage] - /StatemachineMM",
888
- "file"=> File.expand_path(@infile),
889
- "line"=>1},
890
- {"display"=>"StatemachineMM2 [EPackage] - /StatemachineMM2",
891
- "file"=> File.expand_path(ModelFile2),
892
- "line"=>1}], response["elements"]
893
- response = @con.execute_command(
894
- {"command" => "find_elements", "search_pattern" => "target"})
895
- assert_equal \
896
- [{"display"=>"target [EReference] - /StatemachineMM/Transition",
897
- "file"=> File.expand_path(@infile),
898
- "line"=>17}], response["elements"]
899
- response = @con.execute_command(
900
- {"command" => "find_elements", "search_pattern" => ""})
901
- assert_equal [], response["elements"]
902
- response = @con.execute_command(
903
- {"command" => "find_elements", "search_pattern" => "xxx"})
904
- assert_equal [], response["elements"]
905
- end
906
-
907
- TestContext = Struct.new(:line, :col)
908
-
909
- def build_context(text, text2=nil)
910
- if text.is_a?(Hash)
911
- context_lines = text2.split("\n")
912
- pos_in_line = text[:col] || context_lines.last.index("|") + 1
913
- infile = text[:infile] || @infile
914
- else
915
- context_lines = text.split("\n")
916
- pos_in_line = context_lines.last.index("|") + 1
917
- infile = @infile
918
- end
919
- context_lines.last.sub!("|", "")
920
-
921
- # check that the context data actally matches the real file in the filesystem
922
- content = File.open(infile, "rb"){|f| f.read}
923
- ref_lines = content.split(/\r?\n/)[0..context_lines.size-1]
924
- raise "inconsistent test data, expected\n:#{ref_lines.join("\n")}\ngot:\n#{context_lines.join("\n")}\n" \
925
- unless ref_lines == context_lines
926
-
927
- # column numbers start at 1
928
- TestContext.new(context_lines.size, pos_in_line)
929
- end
930
-
931
- def assert_link_targets(context, options)
932
- infile = options[:file] || @infile
933
- content = File.open(infile, "rb") {|f| f.read}
934
- lines = content.split(/\r?\n/)[0..context.line-1]
935
- lines, col = RText::Frontend::Context.new.extract(lines, context.col)
936
- response = @con.execute_command(
937
- {"command" => "link_targets", "context" => lines, "column" => col})
938
- assert_equal "response", response["type"]
939
- assert_equal options[:targets], response["targets"]
940
- assert_equal options[:begin], response["begin_column"]
941
- assert_equal options[:end], response["end_column"]
942
- end
943
-
944
- def assert_completions(context, expected)
945
- content = File.open(@infile, "rb"){|f| f.read}
946
- lines = content.split(/\r?\n/)[0..context.line-1]
947
- lines, col = RText::Frontend::Context.new.extract(lines, context.col)
948
- response = @con.execute_command(
949
- {"command" => "content_complete", "context" => lines, "column" => col})
950
- assert_equal expected, response["options"].collect{|o| o["insert"]}
951
- end
952
-
953
- def load_model
954
- done = false
955
- response = nil
956
- while !done
957
- response = @con.execute_command({"command" => "load_model"})
958
- if response == :connecting && !@connection_timeout
959
- sleep(0.1)
960
- @con.resume
961
- else
962
- done = true
963
- end
964
- end
965
- response
966
- end
967
-
968
- end