rtext 0.9.0 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +113 -98
  3. data/Project.yaml +14 -0
  4. data/RText_Protocol +1 -1
  5. data/lib/rtext/default_completer.rb +212 -208
  6. data/lib/rtext/frontend/connector.rb +122 -55
  7. data/lib/rtext/instantiator.rb +11 -3
  8. data/lib/rtext/service.rb +264 -260
  9. metadata +18 -44
  10. data/Rakefile +0 -46
  11. data/test/completer_test.rb +0 -607
  12. data/test/context_builder_test.rb +0 -949
  13. data/test/frontend/context_test.rb +0 -302
  14. data/test/instantiator_test.rb +0 -1733
  15. data/test/integration/backend.out +0 -16
  16. data/test/integration/crash_on_request_editor.rb +0 -12
  17. data/test/integration/ecore_editor.rb +0 -50
  18. data/test/integration/frontend.log +0 -40058
  19. data/test/integration/model/invalid_encoding.invenc +0 -2
  20. data/test/integration/model/test.crash_on_request +0 -18
  21. data/test/integration/model/test.crashing_backend +0 -18
  22. data/test/integration/model/test.dont_open_socket +0 -0
  23. data/test/integration/model/test.invalid_cmd_line +0 -0
  24. data/test/integration/model/test.not_in_rtext +0 -0
  25. data/test/integration/model/test_large_with_errors.ect3 +0 -43523
  26. data/test/integration/model/test_metamodel.ect +0 -24
  27. data/test/integration/model/test_metamodel2.ect +0 -5
  28. data/test/integration/model/test_metamodel3.ect4 +0 -7
  29. data/test/integration/model/test_metamodel_error.ect2 +0 -3
  30. data/test/integration/model/test_metamodel_ok.ect2 +0 -18
  31. data/test/integration/test.rb +0 -968
  32. data/test/link_detector_test.rb +0 -288
  33. data/test/message_helper_test.rb +0 -117
  34. data/test/rtext_test.rb +0 -11
  35. data/test/serializer_test.rb +0 -1024
  36. data/test/tokenizer_test.rb +0 -174
@@ -1,1024 +0,0 @@
1
- $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
-
3
- gem 'minitest'
4
- require 'minitest/autorun'
5
- require 'bigdecimal'
6
- require 'fileutils'
7
- require 'stringio'
8
- require 'rgen/environment'
9
- require 'rgen/metamodel_builder'
10
- require 'rtext/serializer'
11
- require 'rtext/language'
12
-
13
- class SerializerTest < MiniTest::Test
14
- TestOutputFile = ".serializer_test_file"
15
-
16
- def teardown
17
- FileUtils.rm_f TestOutputFile
18
- end
19
-
20
- class StringWriter < String
21
- alias write concat
22
- end
23
-
24
- module TestMM
25
- extend RGen::MetamodelBuilder::ModuleExtension
26
- SomeEnum = RGen::MetamodelBuilder::DataTypes::Enum.new(
27
- :name => "SomeEnum", :literals => [:A, :B, :'non-word*chars', :'2you'])
28
- class TestNode < RGen::MetamodelBuilder::MMBase
29
- has_attr 'text', String
30
- has_many_attr 'texts', String
31
- has_many_attr 'more_texts', String
32
- has_attr 'unlabled', String
33
- has_attr 'unquoted', String
34
- has_attr 'both', String
35
- has_attr 'none', String
36
- has_attr 'comment', String
37
- has_attr 'integer', Integer
38
- has_attr 'float', Float
39
- has_attr 'enum', SomeEnum
40
- has_attr 'boolean', Boolean
41
- contains_many 'childs', TestNode, 'parent'
42
- end
43
- end
44
-
45
- def test_simple
46
- testModel = TestMM::TestNode.new(:text => "some text", :childs => [
47
- TestMM::TestNode.new(:text => "child")])
48
-
49
- output = StringWriter.new
50
- serialize(testModel, TestMM, output)
51
-
52
- assert_equal %Q(\
53
- TestNode text: "some text" {
54
- TestNode text: "child"
55
- }
56
- ), output
57
- end
58
-
59
- def test_many_attr
60
- testModel = TestMM::TestNode.new(:texts => ["a", "b", "c"])
61
-
62
- output = StringWriter.new
63
- serialize(testModel, TestMM, output)
64
-
65
- assert_equal %Q(\
66
- TestNode texts: ["a", "b", "c"]
67
- ), output
68
- end
69
-
70
- module TestMMFeatureProvider
71
- extend RGen::MetamodelBuilder::ModuleExtension
72
- class TestNode < RGen::MetamodelBuilder::MMBase
73
- has_attr 'attr1', String
74
- has_attr 'attr2', String
75
- has_attr 'attr3', String
76
- contains_many 'childs1', TestNode, 'parent1'
77
- contains_many 'childs2', TestNode, 'parent2'
78
- contains_many 'childs3', TestNode, 'parent3'
79
- end
80
- end
81
-
82
- def test_feature_provider
83
- testModel = TestMMFeatureProvider::TestNode.new(
84
- :attr1 => "attr1",
85
- :attr2 => "attr2",
86
- :attr3 => "attr3",
87
- :childs1 => [TestMMFeatureProvider::TestNode.new(:attr1 => "child1")],
88
- :childs2 => [TestMMFeatureProvider::TestNode.new(:attr1 => "child2")],
89
- :childs3 => [TestMMFeatureProvider::TestNode.new(:attr1 => "child3")])
90
-
91
- output = StringWriter.new
92
- serialize(testModel, TestMMFeatureProvider, output,
93
- :feature_provider => proc {|clazz|
94
- clazz.eAllStructuralFeatures.reject{|f| f.name =~ /parent|2$/}.reverse})
95
-
96
- assert_equal %Q(\
97
- TestNode attr3: "attr3", attr1: "attr1" {
98
- childs3:
99
- TestNode attr1: "child3"
100
- childs1:
101
- TestNode attr1: "child1"
102
- }
103
- ), output
104
- end
105
-
106
- module TestMMUnlabledUnquoted
107
- extend RGen::MetamodelBuilder::ModuleExtension
108
- class TestNode < RGen::MetamodelBuilder::MMBase
109
- has_attr 'unlabled', String
110
- has_attr 'unquoted', String
111
- has_attr 'both', String
112
- has_attr 'none', String
113
- end
114
- end
115
-
116
- def test_unlabled_unquoted
117
- testModel = [
118
- TestMMUnlabledUnquoted::TestNode.new(:unlabled => "unlabled", :unquoted => "unquoted", :both => "both", :none => "none"),
119
- TestMMUnlabledUnquoted::TestNode.new(:unquoted => "no identifier"),
120
- TestMMUnlabledUnquoted::TestNode.new(:unquoted => "true"),
121
- TestMMUnlabledUnquoted::TestNode.new(:unquoted => "333"),
122
- TestMMUnlabledUnquoted::TestNode.new(:unquoted => "33.3"),
123
- TestMMUnlabledUnquoted::TestNode.new(:unquoted => "5x"),
124
- TestMMUnlabledUnquoted::TestNode.new(:unquoted => "//")
125
- ]
126
-
127
- output = StringWriter.new
128
- serialize(testModel, TestMMUnlabledUnquoted, output,
129
- :unlabled_arguments => proc {|clazz| ["unlabled", "both"]},
130
- :unquoted_arguments => proc {|clazz| ["unquoted", "both"]}
131
- )
132
-
133
- assert_equal %Q(\
134
- TestNode "unlabled", both, unquoted: unquoted, none: "none"
135
- TestNode unquoted: "no identifier"
136
- TestNode unquoted: "true"
137
- TestNode unquoted: "333"
138
- TestNode unquoted: "33.3"
139
- TestNode unquoted: "5x"
140
- TestNode unquoted: "//"
141
- ), output
142
- end
143
-
144
- module TestMMComment
145
- extend RGen::MetamodelBuilder::ModuleExtension
146
- class TestNode < RGen::MetamodelBuilder::MMBase
147
- has_attr 'comment', String
148
- contains_many 'childs', TestNode, 'parent'
149
- end
150
- end
151
-
152
- def test_comment_provider
153
- testModel = TestMMComment::TestNode.new(
154
- :comment => "this is a comment",
155
- :childs => [
156
- TestMMComment::TestNode.new(:comment => "\n\ncomment of a child node\n multiline\n\n\nanother\n\n\n"),
157
- TestMMComment::TestNode.new(:comment => "don't show"),
158
- TestMMComment::TestNode.new(:comment => "")])
159
-
160
- output = StringWriter.new
161
- serialize(testModel, TestMMComment, output,
162
- :comment_provider => proc { |e|
163
- if e.comment != "don't show"
164
- c = e.comment
165
- e.comment = nil
166
- c
167
- else
168
- nil
169
- end
170
- })
171
-
172
- assert_equal %Q(\
173
- #this is a comment
174
- TestNode {
175
- #
176
- #
177
- #comment of a child node
178
- # multiline
179
- #
180
- #
181
- #another
182
- TestNode
183
- TestNode comment: "don't show"
184
- TestNode
185
- }
186
- ), output
187
- end
188
-
189
- module TestMMAnnotation
190
- extend RGen::MetamodelBuilder::ModuleExtension
191
- class TestNode < RGen::MetamodelBuilder::MMBase
192
- has_attr 'annotation', String
193
- contains_many 'childs', TestNode, 'parent'
194
- end
195
- end
196
-
197
- def test_annotation_provider
198
- testModel = TestMMAnnotation::TestNode.new(
199
- :annotation => "this is an annotation",
200
- :childs => [
201
- TestMMAnnotation::TestNode.new(:annotation => "annotation of a child node\n multiline"),
202
- TestMMAnnotation::TestNode.new(:annotation => "don't show")])
203
-
204
- output = StringWriter.new
205
- serialize(testModel, TestMMAnnotation, output,
206
- :annotation_provider => proc { |e|
207
- if e.annotation != "don't show"
208
- a = e.annotation
209
- e.annotation = nil
210
- a
211
- else
212
- nil
213
- end
214
- })
215
-
216
- assert_equal %Q(\
217
- @this is an annotation
218
- TestNode {
219
- @annotation of a child node
220
- @ multiline
221
- TestNode
222
- TestNode annotation: "don't show"
223
- }
224
- ), output
225
- end
226
-
227
- def test_indent_string
228
- testModel = TestMM::TestNode.new(:childs => [
229
- TestMM::TestNode.new(:text => "child")])
230
-
231
- output = StringWriter.new
232
- serialize(testModel, TestMM, output, :indent_string => "____")
233
-
234
- assert_equal %Q(\
235
- TestNode {
236
- ____TestNode text: "child"
237
- }
238
- ), output
239
- end
240
-
241
- module TestMMRef
242
- extend RGen::MetamodelBuilder::ModuleExtension
243
- class TestNode < RGen::MetamodelBuilder::MMBase
244
- has_attr 'name', String
245
- contains_many 'childs', TestNode, 'parent'
246
- has_many 'refMany', TestNode
247
- has_one 'refOne', TestNode
248
- one_to_many 'refManyBi', TestNode, 'refManyBack'
249
- one_to_one 'refOneBi', TestNode, 'refOneBack'
250
- many_to_many 'refManyMany', TestNode, 'refManyManyBack'
251
- end
252
- end
253
-
254
- def test_identifier_provider
255
- testModel = [
256
- TestMMRef::TestNode.new(:name => "Source"),
257
- TestMMRef::TestNode.new(:name => "Target")]
258
- testModel[0].refOne = testModel[1]
259
-
260
- output = StringWriter.new
261
- serialize(testModel, TestMMRef, output,
262
- :identifier_provider => proc{|e, context, feature, index|
263
- assert_equal testModel[0], context
264
- assert_equal "refOne", feature.name
265
- assert_equal 0, index
266
- "/target/ref"
267
- }
268
- )
269
-
270
- assert_equal %Q(\
271
- TestNode name: "Source", refOne: /target/ref
272
- TestNode name: "Target"
273
- ),output
274
- end
275
-
276
- def test_identifier_provider_many
277
- testModel = [
278
- TestMMRef::TestNode.new(:name => "Source"),
279
- TestMMRef::TestNode.new(:name => "Target1"),
280
- TestMMRef::TestNode.new(:name => "Target2")]
281
- testModel[0].addRefMany(testModel[1])
282
- testModel[0].addRefMany(testModel[2])
283
-
284
- output = StringWriter.new
285
- call_index = 0
286
- serialize(testModel, TestMMRef, output,
287
- :identifier_provider => proc{|e, context, feature, index|
288
- assert_equal testModel[0], context
289
- assert_equal "refMany", feature.name
290
- if call_index == 0
291
- call_index += 1
292
- assert_equal 0, index
293
- "/target/ref1"
294
- else
295
- assert_equal 1, index
296
- "/target/ref2"
297
- end
298
- }
299
- )
300
- assert_equal %Q(\
301
- TestNode name: "Source", refMany: [/target/ref1, /target/ref2]
302
- TestNode name: "Target1"
303
- TestNode name: "Target2"
304
- ),output
305
- end
306
-
307
- def test_identifier_provider_nil
308
- testModel = [
309
- TestMMRef::TestNode.new(:name => "Source"),
310
- TestMMRef::TestNode.new(:name => "Target")]
311
- testModel[0].refOne = testModel[1]
312
-
313
- output = StringWriter.new
314
- serialize(testModel, TestMMRef, output,
315
- :identifier_provider => proc{|e, context, feature, index|
316
- nil
317
- }
318
- )
319
-
320
- assert_equal %Q(\
321
- TestNode name: "Source"
322
- TestNode name: "Target"
323
- ),output
324
- end
325
-
326
- def test_references
327
- testModel = [
328
- TestMMRef::TestNode.new(:name => "Source"),
329
- TestMMRef::TestNode.new(:name => "Target",
330
- :childs => [
331
- TestMMRef::TestNode.new(:name => "A",
332
- :childs => [
333
- TestMMRef::TestNode.new(:name => "A1")
334
- ]),
335
- TestMMRef::TestNode.new(:name => "B"),
336
- ])
337
- ]
338
- testModel[0].refOne = testModel[1].childs[0].childs[0]
339
- testModel[0].refOneBi = testModel[1].childs[0].childs[0]
340
- testModel[0].refMany = [testModel[1].childs[0], testModel[1].childs[1]]
341
- testModel[0].refManyBi = [testModel[1].childs[0], testModel[1].childs[1]]
342
- testModel[0].refManyMany = [testModel[1].childs[0], testModel[1].childs[1]]
343
- testModel[0].addRefMany(RGen::MetamodelBuilder::MMProxy.new("/some/ref"))
344
-
345
- output = StringWriter.new
346
- serialize(testModel, TestMMRef, output)
347
-
348
- assert_equal %Q(\
349
- TestNode name: "Source", refMany: [/Target/A, /Target/B, /some/ref], refOne: /Target/A/A1, refOneBi: /Target/A/A1
350
- TestNode name: "Target" {
351
- TestNode name: "A", refManyBack: /Source, refManyManyBack: /Source {
352
- TestNode name: "A1"
353
- }
354
- TestNode name: "B", refManyBack: /Source, refManyManyBack: /Source
355
- }
356
- ), output
357
- end
358
-
359
- module TestMMChildRole
360
- extend RGen::MetamodelBuilder::ModuleExtension
361
- class TestNodeA < RGen::MetamodelBuilder::MMBase
362
- has_attr 'text', String
363
- end
364
- class TestNodeB < RGen::MetamodelBuilder::MMBase
365
- has_attr 'text', String
366
- end
367
- class TestNodeC < RGen::MetamodelBuilder::MMBase
368
- has_attr 'text', String
369
- end
370
- class TestNodeD < RGen::MetamodelBuilder::MMBase
371
- has_attr 'text3', String
372
- end
373
- class TestNodeE < RGen::MetamodelBuilder::MMMultiple(TestNodeC, TestNodeD)
374
- has_attr 'text2', String
375
- end
376
- class TestNode < RGen::MetamodelBuilder::MMBase
377
- has_attr 'text', String
378
- has_many_attr 'texts', String
379
- contains_one 'child1', TestNode, 'parent1'
380
- contains_many 'childs2', TestNode, 'parent2'
381
- contains_one 'child3', TestNodeA, 'parent3'
382
- contains_many 'childs4', TestNodeB, 'parent4'
383
- contains_one 'child5', TestNodeC, 'parent5'
384
- contains_many 'childs6', TestNodeD, 'parent6'
385
- contains_one 'child7', TestNodeE, 'parent7'
386
- end
387
- end
388
-
389
- def test_child_role
390
- testModel = TestMMChildRole::TestNode.new(
391
- :child1 => TestMMChildRole::TestNode.new(:text => "child1"),
392
- :childs2 => [
393
- TestMMChildRole::TestNode.new(:text => "child2a"),
394
- TestMMChildRole::TestNode.new(:text => "child2b")
395
- ],
396
- :child3 => TestMMChildRole::TestNodeA.new(:text => "child3"),
397
- :childs4 => [TestMMChildRole::TestNodeB.new(:text => "child4")],
398
- :child5 => TestMMChildRole::TestNodeC.new(:text => "child5"),
399
- :childs6 => [TestMMChildRole::TestNodeD.new(:text3 => "child6"), TestMMChildRole::TestNodeE.new(:text => "child6.1")],
400
- :child7 => TestMMChildRole::TestNodeE.new(:text2 => "child7")
401
- )
402
-
403
- output = StringWriter.new
404
- serialize(testModel, TestMMChildRole, output)
405
-
406
- assert_equal %Q(\
407
- TestNode {
408
- child1:
409
- TestNode text: "child1"
410
- childs2: [
411
- TestNode text: "child2a"
412
- TestNode text: "child2b"
413
- ]
414
- TestNodeA text: "child3"
415
- TestNodeB text: "child4"
416
- TestNodeC text: "child5"
417
- childs6: [
418
- TestNodeD text3: "child6"
419
- TestNodeE text: "child6.1"
420
- ]
421
- child7:
422
- TestNodeE text2: "child7"
423
- }
424
- ), output
425
- end
426
-
427
- module TestMMLabeledContainment
428
- extend RGen::MetamodelBuilder::ModuleExtension
429
- class TestNode < RGen::MetamodelBuilder::MMBase
430
- abstract
431
- has_attr 'text', String
432
- contains_many 'childs', TestNode, 'parent'
433
- end
434
- class TestNode1 < TestNode
435
- end
436
- class TestNode2 < TestNode
437
- end
438
- end
439
-
440
- def test_labeled_containment
441
- testModel = TestMMLabeledContainment::TestNode1.new(:text => "some text", :childs => [
442
- TestMMLabeledContainment::TestNode2.new(:text => "child", :childs => [
443
- TestMMLabeledContainment::TestNode1.new(:text => "nested child")
444
- ])])
445
-
446
- output = StringWriter.new
447
- serialize(testModel, TestMMLabeledContainment, output, :labeled_containments => proc {|c|
448
- if c == TestMMLabeledContainment::TestNode2.ecore
449
- ["childs"]
450
- else
451
- []
452
- end
453
- })
454
-
455
- assert_equal %Q(\
456
- TestNode1 text: "some text" {
457
- TestNode2 text: "child" {
458
- childs:
459
- TestNode1 text: "nested child"
460
- }
461
- }
462
- ), output
463
- end
464
-
465
- def test_escapes
466
- testModel = TestMM::TestNode.new(:text => %Q(some " \\ \\" text \r xx \n xx \r\n xx \t xx \b xx \f))
467
- output = StringWriter.new
468
- serialize(testModel, TestMM, output)
469
-
470
- assert_equal %q(TestNode text: "some \" \\\\ \\\\\" text \r xx \n xx \r\n xx \t xx \b xx \f")+"\n", output
471
- end
472
-
473
- def test_integer
474
- testModel = TestMM::TestNode.new(:integer => 7)
475
- output = StringWriter.new
476
- serialize(testModel, TestMM, output)
477
- assert_equal %q(TestNode integer: 7)+"\n", output
478
- end
479
-
480
- def test_integer_big
481
- testModel = TestMM::TestNode.new(:integer => 12345678901234567890)
482
- output = StringWriter.new
483
- serialize(testModel, TestMM, output)
484
- assert_equal %q(TestNode integer: 12345678901234567890)+"\n", output
485
- end
486
-
487
- def test_integer_format_spec
488
- testModel = TestMM::TestNode.new(:integer => 10)
489
- output = StringWriter.new
490
- serialize(testModel, TestMM, output, :argument_format_provider => proc {|a|
491
- if a.name == "integer"
492
- "0x%02X"
493
- else
494
- nil
495
- end})
496
- assert_equal %q(TestNode integer: 0x0A)+"\n", output
497
- end
498
-
499
- def test_integer_format_spec_big
500
- testModel = TestMM::TestNode.new(:integer => 0xabcdefabcdefabcdef)
501
- output = StringWriter.new
502
- serialize(testModel, TestMM, output, :argument_format_provider => proc {|a|
503
- if a.name == "integer"
504
- "0x%x"
505
- else
506
- nil
507
- end})
508
- assert_equal %q(TestNode integer: 0xabcdefabcdefabcdef)+"\n", output
509
- end
510
-
511
- def test_float
512
- testModel = TestMM::TestNode.new(:float => 1.23)
513
- output = StringWriter.new
514
- serialize(testModel, TestMM, output)
515
- assert_equal %q(TestNode float: 1.23)+"\n", output
516
- end
517
-
518
- def test_float2
519
- testModel = TestMM::TestNode.new(:float => 1.23e-08)
520
- output = StringWriter.new
521
- serialize(testModel, TestMM, output)
522
- assert output =~ /TestNode float: 1.23e-0?08\n/
523
- end
524
-
525
- def test_float_format_spec
526
- testModel = TestMM::TestNode.new(:float => 1.23)
527
- output = StringWriter.new
528
- serialize(testModel, TestMM, output, :argument_format_provider => proc {|a|
529
- if a.name == "float"
530
- "%1.1f"
531
- else
532
- nil
533
- end})
534
- assert_equal %q(TestNode float: 1.2)+"\n", output
535
- end
536
-
537
- def test_float_big_decimal
538
- begin
539
- testModel = TestMM::TestNode.new(:float => BigDecimal.new("1234567890.123456789"))
540
- rescue StandardError
541
- return
542
- end
543
- output = StringWriter.new
544
- serialize(testModel, TestMM, output)
545
- assert_equal %q(TestNode float: 1234567890.123456789)+"\n", output
546
- end
547
-
548
- def test_enum
549
- testModel = [
550
- TestMM::TestNode.new(:enum => :A),
551
- TestMM::TestNode.new(:enum => :B),
552
- TestMM::TestNode.new(:enum => :'non-word*chars'),
553
- TestMM::TestNode.new(:enum => :'2you')
554
- ]
555
- output = StringWriter.new
556
- serialize(testModel, TestMM, output)
557
- assert_equal %Q(\
558
- TestNode enum: A
559
- TestNode enum: B
560
- TestNode enum: "non-word*chars"
561
- TestNode enum: "2you"
562
- ), output
563
- end
564
-
565
- def test_generic
566
- testModel = [
567
- TestMM::TestNode.new(:text => RText::Generic.new("some text angel >bracket")),
568
- TestMM::TestNode.new(:text => RText::Generic.new("some text percent angel %>bracket")),
569
- TestMM::TestNode.new(:text => RText::Generic.new("some text > percent angel%>bracket")),
570
- TestMM::TestNode.new(:integer => RText::Generic.new("a number: 1")),
571
- TestMM::TestNode.new(:float => RText::Generic.new("precision")),
572
- TestMM::TestNode.new(:enum => RText::Generic.new("an option")),
573
- TestMM::TestNode.new(:boolean => RText::Generic.new("falsy"))
574
- ]
575
- output = StringWriter.new
576
- serialize(testModel, TestMM, output)
577
- assert_equal %Q(\
578
- TestNode text: <%some text angel >bracket%>
579
- TestNode text: <some text percent angel >
580
- TestNode text: <%some text > percent angel%>
581
- TestNode integer: <a number: 1>
582
- TestNode float: <precision>
583
- TestNode enum: <an option>
584
- TestNode boolean: <falsy>
585
- ), output
586
- end
587
-
588
- module TestMMData
589
- extend RGen::MetamodelBuilder::ModuleExtension
590
- # class "Data" exists in the standard Ruby namespace
591
- class Data < RGen::MetamodelBuilder::MMBase
592
- has_attr 'notTheBuiltin', String
593
- end
594
- end
595
-
596
- module TestMMSubpackage
597
- extend RGen::MetamodelBuilder::ModuleExtension
598
- module SubPackage
599
- extend RGen::MetamodelBuilder::ModuleExtension
600
- class Data < RGen::MetamodelBuilder::MMBase
601
- has_attr 'notTheBuiltin', String
602
- end
603
- class Data2 < RGen::MetamodelBuilder::MMBase
604
- has_attr 'data2', String
605
- end
606
- end
607
- end
608
-
609
- def test_subpackage
610
- testModel = TestMMSubpackage::SubPackage::Data2.new(:data2 => "xxx")
611
- output = StringWriter.new
612
- serialize(testModel, TestMMSubpackage, output)
613
- assert_equal %q(Data2 data2: "xxx")+"\n", output
614
- end
615
-
616
- def test_command_name_provider
617
- testModel = TestMM::TestNode.new(:text => "some text", :childs => [
618
- TestMM::TestNode.new(:text => "child")])
619
-
620
- output = StringWriter.new
621
- serialize(testModel, TestMM, output, :command_name_provider => proc do |c|
622
- c.name + "X"
623
- end)
624
-
625
- assert_equal %Q(\
626
- TestNodeX text: "some text" {
627
- TestNodeX text: "child"
628
- }
629
- ), output
630
- end
631
-
632
- def test_file_output
633
- testModel = TestMM::TestNode.new(:text => "some text")
634
-
635
- File.open(TestOutputFile, "w") do |f|
636
- serialize(testModel, TestMM, f)
637
- end
638
-
639
- assert_equal %Q(\
640
- TestNode text: "some text"
641
- ), File.read(TestOutputFile)
642
- end
643
-
644
- def test_stringio_output
645
- testModel = TestMM::TestNode.new(:text => "some text")
646
-
647
- output = StringIO.new
648
- serialize(testModel, TestMM, output)
649
-
650
- assert_equal %Q(\
651
- TestNode text: "some text"
652
- ), output.string
653
- end
654
-
655
- #
656
- # line breaks
657
- #
658
- All_features = proc {|clazz|
659
- res = []
660
- clazz.eAllStructuralFeatures.reject{|f| f.name =~ /parent|2$/}.each{|f| res << f.name}
661
- res
662
- }
663
-
664
- def test_linebreak
665
- testModel = TestMM::TestNode.new(
666
- :text => "some text",
667
- :texts => ["some more text", "some more text", "some more text"])
668
-
669
- output = StringWriter.new
670
- serialize(testModel, TestMM, output,
671
- :newline_arguments => All_features,
672
- :newline_arrays => All_features)
673
-
674
- assert_equal %Q(\
675
- TestNode \\
676
- text: "some text",
677
- texts: [
678
- "some more text",
679
- "some more text",
680
- "some more text"
681
- ]
682
- ), output
683
- end
684
-
685
- def test_linebreak_child
686
- testModel1 = TestMM::TestNode.new(
687
- :text => "some text1",
688
- :texts => ["some more text", "some more text", "some more text"])
689
- testModel0 = TestMM::TestNode.new(
690
- :text => "some text0",
691
- :integer => 10,
692
- :childs => [testModel1])
693
-
694
- output = StringWriter.new
695
- serialize(testModel0, TestMM, output,
696
- :newline_arguments => All_features,
697
- :newline_arrays => All_features)
698
-
699
- assert_equal %Q(\
700
- TestNode \\
701
- text: "some text0",
702
- integer: 10 {
703
- TestNode \\
704
- text: "some text1",
705
- texts: [
706
- "some more text",
707
- "some more text",
708
- "some more text"
709
- ]
710
- }
711
- ), output
712
- end
713
-
714
- def test_linebreak_child_no_arguments
715
- testModel1 = TestMM::TestNode.new(
716
- :text => "some text1",
717
- :texts => ["some more text", "some more text", "some more text"])
718
- testModel0 = TestMM::TestNode.new(:childs => [testModel1])
719
-
720
- output = StringWriter.new
721
- serialize(testModel0, TestMM, output,
722
- :newline_arguments => All_features,
723
- :newline_arrays => All_features)
724
-
725
- assert_equal %Q(\
726
- TestNode {
727
- TestNode \\
728
- text: "some text1",
729
- texts: [
730
- "some more text",
731
- "some more text",
732
- "some more text"
733
- ]
734
- }
735
- ), output
736
- end
737
-
738
- def test_linebreak_unlabled_array_arguments
739
- testModel = TestMM::TestNode.new(
740
- :none => "some text",
741
- :texts => ["some more text", "some more text", "some more text"])
742
-
743
- output = StringWriter.new
744
- serialize(testModel, TestMM, output,
745
- :unlabled_arguments => proc {|clazz| ["texts"]},
746
- :newline_arguments => proc {|clazz| All_features.call(clazz) - ["texts"]},
747
- :newline_arrays => All_features)
748
-
749
- assert_equal %Q(\
750
- TestNode [
751
- "some more text",
752
- "some more text",
753
- "some more text"
754
- ],
755
- none: "some text"
756
- ), output
757
- end
758
-
759
- def test_linebreak_unlabled_array_arguments_sameline
760
- testModel = TestMM::TestNode.new(
761
- :none => "some text",
762
- :texts => ["some more text", "some more text", "some more text"])
763
-
764
- output = StringWriter.new
765
- serialize(testModel, TestMM, output,
766
- :unlabled_arguments => proc {|clazz| ["texts"]},
767
- :newline_arguments => proc {|clazz| All_features.call(clazz) - ["texts"]},
768
- :newline_arrays => proc {|clazz| All_features.call(clazz) - ["texts"]})
769
-
770
- assert_equal %Q(\
771
- TestNode ["some more text", "some more text", "some more text"],
772
- none: "some text"
773
- ), output
774
- end
775
-
776
- def test_linebreak_unlabled_both_arguments_and_child
777
- testModel1 = TestMM::TestNode.new(
778
- :texts => ["some more text", "some more text", "some more text"])
779
- testModel0 = TestMM::TestNode.new(
780
- :unlabled => "unlabled",
781
- :both => "both",
782
- :childs => [testModel1])
783
-
784
- output = StringWriter.new
785
- serialize(testModel0, TestMM, output,
786
- :unlabled_arguments => proc {|clazz| ["unlabled", "both"]},
787
- :unquoted_arguments => proc {|clazz| ["both"]},
788
- :newline_arguments => proc {|clazz| All_features.call(clazz) - ["unlabled"]},
789
- :newline_arrays => All_features)
790
-
791
- assert_equal %Q(\
792
- TestNode "unlabled",
793
- both {
794
- TestNode \\
795
- texts: [
796
- "some more text",
797
- "some more text",
798
- "some more text"
799
- ]
800
- }
801
- ), output
802
- end
803
-
804
- def test_linebreak_child_two_attributes
805
- testModel1 = TestMM::TestNode.new(
806
- :text => "some text1",
807
- :texts => ["some more text", "some more text", "some more text"],
808
- :more_texts => ["even more text", "even more text"])
809
- testModel0 = TestMM::TestNode.new(:text => "some text0", :childs => [testModel1])
810
-
811
- output = StringWriter.new
812
- serialize(testModel0, TestMM, output,
813
- :newline_arguments => proc {|clazz| All_features.call(clazz) - ["text"]},
814
- :newline_arrays => proc {|clazz| All_features.call(clazz) - ["text"]})
815
-
816
- assert_equal %Q(\
817
- TestNode text: "some text0" {
818
- TestNode text: "some text1",
819
- texts: [
820
- "some more text",
821
- "some more text",
822
- "some more text"
823
- ],
824
- more_texts: [
825
- "even more text",
826
- "even more text"
827
- ]
828
- }
829
- ), output
830
- end
831
-
832
- def test_linebreak_child_two_attributes_one_sameline
833
- testModel1 = TestMM::TestNode.new(
834
- :text => "some text1",
835
- :texts => ["some more text", "some more text", "some more text"],
836
- :more_texts => ["even more text", "even more text"])
837
- testModel0 = TestMM::TestNode.new(:text => "some text0", :childs => [testModel1])
838
-
839
- output = StringWriter.new
840
- serialize(testModel0, TestMM, output,
841
- :newline_arguments => proc {|clazz| All_features.call(clazz) - ["more_texts"]},
842
- :newline_arrays => proc {|clazz| All_features.call(clazz) - ["more_texts"]})
843
-
844
- assert_equal %Q(\
845
- TestNode \\
846
- text: "some text0" {
847
- TestNode \\
848
- text: "some text1",
849
- texts: [
850
- "some more text",
851
- "some more text",
852
- "some more text"
853
- ], more_texts: ["even more text", "even more text"]
854
- }
855
- ), output
856
- end
857
-
858
- def test_linebreak_two_children
859
- testModel2 = TestMM::TestNode.new(:text => "some text2", :texts => ["some more text"])
860
- testModel1 = TestMM::TestNode.new(:text => "some text1", :texts => ["some more text", "some more text", "some more text"])
861
- testModel0 = TestMM::TestNode.new(:text => "some text0", :childs => [testModel1, testModel2])
862
-
863
- output = StringWriter.new
864
- serialize(testModel0, TestMM, output,
865
- :newline_arguments => proc {|clazz| All_features.call(clazz) - ["text"]},
866
- :newline_arrays => All_features)
867
-
868
- assert_equal %Q(\
869
- TestNode text: "some text0" {
870
- TestNode text: "some text1",
871
- texts: [
872
- "some more text",
873
- "some more text",
874
- "some more text"
875
- ]
876
- TestNode text: "some text2",
877
- texts: "some more text"
878
- }
879
- ), output
880
- end
881
-
882
- def test_linebreak_nested_children
883
- testModel2 = TestMM::TestNode.new(
884
- :text => "some text2",
885
- :texts => ["some more text", "some more text", "some more text"])
886
- testModel1 = TestMM::TestNode.new(
887
- :text => "some text1",
888
- :childs => [testModel2])
889
- testModel0 = TestMM::TestNode.new(
890
- :text => "some text0",
891
- :integer => 10,
892
- :childs => [testModel1])
893
-
894
- output = StringWriter.new
895
- serialize(testModel0, TestMM, output,
896
- :newline_arguments => All_features,
897
- :newline_arrays => All_features)
898
-
899
- assert_equal %Q(\
900
- TestNode \\
901
- text: "some text0",
902
- integer: 10 {
903
- TestNode \\
904
- text: "some text1" {
905
- TestNode \\
906
- text: "some text2",
907
- texts: [
908
- "some more text",
909
- "some more text",
910
- "some more text"
911
- ]
912
- }
913
- }
914
- ), output
915
- end
916
-
917
- def test_linebreak_no_break
918
- testModel = TestMM::TestNode.new(:text => "some text", :texts => ["some more text", "some more text", "some more text"])
919
-
920
- output = StringWriter.new
921
- serialize(testModel, TestMM, output)
922
-
923
- assert_equal %Q(\
924
- TestNode text: "some text", texts: ["some more text", "some more text", "some more text"]
925
- ), output
926
- end
927
-
928
- def test_linebreak_child_role
929
- testModel = TestMMChildRole::TestNode.new(
930
- :child1 => TestMMChildRole::TestNode.new(:text => "child1"),
931
- :childs2 => [
932
- TestMMChildRole::TestNode.new(
933
- :text => "child2a",
934
- :texts => ["some more text", "some more text"]),
935
- TestMMChildRole::TestNode.new(
936
- :text => "child2b",
937
- :texts => ["some more text", "some more text"])
938
- ])
939
-
940
- output = StringWriter.new
941
- serialize(testModel, TestMMChildRole, output,
942
- :newline_arguments => proc {|clazz| All_features.call(clazz) - ["text"]},
943
- :newline_arrays => proc {|clazz| All_features.call(clazz) - ["text"]})
944
-
945
- assert_equal %Q(\
946
- TestNode {
947
- child1:
948
- TestNode text: "child1"
949
- childs2: [
950
- TestNode text: "child2a",
951
- texts: [
952
- "some more text",
953
- "some more text"
954
- ]
955
- TestNode text: "child2b",
956
- texts: [
957
- "some more text",
958
- "some more text"
959
- ]
960
- ]
961
- }
962
- ), output
963
- end
964
-
965
- def test_linebreak_comment
966
- testModel = TestMM::TestNode.new(
967
- :text => "some text",
968
- :comment => "this is a comment",
969
- :childs => [
970
- TestMM::TestNode.new(:comment => "\n\ncomment of a child node\n multiline\n\n\nanother\n\n\n")
971
- ])
972
-
973
- output = StringWriter.new
974
- serialize(testModel, TestMM, output,
975
- :newline_arguments => All_features,
976
- :comment_provider => proc { |e|
977
- c = e.comment
978
- e.comment = nil
979
- c
980
- })
981
-
982
- assert_equal %Q(\
983
- #this is a comment
984
- TestNode \\
985
- text: "some text" {
986
- #
987
- #
988
- #comment of a child node
989
- # multiline
990
- #
991
- #
992
- #another
993
- TestNode
994
- }
995
- ), output
996
- end
997
-
998
- module TestMMObjectAttribute
999
- extend RGen::MetamodelBuilder::ModuleExtension
1000
- class TestNode < RGen::MetamodelBuilder::MMBase
1001
- has_many_attr 'objs', Object
1002
- end
1003
- end
1004
-
1005
- def test_object_attribute
1006
- testModel = TestMMObjectAttribute::TestNode.new(
1007
- :objs => ['some text', -123, :someSymbol, true, false, -0.097, :'some other symbol'])
1008
-
1009
- output = StringWriter.new
1010
- serialize(testModel, TestMMObjectAttribute, output)
1011
-
1012
- assert_equal %Q(\
1013
- TestNode objs: ["some text", -123, someSymbol, true, false, -0.097, "some other symbol"]
1014
- ), output
1015
- end
1016
-
1017
- def serialize(model, mm, output, options={})
1018
- lang = RText::Language.new(mm.ecore, options)
1019
- ser = RText::Serializer.new(lang)
1020
- ser.serialize(model, output)
1021
- end
1022
-
1023
- end
1024
-