require File.join(__FILE__.gsub(/(.*)?\/spec\/.*$/, '\1'), 'spec/spec_helper') def varval(setvar, type, vars = {}) Rtml::ReverseEngineering::Simulator::VariableValue.new(setvar, vars, {setvar['name'] => type}) end describe Rtml::ReverseEngineering::Simulator::VariableValue do it "should resolve variable names in operands" do var = varval(Hpricot::XML("").root, :integer, :start => 0) var.send(:lo).should == 0 end context "with an assignment" do it "should == an operation with same result" do varval(Hpricot::XML("").root, :integer).should == varval(Hpricot::XML("").root, :integer) end context "given an integer" do before :each do @subject = varval(Hpricot::XML("").root, :integer) end it "should set value to :lo" do subject.value.should == 5 end end context "given a string" do before :each do @subject = varval(Hpricot::XML("").root, :string) end it "should set value to :lo" do subject.value.should == '5' end end context "given an opaque" do before :each do @subject = varval(Hpricot::XML("").root, :opaque) end it "should set value to :lo" do subject.value.should == '5' end end context "given a date" do before :each do @subject = varval(Hpricot::XML("").root, :date) end it "should set value to :lo" do subject.value.should == "5/5/5" end end end context "with an operation" do it "should resolve operands" do var = varval(Hpricot::XML("").root, :integer, 'count' => varval(Hpricot::XML("").root, :integer)) var.value.should == 3 end it "should == an assignment with same result" do varval(Hpricot::XML("").root, :integer).should == varval(Hpricot::XML("").root, :integer) end context "given an integer" do it "should set value to :lo plus :ro" do varval(Hpricot::XML("").root, :integer).value.should == 5 end it "should set value to :lo minus :ro" do varval(Hpricot::XML("").root, :integer).value.should == 5 end end context "given an opaque" do it "should raise an error because no operations are possible" do proc do varval(Hpricot::XML("").root, :opaque) end.should raise_error(Rtml::Errors::InvalidOperation) end end context "given a string" do it "should set value to :lo plus :ro" do varval(Hpricot::XML("").root, :string).value.should == "32" end it "should set value to :lo minus :ro" do varval(Hpricot::XML("").root, :string).value.should == "7" end it "should set value to :lo format :ro" #do #varval(Hpricot::XML("").root, :string) #end end context "given a string list" do it "should set value to :lo item :ro" do varval(Hpricot::XML("").root, :string).value.should == "2" end it "should set value to :lo number :ro" do varval(Hpricot::XML("").root, :integer).value.should == 4 end end context "given a date" do it "should set value to :lo plus :ro" it "should set value to :lo minus :ro" end end end