rgen 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +6 -1
  3. data/Rakefile +15 -25
  4. data/lib/rgen/fragment/fragmented_model.rb +2 -0
  5. data/lib/rgen/fragment/model_fragment.rb +3 -0
  6. data/lib/rgen/metamodel_builder/builder_extensions.rb +13 -5
  7. data/lib/rgen/metamodel_builder/builder_runtime.rb +12 -5
  8. data/test/array_extensions_test.rb +7 -7
  9. data/test/ea_instantiator_test.rb +2 -2
  10. data/test/ea_serializer_test.rb +2 -2
  11. data/test/ecore_self_test.rb +2 -2
  12. data/test/ecore_to_ruby_test.rb +2 -2
  13. data/test/environment_test.rb +2 -2
  14. data/test/json_test.rb +4 -4
  15. data/test/metamodel_builder_test.rb +69 -42
  16. data/test/metamodel_from_ecore_test.rb +1 -1
  17. data/test/metamodel_order_test.rb +2 -2
  18. data/test/metamodel_roundtrip_test.rb +2 -2
  19. data/test/method_delegation_test.rb +5 -5
  20. data/test/model_builder/builder_context_test.rb +3 -3
  21. data/test/model_builder/builder_test.rb +11 -11
  22. data/test/model_builder/reference_resolver_test.rb +3 -3
  23. data/test/model_builder/serializer_test.rb +2 -2
  24. data/test/model_fragment_test.rb +2 -2
  25. data/test/output_handler_test.rb +2 -2
  26. data/test/qualified_name_provider_test.rb +2 -2
  27. data/test/qualified_name_resolver_test.rb +4 -4
  28. data/test/reference_resolver_test.rb +4 -4
  29. data/test/rgen_test.rb +1 -1
  30. data/test/template_language_test.rb +6 -8
  31. data/test/testmodel/class_model_checker.rb +17 -17
  32. data/test/testmodel/ecore_model_checker.rb +13 -13
  33. data/test/testmodel/object_model_checker.rb +6 -6
  34. data/test/transformer_test.rb +3 -3
  35. data/test/util/file_cache_map_test.rb +2 -2
  36. data/test/util/pattern_matcher_test.rb +7 -7
  37. data/test/xml_instantiator_test/simple_ecore_model_checker.rb +12 -12
  38. data/test/xml_instantiator_test.rb +8 -8
  39. metadata +54 -23
  40. data/test/metamodel_roundtrip_test/TestModel_Regenerated.rb +0 -71
  41. data/test/metamodel_roundtrip_test/houseMetamodel_Regenerated.ecore +0 -162
  42. data/test/metamodel_roundtrip_test/using_builtin_types_serialized.ecore +0 -9
  43. data/test/model_builder/ecore_internal.rb +0 -113
  44. data/test/template_language_test/line_endings_mixed.txt +0 -2
  45. data/test/template_language_test/line_endings_unix.txt +0 -2
  46. data/test/template_language_test/line_endings_windows.txt +0 -2
  47. data/test/testmodel/ea_testmodel_regenerated.xml +0 -813
  48. data/test/util/file_cache_map_test/testdir/fileA +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb797f971990b12a38d234053b5edd0be3bd3cab
4
- data.tar.gz: 27b2698616fa3536d71800db0784485b3903d019
3
+ metadata.gz: d1c27a6cc15f063ebc9483cb56253ebd20721cd2
4
+ data.tar.gz: b30dfcf5b91d19a8d26b0cc66a5dec9d3c0471c9
5
5
  SHA512:
6
- metadata.gz: 79f31649d8f3a8da15723545841ba91b0b6294478000508b8f5abbd35b84d8c3d52d0b0100b35dd6803621a7e11d450ce4f06253e81be60a8c19ec06b45f4ff7
7
- data.tar.gz: 267ee0574d6ce33e41c19825b86e8fff027c061dde40497124968c654e43cb7822f085c6614ce97cd372e58e2ce4643d8efbc10eebe310da137d5cc8afeaa543
6
+ metadata.gz: 5b74eb0928f9e39911b25dddbff8c73b12a331d651d59fdb27672794c6f6477bcdf23b3e8ac17ca97c2b3138dc33a3788a48ae6100493a710ff06e5557093dc8
7
+ data.tar.gz: cfe2866c2692b7a408cd460205cdc105f2cf792262104adfb6a0f0aa55bf917c26193766abebf43ccfd2f218f74e78910f20b82fa17d585beaca5345301bf985
data/CHANGELOG CHANGED
@@ -212,4 +212,9 @@
212
212
 
213
213
  =0.8.2
214
214
 
215
- * Added helper methods
215
+ * Added helper methods
216
+
217
+ =0.8.3
218
+
219
+ * Performance improvement: getGeneric made a lot faster
220
+
data/Rakefile CHANGED
@@ -1,39 +1,29 @@
1
1
  require 'rubygems/package_task'
2
2
  require 'rdoc/task'
3
+ require 'bundler/setup'
4
+ require 'rake/testtask'
3
5
 
4
- RGenGemSpec = Gem::Specification.new do |s|
5
- s.name = %q{rgen}
6
- s.version = "0.8.2"
7
- s.date = Time.now.strftime("%Y-%m-%d")
8
- s.summary = %q{Ruby Modelling and Generator Framework}
9
- s.email = %q{martin dot thiede at gmx de}
10
- s.homepage = %q{http://ruby-gen.org}
11
- s.rubyforge_project = %q{rgen}
12
- s.description = %q{RGen is a framework for Model Driven Software Development (MDSD) in Ruby. This means that it helps you build Metamodels, instantiate Models, modify and transform Models and finally generate arbitrary textual content from it.}
13
- s.authors = ["Martin Thiede"]
14
- gemfiles = Rake::FileList.new
15
- gemfiles.include("{lib,test}/**/*")
16
- gemfiles.include("README.rdoc", "CHANGELOG", "MIT-LICENSE", "Rakefile")
17
- gemfiles.exclude(/\b\.bak\b/)
18
- s.files = gemfiles
19
- s.rdoc_options = ["--main", "README.rdoc", "-x", "test", "-x", "metamodels", "-x", "ea_support/uml13*"]
20
- s.extra_rdoc_files = ["README.rdoc", "CHANGELOG", "MIT-LICENSE"]
21
- end
6
+ RGenGemSpec = eval(File.read('rgen.gemspec'))
22
7
 
23
8
  RDoc::Task.new do |rd|
24
- rd.main = "README.rdoc"
25
- rd.rdoc_files.include("README.rdoc", "CHANGELOG", "MIT-LICENSE", "lib/**/*.rb")
26
- rd.rdoc_files.exclude("lib/metamodels/*")
27
- rd.rdoc_files.exclude("lib/ea_support/uml13*")
28
- rd.rdoc_dir = "doc"
9
+ rd.main = 'README.rdoc'
10
+ rd.rdoc_files.include('README.rdoc', 'CHANGELOG', 'MIT-LICENSE', 'lib/**/*.rb')
11
+ rd.rdoc_files.exclude('lib/metamodels/*')
12
+ rd.rdoc_files.exclude('lib/ea_support/uml13*')
13
+ rd.rdoc_dir = 'doc'
29
14
  end
30
15
 
31
16
  RGenPackageTask = Gem::PackageTask.new(RGenGemSpec) do |p|
32
17
  p.need_zip = false
33
- end
18
+ end
19
+
20
+ ::Rake::TestTask.new(:test) do |t|
21
+ t.test_files = ['test/rgen_test.rb']
22
+ t.warning = false
23
+ end
34
24
 
35
25
  task :prepare_package_rdoc => :rdoc do
36
- RGenPackageTask.package_files.include("doc/**/*")
26
+ RGenPackageTask.package_files.include('doc/**/*')
37
27
  end
38
28
 
39
29
  task :release => [:prepare_package_rdoc, :package]
@@ -111,6 +111,8 @@ class FragmentedModel
111
111
  # This is a Hash mapping identifiers to model elements accessible via the identifier.
112
112
  #
113
113
  def index
114
+ # Invalidate the cache when any fragment's local index changes.
115
+ # Assumption: If the local index content changes, there is a new index object.
114
116
  fragments.each do |f|
115
117
  if !@fragment_index[f] || (@fragment_index[f].object_id != f.index.object_id)
116
118
  @fragment_index[f] = f.index
@@ -117,6 +117,9 @@ class ModelFragment
117
117
  end
118
118
 
119
119
  # Returns the index of the element contained in this fragment.
120
+ #
121
+ # FragmentedModel's index caching depends on the fact that any change
122
+ # of a fragment's index contents implies a new index object.
120
123
  #
121
124
  def index
122
125
  build_index unless @index
@@ -319,6 +319,10 @@ module BuilderExtensions
319
319
  end
320
320
  <% if name != "class" %>
321
321
  alias <%= name %> get<%= firstToUpper(name) %>
322
+ <% else %>
323
+ def getGeneric(role)
324
+ send("get\#{firstToUpper(role.to_s)}")
325
+ end
322
326
  <% end %>
323
327
 
324
328
  CODE
@@ -380,10 +384,14 @@ module BuilderExtensions
380
384
  @@many_read_builder ||= ERB.new <<-CODE
381
385
 
382
386
  def get<%= firstToUpper(name) %>
383
- ( @<%= name %> ? @<%= name %>.dup : [] )
387
+ ( defined?(@<%= name %>) ? @<%= name %>.dup : [] )
384
388
  end
385
389
  <% if name != "class" %>
386
390
  alias <%= name %> get<%= firstToUpper(name) %>
391
+ <% else %>
392
+ def getGeneric(role)
393
+ send("get\#{firstToUpper(role.to_s)}")
394
+ end
387
395
  <% end %>
388
396
 
389
397
  CODE
@@ -394,7 +402,7 @@ module BuilderExtensions
394
402
  @@many_write_builder ||= ERB.new <<-CODE
395
403
 
396
404
  def add<%= firstToUpper(name) %>(val, index=-1)
397
- @<%= name %> = [] unless @<%= name %>
405
+ @<%= name %> = [] unless defined?(@<%= name %>)
398
406
  return if val.nil? || (val.is_a?(MMBase) || val.is_a?(MMGeneric)) && @<%= name %>.any? {|e| e.equal?(val)}
399
407
  <%= type_check_code("val", props) %>
400
408
  @<%= name %>.insert(index, val)
@@ -407,7 +415,7 @@ module BuilderExtensions
407
415
  end
408
416
 
409
417
  def remove<%= firstToUpper(name) %>(val)
410
- @<%= name %> = [] unless @<%= name %>
418
+ @<%= name %> = [] unless defined?(@<%= name %>)
411
419
  @<%= name %>.each_with_index do |e,i|
412
420
  if e.equal?(val)
413
421
  @<%= name %>.delete_at(i)
@@ -428,7 +436,7 @@ module BuilderExtensions
428
436
  get<%= firstToUpper(name) %>.each {|e|
429
437
  remove<%= firstToUpper(name) %>(e)
430
438
  }
431
- @<%= name %> = [] unless @<%= name %>
439
+ @<%= name %> = [] unless defined?(@<%= name %>)
432
440
  <% if props.reference? %>
433
441
  val.uniq {|elem| elem.object_id }.each {|elem|
434
442
  next if elem.nil?
@@ -451,7 +459,7 @@ module BuilderExtensions
451
459
  alias <%= name %>= set<%= firstToUpper(name) %>
452
460
 
453
461
  def _register<%= firstToUpper(name) %>(val)
454
- @<%= name %> = [] unless @<%= name %>
462
+ @<%= name %> = [] unless defined?(@<%= name %>)
455
463
  @<%= name %>.push val
456
464
  <% if props.reference? && props.value(:containment) %>
457
465
  val._set_container(self, :<%= name %>)
@@ -58,14 +58,17 @@ module BuilderRuntime
58
58
  end
59
59
  end
60
60
 
61
- def getGeneric(role)
62
- send("get#{firstToUpper(role.to_s)}")
63
- end
61
+ alias getGeneric send
64
62
 
65
63
  def getGenericAsArray(role)
66
64
  result = getGeneric(role)
67
- result = [result].compact unless result.is_a?(Array)
68
- result
65
+ if result.nil?
66
+ []
67
+ elsif result.is_a?(Array)
68
+ result
69
+ else
70
+ [result]
71
+ end
69
72
  end
70
73
 
71
74
  def eIsSet(role)
@@ -100,6 +103,10 @@ module BuilderRuntime
100
103
 
101
104
  # if a block is given, calls the block on every contained element in depth first order.
102
105
  # if the block returns :prune, recursion will stop at this point.
106
+ #
107
+ # BEWARE of concurrent modification of contained elements while iterating!
108
+ # (adding/removing containers or contained elements)
109
+ # if you need to do such modifications, use the variant without a block instead.
103
110
  #
104
111
  # if no block is given builds and returns a list of all contained elements.
105
112
  #
@@ -1,9 +1,9 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
2
 
3
- require 'test/unit'
3
+ require 'minitest/autorun'
4
4
  require 'rgen/array_extensions'
5
5
 
6
- class ArrayExtensionsTest < Test::Unit::TestCase
6
+ class ArrayExtensionsTest < MiniTest::Test
7
7
 
8
8
  def test_element_methods
9
9
  c = Struct.new("SomeClass",:name,:age)
@@ -11,11 +11,11 @@ class ArrayExtensionsTest < Test::Unit::TestCase
11
11
  a << c.new('MyName',33)
12
12
  a << c.new('YourName',22)
13
13
  assert_equal ["MyName", "YourName"], a >> :name
14
- assert_raise NoMethodError do
14
+ assert_raises NoMethodError do
15
15
  a.name
16
16
  end
17
17
  assert_equal [33, 22], a>>:age
18
- assert_raise NoMethodError do
18
+ assert_raises NoMethodError do
19
19
  a.age
20
20
  end
21
21
  # unfortunately, any method can be called on an empty array
@@ -42,11 +42,11 @@ class ArrayExtensionsTest < Test::Unit::TestCase
42
42
  # put something into the array that is not an MMBase
43
43
  a << "not a MMBase"
44
44
  # the dot operator will tell that there is something not a MMBase
45
- assert_raise StandardError do
45
+ assert_raises StandardError do
46
46
  a.age
47
47
  end
48
48
  # the >> operator will try to call the method anyway
49
- assert_raise NoMethodError do
49
+ assert_raises NoMethodError do
50
50
  a >> :age
51
51
  end
52
52
  end
@@ -56,7 +56,7 @@ class ArrayExtensionsTest < Test::Unit::TestCase
56
56
  end
57
57
 
58
58
  def test_to_str_on_empty_array
59
- assert_raise NoMethodError do
59
+ assert_raises NoMethodError do
60
60
  [].to_str
61
61
  end
62
62
  end
@@ -1,6 +1,6 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
2
 
3
- require 'test/unit'
3
+ require 'minitest/autorun'
4
4
  require 'rgen/environment'
5
5
  require 'metamodels/uml13_metamodel'
6
6
  require 'ea_support/ea_support'
@@ -9,7 +9,7 @@ require 'testmodel/class_model_checker'
9
9
  require 'testmodel/object_model_checker'
10
10
  require 'testmodel/ecore_model_checker'
11
11
 
12
- class EAInstantiatorTest < Test::Unit::TestCase
12
+ class EAInstantiatorTest < MiniTest::Test
13
13
 
14
14
  include Testmodel::ClassModelChecker
15
15
  include Testmodel::ObjectModelChecker
@@ -1,12 +1,12 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
2
 
3
- require 'test/unit'
3
+ require 'minitest/autorun'
4
4
  require 'rgen/environment'
5
5
  require 'metamodels/uml13_metamodel'
6
6
  require 'ea_support/ea_support'
7
7
  require 'rgen/serializer/xmi11_serializer'
8
8
 
9
- class EASerializerTest < Test::Unit::TestCase
9
+ class EASerializerTest < MiniTest::Test
10
10
 
11
11
  MODEL_DIR = File.join(File.dirname(__FILE__),"testmodel")
12
12
  TEST_DIR = File.join(File.dirname(__FILE__),"ea_serializer_test")
@@ -1,10 +1,10 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
2
 
3
- require 'test/unit'
3
+ require 'minitest/autorun'
4
4
  require 'rgen/ecore/ecore'
5
5
  require 'rgen/array_extensions'
6
6
 
7
- class ECoreSelfTest < Test::Unit::TestCase
7
+ class ECoreSelfTest < MiniTest::Test
8
8
  include RGen::ECore
9
9
 
10
10
  def test_simple
@@ -1,12 +1,12 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
2
 
3
- require 'test/unit'
3
+ require 'minitest/autorun'
4
4
  require 'rgen/environment'
5
5
  require 'rgen/ecore/ecore'
6
6
  require 'rgen/ecore/ecore_ext'
7
7
  require 'rgen/ecore/ecore_to_ruby'
8
8
 
9
- class ECoreToRubyTest < Test::Unit::TestCase
9
+ class ECoreToRubyTest < MiniTest::Test
10
10
 
11
11
  module ContainerSimple
12
12
  end
@@ -1,10 +1,10 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
2
 
3
- require 'test/unit'
3
+ require 'minitest/autorun'
4
4
  require 'rgen/environment'
5
5
  require 'rgen/metamodel_builder'
6
6
 
7
- class EnvironmentTest < Test::Unit::TestCase
7
+ class EnvironmentTest < MiniTest::Test
8
8
 
9
9
  class Model
10
10
  attr_accessor :name
data/test/json_test.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
2
 
3
- require 'test/unit'
3
+ require 'minitest/autorun'
4
4
  require 'rgen/environment'
5
5
  require 'rgen/metamodel_builder'
6
6
  require 'rgen/serializer/json_serializer'
7
7
  require 'rgen/instantiator/json_instantiator'
8
8
 
9
- class JsonTest < Test::Unit::TestCase
9
+ class JsonTest < MiniTest::Test
10
10
 
11
11
  module TestMM
12
12
  extend RGen::MetamodelBuilder::ModuleExtension
@@ -61,7 +61,7 @@ class JsonTest < Test::Unit::TestCase
61
61
  inst.instantiate(%q({ "_class": "TestNode", "text": "some text", "childs": [
62
62
  { "_class": "TestNode", "text": "child" }] }))
63
63
  root = env.find(:class => TestMM::TestNode, :text => "some text").first
64
- assert_not_nil root
64
+ assert root != nil
65
65
  assert_equal 1, root.childs.size
66
66
  assert_equal TestMM::TestNode, root.childs.first.class
67
67
  assert_equal "child", root.childs.first.text
@@ -149,7 +149,7 @@ class JsonTest < Test::Unit::TestCase
149
149
  def test_json_instantiator_subpackage_no_shortname_opt
150
150
  env = RGen::Environment.new
151
151
  inst = RGen::Instantiator::JsonInstantiator.new(env, TestMMSubpackage, :short_class_names => false)
152
- assert_raise RuntimeError do
152
+ assert_raises RuntimeError do
153
153
  inst.instantiate(%q({ "_class": "Data2", "data2": "something" }))
154
154
  end
155
155
  end
@@ -1,11 +1,11 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
2
 
3
- require 'test/unit'
3
+ require 'minitest/autorun'
4
4
  require 'rgen/metamodel_builder'
5
5
  require 'rgen/array_extensions'
6
6
  require 'bigdecimal'
7
7
 
8
- class MetamodelBuilderTest < Test::Unit::TestCase
8
+ class MetamodelBuilderTest < MiniTest::Test
9
9
 
10
10
  module TestMetamodel
11
11
  extend RGen::MetamodelBuilder::ModuleExtension
@@ -168,6 +168,14 @@ class MetamodelBuilderTest < Test::Unit::TestCase
168
168
  end
169
169
  OppositeRefAssocA.one_to_one 'bClass', OppositeRefAssocB, 'aClass'
170
170
 
171
+ class ReservedNameClass < RGen::MetamodelBuilder::MMBase
172
+ has_attr 'class', String
173
+ end
174
+
175
+ class ManyReservedNameClass < RGen::MetamodelBuilder::MMBase
176
+ has_many_attr 'class', String
177
+ end
178
+
171
179
  end
172
180
 
173
181
  def mm
@@ -182,8 +190,8 @@ class MetamodelBuilderTest < Test::Unit::TestCase
182
190
  sc.name = "TestName"
183
191
  assert_equal "TestName", sc.name
184
192
  sc.name = nil
185
- assert_equal nil, sc.name
186
- err = assert_raise StandardError do
193
+ assert_nil sc.name
194
+ err = assert_raises StandardError do
187
195
  sc.name = 5
188
196
  end
189
197
  assert_match /In (\w+::)+SimpleClass : Can not use a Fixnum where a String is expected/, err.message
@@ -212,12 +220,12 @@ class MetamodelBuilderTest < Test::Unit::TestCase
212
220
  sc.allowed = false
213
221
  assert_equal false, sc.allowed
214
222
  sc.allowed = nil
215
- assert_equal nil, sc.allowed
216
- err = assert_raise StandardError do
223
+ assert_nil sc.allowed
224
+ err = assert_raises StandardError do
217
225
  sc.allowed = :someSymbol
218
226
  end
219
227
  assert_match /In (\w+::)+SimpleClass : Can not use a Symbol\(:someSymbol\) where a \[true,false\] is expected/, err.message
220
- err = assert_raise StandardError do
228
+ err = assert_raises StandardError do
221
229
  sc.allowed = "a string"
222
230
  end
223
231
  assert_match /In (\w+::)+SimpleClass : Can not use a String where a \[true,false\] is expected/, err.message
@@ -230,12 +238,12 @@ class MetamodelBuilderTest < Test::Unit::TestCase
230
238
  sc.kind = :extended
231
239
  assert_equal :extended, sc.kind
232
240
  sc.kind = nil
233
- assert_equal nil, sc.kind
234
- err = assert_raise StandardError do
241
+ assert_nil sc.kind
242
+ err = assert_raises StandardError do
235
243
  sc.kind = :false
236
244
  end
237
245
  assert_match /In (\w+::)+SimpleClass : Can not use a Symbol\(:false\) where a \[:simple,:extended\] is expected/, err.message
238
- err = assert_raise StandardError do
246
+ err = assert_raises StandardError do
239
247
  sc.kind = "a string"
240
248
  end
241
249
  assert_match /In (\w+::)+SimpleClass : Can not use a String where a \[:simple,:extended\] is expected/, err.message
@@ -272,7 +280,7 @@ class MetamodelBuilderTest < Test::Unit::TestCase
272
280
  assert_equal (2**(0.size * 8 -2) -1) + 1, sc.longWithDefault
273
281
  assert sc.longWithDefault.is_a?(Bignum)
274
282
  assert sc.longWithDefault.is_a?(Integer)
275
- err = assert_raise StandardError do
283
+ err = assert_raises StandardError do
276
284
  sc.longWithDefault = "a string"
277
285
  end
278
286
  assert_match /In (\w+::)+SimpleClass : Can not use a String where a Integer is expected/, err.message
@@ -285,7 +293,7 @@ class MetamodelBuilderTest < Test::Unit::TestCase
285
293
  assert_respond_to o, :addLiterals
286
294
  assert_respond_to o, :removeLiterals
287
295
 
288
- err = assert_raise(StandardError) do
296
+ err = assert_raises(StandardError) do
289
297
  o.addLiterals(1)
290
298
  end
291
299
  assert_match /In (\w+::)+ManyAttrClass : Can not use a Fixnum where a String is expected/, err.message
@@ -320,7 +328,7 @@ class MetamodelBuilderTest < Test::Unit::TestCase
320
328
  o.literals = ["a", "b", "c"]
321
329
  assert_equal ["a", "b", "c"], o.literals
322
330
  # can only take enumerables
323
- err = assert_raise(StandardError) do
331
+ err = assert_raises(StandardError) do
324
332
  o.literals = 1
325
333
  end
326
334
  assert_match /In (\w+::)+ManyAttrClass : Can not use a Fixnum where a Enumerable is expected/, err.message
@@ -359,7 +367,7 @@ class MetamodelBuilderTest < Test::Unit::TestCase
359
367
  sc.classA = ca
360
368
  assert_equal ca, sc.classA
361
369
  sc.classA = nil
362
- assert_equal nil, sc.classA
370
+ assert_nil sc.classA
363
371
 
364
372
  assert_respond_to sc, :classB
365
373
  assert_respond_to sc, :classB=
@@ -367,7 +375,7 @@ class MetamodelBuilderTest < Test::Unit::TestCase
367
375
  sc.classB = cb
368
376
  assert_equal cb, sc.classB
369
377
 
370
- err = assert_raise StandardError do
378
+ err = assert_raises StandardError do
371
379
  sc.classB = ca
372
380
  end
373
381
  assert_match /In (\w+::)+HasOneTestClass : Can not use a (\w+::)+ClassA where a (\w+::)+ClassB is expected/, err.message
@@ -394,7 +402,7 @@ class MetamodelBuilderTest < Test::Unit::TestCase
394
402
  assert_equal [ca1, ca2], o.classA
395
403
  o.removeClassA(ca2)
396
404
  assert_equal [ca1], o.classA
397
- err = assert_raise StandardError do
405
+ err = assert_raises StandardError do
398
406
  o.addClassA(mm::ClassB.new)
399
407
  end
400
408
  assert_match /In (\w+::)+HasManyTestClass : Can not use a (\w+::)+ClassB where a (\w+::)+ClassA is expected/, err.message
@@ -434,7 +442,7 @@ class MetamodelBuilderTest < Test::Unit::TestCase
434
442
 
435
443
  # remove the OneClass from the ManyClass
436
444
  mc.oneClass = nil
437
- assert_equal nil, mc.oneClass
445
+ assert_nil mc.oneClass
438
446
  assert !oc.manyClasses.include?(mc)
439
447
 
440
448
  # put the ManyClass into the OneClass
@@ -445,7 +453,7 @@ class MetamodelBuilderTest < Test::Unit::TestCase
445
453
  # remove the ManyClass from the OneClass
446
454
  oc.removeManyClasses mc
447
455
  assert !oc.manyClasses.include?(mc)
448
- assert_equal nil, mc.oneClass
456
+ assert_nil mc.oneClass
449
457
 
450
458
  assert_equal [], mm::OneClass.ecore.eReferences.select{|r| r.many == false}
451
459
  assert_equal ["manyClasses"], mm::OneClass.ecore.eReferences.select{|r| r.many == true}.name
@@ -478,7 +486,7 @@ class MetamodelBuilderTest < Test::Unit::TestCase
478
486
  mc1.oneClass = oc
479
487
  assert_equal [mc1], oc.manyClasses
480
488
  assert_equal oc, mc1.oneClass
481
- assert_equal nil, mc2.oneClass
489
+ assert_nil mc2.oneClass
482
490
 
483
491
  mc2.oneClass = oc
484
492
  assert_equal [mc1, mc2], oc.manyClasses
@@ -515,7 +523,7 @@ class MetamodelBuilderTest < Test::Unit::TestCase
515
523
 
516
524
  # remove the OneClass from the ManyClass
517
525
  mc.oneClass = nil
518
- assert_equal nil, mc.oneClass
526
+ assert_nil mc.oneClass
519
527
  assert !oc.manyClasses.include?(mc)
520
528
 
521
529
  # put the ManyClass into the OneClass
@@ -526,7 +534,7 @@ class MetamodelBuilderTest < Test::Unit::TestCase
526
534
  # remove the ManyClass from the OneClass
527
535
  oc.removeManyClasses mc
528
536
  assert !oc.manyClasses.include?(mc)
529
- assert_equal nil, mc.oneClass
537
+ assert_nil mc.oneClass
530
538
 
531
539
  assert_equal [], mm::OneClass2.ecore.eReferences.select{|r| r.many == false}
532
540
  assert_equal ["manyClasses"], mm::OneClass2.ecore.eReferences.select{|r| r.many == true}.name
@@ -552,8 +560,8 @@ class MetamodelBuilderTest < Test::Unit::TestCase
552
560
 
553
561
  # remove the AClass from the BClass
554
562
  bc.aClass = nil
555
- assert_equal nil, bc.aClass
556
- assert_equal nil, ac.bClass
563
+ assert_nil bc.aClass
564
+ assert_nil ac.bClass
557
565
 
558
566
  # put the BClass into the AClass
559
567
  ac.bClass = bc
@@ -562,8 +570,8 @@ class MetamodelBuilderTest < Test::Unit::TestCase
562
570
 
563
571
  # remove the BClass from the AClass
564
572
  ac.bClass = nil
565
- assert_equal nil, ac.bClass
566
- assert_equal nil, bc.aClass
573
+ assert_nil ac.bClass
574
+ assert_nil bc.aClass
567
575
 
568
576
  assert_equal ["bClass"], mm::AClassOO.ecore.eReferences.select{|r| r.many == false}.name
569
577
  assert_equal [], mm::AClassOO.ecore.eReferences.select{|r| r.many == true}
@@ -579,11 +587,11 @@ class MetamodelBuilderTest < Test::Unit::TestCase
579
587
  a.bClass = b1
580
588
  assert_equal b1, a.bClass
581
589
  assert_equal a, b1.aClass
582
- assert_equal nil, b2.aClass
590
+ assert_nil b2.aClass
583
591
 
584
592
  a.bClass = b2
585
593
  assert_equal b2, a.bClass
586
- assert_equal nil, b1.aClass
594
+ assert_nil b1.aClass
587
595
  assert_equal a, b2.aClass
588
596
  end
589
597
 
@@ -603,7 +611,7 @@ class MetamodelBuilderTest < Test::Unit::TestCase
603
611
  assert ac.bClasses.include?(bc)
604
612
 
605
613
  # put something else into the BClass
606
- err = assert_raise StandardError do
614
+ err = assert_raises StandardError do
607
615
  bc.addAClasses :notaaclass
608
616
  end
609
617
  assert_match /In (\w+::)+BClassMM : Can not use a Symbol\(:notaaclass\) where a (\w+::)+AClassMM is expected/, err.message
@@ -619,7 +627,7 @@ class MetamodelBuilderTest < Test::Unit::TestCase
619
627
  assert bc.aClasses.include?(ac)
620
628
 
621
629
  # put something else into the AClass
622
- err = assert_raise StandardError do
630
+ err = assert_raises StandardError do
623
631
  ac.addBClasses :notabclass
624
632
  end
625
633
  assert_match /In (\w+::)+AClassMM : Can not use a Symbol\(:notabclass\) where a (\w+::)+BClassMM is expected/, err.message
@@ -705,7 +713,8 @@ class MetamodelBuilderTest < Test::Unit::TestCase
705
713
 
706
714
  def checkAnnotation(anno, source, hash)
707
715
  assert anno.is_a?(RGen::ECore::EAnnotation)
708
- assert_equal source, anno.source
716
+ assert_equal source, anno.source unless source.nil?
717
+ assert_nil anno.source if source.nil?
709
718
  assert_equal hash.size, anno.details.size
710
719
  hash.each_pair do |k, v|
711
720
  detail = anno.details.find{|d| d.key == k}
@@ -887,7 +896,7 @@ class MetamodelBuilderTest < Test::Unit::TestCase
887
896
  end
888
897
 
889
898
  def test_abstract
890
- err = assert_raise StandardError do
899
+ err = assert_raises StandardError do
891
900
  mm::AbstractClass.new
892
901
  end
893
902
  assert_match /Class (\w+::)+AbstractClass is abstract/, err.message
@@ -939,35 +948,35 @@ class MetamodelBuilderTest < Test::Unit::TestCase
939
948
  end
940
949
 
941
950
  def test_bad_default_value_literal
942
- err = assert_raise StandardError do
951
+ err = assert_raises StandardError do
943
952
  BadDefaultValueLiteralContainer::Test1.call
944
953
  end
945
954
  assert_equal "Property integerWithDefault can not take value 1.1, expected an Integer", err.message
946
- err = assert_raise StandardError do
955
+ err = assert_raises StandardError do
947
956
  BadDefaultValueLiteralContainer::Test2.call
948
957
  end
949
958
  assert_equal "Property integerWithDefault can not take value x, expected an Integer", err.message
950
- err = assert_raise StandardError do
959
+ err = assert_raises StandardError do
951
960
  BadDefaultValueLiteralContainer::Test3.call
952
961
  end
953
962
  assert_equal "Property boolWithDefault can not take value 1, expected true or false", err.message
954
- err = assert_raise StandardError do
963
+ err = assert_raises StandardError do
955
964
  BadDefaultValueLiteralContainer::Test4.call
956
965
  end
957
966
  assert_equal "Property floatWithDefault can not take value 1, expected a Float", err.message
958
- err = assert_raise StandardError do
967
+ err = assert_raises StandardError do
959
968
  BadDefaultValueLiteralContainer::Test5.call
960
969
  end
961
970
  assert_equal "Property floatWithDefault can not take value true, expected a Float", err.message
962
- err = assert_raise StandardError do
971
+ err = assert_raises StandardError do
963
972
  BadDefaultValueLiteralContainer::Test6.call
964
973
  end
965
974
  assert_equal "Property enumWithDefault can not take value xxx, expected one of :simple, :extended", err.message
966
- err = assert_raise StandardError do
975
+ err = assert_raises StandardError do
967
976
  BadDefaultValueLiteralContainer::Test7.call
968
977
  end
969
978
  assert_equal "Property enumWithDefault can not take value 7, expected one of :simple, :extended", err.message
970
- err = assert_raise StandardError do
979
+ err = assert_raises StandardError do
971
980
  BadDefaultValueLiteralContainer::Test8.call
972
981
  end
973
982
  assert_equal "Property longWithDefault can not take value 1.1, expected an Integer", err.message
@@ -1322,9 +1331,7 @@ class MetamodelBuilderTest < Test::Unit::TestCase
1322
1331
 
1323
1332
  def test_container_generic
1324
1333
  a = mm::ContainerClass.new
1325
- assert_nothing_raised do
1326
- a.oneChild = RGen::MetamodelBuilder::MMGeneric.new
1327
- end
1334
+ a.oneChild = RGen::MetamodelBuilder::MMGeneric.new
1328
1335
  end
1329
1336
 
1330
1337
  def test_opposite_assoc_on_first_write
@@ -1479,4 +1486,24 @@ class MetamodelBuilderTest < Test::Unit::TestCase
1479
1486
  assert_equal [], a1.manyChildUni
1480
1487
  end
1481
1488
 
1489
+ def test_reserved_names
1490
+ e = mm::ReservedNameClass.new
1491
+ e.setGeneric("class", "X")
1492
+ assert_equal "X", e.getGeneric(:class)
1493
+ assert_equal "X", e.getGeneric("class")
1494
+ assert_equal ["X"], e.getGenericAsArray(:class)
1495
+ assert_equal ["X"], e.getGenericAsArray("class")
1496
+ assert_equal "X", e.getClass
1497
+ end
1498
+
1499
+ def test_reserved_names_many
1500
+ e = mm::ManyReservedNameClass.new
1501
+ e.addGeneric("class", "X")
1502
+ e.addGeneric("class", "Y")
1503
+ assert_equal ["X", "Y"], e.getGeneric(:class)
1504
+ assert_equal ["X", "Y"], e.getGeneric("class")
1505
+ assert_equal ["X", "Y"], e.getGenericAsArray(:class)
1506
+ assert_equal ["X", "Y"], e.getGenericAsArray("class")
1507
+ assert_equal ["X", "Y"], e.getClass
1508
+ end
1482
1509
  end