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
This commit is contained in:
Torsten Rüger 2019-10-02 17:42:24 +03:00
parent 48e18ac9cd
commit fd8a3e9cc5
9 changed files with 42 additions and 15 deletions

View File

@ -1,5 +1,10 @@
--- ---
engines: engines:
checks:
method-count:
enabled: false
method-lines:
enabled: false
bundler-audit: bundler-audit:
enabled: true enabled: true
duplication: duplication:

View File

@ -38,9 +38,9 @@ module Ruby
def to_s(depth = 0) def to_s(depth = 0)
parts = "if(#{@condition})\n" 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 += "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" parts += "end\n"
at_depth(depth , parts ) at_depth(depth , parts )
end end

View File

@ -16,16 +16,8 @@ module Vool
def initialize( name , supe , body) def initialize( name , supe , body)
@name = name @name = name
@super_class_name = supe || :Object @super_class_name = supe || :Object
case body raise "what body #{body}" unless body.is_a?(Statements)
when MethodExpression @body = body
@body = Statements.new([body])
when Statements
@body = body
when nil
@body = Statements.new([])
else
raise "what body #{body}"
end
end end
# This creates the Parfait class. # This creates the Parfait class.

View File

@ -52,8 +52,8 @@ module Vool
def to_s(depth = 0) def to_s(depth = 0)
parts = "if (#{@condition.to_s(0)})\n" parts = "if (#{@condition.to_s(0)})\n"
parts += " #{@if_true}\n" if @if_true parts += " #{@if_true}\n" if @if_true
parts += "else\n" if(@false) parts += "else\n" if(@if_false)
parts += " #{@if_false}\n" if(@false) parts += " #{@if_false}\n" if(@if_false)
parts += "end\n" parts += "end\n"
at_depth(depth , parts ) at_depth(depth , parts )
end end

View File

@ -19,5 +19,24 @@ module Parfait
def test_type def test_type
assert_equal ::Parfait::Type , @object.get_internal_word( 0 ).class assert_equal ::Parfait::Type , @object.get_internal_word( 0 ).class
end 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
end end

View File

@ -39,7 +39,7 @@ module Ruby
end end
def test_to_s def test_to_s
lst = compile( double_if ) 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 end
end end

View File

@ -12,13 +12,18 @@ module Ruby
end end
def test_true def test_true
assert_equal Vool::LocalAssignment , @lst.if_true.class assert_equal Vool::LocalAssignment , @lst.if_true.class
assert @lst.has_true?
end end
def test_false def test_false
assert_equal Vool::LocalAssignment , @lst.if_false.class assert_equal Vool::LocalAssignment , @lst.if_false.class
assert @lst.has_false?
end end
def test_condition def test_condition
assert_equal Vool::TrueConstant , @lst.condition.class assert_equal Vool::TrueConstant , @lst.condition.class
end end
def test_to_s
assert_tos "if (true);a = 1;else;a = 2;end" , @lst
end
end end
class TestIfStatementVoolHoisted < MiniTest::Test class TestIfStatementVoolHoisted < MiniTest::Test
include RubyTests include RubyTests

View File

@ -1,5 +1,8 @@
module Minitest module Minitest
module Assertions 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) def assert_slot_to_reg( slot , array = nil, index = nil , register = nil)
assert_equal Risc::SlotToReg , slot.class assert_equal Risc::SlotToReg , slot.class
assert_equal( array , slot.array.symbol , "wrong source register") if array assert_equal( array , slot.array.symbol , "wrong source register") if array

View File

@ -25,6 +25,9 @@ module Vool
def test_class_instance def test_class_instance
assert_equal :a , @vool.to_parfait.instance_type.names[1] assert_equal :a , @vool.to_parfait.instance_type.names[1]
end end
def test_to_s
assert_tos "class Test < Object;def main(arg);@a = 5;return @a;end;end" , @vool
end
end end
class TestClassStatementTypeCreation < MiniTest::Test class TestClassStatementTypeCreation < MiniTest::Test
include ScopeHelper include ScopeHelper