From fc96f1d2da65fbe4a68a6147e941a33214cf4ed6 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 15 Jan 2017 16:59:29 +0200 Subject: [PATCH] checking classes don't get created twice --- lib/melon/ruby_compiler.rb | 4 +++- test/melon/test_compiler.rb | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/melon/ruby_compiler.rb b/lib/melon/ruby_compiler.rb index e87be655..90fe4a62 100644 --- a/lib/melon/ruby_compiler.rb +++ b/lib/melon/ruby_compiler.rb @@ -50,7 +50,9 @@ module Melon def get_name( statement ) return nil unless statement - statement.children[1] + name = statement.children[1] + raise "Not symbol #{name}" unless name.is_a? Symbol + name end end diff --git a/test/melon/test_compiler.rb b/test/melon/test_compiler.rb index fb049382..af94ae02 100644 --- a/test/melon/test_compiler.rb +++ b/test/melon/test_compiler.rb @@ -7,6 +7,13 @@ module Melon Register.machine.boot end + def test_doesnt_create_existing_clas + space_class = Parfait.object_space.get_class_by_name(:Space) + RubyCompiler.compile "class Space ; end" + clazz = Parfait.object_space.get_class_by_name(:Space) + assert_equal clazz , space_class + end + def test_creates_class_without_deriviation RubyCompiler.compile "class Testing ; end" clazz = Parfait.object_space.get_class_by_name(:Testing)