diff --git a/lib/typed/tree.rb b/lib/typed/tree.rb index 6a53830d..993ee072 100644 --- a/lib/typed/tree.rb +++ b/lib/typed/tree.rb @@ -15,24 +15,24 @@ end AST::Node.class_eval do - def [](name) - #puts self.inspect - children.each do |child| - if child.is_a?(AST::Node) - #puts child.type - if (child.type == name) - return child.children - end - else - #puts child.class - end - end - nil - end - - def first_from( node_name ) - from = self[node_name] - return nil unless from - from.first - end + # def [](name) + # #puts self.inspect + # children.each do |child| + # if child.is_a?(AST::Node) + # #puts child.type + # if (child.type == name) + # return child.children + # end + # else + # #puts child.class + # end + # end + # nil + # end + # + # def first_from( node_name ) + # from = self[node_name] + # return nil unless from + # from.first + # end end diff --git a/stash/soml/expressions/test_basic.rb b/stash/soml/expressions/test_basic.rb deleted file mode 100644 index 5a69c8cb..00000000 --- a/stash/soml/expressions/test_basic.rb +++ /dev/null @@ -1,52 +0,0 @@ -require_relative "helper" - - -class TestBasic < MiniTest::Test - include ExpressionHelper - - def setup - @root = :basic_type - @output = Register::RegisterValue - end - - def test_number - @string_input = '42 ' - assert_equal 42 , check.value - end - - def test_true - @string_input = 'true' - check - end - def test_false - @string_input = 'false ' - check - end - def test_nil - @string_input = 'nil ' - check - end - - def test_var - @string_input = 'int foo ' - @root = :field_def - @output = NilClass - check - end - - def test_self - @string_input = 'self ' - check - end - - def test_space - @string_input = 'self ' - check - end - - def test_string - @string_input = "\"hello\"" - check - end - -end diff --git a/stash/soml/expressions/helper.rb b/test/typed/expressions/helper.rb similarity index 53% rename from stash/soml/expressions/helper.rb rename to test/typed/expressions/helper.rb index 015079af..67de4f1d 100644 --- a/stash/soml/expressions/helper.rb +++ b/test/typed/expressions/helper.rb @@ -1,5 +1,4 @@ -require_relative '../../helper' -require 'parslet/convenience' +require_relative '../helper' Typed::Compiler.class_eval do def set_main main @@ -17,17 +16,12 @@ module ExpressionHelper def check machine = Register.machine machine.boot unless machine.booted - parser = Parser::Salama.new - parser = parser.send @root - syntax = parser.parse_with_debug(@string_input, reporter: Parslet::ErrorReporter::Deepest.new) - parts = Parser::Transform.new.apply(syntax) - codes = Soml.ast_to_code parts - #puts parts.inspect compiler = Typed::Compiler.new set_main(compiler) - produced = compiler.process( codes ) + code = Typed.ast_to_code @input + produced = compiler.process( code ) assert @output , "No output given" - assert_equal produced.class, @output , "Wrong class" + assert_equal produced.class , @output , "Wrong class" produced end diff --git a/stash/soml/expressions/test_all.rb b/test/typed/expressions/test_all.rb similarity index 100% rename from stash/soml/expressions/test_all.rb rename to test/typed/expressions/test_all.rb diff --git a/test/typed/expressions/test_basic.rb b/test/typed/expressions/test_basic.rb new file mode 100644 index 00000000..1b645476 --- /dev/null +++ b/test/typed/expressions/test_basic.rb @@ -0,0 +1,38 @@ +require_relative "helper" + + +class TestBasic < MiniTest::Test + include ExpressionHelper + include AST::Sexp + + def setup + @output = Register::RegisterValue + end + + def test_number + @input = s(:int , 42) + assert_equal 42 , check.value + end + + def test_true + @input = s(:true) + check + end + def test_false + @input = s(:false) + check + end + def test_nil + @input = s(:nil) + check + end + def test_self + @input = s(:name, :self) + check + end + def test_string + @input = s(:string , "hello") + check + end + +end diff --git a/stash/soml/expressions/test_call.rb b/test/typed/expressions/test_call.rb similarity index 72% rename from stash/soml/expressions/test_call.rb rename to test/typed/expressions/test_call.rb index ced9f8cc..c13634c1 100644 --- a/stash/soml/expressions/test_call.rb +++ b/test/typed/expressions/test_call.rb @@ -11,28 +11,28 @@ module Register end def test_call_main_plain - @string_input = 'main()' + @input = 'main()' check end def test_call_main_int - @string_input = 'main(1)' + @input = 'main(1)' check end def test_call_main_string - @string_input = 'main("1")' + @input = 'main("1")' check end def test_call_main_op Register.machine.space.get_main.ensure_local(:bar , :Integer) - @string_input = 'main( bar )' + @input = 'main( bar )' check end def test_call_string_put - @string_input = '"Hello Raisa, I am salama".putstring()' + @input = '"Hello Raisa, I am salama".putstring()' check end diff --git a/stash/soml/expressions/test_field_access.rb b/test/typed/expressions/test_field_access.rb similarity index 85% rename from stash/soml/expressions/test_field_access.rb rename to test/typed/expressions/test_field_access.rb index d0c9aaca..8ba3be86 100644 --- a/stash/soml/expressions/test_field_access.rb +++ b/test/typed/expressions/test_field_access.rb @@ -10,7 +10,7 @@ module Register def test_field_not_defined @root = :field_access - @string_input = <