Sha256: 6a0767aec220dfa42abec7dfaa7c150bd563baf3e4a836571cbc3cdb804ed9d2

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

require "test_helper"

module Whitespace::ISA
  describe Store do
    before do
      @vm = Whitespace::VM.new
    end

    describe "#execute" do
      describe "when the value stack is empty" do
        it "raises Whitespace::EmptyError" do
          expect(@vm.vstack.size).must_equal 0

          expect { Store.new(@vm).execute }.must_raise Whitespace::EmptyError
        end
      end

      describe "when the value stack has 1 element" do
        it "raises Whitespace::EmptyError" do
          @vm.vstack.push :address
          expect(@vm.vstack.size).must_equal 1

          expect { Store.new(@vm).execute }.must_raise Whitespace::EmptyError
        end
      end

      describe "when the value stack has at least 2 elements" do
        it "stores the value at the given address in memory" do
          @vm.vstack.push 1
          @vm.vstack.push :address
          @vm.vstack.push :value
          expect(@vm.vstack.size).must_equal 3
          expect { @vm.memory[:address] }.must_raise Whitespace::AddressError

          Store.new(@vm).execute

          expect(@vm.memory[:address]).must_equal :value
          expect(@vm.vstack.pop).must_equal 1
          expect(@vm.vstack.size).must_equal 0
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
whitespace-ruby-1.0.0 test/whitespace/instructions/heap_access/store_test.rb