rgen 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +20 -1
- data/MIT-LICENSE +1 -1
- data/README +12 -9
- data/lib/instantiators/ea_instantiator.rb +36 -0
- data/lib/metamodels/uml13_metamodel.rb +559 -0
- data/lib/metamodels/uml13_metamodel_ext.rb +26 -0
- data/lib/mmgen/metamodel_generator.rb +5 -5
- data/lib/mmgen/mm_ext/ecore_ext.rb +95 -0
- data/lib/mmgen/mmgen.rb +6 -4
- data/lib/mmgen/templates/annotations.tpl +37 -0
- data/lib/mmgen/templates/metamodel_generator.tpl +171 -0
- data/lib/rgen/ecore/ecore.rb +190 -0
- data/lib/rgen/ecore/ecore_instantiator.rb +25 -0
- data/lib/rgen/ecore/ecore_transformer.rb +85 -0
- data/lib/rgen/environment.rb +9 -24
- data/lib/rgen/find_helper.rb +68 -0
- data/lib/rgen/{instantiator.rb → instantiator/abstract_instantiator.rb} +6 -2
- data/lib/rgen/instantiator/abstract_xml_instantiator.rb +59 -0
- data/lib/rgen/instantiator/default_xml_instantiator.rb +117 -0
- data/lib/rgen/instantiator/ecore_xml_instantiator.rb +144 -0
- data/lib/rgen/instantiator/nodebased_xml_instantiator.rb +157 -0
- data/lib/rgen/instantiator/xmi11_instantiator.rb +164 -0
- data/lib/rgen/metamodel_builder.rb +103 -9
- data/lib/rgen/metamodel_builder/build_helper.rb +26 -4
- data/lib/rgen/metamodel_builder/builder_extensions.rb +285 -88
- data/lib/rgen/metamodel_builder/builder_runtime.rb +7 -1
- data/lib/rgen/metamodel_builder/data_types.rb +67 -0
- data/lib/rgen/metamodel_builder/intermediate/annotation.rb +30 -0
- data/lib/rgen/metamodel_builder/metamodel_description.rb +232 -0
- data/lib/rgen/metamodel_builder/mm_multiple.rb +23 -0
- data/lib/rgen/metamodel_builder/module_extension.rb +33 -0
- data/lib/rgen/model_comparator.rb +56 -0
- data/lib/rgen/model_dumper.rb +5 -5
- data/lib/rgen/name_helper.rb +17 -1
- data/lib/rgen/template_language.rb +148 -28
- data/lib/rgen/template_language/directory_template_container.rb +56 -38
- data/lib/rgen/template_language/output_handler.rb +93 -77
- data/lib/rgen/template_language/template_container.rb +186 -143
- data/lib/rgen/transformer.rb +19 -14
- data/lib/transformers/uml13_to_ecore.rb +75 -0
- data/redist/xmlscan/ChangeLog +1301 -0
- data/redist/xmlscan/README +34 -0
- data/redist/xmlscan/THANKS +11 -0
- data/redist/xmlscan/doc/changes.html +74 -0
- data/redist/xmlscan/doc/changes.rd +80 -0
- data/redist/xmlscan/doc/en/conformance.html +136 -0
- data/redist/xmlscan/doc/en/conformance.rd +152 -0
- data/redist/xmlscan/doc/en/manual.html +356 -0
- data/redist/xmlscan/doc/en/manual.rd +402 -0
- data/redist/xmlscan/doc/ja/conformance.ja.html +118 -0
- data/redist/xmlscan/doc/ja/conformance.ja.rd +134 -0
- data/redist/xmlscan/doc/ja/manual.ja.html +325 -0
- data/redist/xmlscan/doc/ja/manual.ja.rd +370 -0
- data/redist/xmlscan/doc/src/Makefile +41 -0
- data/redist/xmlscan/doc/src/conformance.rd.src +256 -0
- data/redist/xmlscan/doc/src/langsplit.rb +110 -0
- data/redist/xmlscan/doc/src/manual.rd.src +614 -0
- data/redist/xmlscan/install.rb +41 -0
- data/redist/xmlscan/lib/xmlscan/encoding.rb +311 -0
- data/redist/xmlscan/lib/xmlscan/htmlscan.rb +289 -0
- data/redist/xmlscan/lib/xmlscan/namespace.rb +352 -0
- data/redist/xmlscan/lib/xmlscan/parser.rb +299 -0
- data/redist/xmlscan/lib/xmlscan/scanner.rb +1109 -0
- data/redist/xmlscan/lib/xmlscan/version.rb +22 -0
- data/redist/xmlscan/lib/xmlscan/visitor.rb +158 -0
- data/redist/xmlscan/lib/xmlscan/xmlchar.rb +441 -0
- data/redist/xmlscan/memo/CONFORMANCE +1249 -0
- data/redist/xmlscan/memo/PRODUCTIONS +195 -0
- data/redist/xmlscan/memo/contentspec.ry +335 -0
- data/redist/xmlscan/samples/chibixml.rb +105 -0
- data/redist/xmlscan/samples/getxmlchar.rb +122 -0
- data/redist/xmlscan/samples/rexml.rb +159 -0
- data/redist/xmlscan/samples/xmlbench.rb +88 -0
- data/redist/xmlscan/samples/xmlbench/parser/chibixml.rb +22 -0
- data/redist/xmlscan/samples/xmlbench/parser/nqxml.rb +29 -0
- data/redist/xmlscan/samples/xmlbench/parser/rexml.rb +62 -0
- data/redist/xmlscan/samples/xmlbench/parser/xmlparser.rb +22 -0
- data/redist/xmlscan/samples/xmlbench/parser/xmlscan-0.0.10.rb +62 -0
- data/redist/xmlscan/samples/xmlbench/parser/xmlscan-chibixml.rb +22 -0
- data/redist/xmlscan/samples/xmlbench/parser/xmlscan-rexml.rb +22 -0
- data/redist/xmlscan/samples/xmlbench/parser/xmlscan.rb +99 -0
- data/redist/xmlscan/samples/xmlbench/xmlbench-lib.rb +116 -0
- data/redist/xmlscan/samples/xmlconftest.rb +200 -0
- data/redist/xmlscan/test.rb +7 -0
- data/redist/xmlscan/tests/deftestcase.rb +73 -0
- data/redist/xmlscan/tests/runtest.rb +47 -0
- data/redist/xmlscan/tests/testall.rb +14 -0
- data/redist/xmlscan/tests/testencoding.rb +438 -0
- data/redist/xmlscan/tests/testhtmlscan.rb +752 -0
- data/redist/xmlscan/tests/testnamespace.rb +457 -0
- data/redist/xmlscan/tests/testparser.rb +591 -0
- data/redist/xmlscan/tests/testscanner.rb +1749 -0
- data/redist/xmlscan/tests/testxmlchar.rb +143 -0
- data/redist/xmlscan/tests/visitor.rb +34 -0
- data/test/array_extensions_test.rb +2 -2
- data/test/ea_instantiator_test.rb +41 -0
- data/test/ecore_self_test.rb +53 -0
- data/test/environment_test.rb +11 -6
- data/test/metamodel_builder_test.rb +404 -245
- data/test/metamodel_roundtrip_test.rb +52 -0
- data/test/metamodel_roundtrip_test/TestModel.rb +65 -0
- data/test/metamodel_roundtrip_test/TestModel_Regenerated.rb +64 -0
- data/test/metamodel_roundtrip_test/houseMetamodel.ecore +32 -0
- data/test/metamodel_roundtrip_test/houseMetamodel_from_ecore.rb +39 -0
- data/test/rgen_test.rb +3 -3
- data/test/template_language_test.rb +65 -39
- data/test/template_language_test/expected_result.txt +24 -3
- data/test/template_language_test/templates/code/array.tpl +11 -0
- data/test/template_language_test/templates/content/author.tpl +7 -0
- data/test/template_language_test/templates/content/chapter.tpl +1 -1
- data/test/template_language_test/templates/root.tpl +17 -8
- data/test/template_language_test/testout.txt +24 -3
- data/test/testmodel/class_model_checker.rb +119 -0
- data/test/{xmi_instantiator_test/testmodel.eap → testmodel/ea_testmodel.eap} +0 -0
- data/test/{xmi_instantiator_test/testmodel.xml → testmodel/ea_testmodel.xml} +81 -14
- data/test/testmodel/ea_testmodel_partial.xml +317 -0
- data/test/testmodel/ecore_model_checker.rb +101 -0
- data/test/testmodel/manual_testmodel.xml +22 -0
- data/test/testmodel/object_model_checker.rb +67 -0
- data/test/transformer_test.rb +18 -10
- data/test/xml_instantiator_test.rb +81 -8
- data/test/xml_instantiator_test/simple_ecore_model_checker.rb +94 -0
- data/test/xml_instantiator_test/simple_xmi_ecore_instantiator.rb +53 -0
- data/test/xml_instantiator_test/simple_xmi_metamodel.rb +49 -0
- data/test/xml_instantiator_test/simple_xmi_to_ecore.rb +75 -0
- metadata +126 -28
- data/lib/ea/xmi_class_instantiator.rb +0 -46
- data/lib/ea/xmi_helper.rb +0 -26
- data/lib/ea/xmi_metamodel.rb +0 -34
- data/lib/ea/xmi_object_instantiator.rb +0 -46
- data/lib/ea/xmi_to_classmodel.rb +0 -78
- data/lib/ea/xmi_to_objectmodel.rb +0 -92
- data/lib/mmgen/mm_ext/uml_classmodel_ext.rb +0 -71
- data/lib/mmgen/templates/uml_classmodel.tpl +0 -63
- data/lib/rgen/xml_instantiator.rb +0 -132
- data/lib/uml/objectmodel_instantiator.rb +0 -53
- data/lib/uml/uml_classmodel.rb +0 -92
- data/lib/uml/uml_objectmodel.rb +0 -65
- data/test/metamodel_generator_test.rb +0 -44
- data/test/metamodel_generator_test/TestModel.rb +0 -40
- data/test/metamodel_generator_test/expected_result.txt +0 -40
- data/test/xmi_class_instantiator_test.rb +0 -24
- data/test/xmi_instantiator_test/class_model_checker.rb +0 -97
- data/test/xmi_object_instantiator_test.rb +0 -65
- data/test/xml_instantiator_test/testmodel.xml +0 -7
@@ -0,0 +1,143 @@
|
|
1
|
+
#
|
2
|
+
# tests/xmlchar.rb
|
3
|
+
#
|
4
|
+
# Copyright (C) Ueno Katsuhiro 2002
|
5
|
+
#
|
6
|
+
# $Id: testxmlchar.rb,v 1.4 2005/05/22 07:07:12 nahi Exp $
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'test/unit'
|
10
|
+
require 'deftestcase'
|
11
|
+
require 'xmlscan/xmlchar'
|
12
|
+
require 'visitor'
|
13
|
+
|
14
|
+
|
15
|
+
class TestXMLChar < Test::Unit::TestCase
|
16
|
+
|
17
|
+
include XMLScan::XMLChar
|
18
|
+
|
19
|
+
def test_valid_char_p
|
20
|
+
assert_equal true, valid_char?(9)
|
21
|
+
assert_equal true, valid_char?(10)
|
22
|
+
assert_equal true, valid_char?(13)
|
23
|
+
assert_equal true, valid_char?(32)
|
24
|
+
assert_equal false, valid_char?(8)
|
25
|
+
assert_equal true, valid_char?(0xfffd)
|
26
|
+
assert_equal false, valid_char?(0xfffe)
|
27
|
+
assert_equal false, valid_char?(0xffff)
|
28
|
+
assert_equal false, valid_char?(0x200000)
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
# \xE3\x81\xBB = ho
|
33
|
+
# \xE3\x81\x92 = ge
|
34
|
+
# \xE3\x81\xB5 = fu
|
35
|
+
# \xE3\x81\x8C = ga
|
36
|
+
|
37
|
+
Hoge = "\xE3\x81\xBB\xE3\x81\x92"
|
38
|
+
Fuga = "\xE3\x81\xB5\xE3\x81\x8C"
|
39
|
+
|
40
|
+
Testcases = [
|
41
|
+
# chardata? nmtoken? name?
|
42
|
+
[ 'hogefuga', true, true, true ],
|
43
|
+
[ Hoge+Fuga, true, true, true ],
|
44
|
+
[ Hoge+' '+Fuga, true, false, false ],
|
45
|
+
[ Hoge+"\n"+Fuga, true, false, false ],
|
46
|
+
[ Hoge+"\r"+Fuga, true, false, false ],
|
47
|
+
[ Hoge+"\t"+Fuga, true, false, false ],
|
48
|
+
[ Hoge+"\f"+Fuga, false, false, false ],
|
49
|
+
[ Hoge+'.'+Fuga, true, true, true ],
|
50
|
+
[ Hoge+'-'+Fuga, true, true, true ],
|
51
|
+
[ Hoge+'_'+Fuga, true, true, true ],
|
52
|
+
[ Hoge+':'+Fuga, true, true, true ],
|
53
|
+
[ Hoge+'%'+Fuga, true, false, false ],
|
54
|
+
[ '.'+Hoge+Fuga, true, true, false ],
|
55
|
+
[ '-'+Hoge+Fuga, true, true, false ],
|
56
|
+
[ '_'+Hoge+Fuga, true, true, true ],
|
57
|
+
[ ':'+Hoge+Fuga, true, true, true ],
|
58
|
+
[ '%'+Hoge+Fuga, true, false, false ],
|
59
|
+
[ Hoge+"\xfe"+Fuga, false, false, false ],
|
60
|
+
[ Hoge+"\xff"+Fuga, false, false, false ],
|
61
|
+
[ [0xffff].pack('U'), false, false, false ],
|
62
|
+
]
|
63
|
+
|
64
|
+
|
65
|
+
def test_valid_chardata_p
|
66
|
+
Testcases.each { |str,expect,|
|
67
|
+
assert_equal expect, valid_chardata?(str), str.inspect
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_valid_nmtoken_p
|
72
|
+
Testcases.each { |str,dummy,expect,|
|
73
|
+
assert_equal expect, valid_nmtoken?(str), str.inspect
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_valid_name_p
|
78
|
+
Testcases.each { |str,dummy,dummy,expect,|
|
79
|
+
assert_equal expect, valid_name?(str), str.inspect
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
class TestXMLScannerStrict < Test::Unit::TestCase
|
88
|
+
|
89
|
+
include DefTestCase
|
90
|
+
|
91
|
+
Visitor = RecordingVisitor.new_class(XMLScan::Visitor)
|
92
|
+
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def setup
|
97
|
+
@origkcode = $KCODE
|
98
|
+
$KCODE = 'U'
|
99
|
+
@v = Visitor.new
|
100
|
+
@s = XMLScan::XMLScanner.new(@v, :strict_char)
|
101
|
+
end
|
102
|
+
|
103
|
+
def teardown
|
104
|
+
$KCODE = @origkcode
|
105
|
+
end
|
106
|
+
|
107
|
+
def parse(src)
|
108
|
+
@s.parse src
|
109
|
+
@v.result
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
public
|
114
|
+
|
115
|
+
Hoge = TestXMLChar::Hoge
|
116
|
+
Fuga = TestXMLChar::Fuga
|
117
|
+
|
118
|
+
|
119
|
+
deftestcase 'document', <<-'TESTCASEEND'
|
120
|
+
|
121
|
+
"<:.#{Hoge}>hoge</:.#{Hoge}>"
|
122
|
+
[ :on_stag, ":.#{Hoge}" ]
|
123
|
+
[ :on_stag_end, ":.#{Hoge}" ]
|
124
|
+
[ :on_chardata, "hoge" ]
|
125
|
+
[ :on_etag, ":.#{Hoge}" ]
|
126
|
+
|
127
|
+
"<.:#{Hoge}>hoge</.:#{Hoge}>"
|
128
|
+
[ :parse_error, "`.:#{Hoge}' is not valid for XML name"]
|
129
|
+
[ :on_stag, ".:#{Hoge}" ]
|
130
|
+
[ :on_stag_end, ".:#{Hoge}" ]
|
131
|
+
[ :on_chardata, "hoge" ]
|
132
|
+
[ :parse_error, "`.:#{Hoge}' is not valid for XML name"]
|
133
|
+
[ :on_etag, ".:#{Hoge}" ]
|
134
|
+
|
135
|
+
TESTCASEEND
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
load "#{File.dirname($0)}/runtest.rb" if __FILE__ == $0
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#
|
2
|
+
# tests/visitor.rb
|
3
|
+
#
|
4
|
+
# Copyright (C) UENO Katsuhiro 2002
|
5
|
+
#
|
6
|
+
# $Id: visitor.rb,v 1.3 2002/09/24 21:39:30 katsu Exp $
|
7
|
+
#
|
8
|
+
|
9
|
+
module RecordingVisitor
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@result = []
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :result
|
16
|
+
|
17
|
+
def self.new_class(visitor)
|
18
|
+
klass = Class.new
|
19
|
+
mod = self
|
20
|
+
klass.module_eval { include mod, visitor }
|
21
|
+
methods = visitor.instance_methods
|
22
|
+
visitor.included_modules.each { |i| methods.concat i.instance_methods }
|
23
|
+
methods.sort.uniq.each { |i|
|
24
|
+
klass.module_eval <<-END, __FILE__, __LINE__ + 1
|
25
|
+
def #{i}(*args)
|
26
|
+
@result.push [ :#{i} ].concat(args)
|
27
|
+
end
|
28
|
+
END
|
29
|
+
}
|
30
|
+
klass
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'rgen/environment'
|
5
|
+
require 'metamodels/uml13_metamodel'
|
6
|
+
require 'instantiators/ea_instantiator'
|
7
|
+
require 'transformers/uml13_to_ecore'
|
8
|
+
require 'testmodel/class_model_checker'
|
9
|
+
require 'testmodel/object_model_checker'
|
10
|
+
require 'testmodel/ecore_model_checker'
|
11
|
+
|
12
|
+
class EAInstantiatorTest < Test::Unit::TestCase
|
13
|
+
|
14
|
+
include Testmodel::ClassModelChecker
|
15
|
+
include Testmodel::ObjectModelChecker
|
16
|
+
include Testmodel::ECoreModelChecker
|
17
|
+
|
18
|
+
MODEL_DIR = File.join(File.dirname(__FILE__),"testmodel")
|
19
|
+
|
20
|
+
def test_instantiator
|
21
|
+
envUML = RGen::Environment.new
|
22
|
+
File.open(MODEL_DIR+"/ea_testmodel.xml") { |f|
|
23
|
+
inst = EAInstantiator.new(envUML, EAInstantiator::ERROR)
|
24
|
+
inst.instantiate(f.read)
|
25
|
+
}
|
26
|
+
checkClassModel(envUML)
|
27
|
+
checkObjectModel(envUML)
|
28
|
+
envECore = RGen::Environment.new
|
29
|
+
UML13ToECore.new(envUML, envECore).transform
|
30
|
+
checkECoreModel(envECore)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_partial
|
34
|
+
envUML = RGen::Environment.new
|
35
|
+
File.open(MODEL_DIR+"/ea_testmodel_partial.xml") { |f|
|
36
|
+
inst = EAInstantiator.new(envUML, EAInstantiator::ERROR)
|
37
|
+
inst.instantiate(f.read)
|
38
|
+
}
|
39
|
+
checkClassModelPartial(envUML)
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'rgen/ecore/ecore'
|
5
|
+
require 'rgen/array_extensions'
|
6
|
+
|
7
|
+
class ECoreSelfTest < Test::Unit::TestCase
|
8
|
+
include RGen::ECore
|
9
|
+
|
10
|
+
def test_simple
|
11
|
+
assert_equal \
|
12
|
+
%w(lowerBound ordered unique upperBound many required eType).sort,
|
13
|
+
ETypedElement.ecore.eStructuralFeatures.name.sort
|
14
|
+
|
15
|
+
assert_equal \
|
16
|
+
EClassifier.ecore,
|
17
|
+
ETypedElement.ecore.eStructuralFeatures.find{|f| f.name=="eType"}.eType
|
18
|
+
assert_equal %w(ENamedElement), ETypedElement.ecore.eSuperTypes.name
|
19
|
+
|
20
|
+
assert_equal \
|
21
|
+
EModelElement.ecore,
|
22
|
+
EModelElement.ecore.eStructuralFeatures.find{|f| f.name=="eAnnotations"}.eOpposite.eType
|
23
|
+
|
24
|
+
assert_equal \
|
25
|
+
%w(eType),
|
26
|
+
ETypedElement.ecore.eReferences.name
|
27
|
+
|
28
|
+
assert_equal \
|
29
|
+
%w(lowerBound ordered unique upperBound many required).sort,
|
30
|
+
ETypedElement.ecore.eAttributes.name.sort
|
31
|
+
|
32
|
+
assert RGen::ECore.ecore.is_a?(EPackage)
|
33
|
+
assert_equal "ECore", RGen::ECore.ecore.name
|
34
|
+
assert_equal "RGen", RGen::ECore.ecore.eSuperPackage.name
|
35
|
+
assert_equal %w(ECore), RGen.ecore.eSubpackages.name
|
36
|
+
assert_equal\
|
37
|
+
%w(EObject EModelElement EAnnotation ENamedElement ETypedElement
|
38
|
+
EStructuralFeature EAttribute EClassifier EDataType EEnum EEnumLiteral EFactory
|
39
|
+
EOperation EPackage EParameter EReference EStringToStringMapEntry EClass).sort,
|
40
|
+
RGen::ECore.ecore.eClassifiers.name.sort
|
41
|
+
|
42
|
+
assert_equal "false", EAttribute.ecore.eAllAttributes.
|
43
|
+
find{|a|a.name == "derived"}.defaultValueLiteral
|
44
|
+
assert_equal false, EAttribute.ecore.eAllAttributes.
|
45
|
+
find{|a|a.name == "derived"}.defaultValue
|
46
|
+
|
47
|
+
assert_nil EAttribute.ecore.eAllAttributes.
|
48
|
+
find{|a|a.name == "defaultValueLiteral"}.defaultValueLiteral
|
49
|
+
assert_nil EAttribute.ecore.eAllAttributes.
|
50
|
+
find{|a|a.name == "defaultValueLiteral"}.defaultValue
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
data/test/environment_test.rb
CHANGED
@@ -18,25 +18,30 @@ class EnvironmentTest < Test::Unit::TestCase
|
|
18
18
|
m2 = ModelSub.new
|
19
19
|
m2.name = "M2"
|
20
20
|
m3 = "justAString"
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
env = RGen::Environment.new << m1 << m2 << m3
|
22
|
+
assertFind(env, m1, m2, m3)
|
23
|
+
idx = env.findIndex(:name)
|
24
|
+
assertFind(idx, m1, m2, m3)
|
25
|
+
end
|
26
|
+
|
27
|
+
def assertFind(context, m1, m2, m3)
|
28
|
+
result = context.find(:class => Model, :name => "M1")
|
24
29
|
assert result.is_a?(Array)
|
25
30
|
assert_equal 1, result.size
|
26
31
|
assert_equal m1, result.first
|
27
32
|
|
28
|
-
result =
|
33
|
+
result = context.find(:class => Model)
|
29
34
|
assert result.is_a?(Array)
|
30
35
|
assert_equal 2, result.size
|
31
36
|
assert_equal m1, result[0]
|
32
37
|
assert_equal m2, result[1]
|
33
38
|
|
34
|
-
result =
|
39
|
+
result = context.find(:name => "M2")
|
35
40
|
assert result.is_a?(Array)
|
36
41
|
assert_equal 1, result.size
|
37
42
|
assert_equal m2, result[0]
|
38
43
|
|
39
|
-
result =
|
44
|
+
result = context.find(:class => [Model, String])
|
40
45
|
assert result.is_a?(Array)
|
41
46
|
assert_equal 3, result.size
|
42
47
|
assert_equal m1, result[0]
|
@@ -2,260 +2,419 @@ $:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
|
2
2
|
|
3
3
|
require 'test/unit'
|
4
4
|
require 'rgen/metamodel_builder'
|
5
|
+
require 'rgen/array_extensions'
|
5
6
|
|
6
7
|
class MetamodelBuilderTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
class SimpleClass < RGen::MetamodelBuilder::MMBase
|
10
|
+
KindType = RGen::MetamodelBuilder::DataTypes::Enum.new([:simple, :extended])
|
11
|
+
has_attr 'name' # default is String
|
12
|
+
has_attr 'stringWithDefault', String, :defaultValueLiteral => "xtest"
|
13
|
+
has_attr 'anything', Object
|
14
|
+
has_attr 'allowed', RGen::MetamodelBuilder::DataTypes::Boolean
|
15
|
+
has_attr 'kind', KindType
|
16
|
+
has_attr 'kindWithDefault', KindType, :defaultValueLiteral => "extended"
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_has_attr
|
20
|
+
sc = SimpleClass.new
|
21
|
+
|
22
|
+
assert_respond_to sc, :name
|
23
|
+
assert_respond_to sc, :name=
|
24
|
+
sc.name = "TestName"
|
25
|
+
assert_equal "TestName", sc.name
|
26
|
+
sc.name = nil
|
27
|
+
assert_equal nil, sc.name
|
28
|
+
assert_raise StandardError do
|
29
|
+
sc.name = 5
|
30
|
+
end
|
31
|
+
assert_equal "EString", SimpleClass.ecore.eAttributes.find{|a| a.name=="name"}.eType.name
|
7
32
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
33
|
+
assert_equal "xtest", sc.stringWithDefault
|
34
|
+
assert_equal :extended, sc.kindWithDefault
|
35
|
+
|
36
|
+
sc.anything = :asymbol
|
37
|
+
assert_equal :asymbol, sc.anything
|
38
|
+
sc.anything = self # a class
|
39
|
+
assert_equal self, sc.anything
|
40
|
+
|
41
|
+
assert_respond_to sc, :allowed
|
42
|
+
assert_respond_to sc, :allowed=
|
43
|
+
sc.allowed = true
|
44
|
+
assert_equal true, sc.allowed
|
45
|
+
sc.allowed = false
|
46
|
+
assert_equal false, sc.allowed
|
47
|
+
sc.allowed = nil
|
48
|
+
assert_equal nil, sc.allowed
|
49
|
+
assert_raise StandardError do
|
50
|
+
sc.allowed = :someSymbol
|
51
|
+
end
|
52
|
+
assert_raise StandardError do
|
53
|
+
sc.allowed = "a string"
|
54
|
+
end
|
55
|
+
assert_equal "EBoolean", SimpleClass.ecore.eAttributes.find{|a| a.name=="allowed"}.eType.name
|
56
|
+
|
57
|
+
assert_respond_to sc, :kind
|
58
|
+
assert_respond_to sc, :kind=
|
59
|
+
sc.kind = :simple
|
60
|
+
assert_equal :simple, sc.kind
|
61
|
+
sc.kind = :extended
|
62
|
+
assert_equal :extended, sc.kind
|
63
|
+
sc.kind = nil
|
64
|
+
assert_equal nil, sc.kind
|
65
|
+
assert_raise StandardError do
|
66
|
+
sc.kind = :false
|
67
|
+
end
|
68
|
+
assert_raise StandardError do
|
69
|
+
sc.kind = "a string"
|
70
|
+
end
|
71
|
+
|
72
|
+
enum = SimpleClass.ecore.eAttributes.find{|a| a.name=="kind"}.eType
|
73
|
+
assert_equal ["extended", "simple"], enum.eLiterals.name.sort
|
74
|
+
end
|
75
|
+
|
76
|
+
class ClassA < RGen::MetamodelBuilder::MMBase
|
77
|
+
end
|
78
|
+
|
79
|
+
class ClassB < RGen::MetamodelBuilder::MMBase
|
80
|
+
end
|
81
|
+
|
82
|
+
class ClassC < RGen::MetamodelBuilder::MMBase
|
83
|
+
end
|
84
|
+
|
85
|
+
class HasOneTestClass < RGen::MetamodelBuilder::MMBase
|
86
|
+
has_one 'classA', ClassA
|
87
|
+
has_one 'classB', ClassB
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_has_one
|
91
|
+
sc = HasOneTestClass.new
|
92
|
+
assert_respond_to sc, :classA
|
93
|
+
assert_respond_to sc, :classA=
|
94
|
+
ca = ClassA.new
|
95
|
+
sc.classA = ca
|
96
|
+
assert_equal ca, sc.classA
|
97
|
+
sc.classA = nil
|
98
|
+
assert_equal nil, sc.classA
|
99
|
+
|
100
|
+
assert_respond_to sc, :classB
|
101
|
+
assert_respond_to sc, :classB=
|
102
|
+
cb = ClassB.new
|
103
|
+
sc.classB = cb
|
104
|
+
assert_equal cb, sc.classB
|
105
|
+
|
106
|
+
assert_raise StandardError do
|
107
|
+
sc.classB = ca
|
108
|
+
end
|
109
|
+
|
110
|
+
assert_equal [], ClassA.ecore.eReferences
|
111
|
+
assert_equal [], ClassB.ecore.eReferences
|
112
|
+
assert_equal ["classA", "classB"].sort, HasOneTestClass.ecore.eReferences.name.sort
|
113
|
+
assert_equal [], HasOneTestClass.ecore.eReferences.select { |a| a.many == true }
|
114
|
+
assert_equal [], HasOneTestClass.ecore.eAttributes
|
115
|
+
end
|
116
|
+
|
117
|
+
class HasManyTestClass < RGen::MetamodelBuilder::MMBase
|
118
|
+
has_many 'classA', ClassA
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_has_many
|
122
|
+
o = HasManyTestClass.new
|
123
|
+
ca1 = ClassA.new
|
124
|
+
ca2 = ClassA.new
|
125
|
+
ca3 = ClassA.new
|
126
|
+
o.addClassA(ca1)
|
127
|
+
o.addClassA(ca2)
|
128
|
+
assert_equal [ca1, ca2], o.classA
|
129
|
+
# make sure we get a copy
|
130
|
+
o.classA.clear
|
131
|
+
assert_equal [ca1, ca2], o.classA
|
132
|
+
o.removeClassA(ca3)
|
133
|
+
assert_equal [ca1, ca2], o.classA
|
134
|
+
o.removeClassA(ca2)
|
135
|
+
assert_equal [ca1], o.classA
|
136
|
+
assert_raise StandardError do
|
137
|
+
o.addClassA(ClassB.new)
|
138
|
+
end
|
139
|
+
assert_equal [], HasManyTestClass.ecore.eReferences.select{|r| r.many == false}
|
140
|
+
assert_equal ["classA"], HasManyTestClass.ecore.eReferences.select{|r| r.many == true}.name
|
141
|
+
end
|
142
|
+
|
143
|
+
class OneClass < RGen::MetamodelBuilder::MMBase
|
144
|
+
end
|
145
|
+
class ManyClass < RGen::MetamodelBuilder::MMBase
|
146
|
+
end
|
147
|
+
OneClass.one_to_many 'manyClasses', ManyClass, 'oneClass'
|
148
|
+
|
149
|
+
def test_one_to_many
|
150
|
+
oc = OneClass.new
|
151
|
+
assert_respond_to oc, :manyClasses
|
152
|
+
assert oc.manyClasses.empty?
|
153
|
+
|
154
|
+
mc = ManyClass.new
|
155
|
+
assert_respond_to mc, :oneClass
|
156
|
+
assert_respond_to mc, :oneClass=
|
157
|
+
assert_nil mc.oneClass
|
158
|
+
|
159
|
+
# put the OneClass into the ManyClass
|
160
|
+
mc.oneClass = oc
|
161
|
+
assert_equal oc, mc.oneClass
|
162
|
+
assert oc.manyClasses.include?(mc)
|
163
|
+
|
164
|
+
# remove the OneClass from the ManyClass
|
165
|
+
mc.oneClass = nil
|
166
|
+
assert_equal nil, mc.oneClass
|
167
|
+
assert !oc.manyClasses.include?(mc)
|
168
|
+
|
169
|
+
# put the ManyClass into the OneClass
|
170
|
+
oc.addManyClasses mc
|
171
|
+
assert oc.manyClasses.include?(mc)
|
172
|
+
assert_equal oc, mc.oneClass
|
173
|
+
|
174
|
+
# remove the ManyClass from the OneClass
|
175
|
+
oc.removeManyClasses mc
|
176
|
+
assert !oc.manyClasses.include?(mc)
|
177
|
+
assert_equal nil, mc.oneClass
|
178
|
+
|
179
|
+
assert_equal [], OneClass.ecore.eReferences.select{|r| r.many == false}
|
180
|
+
assert_equal ["manyClasses"], OneClass.ecore.eReferences.select{|r| r.many == true}.name
|
181
|
+
assert_equal ["oneClass"], ManyClass.ecore.eReferences.select{|r| r.many == false}.name
|
182
|
+
assert_equal [], ManyClass.ecore.eReferences.select{|r| r.many == true}
|
183
|
+
end
|
184
|
+
|
185
|
+
class OneClass2 < RGen::MetamodelBuilder::MMBase
|
186
|
+
end
|
187
|
+
class ManyClass2 < RGen::MetamodelBuilder::MMBase
|
188
|
+
end
|
189
|
+
ManyClass2.many_to_one 'oneClass', OneClass2, 'manyClasses'
|
190
|
+
|
191
|
+
def test_one_to_many2
|
192
|
+
oc = OneClass2.new
|
193
|
+
assert_respond_to oc, :manyClasses
|
194
|
+
assert oc.manyClasses.empty?
|
195
|
+
|
196
|
+
mc = ManyClass2.new
|
197
|
+
assert_respond_to mc, :oneClass
|
198
|
+
assert_respond_to mc, :oneClass=
|
199
|
+
assert_nil mc.oneClass
|
200
|
+
|
201
|
+
# put the OneClass into the ManyClass
|
202
|
+
mc.oneClass = oc
|
203
|
+
assert_equal oc, mc.oneClass
|
204
|
+
assert oc.manyClasses.include?(mc)
|
205
|
+
|
206
|
+
# remove the OneClass from the ManyClass
|
207
|
+
mc.oneClass = nil
|
208
|
+
assert_equal nil, mc.oneClass
|
209
|
+
assert !oc.manyClasses.include?(mc)
|
210
|
+
|
211
|
+
# put the ManyClass into the OneClass
|
212
|
+
oc.addManyClasses mc
|
213
|
+
assert oc.manyClasses.include?(mc)
|
214
|
+
assert_equal oc, mc.oneClass
|
215
|
+
|
216
|
+
# remove the ManyClass from the OneClass
|
217
|
+
oc.removeManyClasses mc
|
218
|
+
assert !oc.manyClasses.include?(mc)
|
219
|
+
assert_equal nil, mc.oneClass
|
220
|
+
|
221
|
+
assert_equal [], OneClass2.ecore.eReferences.select{|r| r.many == false}
|
222
|
+
assert_equal ["manyClasses"], OneClass2.ecore.eReferences.select{|r| r.many == true}.name
|
223
|
+
assert_equal ["oneClass"], ManyClass2.ecore.eReferences.select{|r| r.many == false}.name
|
224
|
+
assert_equal [], ManyClass2.ecore.eReferences.select{|r| r.many == true}
|
225
|
+
end
|
226
|
+
|
227
|
+
class AClassOO < RGen::MetamodelBuilder::MMBase
|
228
|
+
end
|
229
|
+
class BClassOO < RGen::MetamodelBuilder::MMBase
|
230
|
+
end
|
231
|
+
AClassOO.one_to_one 'bClass', BClassOO, 'aClass'
|
232
|
+
|
233
|
+
def test_one_to_one
|
234
|
+
ac = AClassOO.new
|
235
|
+
assert_respond_to ac, :bClass
|
236
|
+
assert_respond_to ac, :bClass=
|
237
|
+
assert_nil ac.bClass
|
238
|
+
|
239
|
+
bc = BClassOO.new
|
240
|
+
assert_respond_to bc, :aClass
|
241
|
+
assert_respond_to bc, :aClass=
|
242
|
+
assert_nil bc.aClass
|
243
|
+
|
244
|
+
# put the AClass into the BClass
|
245
|
+
bc.aClass = ac
|
246
|
+
assert_equal ac, bc.aClass
|
247
|
+
assert_equal bc, ac.bClass
|
248
|
+
|
249
|
+
# remove the AClass from the BClass
|
250
|
+
bc.aClass = nil
|
251
|
+
assert_equal nil, bc.aClass
|
252
|
+
assert_equal nil, ac.bClass
|
253
|
+
|
254
|
+
# put the BClass into the AClass
|
255
|
+
ac.bClass = bc
|
256
|
+
assert_equal bc, ac.bClass
|
257
|
+
assert_equal ac, bc.aClass
|
258
|
+
|
259
|
+
# remove the BClass from the AClass
|
260
|
+
ac.bClass = nil
|
261
|
+
assert_equal nil, ac.bClass
|
262
|
+
assert_equal nil, bc.aClass
|
263
|
+
|
264
|
+
assert_equal ["bClass"], AClassOO.ecore.eReferences.select{|r| r.many == false}.name
|
265
|
+
assert_equal [], AClassOO.ecore.eReferences.select{|r| r.many == true}
|
266
|
+
assert_equal ["aClass"], BClassOO.ecore.eReferences.select{|r| r.many == false}.name
|
267
|
+
assert_equal [], BClassOO.ecore.eReferences.select{|r| r.many == true}
|
268
|
+
end
|
269
|
+
|
270
|
+
class AClassMM < RGen::MetamodelBuilder::MMBase
|
271
|
+
end
|
272
|
+
class BClassMM < RGen::MetamodelBuilder::MMBase
|
273
|
+
end
|
274
|
+
AClassMM.many_to_many 'bClasses', BClassMM, 'aClasses'
|
275
|
+
|
276
|
+
def test_many_to_many
|
277
|
+
|
278
|
+
ac = AClassMM.new
|
279
|
+
assert_respond_to ac, :bClasses
|
280
|
+
assert ac.bClasses.empty?
|
281
|
+
|
282
|
+
bc = BClassMM.new
|
283
|
+
assert_respond_to bc, :aClasses
|
284
|
+
assert bc.aClasses.empty?
|
285
|
+
|
286
|
+
# put the AClass into the BClass
|
287
|
+
bc.addAClasses ac
|
288
|
+
assert bc.aClasses.include?(ac)
|
289
|
+
assert ac.bClasses.include?(bc)
|
290
|
+
|
291
|
+
# put something else into the BClass
|
292
|
+
assert_raise StandardError do
|
293
|
+
bc.addAClasses :notaaclass
|
294
|
+
end
|
295
|
+
|
296
|
+
# remove the AClass from the BClass
|
297
|
+
bc.removeAClasses ac
|
298
|
+
assert !bc.aClasses.include?(ac)
|
299
|
+
assert !ac.bClasses.include?(bc)
|
300
|
+
|
301
|
+
# put the BClass into the AClass
|
302
|
+
ac.addBClasses bc
|
303
|
+
assert ac.bClasses.include?(bc)
|
304
|
+
assert bc.aClasses.include?(ac)
|
305
|
+
|
306
|
+
# put something else into the AClass
|
307
|
+
assert_raise StandardError do
|
308
|
+
ac.addBClasses :notabclass
|
309
|
+
end
|
310
|
+
|
311
|
+
# remove the BClass from the AClass
|
312
|
+
ac.removeBClasses bc
|
313
|
+
assert !ac.bClasses.include?(bc)
|
314
|
+
assert !bc.aClasses.include?(ac)
|
315
|
+
|
316
|
+
assert_equal [], AClassMM.ecore.eReferences.select{|r| r.many == false}
|
317
|
+
assert_equal ["bClasses"], AClassMM.ecore.eReferences.select{|r| r.many == true}.name
|
318
|
+
assert_equal [], BClassMM.ecore.eReferences.select{|r| r.many == false}
|
319
|
+
assert_equal ["aClasses"], BClassMM.ecore.eReferences.select{|r| r.many == true}.name
|
320
|
+
end
|
321
|
+
|
322
|
+
class SomeSuperClass < RGen::MetamodelBuilder::MMBase
|
323
|
+
has_attr "name"
|
324
|
+
has_many "classAs", ClassA
|
325
|
+
end
|
326
|
+
|
327
|
+
class SomeSubClass < SomeSuperClass
|
328
|
+
has_attr "subname"
|
329
|
+
has_many "classBs", ClassB
|
330
|
+
end
|
331
|
+
|
332
|
+
class OtherSubClass < SomeSuperClass
|
333
|
+
has_attr "othersubname"
|
334
|
+
has_many "classCs", ClassC
|
335
|
+
end
|
336
|
+
|
337
|
+
def test_inheritance
|
338
|
+
assert_equal ["name"], SomeSuperClass.ecore.eAllAttributes.name
|
339
|
+
assert_equal ["classAs"], SomeSuperClass.ecore.eAllReferences.name
|
340
|
+
assert_equal ["name", "subname"], SomeSubClass.ecore.eAllAttributes.name.sort
|
341
|
+
assert_equal ["classAs", "classBs"], SomeSubClass.ecore.eAllReferences.name.sort
|
342
|
+
assert_equal ["name", "othersubname"], OtherSubClass.ecore.eAllAttributes.name.sort
|
343
|
+
assert_equal ["classAs", "classCs"], OtherSubClass.ecore.eAllReferences.name.sort
|
344
|
+
end
|
345
|
+
|
346
|
+
module AnnotatedModule
|
347
|
+
extend RGen::MetamodelBuilder::ModuleExtension
|
21
348
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
assert_equal HasOneTestClass.one_attributes, ["name", "an_array"]
|
33
|
-
assert_equal HasOneTestClass.many_attributes, []
|
34
|
-
end
|
35
|
-
|
36
|
-
class HasManyTestClass < RGen::MetamodelBuilder::MMBase
|
37
|
-
has_many 'string', String
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_has_many
|
41
|
-
o = HasManyTestClass.new
|
42
|
-
o.addString("s1")
|
43
|
-
o.addString("s2")
|
44
|
-
assert_equal ["s1","s2"], o.string
|
45
|
-
# make sure we get a copy
|
46
|
-
o.string.clear
|
47
|
-
assert_equal ["s1","s2"], o.string
|
48
|
-
o.removeString("s3")
|
49
|
-
assert_equal ["s1","s2"], o.string
|
50
|
-
o.removeString("s2")
|
51
|
-
assert_equal ["s1"], o.string
|
52
|
-
assert_raise StandardError do
|
53
|
-
o.addString(:notastring)
|
54
|
-
end
|
55
|
-
assert_equal HasManyTestClass.one_attributes, []
|
56
|
-
assert_equal HasManyTestClass.many_attributes, ["string"]
|
57
|
-
end
|
349
|
+
annotation "moduletag" => "modulevalue"
|
350
|
+
|
351
|
+
class AnnotatedClass < RGen::MetamodelBuilder::MMBase
|
352
|
+
annotation "sometag" => "somevalue", "othertag" => "othervalue"
|
353
|
+
annotation :source => "rgen/test", :details => {"thirdtag" => "thirdvalue"}
|
354
|
+
|
355
|
+
has_attr "boolAttr", Boolean do
|
356
|
+
annotation "attrtag" => "attrval"
|
357
|
+
annotation :source => "rgen/test2", :details => {"attrtag2" => "attrvalue2", "attrtag3" => "attrvalue3"}
|
358
|
+
end
|
58
359
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
OneClass.one_to_many 'manyClasses', ManyClass, 'oneClass'
|
64
|
-
|
65
|
-
def test_one_to_many
|
66
|
-
oc = OneClass.new
|
67
|
-
assert_respond_to oc, :manyClasses
|
68
|
-
assert oc.manyClasses.empty?
|
69
|
-
|
70
|
-
mc = ManyClass.new
|
71
|
-
assert_respond_to mc, :oneClass
|
72
|
-
assert_respond_to mc, :oneClass=
|
73
|
-
assert_nil mc.oneClass
|
74
|
-
|
75
|
-
# put the OneClass into the ManyClass
|
76
|
-
mc.oneClass = oc
|
77
|
-
assert_equal oc, mc.oneClass
|
78
|
-
assert oc.manyClasses.include?(mc)
|
79
|
-
|
80
|
-
# remove the OneClass from the ManyClass
|
81
|
-
mc.oneClass = nil
|
82
|
-
assert_equal nil, mc.oneClass
|
83
|
-
assert !oc.manyClasses.include?(mc)
|
360
|
+
has_many "others", AnnotatedClass do
|
361
|
+
annotation "reftag" => "refval"
|
362
|
+
annotation :source => "rgen/test3", :details => {"reftag2" => "refvalue2", "reftag3" => "refvalue3"}
|
363
|
+
end
|
84
364
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
365
|
+
many_to_many "m2m", AnnotatedClass, "m2mback" do
|
366
|
+
annotation "m2mtag" => "m2mval"
|
367
|
+
opposite_annotation "opposite_m2mtag" => "opposite_m2mval"
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
end
|
372
|
+
|
373
|
+
def test_annotations
|
374
|
+
assert_equal 1, AnnotatedModule.ecore.eAnnotations.size
|
375
|
+
anno = AnnotatedModule.ecore.eAnnotations.first
|
376
|
+
checkAnnotation(anno, nil, {"moduletag" => "modulevalue"})
|
94
377
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
378
|
+
eClass = AnnotatedModule::AnnotatedClass.ecore
|
379
|
+
assert_equal 2, eClass.eAnnotations.size
|
380
|
+
anno = eClass.eAnnotations.find{|a| a.source == "rgen/test"}
|
381
|
+
checkAnnotation(anno, "rgen/test", {"thirdtag" => "thirdvalue"})
|
382
|
+
anno = eClass.eAnnotations.find{|a| a.source == nil}
|
383
|
+
checkAnnotation(anno, nil, {"sometag" => "somevalue", "othertag" => "othervalue"})
|
100
384
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
def test_one_to_many2
|
108
|
-
oc = OneClass2.new
|
109
|
-
assert_respond_to oc, :manyClasses
|
110
|
-
assert oc.manyClasses.empty?
|
111
|
-
|
112
|
-
mc = ManyClass2.new
|
113
|
-
assert_respond_to mc, :oneClass
|
114
|
-
assert_respond_to mc, :oneClass=
|
115
|
-
assert_nil mc.oneClass
|
116
|
-
|
117
|
-
# put the OneClass into the ManyClass
|
118
|
-
mc.oneClass = oc
|
119
|
-
assert_equal oc, mc.oneClass
|
120
|
-
assert oc.manyClasses.include?(mc)
|
121
|
-
|
122
|
-
# remove the OneClass from the ManyClass
|
123
|
-
mc.oneClass = nil
|
124
|
-
assert_equal nil, mc.oneClass
|
125
|
-
assert !oc.manyClasses.include?(mc)
|
385
|
+
eAttr = eClass.eAttributes.first
|
386
|
+
assert_equal 2, eAttr.eAnnotations.size
|
387
|
+
anno = eAttr.eAnnotations.find{|a| a.source == "rgen/test2"}
|
388
|
+
checkAnnotation(anno, "rgen/test2", {"attrtag2" => "attrvalue2", "attrtag3" => "attrvalue3"})
|
389
|
+
anno = eAttr.eAnnotations.find{|a| a.source == nil}
|
390
|
+
checkAnnotation(anno, nil, {"attrtag" => "attrval"})
|
126
391
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
oc.removeManyClasses mc
|
134
|
-
assert !oc.manyClasses.include?(mc)
|
135
|
-
assert_equal nil, mc.oneClass
|
392
|
+
eRef = eClass.eReferences.find{|r| !r.eOpposite}
|
393
|
+
assert_equal 2, eRef.eAnnotations.size
|
394
|
+
anno = eRef.eAnnotations.find{|a| a.source == "rgen/test3"}
|
395
|
+
checkAnnotation(anno, "rgen/test3", {"reftag2" => "refvalue2", "reftag3" => "refvalue3"})
|
396
|
+
anno = eRef.eAnnotations.find{|a| a.source == nil}
|
397
|
+
checkAnnotation(anno, nil, {"reftag" => "refval"})
|
136
398
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
399
|
+
eRef = eClass.eReferences.find{|r| r.eOpposite}
|
400
|
+
assert_equal 1, eRef.eAnnotations.size
|
401
|
+
anno = eRef.eAnnotations.first
|
402
|
+
checkAnnotation(anno, nil, {"m2mtag" => "m2mval"})
|
403
|
+
eRef = eRef.eOpposite
|
404
|
+
assert_equal 1, eRef.eAnnotations.size
|
405
|
+
anno = eRef.eAnnotations.first
|
406
|
+
checkAnnotation(anno, nil, {"opposite_m2mtag" => "opposite_m2mval"})
|
407
|
+
end
|
142
408
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
bc = BClassOO.new
|
156
|
-
assert_respond_to bc, :aClass
|
157
|
-
assert_respond_to bc, :aClass=
|
158
|
-
assert_nil bc.aClass
|
159
|
-
|
160
|
-
# put the AClass into the BClass
|
161
|
-
bc.aClass = ac
|
162
|
-
assert_equal ac, bc.aClass
|
163
|
-
assert_equal bc, ac.bClass
|
164
|
-
|
165
|
-
# remove the AClass from the BClass
|
166
|
-
bc.aClass = nil
|
167
|
-
assert_equal nil, bc.aClass
|
168
|
-
assert_equal nil, ac.bClass
|
169
|
-
|
170
|
-
# put the BClass into the AClass
|
171
|
-
ac.bClass = bc
|
172
|
-
assert_equal bc, ac.bClass
|
173
|
-
assert_equal ac, bc.aClass
|
174
|
-
|
175
|
-
# remove the BClass from the AClass
|
176
|
-
ac.bClass = nil
|
177
|
-
assert_equal nil, ac.bClass
|
178
|
-
assert_equal nil, bc.aClass
|
179
|
-
|
180
|
-
assert_equal AClassOO.one_attributes, ["bClass"]
|
181
|
-
assert_equal AClassOO.many_attributes, []
|
182
|
-
assert_equal BClassOO.one_attributes, ["aClass"]
|
183
|
-
assert_equal BClassOO.many_attributes, []
|
184
|
-
end
|
185
|
-
|
186
|
-
class AClassMM < RGen::MetamodelBuilder::MMBase
|
187
|
-
end
|
188
|
-
class BClassMM < RGen::MetamodelBuilder::MMBase
|
189
|
-
end
|
190
|
-
AClassMM.many_to_many 'bClasses', BClassMM, 'aClasses'
|
191
|
-
|
192
|
-
def test_many_to_many
|
193
|
-
|
194
|
-
ac = AClassMM.new
|
195
|
-
assert_respond_to ac, :bClasses
|
196
|
-
assert ac.bClasses.empty?
|
197
|
-
|
198
|
-
bc = BClassMM.new
|
199
|
-
assert_respond_to bc, :aClasses
|
200
|
-
assert bc.aClasses.empty?
|
201
|
-
|
202
|
-
# put the AClass into the BClass
|
203
|
-
bc.addAClasses ac
|
204
|
-
assert bc.aClasses.include?(ac)
|
205
|
-
assert ac.bClasses.include?(bc)
|
206
|
-
|
207
|
-
# put something else into the BClass
|
208
|
-
assert_raise StandardError do
|
209
|
-
bc.addAClasses :notaaclass
|
210
|
-
end
|
211
|
-
|
212
|
-
# remove the AClass from the BClass
|
213
|
-
bc.removeAClasses ac
|
214
|
-
assert !bc.aClasses.include?(ac)
|
215
|
-
assert !ac.bClasses.include?(bc)
|
216
|
-
|
217
|
-
# put the BClass into the AClass
|
218
|
-
ac.addBClasses bc
|
219
|
-
assert ac.bClasses.include?(bc)
|
220
|
-
assert bc.aClasses.include?(ac)
|
221
|
-
|
222
|
-
# put something else into the AClass
|
223
|
-
assert_raise StandardError do
|
224
|
-
ac.addBClasses :notabclass
|
225
|
-
end
|
226
|
-
|
227
|
-
# remove the BClass from the AClass
|
228
|
-
ac.removeBClasses bc
|
229
|
-
assert !ac.bClasses.include?(bc)
|
230
|
-
assert !bc.aClasses.include?(ac)
|
231
|
-
|
232
|
-
assert_equal AClassMM.one_attributes, []
|
233
|
-
assert_equal AClassMM.many_attributes, ["bClasses"]
|
234
|
-
assert_equal BClassMM.one_attributes, []
|
235
|
-
assert_equal BClassMM.many_attributes, ["aClasses"]
|
236
|
-
end
|
237
|
-
|
238
|
-
class SomeSuperClass < RGen::MetamodelBuilder::MMBase
|
239
|
-
has_one "name"
|
240
|
-
has_many "others"
|
241
|
-
end
|
242
|
-
|
243
|
-
class SomeSubClass < SomeSuperClass
|
244
|
-
has_one "subname"
|
245
|
-
has_many "subothers"
|
246
|
-
end
|
247
|
-
|
248
|
-
class OtherSubClass < SomeSuperClass
|
249
|
-
has_one "othersubname"
|
250
|
-
has_many "othersubothers"
|
251
|
-
end
|
252
|
-
|
253
|
-
def test_inheritance
|
254
|
-
assert_equal SomeSuperClass.one_attributes, ["name"]
|
255
|
-
assert_equal SomeSuperClass.many_attributes, ["others"]
|
256
|
-
assert_equal SomeSubClass.one_attributes.sort, ["name", "subname"]
|
257
|
-
assert_equal SomeSubClass.many_attributes.sort, ["others", "subothers"]
|
258
|
-
assert_equal OtherSubClass.one_attributes.sort, ["name", "othersubname"]
|
259
|
-
assert_equal OtherSubClass.many_attributes.sort, ["others", "othersubothers"]
|
260
|
-
end
|
409
|
+
def checkAnnotation(anno, source, hash)
|
410
|
+
assert anno.is_a?(RGen::ECore::EAnnotation)
|
411
|
+
assert_equal source, anno.source
|
412
|
+
assert_equal hash.size, anno.details.size
|
413
|
+
hash.each_pair do |k, v|
|
414
|
+
detail = anno.details.find{|d| d.key == k}
|
415
|
+
assert detail.is_a?(RGen::ECore::EStringToStringMapEntry)
|
416
|
+
assert_equal v, detail.value
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
261
420
|
end
|