From 7b4a0126f7585e4bce604739e0a1ba9808c98866 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Thu, 19 Jul 2018 20:59:15 +0300 Subject: [PATCH] add a helper to get the vool equivalent of a ruby class --- lib/ruby/statement.rb | 6 ++++++ test/ruby/test_statement.rb | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test/ruby/test_statement.rb diff --git a/lib/ruby/statement.rb b/lib/ruby/statement.rb index 330e8738..7993498e 100644 --- a/lib/ruby/statement.rb +++ b/lib/ruby/statement.rb @@ -12,6 +12,12 @@ module Ruby strings.collect{|str| prefix + str}.join("\n") end + def vool_brother + eval "Vool::#{class_name}" + end + def class_name + self.class.name.split("::").last + end end class Expression diff --git a/test/ruby/test_statement.rb b/test/ruby/test_statement.rb new file mode 100644 index 00000000..cfd8d99e --- /dev/null +++ b/test/ruby/test_statement.rb @@ -0,0 +1,23 @@ +require_relative "helper" + +module Ruby + class TestStatement < MiniTest::Test + include RubyTests + + def test_class_name + assert_equal "Statement" , Statement.new.class_name + end + def test_brother + assert_equal Vool::Statement , Statement.new.vool_brother + end + def test_yield + lst = compile( "yield") + assert_equal Vool::YieldStatement , lst.vool_brother + end + def test_assign + lst = compile( "a = 4") + assert_equal Vool::LocalAssignment , lst.vool_brother + end + + end +end