rtext 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/CHANGELOG +20 -0
  2. data/{README → README.rdoc} +5 -1
  3. data/RText_Protocol +444 -0
  4. data/Rakefile +10 -10
  5. data/lib/rtext/completer.rb +32 -26
  6. data/lib/rtext/context_builder.rb +113 -59
  7. data/lib/rtext/default_loader.rb +73 -8
  8. data/lib/rtext/default_service_provider.rb +30 -14
  9. data/lib/rtext/frontend/config.rb +58 -0
  10. data/lib/rtext/frontend/connector.rb +233 -0
  11. data/lib/rtext/frontend/connector_manager.rb +81 -0
  12. data/lib/rtext/frontend/context.rb +56 -0
  13. data/lib/rtext/generic.rb +13 -0
  14. data/lib/rtext/instantiator.rb +30 -7
  15. data/lib/rtext/language.rb +54 -27
  16. data/lib/rtext/link_detector.rb +57 -0
  17. data/lib/rtext/message_helper.rb +77 -0
  18. data/lib/rtext/parser.rb +19 -68
  19. data/lib/rtext/serializer.rb +18 -3
  20. data/lib/rtext/service.rb +182 -118
  21. data/lib/rtext/tokenizer.rb +102 -0
  22. data/test/completer_test.rb +327 -70
  23. data/test/context_builder_test.rb +671 -91
  24. data/test/instantiator_test.rb +153 -0
  25. data/test/integration/backend.out +10 -0
  26. data/test/integration/crash_on_request_editor.rb +12 -0
  27. data/test/integration/ecore_editor.rb +50 -0
  28. data/test/integration/frontend.log +25138 -0
  29. data/test/integration/model/invalid_encoding.invenc +2 -0
  30. data/test/integration/model/test.crash_on_request +18 -0
  31. data/test/integration/model/test.crashing_backend +18 -0
  32. data/test/integration/model/test.dont_open_socket +0 -0
  33. data/test/integration/model/test.invalid_cmd_line +0 -0
  34. data/test/integration/model/test.not_in_rtext +0 -0
  35. data/test/integration/model/test_large_with_errors.ect3 +43523 -0
  36. data/test/integration/model/test_metamodel.ect +18 -0
  37. data/test/integration/model/test_metamodel2.ect +5 -0
  38. data/test/integration/model/test_metamodel_error.ect2 +3 -0
  39. data/test/integration/model/test_metamodel_ok.ect2 +18 -0
  40. data/test/integration/test.rb +684 -0
  41. data/test/link_detector_test.rb +276 -0
  42. data/test/message_helper_test.rb +118 -0
  43. data/test/rtext_test.rb +4 -1
  44. data/test/serializer_test.rb +96 -1
  45. data/test/tokenizer_test.rb +125 -0
  46. metadata +36 -10
  47. data/RText_Plugin_Implementation_Guide +0 -268
  48. data/lib/rtext_plugin/connection_manager.rb +0 -59
@@ -11,37 +11,430 @@ module TestMM
11
11
  extend RGen::MetamodelBuilder::ModuleExtension
12
12
  class TestNode < RGen::MetamodelBuilder::MMBase
13
13
  has_attr 'text', String
14
+ has_attr 'unlabled', String
15
+ has_many_attr 'unlabled_array', String
14
16
  has_many_attr 'nums', Integer
17
+ has_many_attr 'strings', String
18
+ has_attr 'boolean', Boolean
15
19
  has_one 'related', TestNode
16
20
  has_many 'others', TestNode
17
21
  contains_many 'childs', TestNode, 'parent'
18
22
  end
19
23
  end
20
24
 
25
+ def test_root
26
+ c = build_context TestMM, <<-END
27
+ |
28
+ END
29
+ assert_context c, :prefix => "", :feature => nil, :in_array => false, :in_block => false
30
+ assert_nil(c.element)
31
+ end
32
+
33
+ def test_root2
34
+ c = build_context TestMM, <<-END
35
+ |TestNode
36
+ END
37
+ assert_context c, :prefix => "", :feature => nil, :in_array => false, :in_block => false
38
+ assert_nil(c.element)
39
+ end
40
+
41
+ def test_root_in_cmd
42
+ c = build_context TestMM, <<-END
43
+ Test|Node
44
+ END
45
+ assert_context c, :prefix => "Test", :feature => nil, :in_array => false, :in_block => false
46
+ assert_nil(c.element)
47
+ end
48
+
49
+ def test_root_after_cmd
50
+ c = build_context TestMM, <<-END
51
+ TestNode|
52
+ END
53
+ assert_context c, :prefix => "TestNode", :feature => nil, :in_array => false, :in_block => false
54
+ assert_nil(c.element)
55
+ end
56
+
57
+ def test_root_after_cmd2
58
+ c = build_context TestMM, <<-END
59
+ TestNode |
60
+ END
61
+ assert_context c, :prefix => "", :feature => "unlabled", :in_array => false, :in_block => false
62
+ assert(c.element.is_a?(TestMM::TestNode))
63
+ end
64
+
65
+ def test_root_in_lable
66
+ c = build_context TestMM, <<-END
67
+ TestNode ot|hers:
68
+ END
69
+ assert_context c, :prefix => "ot", :feature => "unlabled", :in_array => false, :in_block => false
70
+ assert(c.element.is_a?(TestMM::TestNode))
71
+ end
72
+
73
+ def test_root_after_lable
74
+ c = build_context TestMM, <<-END
75
+ TestNode others:|
76
+ END
77
+ assert_context c, :prefix => "", :feature => "others", :in_array => false, :in_block => false, :after_label => true
78
+ assert(c.element.is_a?(TestMM::TestNode))
79
+ end
80
+
81
+ def test_root_after_lable2
82
+ c = build_context TestMM, <<-END
83
+ TestNode others: |
84
+ END
85
+ assert_context c, :prefix => "", :feature => "others", :in_array => false, :in_block => false, :after_label => true
86
+ assert(c.element.is_a?(TestMM::TestNode))
87
+ end
88
+
89
+ def test_root_after_lable_with_value
90
+ c = build_context TestMM, <<-END
91
+ TestNode text: xx, others: |
92
+ END
93
+ assert_context c, :prefix => "", :feature => "others", :in_array => false, :in_block => false, :after_label => true
94
+ assert(c.element.is_a?(TestMM::TestNode))
95
+ assert_equal("xx", c.element.text)
96
+ end
97
+
98
+ def test_root_after_lable_with_value_missing_comma
99
+ c = build_context TestMM, <<-END
100
+ TestNode text: xx others: |
101
+ END
102
+ assert_context c, :prefix => "", :feature => "others", :in_array => false, :in_block => false, :after_label => true
103
+ assert(c.element.is_a?(TestMM::TestNode))
104
+ assert_equal("xx", c.element.text)
105
+ end
106
+
107
+ def test_root_after_unlabled
108
+ c = build_context TestMM, <<-END
109
+ TestNode "bla"|
110
+ END
111
+ assert_context c, :prefix => "bla", :feature => "unlabled", :in_array => false, :in_block => false
112
+ assert(c.element.is_a?(TestMM::TestNode))
113
+ assert_nil(c.element.unlabled)
114
+ end
115
+
116
+ def test_root_after_unlabled_string_with_comma
117
+ c = build_context TestMM, <<-END
118
+ TestNode "a,b"|
119
+ END
120
+ assert_context c, :prefix => "a,b", :feature => "unlabled", :in_array => false, :in_block => false
121
+ assert(c.element.is_a?(TestMM::TestNode))
122
+ assert_nil(c.element.unlabled)
123
+ end
124
+
125
+ def test_root_after_unlabled_string_with_quoted_quote
126
+ c = build_context TestMM, <<-END
127
+ TestNode "a,\\"b"|
128
+ END
129
+ assert_context c, :prefix => "a,\"b", :feature => "unlabled", :in_array => false, :in_block => false
130
+ assert(c.element.is_a?(TestMM::TestNode))
131
+ assert_nil(c.element.unlabled)
132
+ end
133
+
134
+ def test_root_after_unlabled_unclosed_string_with_comma
135
+ c = build_context TestMM, <<-END
136
+ TestNode "a,b|
137
+ END
138
+ assert_context c, :prefix => "\"a,b", :feature => "unlabled", :in_array => false, :in_block => false
139
+ assert(c.element.is_a?(TestMM::TestNode))
140
+ assert_nil(c.element.unlabled)
141
+ end
142
+
143
+ def test_root_after_unlabled_no_quot
144
+ c = build_context TestMM, <<-END
145
+ TestNode bla|
146
+ END
147
+ assert_context c, :prefix => "bla", :feature => "unlabled", :in_array => false, :in_block => false
148
+ assert(c.element.is_a?(TestMM::TestNode))
149
+ assert_nil(c.element.unlabled)
150
+ end
151
+
152
+ def test_root_after_unlabled2
153
+ c = build_context TestMM, <<-END
154
+ TestNode "bla" |
155
+ END
156
+ assert_context c, :prefix => "", :feature => nil, :in_array => false, :in_block => false, :problem => :missing_comma
157
+ assert(c.element.is_a?(TestMM::TestNode))
158
+ assert_equal("bla", c.element.unlabled)
159
+ end
160
+
161
+ def test_root_after_unlabled2_no_quot
162
+ c = build_context TestMM, <<-END
163
+ TestNode bla |
164
+ END
165
+ assert_context c, :prefix => "", :feature => nil, :in_array => false, :in_block => false, :problem => :missing_comma
166
+ assert(c.element.is_a?(TestMM::TestNode))
167
+ assert_equal("bla", c.element.unlabled)
168
+ end
169
+
170
+ def test_root_after_unlabled_comma_no_quot
171
+ c = build_context TestMM, <<-END
172
+ TestNode bla,|
173
+ END
174
+ assert_context c, :prefix => "", :feature => "unlabled_array", :in_array => false, :in_block => false
175
+ assert(c.element.is_a?(TestMM::TestNode))
176
+ assert_equal("bla", c.element.unlabled)
177
+ end
178
+
179
+ def test_root_after_unlabled_comma
180
+ c = build_context TestMM, <<-END
181
+ TestNode "bla", |
182
+ END
183
+ assert_context c, :prefix => "", :feature => "unlabled_array", :in_array => false, :in_block => false
184
+ assert(c.element.is_a?(TestMM::TestNode))
185
+ assert_equal("bla", c.element.unlabled)
186
+ end
187
+
188
+ def test_root_after_unlabled_comma_no_ws
189
+ c = build_context TestMM, <<-END
190
+ TestNode "bla",|
191
+ END
192
+ assert_context c, :prefix => "", :feature => "unlabled_array", :in_array => false, :in_block => false
193
+ assert(c.element.is_a?(TestMM::TestNode))
194
+ assert_equal("bla", c.element.unlabled)
195
+ end
196
+
197
+ def test_root_unlabled_array
198
+ c = build_context TestMM, <<-END
199
+ TestNode "bla", [|
200
+ END
201
+ assert_context c, :prefix => "", :feature => "unlabled_array", :in_array => true, :in_block => false
202
+ assert(c.element.is_a?(TestMM::TestNode))
203
+ assert_equal("bla", c.element.unlabled)
204
+ assert_equal([], c.element.unlabled_array)
205
+ end
206
+
207
+ def test_root_unlabled_array_first_value
208
+ c = build_context TestMM, <<-END
209
+ TestNode "bla", [a|
210
+ END
211
+ assert_context c, :prefix => "a", :feature => "unlabled_array", :in_array => true, :in_block => false
212
+ assert(c.element.is_a?(TestMM::TestNode))
213
+ assert_equal("bla", c.element.unlabled)
214
+ assert_equal([], c.element.unlabled_array)
215
+ end
216
+
217
+ def test_root_unlabled_array_first_value_quoted
218
+ c = build_context TestMM, <<-END
219
+ TestNode "bla", ["a"|
220
+ END
221
+ assert_context c, :prefix => "a", :feature => "unlabled_array", :in_array => true, :in_block => false
222
+ assert(c.element.is_a?(TestMM::TestNode))
223
+ assert_equal("bla", c.element.unlabled)
224
+ assert_equal([], c.element.unlabled_array)
225
+ end
226
+
227
+ def test_root_unlabled_array_first_value_quoted_open
228
+ c = build_context TestMM, <<-END
229
+ TestNode "bla", ["a|
230
+ END
231
+ assert_context c, :prefix => "\"a", :feature => "unlabled_array", :in_array => true, :in_block => false
232
+ assert(c.element.is_a?(TestMM::TestNode))
233
+ assert_equal("bla", c.element.unlabled)
234
+ assert_equal([], c.element.unlabled_array)
235
+ end
236
+
237
+ def test_root_unlabled_array_first_value_after_space
238
+ c = build_context TestMM, <<-END
239
+ TestNode "bla", ["a" |
240
+ END
241
+ # although not having a comma in front is an error, we are already within a feature
242
+ # due to the opening square bracket
243
+ assert_context c, :prefix => "", :feature => "unlabled_array", :in_array => true, :in_block => false, :problem => :missing_comma
244
+ assert(c.element.is_a?(TestMM::TestNode))
245
+ assert_equal("bla", c.element.unlabled)
246
+ assert_equal(["a"], c.element.unlabled_array)
247
+ end
248
+
249
+ def test_root_unlabled_array_first_value_after_comma
250
+ c = build_context TestMM, <<-END
251
+ TestNode "bla", ["a",|
252
+ END
253
+ assert_context c, :prefix => "", :feature => "unlabled_array", :in_array => true, :in_block => false
254
+ assert(c.element.is_a?(TestMM::TestNode))
255
+ assert_equal("bla", c.element.unlabled)
256
+ assert_equal(["a"], c.element.unlabled_array)
257
+ end
258
+
259
+ def test_root_unlabled_array_second_value
260
+ c = build_context TestMM, <<-END
261
+ TestNode "bla", ["a", b|
262
+ END
263
+ assert_context c, :prefix => "b", :feature => "unlabled_array", :in_array => true, :in_block => false
264
+ assert(c.element.is_a?(TestMM::TestNode))
265
+ assert_equal("bla", c.element.unlabled)
266
+ assert_equal(["a"], c.element.unlabled_array)
267
+ end
268
+
269
+ def test_root_unlabled_array_second_value_quoted
270
+ c = build_context TestMM, <<-END
271
+ TestNode "bla", ["a", "b"|
272
+ END
273
+ assert_context c, :prefix => "b", :feature => "unlabled_array", :in_array => true, :in_block => false
274
+ assert(c.element.is_a?(TestMM::TestNode))
275
+ assert_equal("bla", c.element.unlabled)
276
+ assert_equal(["a"], c.element.unlabled_array)
277
+ end
278
+
279
+ def test_root_unlabled_array_second_value_quoted_open
280
+ c = build_context TestMM, <<-END
281
+ TestNode "bla", ["a", "b|
282
+ END
283
+ assert_context c, :prefix => "\"b", :feature => "unlabled_array", :in_array => true, :in_block => false
284
+ assert(c.element.is_a?(TestMM::TestNode))
285
+ assert_equal("bla", c.element.unlabled)
286
+ assert_equal(["a"], c.element.unlabled_array)
287
+ end
288
+
289
+ def test_root_unlabled_array_second_value_after_comma
290
+ c = build_context TestMM, <<-END
291
+ TestNode "bla", ["a", b,|
292
+ END
293
+ assert_context c, :prefix => "", :feature => "unlabled_array", :in_array => true, :in_block => false
294
+ assert(c.element.is_a?(TestMM::TestNode))
295
+ assert_equal("bla", c.element.unlabled)
296
+ assert_equal(["a", "b"], c.element.unlabled_array)
297
+ end
298
+
299
+ def test_root_unlabled_array_after_array
300
+ c = build_context TestMM, <<-END
301
+ TestNode "bla", ["a", b]|
302
+ END
303
+ assert_context c, :prefix => "", :feature => nil, :in_array => false, :in_block => false, :problem => :missing_comma
304
+ assert(c.element.is_a?(TestMM::TestNode))
305
+ assert_equal("bla", c.element.unlabled)
306
+ assert_equal(["a", "b"], c.element.unlabled_array)
307
+ end
308
+
309
+ def test_root_unlabled_array_after_array2
310
+ c = build_context TestMM, <<-END
311
+ TestNode "bla", ["a", b] |
312
+ END
313
+ assert_context c, :prefix => "", :feature => nil, :in_array => false, :in_block => false, :problem => :missing_comma
314
+ assert(c.element.is_a?(TestMM::TestNode))
315
+ assert_equal("bla", c.element.unlabled)
316
+ assert_equal(["a", "b"], c.element.unlabled_array)
317
+ end
318
+
319
+ def test_root_unlabled_array_after_array3
320
+ c = build_context TestMM, <<-END
321
+ TestNode "bla", ["a", b],|
322
+ END
323
+ assert_context c, :prefix => "", :feature => nil, :in_array => false, :in_block => false
324
+ assert(c.element.is_a?(TestMM::TestNode))
325
+ assert_equal("bla", c.element.unlabled)
326
+ assert_equal(["a", "b"], c.element.unlabled_array)
327
+ end
328
+
329
+ def test_root_labled_string_value
330
+ c = build_context TestMM, <<-END
331
+ TestNode text: "a,b"|
332
+ END
333
+ assert_context c, :prefix => "a,b", :feature => "text", :in_array => false, :in_block => false, :after_label => true
334
+ assert(c.element.is_a?(TestMM::TestNode))
335
+ assert_nil(c.element.text)
336
+ end
337
+
338
+ def test_root_labled_string_value2
339
+ c = build_context TestMM, <<-END
340
+ TestNode text: "a,b" |
341
+ END
342
+ assert_context c, :prefix => "", :feature => nil, :in_array => false, :in_block => false, :problem => :missing_comma
343
+ assert(c.element.is_a?(TestMM::TestNode))
344
+ assert_equal("a,b", c.element.text)
345
+ end
346
+
347
+ def test_root_labled_string_value3
348
+ c = build_context TestMM, <<-END
349
+ TestNode text: "a,b",|
350
+ END
351
+ assert_context c, :prefix => "", :feature => nil, :in_array => false, :in_block => false
352
+ assert(c.element.is_a?(TestMM::TestNode))
353
+ assert_equal("a,b", c.element.text)
354
+ end
355
+
356
+ def test_root_labled_string_value_within
357
+ c = build_context TestMM, <<-END
358
+ TestNode text: "a,b|
359
+ END
360
+ assert_context c, :prefix => "\"a,b", :feature => "text", :in_array => false, :in_block => false, :after_label => true
361
+ assert(c.element.is_a?(TestMM::TestNode))
362
+ assert_nil(c.element.text)
363
+ end
364
+
365
+ def test_root_labled_string_value_within_no_ws
366
+ c = build_context TestMM, <<-END
367
+ TestNode text:"a,b|
368
+ END
369
+ assert_context c, :prefix => "\"a,b", :feature => "text", :in_array => false, :in_block => false, :after_label => true
370
+ assert(c.element.is_a?(TestMM::TestNode))
371
+ assert_nil(c.element.text)
372
+ end
373
+
374
+ def test_root_labled_string_value_no_quot
375
+ c = build_context TestMM, <<-END
376
+ TestNode text: t|
377
+ END
378
+ assert_context c, :prefix => "t", :feature => "text", :in_array => false, :in_block => false, :after_label => true
379
+ assert(c.element.is_a?(TestMM::TestNode))
380
+ assert_nil(c.element.text)
381
+ end
382
+
383
+ def test_root_labled_bool_value
384
+ c = build_context TestMM, <<-END
385
+ TestNode boolean: t|
386
+ END
387
+ assert_context c, :prefix => "t", :feature => "boolean", :in_array => false, :in_block => false, :after_label => true
388
+ assert(c.element.is_a?(TestMM::TestNode))
389
+ assert_nil(c.element.text)
390
+ end
391
+
392
+ def test_root_after_curly
393
+ c = build_context TestMM, <<-END
394
+ TestNode {|
395
+ END
396
+ assert_context c, :prefix => "", :feature => nil, :in_array => false, :in_block => false, :problem => :after_curly
397
+ assert(c.element.is_a?(TestMM::TestNode))
398
+ end
399
+
21
400
  def test_in_cmd_after_cmd
22
401
  c = build_context TestMM, <<-END
23
402
  TestNode text: a {
24
403
  TestNode nums: 3 {
25
404
  TestNode |others: /dummy {
26
405
  END
27
- assert_equal("", c.prefix)
28
- assert_nil(c.feature)
29
- assert(!c.in_array)
30
- assert(!c.in_block)
406
+ assert_context c, :prefix => "", :feature => "unlabled", :in_array => false, :in_block => false
31
407
  assert_simple_model(c.element)
32
408
  assert_other_values(c.element, [])
33
409
  end
34
410
 
411
+ def test_in_cmd_after_cmd2
412
+ c = build_context TestMM, <<-END
413
+ TestNode text: a {
414
+ TestNode| nums: 3 {
415
+ END
416
+ assert_context c, :prefix => "TestNode", :feature => nil, :in_array => false, :in_block => true
417
+ assert(c.element.is_a?(TestMM::TestNode))
418
+ end
419
+
35
420
  def test_in_cmd_in_label
36
421
  c = build_context TestMM, <<-END
37
422
  TestNode text: a {
38
423
  TestNode nums: 3 {
39
424
  TestNode ot|hers: /dummy {
40
425
  END
41
- assert_equal("ot", c.prefix)
42
- assert_nil(c.feature)
43
- assert(!c.in_array)
44
- assert(!c.in_block)
426
+ assert_context c, :prefix => "ot", :feature => "unlabled", :in_array => false, :in_block => false
427
+ assert_simple_model(c.element)
428
+ assert_other_values(c.element, [])
429
+ end
430
+
431
+ def test_in_cmd_after_label
432
+ c = build_context TestMM, <<-END
433
+ TestNode text: a {
434
+ TestNode nums: 3 {
435
+ TestNode others: |/dummy {
436
+ END
437
+ assert_context c, :prefix => "", :feature => "others", :in_array => false, :in_block => false, :after_label => true
45
438
  assert_simple_model(c.element)
46
439
  assert_other_values(c.element, [])
47
440
  end
@@ -52,24 +445,18 @@ def test_in_cmd_in_label2
52
445
  TestNode nums: 3 {
53
446
  TestNode others:| /dummy {
54
447
  END
55
- assert_equal("", c.prefix)
56
- assert_equal("others", c.feature.name)
57
- assert(!c.in_array)
58
- assert(!c.in_block)
448
+ assert_context c, :prefix => "", :feature => "others", :in_array => false, :in_block => false, :after_label => true
59
449
  assert_simple_model(c.element)
60
450
  assert_other_values(c.element, [])
61
451
  end
62
452
 
63
- def test_in_cmd_after_label
453
+ def test_in_cmd_after_label_no_ws
64
454
  c = build_context TestMM, <<-END
65
455
  TestNode text: a {
66
456
  TestNode nums: 3 {
67
- TestNode others: |/dummy {
457
+ TestNode others:|/dummy {
68
458
  END
69
- assert_equal("", c.prefix)
70
- assert_equal("others", c.feature.name)
71
- assert(!c.in_array)
72
- assert(!c.in_block)
459
+ assert_context c, :prefix => "", :feature => "others", :in_array => false, :in_block => false, :after_label => true
73
460
  assert_simple_model(c.element)
74
461
  assert_other_values(c.element, [])
75
462
  end
@@ -80,10 +467,7 @@ def test_in_cmd_in_value
80
467
  TestNode nums: 3 {
81
468
  TestNode others: /du|mmy {
82
469
  END
83
- assert_equal("/du", c.prefix)
84
- assert_equal("others", c.feature.name)
85
- assert(!c.in_array)
86
- assert(!c.in_block)
470
+ assert_context c, :prefix => "/du", :feature => "others", :in_array => false, :in_block => false, :after_label => true
87
471
  assert_simple_model(c.element)
88
472
  assert_other_values(c.element, [])
89
473
  end
@@ -94,10 +478,7 @@ def test_in_cmd_in_value2
94
478
  TestNode nums: 3 {
95
479
  TestNode others: /dummy| {
96
480
  END
97
- assert_equal("/dummy", c.prefix)
98
- assert_equal("others", c.feature.name)
99
- assert(!c.in_array)
100
- assert(!c.in_block)
481
+ assert_context c, :prefix => "/dummy", :feature => "others", :in_array => false, :in_block => false, :after_label => true
101
482
  assert_simple_model(c.element)
102
483
  assert_other_values(c.element, [])
103
484
  end
@@ -108,10 +489,40 @@ def test_in_cmd_after_value
108
489
  TestNode nums: 3 {
109
490
  TestNode others: /dummy, |text: x {
110
491
  END
111
- assert_equal("", c.prefix)
112
- assert_nil(c.feature)
113
- assert(!c.in_array)
114
- assert(!c.in_block)
492
+ assert_context c, :prefix => "", :feature => nil, :in_array => false, :in_block => false
493
+ assert_simple_model(c.element)
494
+ assert_other_values(c.element, ["/dummy"])
495
+ end
496
+
497
+ def test_in_cmd_after_value_no_ws
498
+ c = build_context TestMM, <<-END
499
+ TestNode text: a {
500
+ TestNode nums: 3 {
501
+ TestNode others: /dummy,|text: x {
502
+ END
503
+ assert_context c, :prefix => "", :feature => nil, :in_array => false, :in_block => false
504
+ assert_simple_model(c.element)
505
+ assert_other_values(c.element, ["/dummy"])
506
+ end
507
+
508
+ def test_in_cmd_after_value_no_ws2
509
+ c = build_context TestMM, <<-END
510
+ TestNode text: a {
511
+ TestNode nums: 3 {
512
+ TestNode others:/dummy,|text: x {
513
+ END
514
+ assert_context c, :prefix => "", :feature => nil, :in_array => false, :in_block => false
515
+ assert_simple_model(c.element)
516
+ assert_other_values(c.element, ["/dummy"])
517
+ end
518
+
519
+ def test_in_cmd_after_value_directly_after_comma
520
+ c = build_context TestMM, <<-END
521
+ TestNode text: a {
522
+ TestNode nums: 3 {
523
+ TestNode others: /dummy,| text: x {
524
+ END
525
+ assert_context c, :prefix => "", :feature => nil, :in_array => false, :in_block => false
115
526
  assert_simple_model(c.element)
116
527
  assert_other_values(c.element, ["/dummy"])
117
528
  end
@@ -122,10 +533,7 @@ def test_in_cmd_in_second_label
122
533
  TestNode nums: 3 {
123
534
  TestNode others: /dummy, te|xt: x {
124
535
  END
125
- assert_equal("te", c.prefix)
126
- assert_nil(c.feature)
127
- assert(!c.in_array)
128
- assert(!c.in_block)
536
+ assert_context c, :prefix => "te", :feature => nil, :in_array => false, :in_block => false
129
537
  assert_simple_model(c.element)
130
538
  assert_other_values(c.element, ["/dummy"])
131
539
  end
@@ -136,10 +544,18 @@ def test_in_cmd_after_second_label
136
544
  TestNode nums: 3 {
137
545
  TestNode others: /dummy, text: |x {
138
546
  END
139
- assert_equal("", c.prefix)
140
- assert_equal("text", c.feature.name)
141
- assert(!c.in_array)
142
- assert(!c.in_block)
547
+ assert_context c, :prefix => "", :feature => "text", :in_array => false, :in_block => false, :after_label => true
548
+ assert_simple_model(c.element)
549
+ assert_other_values(c.element, ["/dummy"])
550
+ end
551
+
552
+ def test_in_cmd_after_second_label_no_ws
553
+ c = build_context TestMM, <<-END
554
+ TestNode text: a {
555
+ TestNode nums: 3 {
556
+ TestNode others:/dummy,text:|x {
557
+ END
558
+ assert_context c, :prefix => "", :feature => "text", :in_array => false, :in_block => false, :after_label => true
143
559
  assert_simple_model(c.element)
144
560
  assert_other_values(c.element, ["/dummy"])
145
561
  end
@@ -150,10 +566,18 @@ def test_in_cmd_in_second_value
150
566
  TestNode nums: 3 {
151
567
  TestNode others: /dummy, text: x| {
152
568
  END
153
- assert_equal("x", c.prefix)
154
- assert_equal("text", c.feature.name)
155
- assert(!c.in_array)
156
- assert(!c.in_block)
569
+ assert_context c, :prefix => "x", :feature => "text", :in_array => false, :in_block => false, :after_label => true
570
+ assert_simple_model(c.element)
571
+ assert_other_values(c.element, ["/dummy"])
572
+ end
573
+
574
+ def test_in_cmd_in_second_value_no_ws
575
+ c = build_context TestMM, <<-END
576
+ TestNode text: a {
577
+ TestNode nums: 3 {
578
+ TestNode others:/dummy,text:x| {
579
+ END
580
+ assert_context c, :prefix => "x", :feature => "text", :in_array => false, :in_block => false, :after_label => true
157
581
  assert_simple_model(c.element)
158
582
  assert_other_values(c.element, ["/dummy"])
159
583
  end
@@ -164,24 +588,106 @@ def test_in_cmd_in_array
164
588
  TestNode nums: 3 {
165
589
  TestNode others: [|/dummy, text: x
166
590
  END
167
- assert_equal("", c.prefix)
168
- assert_equal("others", c.feature.name)
169
- assert(c.in_array)
170
- assert(!c.in_block)
591
+ assert_context c, :prefix => "", :feature => "others", :in_array => true, :in_block => false, :after_label => true
592
+ assert_simple_model(c.element)
593
+ assert_other_values(c.element, [])
594
+ end
595
+
596
+ def test_in_cmd_in_array_no_ws
597
+ c = build_context TestMM, <<-END
598
+ TestNode text: a {
599
+ TestNode nums: 3 {
600
+ TestNode others:[|/dummy, text: x
601
+ END
602
+ assert_context c, :prefix => "", :feature => "others", :in_array => true, :in_block => false, :after_label => true
171
603
  assert_simple_model(c.element)
172
604
  assert_other_values(c.element, [])
173
605
  end
174
606
 
607
+ def test_in_cmd_in_array_within_string_value_empty
608
+ c = build_context TestMM, <<-END
609
+ TestNode text: a {
610
+ TestNode nums: 3 {
611
+ TestNode strings: ["|
612
+ END
613
+ assert_context c, :prefix => "\"", :feature => "strings", :in_array => true, :in_block => false, :after_label => true
614
+ assert_simple_model(c.element)
615
+ assert_other_values(c.element, [])
616
+ end
617
+
618
+ def test_in_cmd_in_array_within_string_value
619
+ c = build_context TestMM, <<-END
620
+ TestNode text: a {
621
+ TestNode nums: 3 {
622
+ TestNode strings: ["a,b|
623
+ END
624
+ assert_context c, :prefix => "\"a,b", :feature => "strings", :in_array => true, :in_block => false, :after_label => true
625
+ assert_simple_model(c.element)
626
+ assert_other_values(c.element, [])
627
+ end
628
+
629
+ def test_in_cmd_in_array_within_second_string_value
630
+ c = build_context TestMM, <<-END
631
+ TestNode text: a {
632
+ TestNode nums: 3 {
633
+ TestNode strings: ["a,b", "c,d|
634
+ END
635
+ assert_context c, :prefix => "\"c,d", :feature => "strings", :in_array => true, :in_block => false, :after_label => true
636
+ assert_simple_model(c.element)
637
+ assert_other_values(c.element, [])
638
+ end
639
+
640
+ def test_in_cmd_in_array_after_second_string_value
641
+ c = build_context TestMM, <<-END
642
+ TestNode text: a {
643
+ TestNode nums: 3 {
644
+ TestNode strings: ["a,b", "c,d"|
645
+ END
646
+ assert_context c, :prefix => "c,d", :feature => "strings", :in_array => true, :in_block => false, :after_label => true
647
+ assert_simple_model(c.element)
648
+ assert_equal(["a,b"], c.element.strings)
649
+ end
650
+
651
+ def test_in_cmd_in_array_after_second_string_value2
652
+ c = build_context TestMM, <<-END
653
+ TestNode text: a {
654
+ TestNode nums: 3 {
655
+ TestNode strings: ["a,b", "c,d" |
656
+ END
657
+ assert_context c, :prefix => "", :feature => "strings", :in_array => true, :in_block => false, :problem => :missing_comma, :after_label => true
658
+ assert_simple_model(c.element)
659
+ assert_equal(["a,b", "c,d"], c.element.strings)
660
+ end
661
+
662
+ def test_in_cmd_in_array_after_string_array
663
+ c = build_context TestMM, <<-END
664
+ TestNode text: a {
665
+ TestNode nums: 3 {
666
+ TestNode strings: ["a,b", "c,d"]|
667
+ END
668
+ assert_context c, :prefix => "", :feature => nil, :in_array => false, :in_block => false, :problem => :missing_comma
669
+ assert_simple_model(c.element)
670
+ assert_equal(["a,b", "c,d"], c.element.strings)
671
+ end
672
+
175
673
  def test_in_cmd_in_array_value
176
674
  c = build_context TestMM, <<-END
177
675
  TestNode text: a {
178
676
  TestNode nums: 3 {
179
677
  TestNode others: [/d|ummy, text: x
180
678
  END
181
- assert_equal("/d", c.prefix)
182
- assert_equal("others", c.feature.name)
183
- assert(c.in_array)
184
- assert(!c.in_block)
679
+ assert_context c, :prefix => "/d", :feature => "others", :in_array => true, :in_block => false, :after_label => true
680
+ assert_simple_model(c.element)
681
+ assert_other_values(c.element, [])
682
+ end
683
+
684
+ def test_in_cmd_in_array_value_no_ws
685
+ c = build_context TestMM, <<-END
686
+ TestNode text: a {
687
+ TestNode nums: 3 {
688
+ TestNode others:[/d|ummy, text: x
689
+ END
690
+ assert_context c, :prefix => "/d", :feature => "others", :in_array => true, :in_block => false, :after_label => true
185
691
  assert_simple_model(c.element)
186
692
  assert_other_values(c.element, [])
187
693
  end
@@ -192,10 +698,18 @@ def test_in_cmd_after_array_value
192
698
  TestNode nums: 3 {
193
699
  TestNode others: [/dummy,| text: x
194
700
  END
195
- assert_equal("", c.prefix)
196
- assert_equal("others", c.feature.name)
197
- assert(c.in_array)
198
- assert(!c.in_block)
701
+ assert_context c, :prefix => "", :feature => "others", :in_array => true, :in_block => false, :after_label => true
702
+ assert_simple_model(c.element)
703
+ assert_other_values(c.element, ["/dummy"])
704
+ end
705
+
706
+ def test_in_cmd_after_array_value_no_ws
707
+ c = build_context TestMM, <<-END
708
+ TestNode text: a {
709
+ TestNode nums: 3 {
710
+ TestNode others:[/dummy,| text: x
711
+ END
712
+ assert_context c, :prefix => "", :feature => "others", :in_array => true, :in_block => false, :after_label => true
199
713
  assert_simple_model(c.element)
200
714
  assert_other_values(c.element, ["/dummy"])
201
715
  end
@@ -206,10 +720,29 @@ def test_in_cmd_in_second_array_value
206
720
  TestNode nums: 3 {
207
721
  TestNode others: [/dummy, /dom|my
208
722
  END
209
- assert_equal("/dom", c.prefix)
210
- assert_equal("others", c.feature.name)
211
- assert(c.in_array)
212
- assert(!c.in_block)
723
+ assert_context c, :prefix => "/dom", :feature => "others", :in_array => true, :in_block => false, :after_label => true
724
+ assert_simple_model(c.element)
725
+ assert_other_values(c.element, ["/dummy"])
726
+ end
727
+
728
+ def test_in_cmd_in_second_array_value_no_ws
729
+ c = build_context TestMM, <<-END
730
+ TestNode text: a {
731
+ TestNode nums: 3 {
732
+ TestNode others: [/dummy,/dom|my
733
+ END
734
+ assert_context c, :prefix => "/dom", :feature => "others", :in_array => true, :in_block => false, :after_label => true
735
+ assert_simple_model(c.element)
736
+ assert_other_values(c.element, ["/dummy"])
737
+ end
738
+
739
+ def test_in_cmd_in_second_array_value_no_ws2
740
+ c = build_context TestMM, <<-END
741
+ TestNode text: a {
742
+ TestNode nums: 3 {
743
+ TestNode others:[/dummy,/dom|my
744
+ END
745
+ assert_context c, :prefix => "/dom", :feature => "others", :in_array => true, :in_block => false, :after_label => true
213
746
  assert_simple_model(c.element)
214
747
  assert_other_values(c.element, ["/dummy"])
215
748
  end
@@ -220,10 +753,18 @@ def test_in_cmd_after_array
220
753
  TestNode nums: 3 {
221
754
  TestNode others: [/dummy, /dommy], |
222
755
  END
223
- assert_equal("", c.prefix)
224
- assert_nil(c.feature)
225
- assert(!c.in_array)
226
- assert(!c.in_block)
756
+ assert_context c, :prefix => "", :feature => nil, :in_array => false, :in_block => false
757
+ assert_simple_model(c.element)
758
+ assert_other_values(c.element, ["/dummy", "/dommy"])
759
+ end
760
+
761
+ def test_in_cmd_after_array_no_ws
762
+ c = build_context TestMM, <<-END
763
+ TestNode text: a {
764
+ TestNode nums: 3 {
765
+ TestNode others:[/dummy,/dommy],|
766
+ END
767
+ assert_context c, :prefix => "", :feature => nil, :in_array => false, :in_block => false
227
768
  assert_simple_model(c.element)
228
769
  assert_other_values(c.element, ["/dummy", "/dommy"])
229
770
  end
@@ -234,14 +775,32 @@ def test_in_cmd_after_array2
234
775
  TestNode nums: 3 {
235
776
  TestNode others: [/dummy, /dommy], nums: |
236
777
  END
237
- assert_equal("", c.prefix)
238
- assert_equal("nums", c.feature.name)
239
- assert(!c.in_array)
240
- assert(!c.in_block)
778
+ assert_context c, :prefix => "", :feature => "nums", :in_array => false, :in_block => false, :after_label => true
779
+ assert_simple_model(c.element)
780
+ assert_other_values(c.element, ["/dummy", "/dommy"])
781
+ end
782
+
783
+ def test_in_cmd_after_array2_no_ws
784
+ c = build_context TestMM, <<-END
785
+ TestNode text: a {
786
+ TestNode nums: 3 {
787
+ TestNode others:[/dummy,/dommy],nums:|
788
+ END
789
+ assert_context c, :prefix => "", :feature => "nums", :in_array => false, :in_block => false, :after_label => true
241
790
  assert_simple_model(c.element)
242
791
  assert_other_values(c.element, ["/dummy", "/dommy"])
243
792
  end
244
793
 
794
+ def test_in_cmd_boolean_value
795
+ c = build_context TestMM, <<-END
796
+ TestNode text: a {
797
+ TestNode nums: 3 {
798
+ TestNode boolean: t|
799
+ END
800
+ assert_context c, :prefix => "t", :feature => "boolean", :in_array => false, :in_block => false, :after_label => true
801
+ assert_simple_model(c.element)
802
+ end
803
+
245
804
  def test_below_single_label
246
805
  c = build_context TestMM, <<-END
247
806
  TestNode text: a {
@@ -250,10 +809,7 @@ def test_below_single_label
250
809
  childs:
251
810
  |
252
811
  END
253
- assert_equal("", c.prefix)
254
- assert_equal("childs", c.feature.name)
255
- assert(!c.in_array)
256
- assert(c.in_block)
812
+ assert_context c, :prefix => "", :feature => "childs", :in_array => false, :in_block => true, :after_label => true
257
813
  assert_simple_model(c.element)
258
814
  assert_other_values(c.element, ["/dummy"])
259
815
  end
@@ -266,14 +822,23 @@ def test_below_single_label_started_command
266
822
  childs:
267
823
  Tes|
268
824
  END
269
- assert_equal("Tes", c.prefix)
270
- assert_equal("childs", c.feature.name)
271
- assert(!c.in_array)
272
- assert(c.in_block)
825
+ assert_context c, :prefix => "Tes", :feature => "childs", :in_array => false, :in_block => true, :after_label => true
273
826
  assert_simple_model(c.element)
274
827
  assert_other_values(c.element, ["/dummy"])
275
828
  end
276
829
 
830
+ def test_below_single_label_after_command
831
+ c = build_context TestMM, <<-END
832
+ TestNode text: a {
833
+ TestNode nums: 3 {
834
+ TestNode others: /dummy {
835
+ childs:
836
+ TestNode |
837
+ END
838
+ assert_context c, :prefix => "", :feature => "unlabled", :in_array => false, :in_block => false
839
+ assert_equal [3], c.element.parent.parent.nums
840
+ end
841
+
277
842
  def test_below_multi_label
278
843
  c = build_context TestMM, <<-END
279
844
  TestNode text: a {
@@ -282,10 +847,7 @@ def test_below_multi_label
282
847
  childs: [
283
848
  |
284
849
  END
285
- assert_equal("", c.prefix)
286
- assert_equal("childs", c.feature.name)
287
- assert(c.in_array)
288
- assert(c.in_block)
850
+ assert_context c, :prefix => "", :feature => "childs", :in_array => true, :in_block => true, :after_label => true
289
851
  assert_simple_model(c.element)
290
852
  assert_other_values(c.element, ["/dummy"])
291
853
  end
@@ -298,14 +860,23 @@ def test_below_multi_label_started_command
298
860
  childs: [
299
861
  Tes|
300
862
  END
301
- assert_equal("Tes", c.prefix)
302
- assert_equal("childs", c.feature.name)
303
- assert(c.in_array)
304
- assert(c.in_block)
863
+ assert_context c, :prefix => "Tes", :feature => "childs", :in_array => true, :in_block => true, :after_label => true
305
864
  assert_simple_model(c.element)
306
865
  assert_other_values(c.element, ["/dummy"])
307
866
  end
308
867
 
868
+ def test_below_multi_label_after_command
869
+ c = build_context TestMM, <<-END
870
+ TestNode text: a {
871
+ TestNode nums: 3 {
872
+ TestNode others: /dummy {
873
+ childs: [
874
+ TestNode |
875
+ END
876
+ assert_context c, :prefix => "", :feature => "unlabled", :in_array => false, :in_block => false
877
+ assert_equal [3], c.element.parent.parent.nums
878
+ end
879
+
309
880
  def test_in_new_line
310
881
  c = build_context TestMM, <<-END
311
882
  TestNode text: a {
@@ -313,10 +884,7 @@ def test_in_new_line
313
884
  TestNode others: /dummy {
314
885
  |
315
886
  END
316
- assert_equal("", c.prefix)
317
- assert_nil(c.feature)
318
- assert(!c.in_array)
319
- assert(c.in_block)
887
+ assert_context c, :prefix => "", :feature => nil, :in_array => false, :in_block => true
320
888
  assert_simple_model(c.element)
321
889
  assert_other_values(c.element, ["/dummy"])
322
890
  end
@@ -328,14 +896,24 @@ def test_in_new_line_started_command
328
896
  TestNode others: /dummy {
329
897
  Tes|
330
898
  END
331
- assert_equal("Tes", c.prefix)
332
- assert_nil(c.feature)
333
- assert(!c.in_array)
334
- assert(c.in_block)
899
+ assert_context c, :prefix => "Tes", :feature => nil, :in_array => false, :in_block => true
335
900
  assert_simple_model(c.element)
336
901
  assert_other_values(c.element, ["/dummy"])
337
902
  end
338
903
 
904
+ def assert_context(c, options)
905
+ assert_equal(options[:prefix], c.prefix)
906
+ assert_equal(options[:in_array], c.in_array)
907
+ assert_equal(options[:in_block], c.in_block)
908
+ assert_equal((options[:after_label] || false), c.after_label)
909
+ assert_equal(options[:problem], c.problem)
910
+ if options[:feature]
911
+ assert_equal(options[:feature], c.feature.name)
912
+ else
913
+ assert_nil(c.feature)
914
+ end
915
+ end
916
+
339
917
  def assert_simple_model(c)
340
918
  assert c.is_a?(TestMM::TestNode)
341
919
  assert c.parent.is_a?(TestMM::TestNode)
@@ -352,7 +930,9 @@ def build_context(mm, text)
352
930
  context_lines = text.split("\n")
353
931
  pos_in_line = context_lines.last.index("|")
354
932
  context_lines.last.sub!("|", "")
355
- lang = RText::Language.new(mm.ecore, :root_classes => mm.ecore.eAllClasses)
933
+ lang = RText::Language.new(mm.ecore,
934
+ :root_classes => mm.ecore.eAllClasses,
935
+ :unlabled_arguments => lambda {|c| ["unlabled", "unlabled_array"]})
356
936
  RText::ContextBuilder.build_context(lang, context_lines, pos_in_line)
357
937
  end
358
938