summaryrefslogtreecommitdiff
path: root/test/reline/test_reline_key.rb
blob: fb700a6f2eb1d8506b610579ddaacea20ec6d069 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require_relative 'helper'
require "reline"

class Reline::TestKey < Reline::TestCase
  def setup
  end

  def teardown
    Reline.test_reset
  end

  def test_match_key
    assert(Reline::Key.new(1, 2, false).match?(Reline::Key.new(1, 2, false)))
    assert(Reline::Key.new(1, 2, false).match?(Reline::Key.new(nil, 2, false)))
    assert(Reline::Key.new(1, 2, false).match?(Reline::Key.new(1, 2, nil)))

    assert(Reline::Key.new(nil, 2, false).match?(Reline::Key.new(nil, 2, false)))
    assert(Reline::Key.new(1, nil, false).match?(Reline::Key.new(1, nil, false)))
    assert(Reline::Key.new(1, 2, nil).match?(Reline::Key.new(1, 2, nil)))

    assert(Reline::Key.new(nil, 2, false).match?(Reline::Key.new(nil, 2, false)))
    assert(Reline::Key.new(1, nil, false).match?(Reline::Key.new(1, nil, false)))
    assert(Reline::Key.new(1, 2, nil).match?(Reline::Key.new(1, 2, nil)))

    assert(!Reline::Key.new(1, 2, false).match?(Reline::Key.new(3, 1, false)))
    assert(!Reline::Key.new(1, 2, false).match?(Reline::Key.new(1, 3, false)))
    assert(!Reline::Key.new(1, 2, false).match?(Reline::Key.new(1, 3, true)))
  end

  def test_match_integer
    assert(Reline::Key.new(1, 2, false).match?(2))
    assert(Reline::Key.new(nil, 2, false).match?(2))
    assert(Reline::Key.new(1, nil, false).match?(1))

    assert(!Reline::Key.new(1, 2, false).match?(1))
    assert(!Reline::Key.new(1, nil, false).match?(2))
    assert(!Reline::Key.new(nil, nil, false).match?(1))
  end

  def test_match_symbol
    assert(Reline::Key.new(:key1, :key2, false).match?(:key2))
    assert(Reline::Key.new(:key1, nil, false).match?(:key1))

    assert(!Reline::Key.new(:key1, :key2, false).match?(:key1))
    assert(!Reline::Key.new(:key1, nil, false).match?(:key2))
    assert(!Reline::Key.new(nil, nil, false).match?(:key1))
  end

  def test_match_other
    assert(!Reline::Key.new(:key1, 2, false).match?("key1"))
    assert(!Reline::Key.new(nil, nil, false).match?(nil))
  end
end