Sha256: 98492e1efd459a4861e0b8df070792c240185a8213a63b725f00ed6a2e5110c6

Contents?: true

Size: 1.47 KB

Versions: 7

Compression:

Stored size: 1.47 KB

Contents

require 'test_helper'

module Vedeu
  describe Input do
    describe '.capture' do
      keypresses = {
        "\r"      => :enter,
        "\t"      => :tab,
        # "\e"      => :escape, # handled below in separate test
        "\e[A"    => :up,
        "\e[B"    => :down,
        "\e[C"    => :right,
        "\e[D"    => :left,
        "\e[5~"   => :page_up,
        "\e[6~"   => :page_down,
        "\e[H"    => :home,
        "\e[3~"   => :delete,
        "\e[F"    => :end,
        "\eOP"    => :f1,
        "\eOQ"    => :f2,
        "\eOR"    => :f3,
        "\eOS"    => :f4,
        "\e[15~"  => :f5,
        "\e[17~"  => :f6,
        "\e[18~"  => :f7,
        "\e[19~"  => :f8,
        "\e[20~"  => :f9,
        "\e[21~"  => :f10,
        "\e[23~"  => :f11,
        "\e[24~"  => :f12,
        "\e[1;2P" => :print_screen,
        "\e[1;2Q" => :scroll_lock,
        "\e[1;2R" => :pause_break,
        "\u007F"  => :backspace,
        "k"       => "k"
      }

      keypresses.each do |keypress, value|
        it 'triggers a :key event with the key pressed' do
          Terminal.stub :input, keypress do
            Vedeu.stub :trigger, value do
              Input.capture.must_equal(value)
            end
          end
        end
      end

      it 'switches the terminal mode when escape is pressed' do
        Terminal.stub :input, "\e" do
          Vedeu.stub :log, nil do
            proc { Input.capture }.must_raise(ModeSwitch)
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
vedeu-0.1.17 test/lib/vedeu/support/input_test.rb
vedeu-0.1.16 test/lib/vedeu/support/input_test.rb
vedeu-0.1.15 test/lib/vedeu/support/input_test.rb
vedeu-0.1.14 test/lib/vedeu/support/input_test.rb
vedeu-0.1.13 test/lib/vedeu/support/input_test.rb
vedeu-0.1.12 test/lib/vedeu/support/input_test.rb
vedeu-0.1.10 test/lib/vedeu/support/input_test.rb