Sha256: a1f9d532376386d0e9eb02b3e708a232478681ab930563a235c22fb8a4259422

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

require "test_helper"

module Whitespace::ISA
  describe Putn 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 { Putn.new(@vm, Whitespace::Console.new).execute }.must_raise \
            Whitespace::EmptyError
        end
      end

      describe "when the value stack has at least 1 element" do
        describe "when it is an integer" do
          it "outputs it as an integer" do
            @vm.vstack.push 65
            expect(@vm.vstack.size).must_equal 1

            expect { Putn.new(@vm, Whitespace::Console.new).execute } \
              .must_output "65"
            expect(@vm.vstack.size).must_equal 0
          end
        end

        describe "when it is not an integer" do
          it "raises ArgumentError" do
            @vm.vstack.push "6s"
            expect(@vm.vstack.size).must_equal 1

            e = expect { Putn.new(@vm, Whitespace::Console.new).execute } \
              .must_raise ArgumentError
            expect(e.message).must_match /must be an integer: 6s/
          end
        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/io/putn_test.rb