From fd8a3e9cc5c7d931de338a9b8e06b0b21e149163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20R=C3=BCger?= Date: Wed, 2 Oct 2019 17:42:24 +0300 Subject: [PATCH] some cc driven cleanup bit anoying that the builtin engine is used Even it is not as well configurable as preferred reek. Still, found one minor bug --- .codeclimate.yml | 5 +++++ lib/ruby/if_statement.rb | 4 ++-- lib/vool/class_expression.rb | 12 ++---------- lib/vool/if_statement.rb | 4 ++-- test/parfait/test_object.rb | 19 +++++++++++++++++++ test/ruby/test_if_statement.rb | 2 +- test/ruby/test_if_statement2.rb | 5 +++++ test/support/risc_assert.rb | 3 +++ test/vool/test_class_expression.rb | 3 +++ 9 files changed, 42 insertions(+), 15 deletions(-) diff --git a/.codeclimate.yml b/.codeclimate.yml index b7519f82..dcda29a0 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,5 +1,10 @@ --- engines: + checks: + method-count: + enabled: false + method-lines: + enabled: false bundler-audit: enabled: true duplication: diff --git a/lib/ruby/if_statement.rb b/lib/ruby/if_statement.rb index 509e93a7..26d4c7b6 100644 --- a/lib/ruby/if_statement.rb +++ b/lib/ruby/if_statement.rb @@ -38,9 +38,9 @@ module Ruby def to_s(depth = 0) parts = "if(#{@condition})\n" - parts += " #{@if_true.to_s(depth + 1)}\n" if(@if_true) + parts += " #{@if_true.to_s(1)}\n" if(@if_true) parts += "else\n" if(@if_false) - parts += " #{@if_false.to_s(depth + 1)}\n" if(@if_false) + parts += " #{@if_false.to_s(1)}\n" if(@if_false) parts += "end\n" at_depth(depth , parts ) end diff --git a/lib/vool/class_expression.rb b/lib/vool/class_expression.rb index e5522573..b867601f 100644 --- a/lib/vool/class_expression.rb +++ b/lib/vool/class_expression.rb @@ -16,16 +16,8 @@ module Vool def initialize( name , supe , body) @name = name @super_class_name = supe || :Object - case body - when MethodExpression - @body = Statements.new([body]) - when Statements - @body = body - when nil - @body = Statements.new([]) - else - raise "what body #{body}" - end + raise "what body #{body}" unless body.is_a?(Statements) + @body = body end # This creates the Parfait class. diff --git a/lib/vool/if_statement.rb b/lib/vool/if_statement.rb index a4d3e365..5a8ded38 100644 --- a/lib/vool/if_statement.rb +++ b/lib/vool/if_statement.rb @@ -52,8 +52,8 @@ module Vool def to_s(depth = 0) parts = "if (#{@condition.to_s(0)})\n" parts += " #{@if_true}\n" if @if_true - parts += "else\n" if(@false) - parts += " #{@if_false}\n" if(@false) + parts += "else\n" if(@if_false) + parts += " #{@if_false}\n" if(@if_false) parts += "end\n" at_depth(depth , parts ) end diff --git a/test/parfait/test_object.rb b/test/parfait/test_object.rb index a0e1aac6..2dae591d 100644 --- a/test/parfait/test_object.rb +++ b/test/parfait/test_object.rb @@ -19,5 +19,24 @@ module Parfait def test_type assert_equal ::Parfait::Type , @object.get_internal_word( 0 ).class end + def test_type_length + assert_equal 1 , Object.type_length + end + def test_set_type + type = @object.type + assert @object.set_type(type) + assert @object.type = type + end + def test_has_type + assert @object.has_type? + end + def test_set_inst + type = @object.type + assert @object.set_instance_variable(:type , type) + assert_equal type , @object.type + end + def test_names + assert_equal "[:type]" , @object.instance_variables.to_s + end end end diff --git a/test/ruby/test_if_statement.rb b/test/ruby/test_if_statement.rb index 45b32d52..875307aa 100644 --- a/test/ruby/test_if_statement.rb +++ b/test/ruby/test_if_statement.rb @@ -39,7 +39,7 @@ module Ruby end def test_to_s lst = compile( double_if ) - assert_equal "if(false); true;else; false;end" , lst.to_s.gsub("\n",";") + assert_tos "if(false);true;else;false;end" , lst end end end diff --git a/test/ruby/test_if_statement2.rb b/test/ruby/test_if_statement2.rb index 89723c5c..98b13dc1 100644 --- a/test/ruby/test_if_statement2.rb +++ b/test/ruby/test_if_statement2.rb @@ -12,13 +12,18 @@ module Ruby end def test_true assert_equal Vool::LocalAssignment , @lst.if_true.class + assert @lst.has_true? end def test_false assert_equal Vool::LocalAssignment , @lst.if_false.class + assert @lst.has_false? end def test_condition assert_equal Vool::TrueConstant , @lst.condition.class end + def test_to_s + assert_tos "if (true);a = 1;else;a = 2;end" , @lst + end end class TestIfStatementVoolHoisted < MiniTest::Test include RubyTests diff --git a/test/support/risc_assert.rb b/test/support/risc_assert.rb index b6e6c79e..4fae6868 100644 --- a/test/support/risc_assert.rb +++ b/test/support/risc_assert.rb @@ -1,5 +1,8 @@ module Minitest module Assertions + def assert_tos string , object + assert_equal string , object.to_s.gsub("\n",";").gsub(/\s+/," ").gsub("; ",";") + end def assert_slot_to_reg( slot , array = nil, index = nil , register = nil) assert_equal Risc::SlotToReg , slot.class assert_equal( array , slot.array.symbol , "wrong source register") if array diff --git a/test/vool/test_class_expression.rb b/test/vool/test_class_expression.rb index 6d80f3a4..d72b2737 100644 --- a/test/vool/test_class_expression.rb +++ b/test/vool/test_class_expression.rb @@ -25,6 +25,9 @@ module Vool def test_class_instance assert_equal :a , @vool.to_parfait.instance_type.names[1] end + def test_to_s + assert_tos "class Test < Object;def main(arg);@a = 5;return @a;end;end" , @vool + end end class TestClassStatementTypeCreation < MiniTest::Test include ScopeHelper