Sha256: d8be7571186eb402c2fcc5b29b5dfd6b30473c826e49cbeb6d6cf44e1a05a6d8

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

require "test_helper"

module Whitespace::ISA
  describe Putc 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 { Putc.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 the top element is an ASCII character" do
          it "outputs it as a character" do
            @vm.vstack.push 65
            expect(@vm.vstack.size).must_equal 1

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

        describe "when the top element is not an ASCII character" do
          it "raises ArgumentError" do
            @vm.vstack.push 0
            expect(@vm.vstack.size).must_equal 1

            e = expect { Putc.new(@vm, Whitespace::Console.new).execute } \
              .must_raise ArgumentError
            expect(e.message).must_match /must be an ASCII character/
          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/putc_test.rb