rtext 0.9.0 → 0.9.1

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