Rename Vool to Sol
Simple is really the descriptive name for the layer Sure, it is "virtual" but that is not as important as the fact that it is simple (or simplified) Also objct (based really) is better, since orientated implies it is a little like that, but only orientated, not really it. Sol only has objects, nothing else Just cause i was renaming anyway
This commit is contained in:
1
test/sol/lambdas/helper.rb
Normal file
1
test/sol/lambdas/helper.rb
Normal file
@ -0,0 +1 @@
|
||||
require_relative "../helper"
|
80
test/sol/lambdas/test_assign.rb
Normal file
80
test/sol/lambdas/test_assign.rb
Normal file
@ -0,0 +1,80 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module SolBlocks
|
||||
class TestAssignSlotMachine < MiniTest::Test
|
||||
include SolCompile
|
||||
|
||||
def setup
|
||||
@ins = compile_main_block( "local = 5" )
|
||||
end
|
||||
def test_block_compiles
|
||||
assert_equal SlotMachine::SlotLoad , @ins.class , @ins
|
||||
end
|
||||
def test_slot_is_set
|
||||
assert @ins.left
|
||||
end
|
||||
def test_slot_starts_at_message
|
||||
assert_equal :message , @ins.left.known_object
|
||||
end
|
||||
def test_slots_left
|
||||
assert_equal [:local1] , @ins.left.slots
|
||||
end
|
||||
def test_slot_assigns_something
|
||||
assert @ins.right
|
||||
end
|
||||
def test_slot_assigns_int
|
||||
assert_equal SlotMachine::IntegerConstant , @ins.right.known_object.class
|
||||
end
|
||||
end
|
||||
|
||||
class TestAssignSlotMachineInstanceToLocal < MiniTest::Test
|
||||
include SolCompile
|
||||
def setup
|
||||
@ins = compile_main_block( "local = @a" , "@a = 5") #second arg in method scope
|
||||
end
|
||||
def test_class_compiles
|
||||
assert_equal SlotMachine::SlotLoad , @ins.class , @ins
|
||||
end
|
||||
def test_slots_left
|
||||
assert_equal [:local1] , @ins.left.slots
|
||||
end
|
||||
def test_slots_right
|
||||
assert_equal [:receiver, :a] , @ins.right.slots
|
||||
end
|
||||
end
|
||||
|
||||
class TestAssignToArg < MiniTest::Test
|
||||
include SolCompile
|
||||
|
||||
def setup
|
||||
@ins = compile_main_block( "arg = 5")
|
||||
end
|
||||
|
||||
def test_class_compiles
|
||||
assert_equal SlotMachine::SlotLoad , @ins.class , @ins
|
||||
end
|
||||
def test_slot_is_set
|
||||
assert @ins.left
|
||||
end
|
||||
def test_slots_left
|
||||
assert_equal [:caller,:caller, :arg1] , @ins.left.slots
|
||||
end
|
||||
end
|
||||
|
||||
class TestAssignSlotMachineToInstance < MiniTest::Test
|
||||
include SolCompile
|
||||
def setup
|
||||
end
|
||||
def test_assigns_const
|
||||
@ins = compile_main_block( "@a = 5")
|
||||
assert_equal SlotMachine::SlotLoad , @ins.class , @ins
|
||||
assert_equal SlotMachine::IntegerConstant , @ins.right.known_object.class , @ins
|
||||
end
|
||||
def test_assigns_move
|
||||
@ins = compile_main_block( "@a = arg")
|
||||
assert_equal SlotMachine::SlotLoad , @ins.class , @ins
|
||||
assert_equal SlotMachine::SlotDefinition , @ins.right.class , @ins
|
||||
end
|
||||
end
|
||||
|
||||
end
|
28
test/sol/lambdas/test_class_blocks.rb
Normal file
28
test/sol/lambdas/test_class_blocks.rb
Normal file
@ -0,0 +1,28 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module SolBlocks
|
||||
class TestClassAssignSlotMachine < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
end
|
||||
def as_class_method(source)
|
||||
"class Space;def self.main();#{source};end;end"
|
||||
end
|
||||
def test_block_not_compiles
|
||||
source = "main{|val| val = 0}"
|
||||
sol = Ruby::RubyCompiler.compile( as_class_method(source) ).to_sol
|
||||
sol.to_parfait
|
||||
begin
|
||||
sol.to_slot(nil)
|
||||
rescue => err
|
||||
assert err.message.include?("Blocks") , err.message
|
||||
end
|
||||
end
|
||||
def test_assign_compiles
|
||||
sol = Ruby::RubyCompiler.compile( as_class_method("val = 0") ).to_sol
|
||||
sol.to_parfait
|
||||
assert_equal SlotMachine::SlotCollection , sol.to_slot(nil).class
|
||||
end
|
||||
end
|
||||
end
|
28
test/sol/lambdas/test_if_condition.rb
Normal file
28
test/sol/lambdas/test_if_condition.rb
Normal file
@ -0,0 +1,28 @@
|
||||
require_relative "helper"
|
||||
|
||||
module SolBlocks
|
||||
class TestConditionIfSlotMachine < MiniTest::Test
|
||||
include SolCompile
|
||||
|
||||
def setup
|
||||
@ins = compile_main_block( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end" , "local=5", "Integer.div4")
|
||||
end
|
||||
|
||||
def test_condition
|
||||
assert_equal TruthCheck , @ins.next(3).class
|
||||
end
|
||||
def test_condition_is_slot
|
||||
assert_equal SlotDefinition , @ins.next(3).condition.class , @ins
|
||||
end
|
||||
def test_simple_call
|
||||
assert_equal SimpleCall , @ins.next(2).class
|
||||
assert_equal :div4 , @ins.next(2).method.name
|
||||
end
|
||||
def test_array
|
||||
check_array [MessageSetup, ArgumentTransfer, SimpleCall, TruthCheck, Label ,
|
||||
SlotLoad, Jump, Label, SlotLoad, Label ,
|
||||
Label, ReturnSequence, Label] , @ins
|
||||
end
|
||||
|
||||
end
|
||||
end
|
25
test/sol/lambdas/test_while_simple.rb
Normal file
25
test/sol/lambdas/test_while_simple.rb
Normal file
@ -0,0 +1,25 @@
|
||||
require_relative "helper"
|
||||
|
||||
module SolBlocks
|
||||
class TestSimpleWhileSlotMachine < MiniTest::Test
|
||||
include SolCompile
|
||||
|
||||
def setup
|
||||
@ins = compile_main_block( "while(@a) ; @a = 5 ; end")
|
||||
end
|
||||
|
||||
def test_compiles_as_while
|
||||
assert_equal Label , @ins.class , @ins
|
||||
end
|
||||
def test_condition_compiles_to_check
|
||||
assert_equal TruthCheck , @ins.next.class , @ins
|
||||
end
|
||||
def test_condition_is_slot
|
||||
assert_equal SlotDefinition , @ins.next.condition.class , @ins
|
||||
end
|
||||
def test_array
|
||||
check_array [Label, TruthCheck, SlotLoad, Jump, Label,
|
||||
Label, ReturnSequence, Label], @ins
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user