rtext 0.7.0 → 0.8.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +4 -0
- data/RText_Protocol +8 -0
- data/Rakefile +1 -1
- data/lib/rtext/context_builder.rb +4 -2
- data/lib/rtext/frontend/context.rb +64 -32
- data/lib/rtext/language.rb +33 -4
- data/lib/rtext/parser.rb +12 -4
- data/lib/rtext/serializer.rb +29 -6
- data/lib/rtext/tokenizer.rb +12 -2
- data/test/context_builder_test.rb +8 -0
- data/test/frontend/context_test.rb +205 -0
- data/test/instantiator_test.rb +122 -31
- data/test/integration/backend.out +12 -12
- data/test/integration/frontend.log +2699 -0
- data/test/integration/model/test_metamodel.ect +8 -2
- data/test/integration/test.rb +247 -19
- data/test/link_detector_test.rb +11 -0
- data/test/rtext_test.rb +1 -0
- data/test/serializer_test.rb +388 -0
- data/test/tokenizer_test.rb +16 -0
- metadata +11 -14
@@ -1,10 +1,16 @@
|
|
1
1
|
EPackage StatemachineMM {
|
2
2
|
EClass State, abstract: true {
|
3
3
|
EAttribute name, eType: /StatemachineMM/StringType
|
4
|
-
EReference parent,
|
4
|
+
EReference parent,
|
5
|
+
eType: /StatemachineMM/CompositeState,
|
6
|
+
eOpposite: /StatemachineMM/CompositeState/substates
|
5
7
|
}
|
6
8
|
EClass SimpleState, eSuperTypes: [/StatemachineMM/State]
|
7
|
-
EClass CompositeState,
|
9
|
+
EClass CompositeState,
|
10
|
+
eSuperTypes: [
|
11
|
+
/StatemachineMM/State
|
12
|
+
],
|
13
|
+
abstract: false {
|
8
14
|
EReference substates, upperBound: -1, containment: true, eType: /StatemachineMM/State, eOpposite: /StatemachineMM/State/parent
|
9
15
|
}
|
10
16
|
EClass Transition {
|
data/test/integration/test.rb
CHANGED
@@ -350,6 +350,160 @@ EPackage StatemachineMM {
|
|
350
350
|
]
|
351
351
|
end
|
352
352
|
|
353
|
+
def test_complete_feature_after_linebreak
|
354
|
+
setup_connector(ModelFile)
|
355
|
+
load_model
|
356
|
+
context = build_context <<-END
|
357
|
+
EPackage StatemachineMM {
|
358
|
+
EClass State, abstract: true {
|
359
|
+
EAttribute name, eType: /StatemachineMM/StringType
|
360
|
+
EReference parent,
|
361
|
+
|eType: /StatemachineMM/CompositeState,
|
362
|
+
END
|
363
|
+
assert_completions context, [
|
364
|
+
"containment:",
|
365
|
+
"resolveProxies:",
|
366
|
+
"eOpposite:",
|
367
|
+
"changeable:",
|
368
|
+
"defaultValueLiteral:",
|
369
|
+
"derived:",
|
370
|
+
"transient:",
|
371
|
+
"unsettable:",
|
372
|
+
"volatile:",
|
373
|
+
"lowerBound:",
|
374
|
+
"ordered:",
|
375
|
+
"unique:",
|
376
|
+
"upperBound:",
|
377
|
+
"eType:"
|
378
|
+
]
|
379
|
+
end
|
380
|
+
|
381
|
+
def test_complete_reference_after_linebreak
|
382
|
+
setup_connector(ModelFile)
|
383
|
+
load_model
|
384
|
+
context = build_context <<-END
|
385
|
+
EPackage StatemachineMM {
|
386
|
+
EClass State, abstract: true {
|
387
|
+
EAttribute name, eType: /StatemachineMM/StringType
|
388
|
+
EReference parent,
|
389
|
+
eType: |/StatemachineMM/CompositeState,
|
390
|
+
END
|
391
|
+
assert_completions context, [
|
392
|
+
"/StatemachineMM/CompositeState",
|
393
|
+
"/StatemachineMM/SimpleState",
|
394
|
+
"/StatemachineMM/State",
|
395
|
+
"/StatemachineMM/StringType",
|
396
|
+
"/StatemachineMM/Transition",
|
397
|
+
"/StatemachineMM2/SimpleState",
|
398
|
+
"/StatemachineMM2/State"
|
399
|
+
]
|
400
|
+
end
|
401
|
+
|
402
|
+
def test_complete_command_after_linebreak
|
403
|
+
setup_connector(ModelFile)
|
404
|
+
load_model
|
405
|
+
context = build_context <<-END
|
406
|
+
EPackage StatemachineMM {
|
407
|
+
EClass State, abstract: true {
|
408
|
+
EAttribute name, eType: /StatemachineMM/StringType
|
409
|
+
EReference parent,
|
410
|
+
eType: /StatemachineMM/CompositeState,
|
411
|
+
eOpposite: /StatemachineMM/CompositeState/substates
|
412
|
+
}
|
413
|
+
EClass SimpleState, eSuperTypes: [/StatemachineMM/State]
|
414
|
+
EClass CompositeState,
|
415
|
+
eSuperTypes: [
|
416
|
+
/StatemachineMM/State
|
417
|
+
],
|
418
|
+
abstract: false {
|
419
|
+
|EReference substates, upperBound: -1, containment: true, eType: /StatemachineMM/State, eOpposite: /StatemachineMM/State/parent
|
420
|
+
END
|
421
|
+
assert_completions context, [
|
422
|
+
"EAnnotation",
|
423
|
+
"EAttribute",
|
424
|
+
"EOperation",
|
425
|
+
"EReference",
|
426
|
+
"EStructuralFeature"
|
427
|
+
]
|
428
|
+
end
|
429
|
+
|
430
|
+
def test_complete_value_after_linebreak
|
431
|
+
setup_connector(ModelFile)
|
432
|
+
load_model
|
433
|
+
context = build_context <<-END
|
434
|
+
EPackage StatemachineMM {
|
435
|
+
EClass State, abstract: true {
|
436
|
+
EAttribute name, eType: /StatemachineMM/StringType
|
437
|
+
EReference parent,
|
438
|
+
eType: /StatemachineMM/CompositeState,
|
439
|
+
eOpposite: /StatemachineMM/CompositeState/substates
|
440
|
+
}
|
441
|
+
EClass SimpleState, eSuperTypes: [/StatemachineMM/State]
|
442
|
+
EClass CompositeState,
|
443
|
+
eSuperTypes: [
|
444
|
+
/StatemachineMM/State
|
445
|
+
],
|
446
|
+
abstract: |false {
|
447
|
+
END
|
448
|
+
assert_completions context, [
|
449
|
+
"true",
|
450
|
+
"false"
|
451
|
+
]
|
452
|
+
end
|
453
|
+
|
454
|
+
def test_complete_in_array_after_linebreak
|
455
|
+
setup_connector(ModelFile)
|
456
|
+
load_model
|
457
|
+
context = build_context <<-END
|
458
|
+
EPackage StatemachineMM {
|
459
|
+
EClass State, abstract: true {
|
460
|
+
EAttribute name, eType: /StatemachineMM/StringType
|
461
|
+
EReference parent,
|
462
|
+
eType: /StatemachineMM/CompositeState,
|
463
|
+
eOpposite: /StatemachineMM/CompositeState/substates
|
464
|
+
}
|
465
|
+
EClass SimpleState, eSuperTypes: [/StatemachineMM/State]
|
466
|
+
EClass CompositeState,
|
467
|
+
eSuperTypes: [
|
468
|
+
|/StatemachineMM/State
|
469
|
+
END
|
470
|
+
assert_completions context, [
|
471
|
+
"/StatemachineMM/CompositeState",
|
472
|
+
"/StatemachineMM/SimpleState",
|
473
|
+
"/StatemachineMM/State",
|
474
|
+
"/StatemachineMM/Transition",
|
475
|
+
"/StatemachineMM2/SimpleState",
|
476
|
+
"/StatemachineMM2/State"
|
477
|
+
]
|
478
|
+
end
|
479
|
+
|
480
|
+
def test_complete_in_array_after_linebreak2
|
481
|
+
setup_connector(ModelFile)
|
482
|
+
load_model
|
483
|
+
context = build_context <<-END
|
484
|
+
EPackage StatemachineMM {
|
485
|
+
EClass State, abstract: true {
|
486
|
+
EAttribute name, eType: /StatemachineMM/StringType
|
487
|
+
EReference parent,
|
488
|
+
eType: /StatemachineMM/CompositeState,
|
489
|
+
eOpposite: /StatemachineMM/CompositeState/substates
|
490
|
+
}
|
491
|
+
EClass SimpleState, eSuperTypes: [/StatemachineMM/State]
|
492
|
+
EClass CompositeState,
|
493
|
+
eSuperTypes: [
|
494
|
+
/StatemachineMM/State
|
495
|
+
|],
|
496
|
+
END
|
497
|
+
assert_completions context, [
|
498
|
+
"/StatemachineMM/CompositeState",
|
499
|
+
"/StatemachineMM/SimpleState",
|
500
|
+
"/StatemachineMM/State",
|
501
|
+
"/StatemachineMM/Transition",
|
502
|
+
"/StatemachineMM2/SimpleState",
|
503
|
+
"/StatemachineMM2/State"
|
504
|
+
]
|
505
|
+
end
|
506
|
+
|
353
507
|
def test_reference_completion
|
354
508
|
setup_connector(ModelFile)
|
355
509
|
load_model
|
@@ -418,7 +572,9 @@ def test_reference_completion_in_array
|
|
418
572
|
EPackage StatemachineMM {
|
419
573
|
EClass State, abstract: true {
|
420
574
|
EAttribute name, eType: /StatemachineMM/StringType
|
421
|
-
EReference parent,
|
575
|
+
EReference parent,
|
576
|
+
eType: /StatemachineMM/CompositeState,
|
577
|
+
eOpposite: /StatemachineMM/CompositeState/substates
|
422
578
|
}
|
423
579
|
EClass SimpleState, eSuperTypes: [|/StatemachineMM/State]
|
424
580
|
END
|
@@ -434,7 +590,9 @@ EPackage StatemachineMM {
|
|
434
590
|
EPackage StatemachineMM {
|
435
591
|
EClass State, abstract: true {
|
436
592
|
EAttribute name, eType: /StatemachineMM/StringType
|
437
|
-
EReference parent,
|
593
|
+
EReference parent,
|
594
|
+
eType: /StatemachineMM/CompositeState,
|
595
|
+
eOpposite: /StatemachineMM/CompositeState/substates
|
438
596
|
}
|
439
597
|
EClass SimpleState, eSuperTypes: [/StatemachineMM/S|tate]
|
440
598
|
END
|
@@ -450,7 +608,9 @@ EPackage StatemachineMM {
|
|
450
608
|
EPackage StatemachineMM {
|
451
609
|
EClass State, abstract: true {
|
452
610
|
EAttribute name, eType: /StatemachineMM/StringType
|
453
|
-
EReference parent,
|
611
|
+
EReference parent,
|
612
|
+
eType: /StatemachineMM/CompositeState,
|
613
|
+
eOpposite: /StatemachineMM/CompositeState/substates
|
454
614
|
}
|
455
615
|
EClass SimpleState, eSuperTypes: [/StatemachineMM/State|]
|
456
616
|
END
|
@@ -466,7 +626,9 @@ EPackage StatemachineMM {
|
|
466
626
|
EPackage StatemachineMM {
|
467
627
|
EClass State, abstract: true {
|
468
628
|
EAttribute name, eType: /StatemachineMM/StringType
|
469
|
-
EReference parent,
|
629
|
+
EReference parent,
|
630
|
+
eType: /StatemachineMM/CompositeState,
|
631
|
+
eOpposite: /StatemachineMM/CompositeState/substates
|
470
632
|
}
|
471
633
|
EClass SimpleState, eSuperTypes: [/StatemachineMM/State]|
|
472
634
|
END
|
@@ -481,10 +643,16 @@ def test_integer_completion
|
|
481
643
|
EPackage StatemachineMM {
|
482
644
|
EClass State, abstract: true {
|
483
645
|
EAttribute name, eType: /StatemachineMM/StringType
|
484
|
-
EReference parent,
|
646
|
+
EReference parent,
|
647
|
+
eType: /StatemachineMM/CompositeState,
|
648
|
+
eOpposite: /StatemachineMM/CompositeState/substates
|
485
649
|
}
|
486
650
|
EClass SimpleState, eSuperTypes: [/StatemachineMM/State]
|
487
|
-
EClass CompositeState,
|
651
|
+
EClass CompositeState,
|
652
|
+
eSuperTypes: [
|
653
|
+
/StatemachineMM/State
|
654
|
+
],
|
655
|
+
abstract: false {
|
488
656
|
EReference substates, upperBound: |-1, containment: true, eType: /StatemachineMM/State, eOpposite: /StatemachineMM/State/parent
|
489
657
|
END
|
490
658
|
assert_completions context, [
|
@@ -494,10 +662,16 @@ EPackage StatemachineMM {
|
|
494
662
|
EPackage StatemachineMM {
|
495
663
|
EClass State, abstract: true {
|
496
664
|
EAttribute name, eType: /StatemachineMM/StringType
|
497
|
-
EReference parent,
|
665
|
+
EReference parent,
|
666
|
+
eType: /StatemachineMM/CompositeState,
|
667
|
+
eOpposite: /StatemachineMM/CompositeState/substates
|
498
668
|
}
|
499
669
|
EClass SimpleState, eSuperTypes: [/StatemachineMM/State]
|
500
|
-
EClass CompositeState,
|
670
|
+
EClass CompositeState,
|
671
|
+
eSuperTypes: [
|
672
|
+
/StatemachineMM/State
|
673
|
+
],
|
674
|
+
abstract: false {
|
501
675
|
EReference substates, upperBound: -1|, containment: true, eType: /StatemachineMM/State, eOpposite: /StatemachineMM/State/parent
|
502
676
|
END
|
503
677
|
assert_completions context, [
|
@@ -515,7 +689,7 @@ EPackage StatemachineMM {
|
|
515
689
|
END
|
516
690
|
assert_link_targets context, :begin => 29, :end => 54, :targets => [
|
517
691
|
{"file"=> File.expand_path(@infile),
|
518
|
-
"line"=>
|
692
|
+
"line"=>20,
|
519
693
|
"display"=>"/StatemachineMM/StringType [EDataType]"}
|
520
694
|
]
|
521
695
|
context = build_context <<-END
|
@@ -525,7 +699,7 @@ EPackage StatemachineMM {
|
|
525
699
|
END
|
526
700
|
assert_link_targets context, :begin => 29, :end => 54, :targets => [
|
527
701
|
{"file"=> File.expand_path(@infile),
|
528
|
-
"line"=>
|
702
|
+
"line"=>20,
|
529
703
|
"display"=>"/StatemachineMM/StringType [EDataType]"}
|
530
704
|
]
|
531
705
|
context = build_context <<-END
|
@@ -535,7 +709,7 @@ EPackage StatemachineMM {
|
|
535
709
|
END
|
536
710
|
assert_link_targets context, :begin => 29, :end => 54, :targets => [
|
537
711
|
{"file"=> File.expand_path(@infile),
|
538
|
-
"line"=>
|
712
|
+
"line"=>20,
|
539
713
|
"display"=>"/StatemachineMM/StringType [EDataType]"}
|
540
714
|
]
|
541
715
|
context = build_context <<-END
|
@@ -557,17 +731,19 @@ EPackage StatemachineMM {
|
|
557
731
|
END
|
558
732
|
assert_link_targets context, :begin => 3, :end => 8, :targets => [
|
559
733
|
{"file"=> File.expand_path(@infile),
|
560
|
-
"line"=>
|
734
|
+
"line"=>8,
|
561
735
|
"display"=>"/StatemachineMM/SimpleState [EClass]"},
|
562
736
|
{"file"=> File.expand_path(@infile),
|
563
|
-
"line"=>
|
737
|
+
"line"=>9,
|
564
738
|
"display"=>"/StatemachineMM/CompositeState [EClass]"}
|
565
739
|
]
|
566
740
|
context = build_context <<-END
|
567
741
|
EPackage StatemachineMM {
|
568
742
|
EClass State, abstract: true {
|
569
743
|
EAttribute name, eType: /StatemachineMM/StringType
|
570
|
-
EReference parent,
|
744
|
+
EReference parent,
|
745
|
+
eType: /StatemachineMM/CompositeState,
|
746
|
+
eOpposite: /StatemachineMM/CompositeState/substates
|
571
747
|
}
|
572
748
|
|EClass SimpleState, eSuperTypes: [/StatemachineMM/State]
|
573
749
|
END
|
@@ -594,6 +770,58 @@ EPackage StatemachineMM2 {
|
|
594
770
|
]
|
595
771
|
end
|
596
772
|
|
773
|
+
def test_link_targets_after_linebreak
|
774
|
+
setup_connector(ModelFile)
|
775
|
+
load_model
|
776
|
+
context = build_context <<-END
|
777
|
+
EPackage StatemachineMM {
|
778
|
+
EClass State, abstract: true {
|
779
|
+
EAttribute name, eType: /StatemachineMM/StringType
|
780
|
+
EReference parent,
|
781
|
+
eType: /St|atemachineMM/CompositeState,
|
782
|
+
END
|
783
|
+
# in case of linebreaks, the begin and end column refer to the string which
|
784
|
+
# was passed to the backend as the context; in this case the context extractor
|
785
|
+
# appends each broken line to the previous line with all the leading whitespace removed
|
786
|
+
assert_link_targets context, :begin => 30, :end => 59, :targets => [
|
787
|
+
{"file"=> File.expand_path(@infile),
|
788
|
+
"line"=>9,
|
789
|
+
"display"=>"/StatemachineMM/CompositeState [EClass]"}
|
790
|
+
]
|
791
|
+
context = build_context <<-END
|
792
|
+
EPackage StatemachineMM {
|
793
|
+
EClass State, abstract: true {
|
794
|
+
EAttribute name, eType: /StatemachineMM/StringType
|
795
|
+
EReference parent,
|
796
|
+
eType: |/StatemachineMM/CompositeState,
|
797
|
+
END
|
798
|
+
assert_link_targets context, :begin => 30, :end => 59, :targets => [
|
799
|
+
{"file"=> File.expand_path(@infile),
|
800
|
+
"line"=>9,
|
801
|
+
"display"=>"/StatemachineMM/CompositeState [EClass]"}
|
802
|
+
]
|
803
|
+
context = build_context <<-END
|
804
|
+
EPackage StatemachineMM {
|
805
|
+
EClass State, abstract: true {
|
806
|
+
EAttribute name, eType: /StatemachineMM/StringType
|
807
|
+
EReference parent,
|
808
|
+
eType: /StatemachineMM/CompositeStat|e,
|
809
|
+
END
|
810
|
+
assert_link_targets context, :begin => 30, :end => 59, :targets => [
|
811
|
+
{"file"=> File.expand_path(@infile),
|
812
|
+
"line"=>9,
|
813
|
+
"display"=>"/StatemachineMM/CompositeState [EClass]"}
|
814
|
+
]
|
815
|
+
context = build_context <<-END
|
816
|
+
EPackage StatemachineMM {
|
817
|
+
EClass State, abstract: true {
|
818
|
+
EAttribute name, eType: /StatemachineMM/StringType
|
819
|
+
EReference parent,
|
820
|
+
eType: /StatemachineMM/CompositeState|,
|
821
|
+
END
|
822
|
+
assert_link_targets context, :begin => nil, :end => nil, :targets => []
|
823
|
+
end
|
824
|
+
|
597
825
|
def test_find_elements
|
598
826
|
setup_connector(ModelFile)
|
599
827
|
load_model
|
@@ -617,7 +845,7 @@ def test_find_elements
|
|
617
845
|
assert_equal \
|
618
846
|
[{"display"=>"target [EReference] - /StatemachineMM/Transition",
|
619
847
|
"file"=> File.expand_path(@infile),
|
620
|
-
"line"=>
|
848
|
+
"line"=>17}], response["elements"]
|
621
849
|
response = @con.execute_command(
|
622
850
|
{"command" => "find_elements", "search_pattern" => ""})
|
623
851
|
assert_equal [], response["elements"]
|
@@ -654,9 +882,9 @@ def assert_link_targets(context, options)
|
|
654
882
|
infile = options[:file] || @infile
|
655
883
|
content = File.open(infile, "rb") {|f| f.read}
|
656
884
|
lines = content.split(/\r?\n/)[0..context.line-1]
|
657
|
-
lines = RText::Frontend::Context.extract(lines)
|
885
|
+
lines, col = RText::Frontend::Context.new.extract(lines, context.col)
|
658
886
|
response = @con.execute_command(
|
659
|
-
{"command" => "link_targets", "context" => lines, "column" =>
|
887
|
+
{"command" => "link_targets", "context" => lines, "column" => col})
|
660
888
|
assert_equal "response", response["type"]
|
661
889
|
assert_equal options[:targets], response["targets"]
|
662
890
|
assert_equal options[:begin], response["begin_column"]
|
@@ -666,9 +894,9 @@ end
|
|
666
894
|
def assert_completions(context, expected)
|
667
895
|
content = File.open(@infile, "rb"){|f| f.read}
|
668
896
|
lines = content.split(/\r?\n/)[0..context.line-1]
|
669
|
-
lines = RText::Frontend::Context.extract(lines)
|
897
|
+
lines, col = RText::Frontend::Context.new.extract(lines, context.col)
|
670
898
|
response = @con.execute_command(
|
671
|
-
{"command" => "content_complete", "context" => lines, "column" =>
|
899
|
+
{"command" => "content_complete", "context" => lines, "column" => col})
|
672
900
|
assert_equal expected, response["options"].collect{|o| o["insert"]}
|
673
901
|
end
|
674
902
|
|
data/test/link_detector_test.rb
CHANGED
@@ -189,6 +189,14 @@ TestNode |SomeNode
|
|
189
189
|
assert_link_desc ld, :element => "TestNode", :feature => "name", :index => 0, :backward => true, :value => "SomeNode", :scol => 10, :ecol => 17
|
190
190
|
end
|
191
191
|
|
192
|
+
def test_command_and_name_curly_no_ws
|
193
|
+
ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
|
194
|
+
TestNode Some|Node{
|
195
|
+
END
|
196
|
+
)
|
197
|
+
assert_link_desc ld, :element => "TestNode", :element_name => "SomeNode", :feature => "name", :index => 0, :backward => true, :value => "SomeNode", :scol => 10, :ecol => 17
|
198
|
+
end
|
199
|
+
|
192
200
|
def test_child_within_command
|
193
201
|
ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
|
194
202
|
TestNode SomeNode {
|
@@ -256,6 +264,9 @@ def assert_link_desc(ld, options)
|
|
256
264
|
else
|
257
265
|
assert_nil ld.element
|
258
266
|
end
|
267
|
+
if options[:element_name]
|
268
|
+
assert_equal options[:element_name], ld.element.name
|
269
|
+
end
|
259
270
|
if options[:feature]
|
260
271
|
assert_equal options[:feature], ld.feature.name
|
261
272
|
else
|
data/test/rtext_test.rb
CHANGED
data/test/serializer_test.rb
CHANGED
@@ -27,6 +27,12 @@ class SerializerTest < Test::Unit::TestCase
|
|
27
27
|
class TestNode < RGen::MetamodelBuilder::MMBase
|
28
28
|
has_attr 'text', String
|
29
29
|
has_many_attr 'texts', String
|
30
|
+
has_many_attr 'more_texts', String
|
31
|
+
has_attr 'unlabled', String
|
32
|
+
has_attr 'unquoted', String
|
33
|
+
has_attr 'both', String
|
34
|
+
has_attr 'none', String
|
35
|
+
has_attr 'comment', String
|
30
36
|
has_attr 'integer', Integer
|
31
37
|
has_attr 'float', Float
|
32
38
|
has_attr 'enum', SomeEnum
|
@@ -297,6 +303,25 @@ TestNode name: "Target2"
|
|
297
303
|
),output
|
298
304
|
end
|
299
305
|
|
306
|
+
def test_identifier_provider_nil
|
307
|
+
testModel = [
|
308
|
+
TestMMRef::TestNode.new(:name => "Source"),
|
309
|
+
TestMMRef::TestNode.new(:name => "Target")]
|
310
|
+
testModel[0].refOne = testModel[1]
|
311
|
+
|
312
|
+
output = StringWriter.new
|
313
|
+
serialize(testModel, TestMMRef, output,
|
314
|
+
:identifier_provider => proc{|e, context, feature, index|
|
315
|
+
nil
|
316
|
+
}
|
317
|
+
)
|
318
|
+
|
319
|
+
assert_equal %Q(\
|
320
|
+
TestNode name: "Source"
|
321
|
+
TestNode name: "Target"
|
322
|
+
),output
|
323
|
+
end
|
324
|
+
|
300
325
|
def test_references
|
301
326
|
testModel = [
|
302
327
|
TestMMRef::TestNode.new(:name => "Source"),
|
@@ -349,6 +374,7 @@ TestNode name: "Target" {
|
|
349
374
|
end
|
350
375
|
class TestNode < RGen::MetamodelBuilder::MMBase
|
351
376
|
has_attr 'text', String
|
377
|
+
has_many_attr 'texts', String
|
352
378
|
contains_one 'child1', TestNode, 'parent1'
|
353
379
|
contains_many 'childs2', TestNode, 'parent2'
|
354
380
|
contains_one 'child3', TestNodeA, 'parent3'
|
@@ -450,6 +476,13 @@ TestNode1 text: "some text" {
|
|
450
476
|
assert_equal %q(TestNode integer: 7)+"\n", output
|
451
477
|
end
|
452
478
|
|
479
|
+
def test_integer_big
|
480
|
+
testModel = TestMM::TestNode.new(:integer => 12345678901234567890)
|
481
|
+
output = StringWriter.new
|
482
|
+
serialize(testModel, TestMM, output)
|
483
|
+
assert_equal %q(TestNode integer: 12345678901234567890)+"\n", output
|
484
|
+
end
|
485
|
+
|
453
486
|
def test_integer_format_spec
|
454
487
|
testModel = TestMM::TestNode.new(:integer => 10)
|
455
488
|
output = StringWriter.new
|
@@ -462,6 +495,18 @@ TestNode1 text: "some text" {
|
|
462
495
|
assert_equal %q(TestNode integer: 0x0A)+"\n", output
|
463
496
|
end
|
464
497
|
|
498
|
+
def test_integer_format_spec_big
|
499
|
+
testModel = TestMM::TestNode.new(:integer => 0xabcdefabcdefabcdef)
|
500
|
+
output = StringWriter.new
|
501
|
+
serialize(testModel, TestMM, output, :argument_format_provider => proc {|a|
|
502
|
+
if a.name == "integer"
|
503
|
+
"0x%x"
|
504
|
+
else
|
505
|
+
nil
|
506
|
+
end})
|
507
|
+
assert_equal %q(TestNode integer: 0xabcdefabcdefabcdef)+"\n", output
|
508
|
+
end
|
509
|
+
|
465
510
|
def test_float
|
466
511
|
testModel = TestMM::TestNode.new(:float => 1.23)
|
467
512
|
output = StringWriter.new
|
@@ -606,6 +651,349 @@ TestNode text: "some text"
|
|
606
651
|
), output.string
|
607
652
|
end
|
608
653
|
|
654
|
+
#
|
655
|
+
# line breaks
|
656
|
+
#
|
657
|
+
All_features = proc {|clazz|
|
658
|
+
res = []
|
659
|
+
clazz.eAllStructuralFeatures.reject{|f| f.name =~ /parent|2$/}.each{|f| res << f.name}
|
660
|
+
res
|
661
|
+
}
|
662
|
+
|
663
|
+
def test_linebreak
|
664
|
+
testModel = TestMM::TestNode.new(
|
665
|
+
:text => "some text",
|
666
|
+
:texts => ["some more text", "some more text", "some more text"])
|
667
|
+
|
668
|
+
output = StringWriter.new
|
669
|
+
serialize(testModel, TestMM, output,
|
670
|
+
:newline_arguments => All_features,
|
671
|
+
:newline_arrays => All_features)
|
672
|
+
|
673
|
+
assert_equal %Q(\
|
674
|
+
TestNode \\
|
675
|
+
text: "some text",
|
676
|
+
texts: [
|
677
|
+
"some more text",
|
678
|
+
"some more text",
|
679
|
+
"some more text"
|
680
|
+
]
|
681
|
+
), output
|
682
|
+
end
|
683
|
+
|
684
|
+
def test_linebreak_child
|
685
|
+
testModel1 = TestMM::TestNode.new(
|
686
|
+
:text => "some text1",
|
687
|
+
:texts => ["some more text", "some more text", "some more text"])
|
688
|
+
testModel0 = TestMM::TestNode.new(
|
689
|
+
:text => "some text0",
|
690
|
+
:integer => 10,
|
691
|
+
:childs => [testModel1])
|
692
|
+
|
693
|
+
output = StringWriter.new
|
694
|
+
serialize(testModel0, TestMM, output,
|
695
|
+
:newline_arguments => All_features,
|
696
|
+
:newline_arrays => All_features)
|
697
|
+
|
698
|
+
assert_equal %Q(\
|
699
|
+
TestNode \\
|
700
|
+
text: "some text0",
|
701
|
+
integer: 10 {
|
702
|
+
TestNode \\
|
703
|
+
text: "some text1",
|
704
|
+
texts: [
|
705
|
+
"some more text",
|
706
|
+
"some more text",
|
707
|
+
"some more text"
|
708
|
+
]
|
709
|
+
}
|
710
|
+
), output
|
711
|
+
end
|
712
|
+
|
713
|
+
def test_linebreak_child_no_arguments
|
714
|
+
testModel1 = TestMM::TestNode.new(
|
715
|
+
:text => "some text1",
|
716
|
+
:texts => ["some more text", "some more text", "some more text"])
|
717
|
+
testModel0 = TestMM::TestNode.new(:childs => [testModel1])
|
718
|
+
|
719
|
+
output = StringWriter.new
|
720
|
+
serialize(testModel0, TestMM, output,
|
721
|
+
:newline_arguments => All_features,
|
722
|
+
:newline_arrays => All_features)
|
723
|
+
|
724
|
+
assert_equal %Q(\
|
725
|
+
TestNode {
|
726
|
+
TestNode \\
|
727
|
+
text: "some text1",
|
728
|
+
texts: [
|
729
|
+
"some more text",
|
730
|
+
"some more text",
|
731
|
+
"some more text"
|
732
|
+
]
|
733
|
+
}
|
734
|
+
), output
|
735
|
+
end
|
736
|
+
|
737
|
+
def test_linebreak_unlabled_array_arguments
|
738
|
+
testModel = TestMM::TestNode.new(
|
739
|
+
:none => "some text",
|
740
|
+
:texts => ["some more text", "some more text", "some more text"])
|
741
|
+
|
742
|
+
output = StringWriter.new
|
743
|
+
serialize(testModel, TestMM, output,
|
744
|
+
:unlabled_arguments => proc {|clazz| ["texts"]},
|
745
|
+
:newline_arguments => proc {|clazz| All_features.call(clazz) - ["texts"]},
|
746
|
+
:newline_arrays => All_features)
|
747
|
+
|
748
|
+
assert_equal %Q(\
|
749
|
+
TestNode [
|
750
|
+
"some more text",
|
751
|
+
"some more text",
|
752
|
+
"some more text"
|
753
|
+
],
|
754
|
+
none: "some text"
|
755
|
+
), output
|
756
|
+
end
|
757
|
+
|
758
|
+
def test_linebreak_unlabled_array_arguments_sameline
|
759
|
+
testModel = TestMM::TestNode.new(
|
760
|
+
:none => "some text",
|
761
|
+
:texts => ["some more text", "some more text", "some more text"])
|
762
|
+
|
763
|
+
output = StringWriter.new
|
764
|
+
serialize(testModel, TestMM, output,
|
765
|
+
:unlabled_arguments => proc {|clazz| ["texts"]},
|
766
|
+
:newline_arguments => proc {|clazz| All_features.call(clazz) - ["texts"]},
|
767
|
+
:newline_arrays => proc {|clazz| All_features.call(clazz) - ["texts"]})
|
768
|
+
|
769
|
+
assert_equal %Q(\
|
770
|
+
TestNode ["some more text", "some more text", "some more text"],
|
771
|
+
none: "some text"
|
772
|
+
), output
|
773
|
+
end
|
774
|
+
|
775
|
+
def test_linebreak_unlabled_both_arguments_and_child
|
776
|
+
testModel1 = TestMM::TestNode.new(
|
777
|
+
:texts => ["some more text", "some more text", "some more text"])
|
778
|
+
testModel0 = TestMM::TestNode.new(
|
779
|
+
:unlabled => "unlabled",
|
780
|
+
:both => "both",
|
781
|
+
:childs => [testModel1])
|
782
|
+
|
783
|
+
output = StringWriter.new
|
784
|
+
serialize(testModel0, TestMM, output,
|
785
|
+
:unlabled_arguments => proc {|clazz| ["unlabled", "both"]},
|
786
|
+
:unquoted_arguments => proc {|clazz| ["both"]},
|
787
|
+
:newline_arguments => proc {|clazz| All_features.call(clazz) - ["unlabled"]},
|
788
|
+
:newline_arrays => All_features)
|
789
|
+
|
790
|
+
assert_equal %Q(\
|
791
|
+
TestNode "unlabled",
|
792
|
+
both {
|
793
|
+
TestNode \\
|
794
|
+
texts: [
|
795
|
+
"some more text",
|
796
|
+
"some more text",
|
797
|
+
"some more text"
|
798
|
+
]
|
799
|
+
}
|
800
|
+
), output
|
801
|
+
end
|
802
|
+
|
803
|
+
def test_linebreak_child_two_attributes
|
804
|
+
testModel1 = TestMM::TestNode.new(
|
805
|
+
:text => "some text1",
|
806
|
+
:texts => ["some more text", "some more text", "some more text"],
|
807
|
+
:more_texts => ["even more text", "even more text"])
|
808
|
+
testModel0 = TestMM::TestNode.new(:text => "some text0", :childs => [testModel1])
|
809
|
+
|
810
|
+
output = StringWriter.new
|
811
|
+
serialize(testModel0, TestMM, output,
|
812
|
+
:newline_arguments => proc {|clazz| All_features.call(clazz) - ["text"]},
|
813
|
+
:newline_arrays => proc {|clazz| All_features.call(clazz) - ["text"]})
|
814
|
+
|
815
|
+
assert_equal %Q(\
|
816
|
+
TestNode text: "some text0" {
|
817
|
+
TestNode text: "some text1",
|
818
|
+
texts: [
|
819
|
+
"some more text",
|
820
|
+
"some more text",
|
821
|
+
"some more text"
|
822
|
+
],
|
823
|
+
more_texts: [
|
824
|
+
"even more text",
|
825
|
+
"even more text"
|
826
|
+
]
|
827
|
+
}
|
828
|
+
), output
|
829
|
+
end
|
830
|
+
|
831
|
+
def test_linebreak_child_two_attributes_one_sameline
|
832
|
+
testModel1 = TestMM::TestNode.new(
|
833
|
+
:text => "some text1",
|
834
|
+
:texts => ["some more text", "some more text", "some more text"],
|
835
|
+
:more_texts => ["even more text", "even more text"])
|
836
|
+
testModel0 = TestMM::TestNode.new(:text => "some text0", :childs => [testModel1])
|
837
|
+
|
838
|
+
output = StringWriter.new
|
839
|
+
serialize(testModel0, TestMM, output,
|
840
|
+
:newline_arguments => proc {|clazz| All_features.call(clazz) - ["more_texts"]},
|
841
|
+
:newline_arrays => proc {|clazz| All_features.call(clazz) - ["more_texts"]})
|
842
|
+
|
843
|
+
assert_equal %Q(\
|
844
|
+
TestNode \\
|
845
|
+
text: "some text0" {
|
846
|
+
TestNode \\
|
847
|
+
text: "some text1",
|
848
|
+
texts: [
|
849
|
+
"some more text",
|
850
|
+
"some more text",
|
851
|
+
"some more text"
|
852
|
+
], more_texts: ["even more text", "even more text"]
|
853
|
+
}
|
854
|
+
), output
|
855
|
+
end
|
856
|
+
|
857
|
+
def test_linebreak_two_children
|
858
|
+
testModel2 = TestMM::TestNode.new(:text => "some text2", :texts => ["some more text"])
|
859
|
+
testModel1 = TestMM::TestNode.new(:text => "some text1", :texts => ["some more text", "some more text", "some more text"])
|
860
|
+
testModel0 = TestMM::TestNode.new(:text => "some text0", :childs => [testModel1, testModel2])
|
861
|
+
|
862
|
+
output = StringWriter.new
|
863
|
+
serialize(testModel0, TestMM, output,
|
864
|
+
:newline_arguments => proc {|clazz| All_features.call(clazz) - ["text"]},
|
865
|
+
:newline_arrays => All_features)
|
866
|
+
|
867
|
+
assert_equal %Q(\
|
868
|
+
TestNode text: "some text0" {
|
869
|
+
TestNode text: "some text1",
|
870
|
+
texts: [
|
871
|
+
"some more text",
|
872
|
+
"some more text",
|
873
|
+
"some more text"
|
874
|
+
]
|
875
|
+
TestNode text: "some text2",
|
876
|
+
texts: "some more text"
|
877
|
+
}
|
878
|
+
), output
|
879
|
+
end
|
880
|
+
|
881
|
+
def test_linebreak_nested_children
|
882
|
+
testModel2 = TestMM::TestNode.new(
|
883
|
+
:text => "some text2",
|
884
|
+
:texts => ["some more text", "some more text", "some more text"])
|
885
|
+
testModel1 = TestMM::TestNode.new(
|
886
|
+
:text => "some text1",
|
887
|
+
:childs => [testModel2])
|
888
|
+
testModel0 = TestMM::TestNode.new(
|
889
|
+
:text => "some text0",
|
890
|
+
:integer => 10,
|
891
|
+
:childs => [testModel1])
|
892
|
+
|
893
|
+
output = StringWriter.new
|
894
|
+
serialize(testModel0, TestMM, output,
|
895
|
+
:newline_arguments => All_features,
|
896
|
+
:newline_arrays => All_features)
|
897
|
+
|
898
|
+
assert_equal %Q(\
|
899
|
+
TestNode \\
|
900
|
+
text: "some text0",
|
901
|
+
integer: 10 {
|
902
|
+
TestNode \\
|
903
|
+
text: "some text1" {
|
904
|
+
TestNode \\
|
905
|
+
text: "some text2",
|
906
|
+
texts: [
|
907
|
+
"some more text",
|
908
|
+
"some more text",
|
909
|
+
"some more text"
|
910
|
+
]
|
911
|
+
}
|
912
|
+
}
|
913
|
+
), output
|
914
|
+
end
|
915
|
+
|
916
|
+
def test_linebreak_no_break
|
917
|
+
testModel = TestMM::TestNode.new(:text => "some text", :texts => ["some more text", "some more text", "some more text"])
|
918
|
+
|
919
|
+
output = StringWriter.new
|
920
|
+
serialize(testModel, TestMM, output)
|
921
|
+
|
922
|
+
assert_equal %Q(\
|
923
|
+
TestNode text: "some text", texts: ["some more text", "some more text", "some more text"]
|
924
|
+
), output
|
925
|
+
end
|
926
|
+
|
927
|
+
def test_linebreak_child_role
|
928
|
+
testModel = TestMMChildRole::TestNode.new(
|
929
|
+
:child1 => TestMMChildRole::TestNode.new(:text => "child1"),
|
930
|
+
:childs2 => [
|
931
|
+
TestMMChildRole::TestNode.new(
|
932
|
+
:text => "child2a",
|
933
|
+
:texts => ["some more text", "some more text"]),
|
934
|
+
TestMMChildRole::TestNode.new(
|
935
|
+
:text => "child2b",
|
936
|
+
:texts => ["some more text", "some more text"])
|
937
|
+
])
|
938
|
+
|
939
|
+
output = StringWriter.new
|
940
|
+
serialize(testModel, TestMMChildRole, output,
|
941
|
+
:newline_arguments => proc {|clazz| All_features.call(clazz) - ["text"]},
|
942
|
+
:newline_arrays => proc {|clazz| All_features.call(clazz) - ["text"]})
|
943
|
+
|
944
|
+
assert_equal %Q(\
|
945
|
+
TestNode {
|
946
|
+
child1:
|
947
|
+
TestNode text: "child1"
|
948
|
+
childs2: [
|
949
|
+
TestNode text: "child2a",
|
950
|
+
texts: [
|
951
|
+
"some more text",
|
952
|
+
"some more text"
|
953
|
+
]
|
954
|
+
TestNode text: "child2b",
|
955
|
+
texts: [
|
956
|
+
"some more text",
|
957
|
+
"some more text"
|
958
|
+
]
|
959
|
+
]
|
960
|
+
}
|
961
|
+
), output
|
962
|
+
end
|
963
|
+
|
964
|
+
def test_linebreak_comment
|
965
|
+
testModel = TestMM::TestNode.new(
|
966
|
+
:text => "some text",
|
967
|
+
:comment => "this is a comment",
|
968
|
+
:childs => [
|
969
|
+
TestMM::TestNode.new(:comment => "\n\ncomment of a child node\n multiline\n\n\nanother\n\n\n")
|
970
|
+
])
|
971
|
+
|
972
|
+
output = StringWriter.new
|
973
|
+
serialize(testModel, TestMM, output,
|
974
|
+
:newline_arguments => All_features,
|
975
|
+
:comment_provider => proc { |e|
|
976
|
+
c = e.comment
|
977
|
+
e.comment = nil
|
978
|
+
c
|
979
|
+
})
|
980
|
+
|
981
|
+
assert_equal %Q(\
|
982
|
+
#this is a comment
|
983
|
+
TestNode \\
|
984
|
+
text: "some text" {
|
985
|
+
#
|
986
|
+
#
|
987
|
+
#comment of a child node
|
988
|
+
# multiline
|
989
|
+
#
|
990
|
+
#
|
991
|
+
#another
|
992
|
+
TestNode
|
993
|
+
}
|
994
|
+
), output
|
995
|
+
end
|
996
|
+
|
609
997
|
def serialize(model, mm, output, options={})
|
610
998
|
lang = RText::Language.new(mm.ecore, options)
|
611
999
|
ser = RText::Serializer.new(lang)
|