Sha256: af903888247ee32d49fbd388ea0db5566f8fbf607901a98453de606099162eb8

Contents?: true

Size: 1.96 KB

Versions: 14

Compression:

Stored size: 1.96 KB

Contents

#encoding: utf-8
require File.join(File.dirname(__FILE__), "../../spec_helper")
include Nudge


describe CodeNthInstruction do
  
  it_should_behave_like "every Nudge Instruction"
  
  before(:each) do
    @context = Interpreter.new
    @i1 = CodeNthInstruction.new(@context)
  end
  
  describe "\#go" do
    before(:each) do
      @context = Interpreter.new
      @i1 = CodeNthInstruction.new(@context)
    end
    
    describe "\#preconditions?" do
      it "should need at least one item on the :int stack and :code stacks" do
        @context.clear_stacks
        lambda{@i1.preconditions?}.should raise_error
        @context.stacks[:int].push(ValuePoint.new("int", 2))
        @context.stacks[:code].push(ValuePoint.new("code", "block {ref a ref b ref c}"))
        lambda{@i1.preconditions?}.should_not raise_error
      end
    end
    
    describe "\#cleanup" do
      before(:each) do
        @context.stacks[:code].push(ValuePoint.new("code", "block {ref a ref b ref c}"))
      end
      
      it "should get the Nth item from the backbone of the top :code value" do
        @context.stacks[:int].push(ValuePoint.new("int", 1))
        @i1.go
        @context.stacks[:code].peek.value.should == "ref b"
      end
      
      it "should use the top :int modulo the length of the backbone" do
        @context.stacks[:int].push(ValuePoint.new("int", 11))
        @i1.go
        @context.stacks[:code].peek.value.should == "ref c"        
      end
      
      it "should work for negative values too" do
        @context.stacks[:int].push(ValuePoint.new("int", -8172))
        @i1.go
        @context.stacks[:code].peek.value.should == "ref a"
      end
      it "should return the top :code value itself if it's not a CodeblockPoint" do
        @context.stacks[:code].push(ValuePoint.new("code", "do int_rob"))
        @context.stacks[:int].push(ValuePoint.new("int", 21))
        @i1.go
        @context.stacks[:code].peek.value.should == "do int_rob"
        
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
nudge-0.2.9 spec/instructions/code/code_nth_spec.rb
nudge-0.2.8 spec/instructions/code/code_nth_spec.rb
nudge-0.2.7 spec/instructions/code/code_nth_spec.rb
nudge-0.2.6 spec/instructions/code/code_nth_spec.rb
nudge-0.2.5 spec/instructions/code/code_nth_spec.rb
nudge-0.2.4 spec/instructions/code/code_nth_spec.rb
nudge-0.2.3 spec/instructions/code/code_nth_spec.rb
nudge-0.2.2 spec/instructions/code/code_nth_spec.rb
nudge-0.2.1 spec/instructions/code/code_nth_spec.rb
nudge-0.2.0 spec/instructions/code/code_nth_spec.rb
nudge-0.1.3 spec/instructions/code/code_nth_spec.rb
nudge-0.1.2 spec/instructions/code/code_nth_spec.rb
nudge-0.1.1 spec/instructions/code/code_nth_spec.rb
nudge-0.1.0 spec/instructions/code/code_nth_spec.rb