File: case_predicate_test.rb

package info (click to toggle)
ruby-tins 1.32.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,248 kB
  • sloc: ruby: 6,659; makefile: 3
file content (29 lines) | stat: -rw-r--r-- 691 bytes parent folder | download
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
require 'test_helper'
require 'tins/xt/case_predicate'

module Tins
  class CasePredicateTest < Test::Unit::TestCase
    def test_case_predicate_failure
      assert_nil 4.case?(1, 2..3, 5...7)
    end

    def test_case_predicate_failure_is_a
      s = 'foo'
      assert_nil s.case?(Array, Hash)
      s = Class.new(String).new
      assert_nil s.case?(Array, Hash)
    end

    def test_case_predicate_success
      assert_equal 2..3, 3.case?(1, 2..3, 5...7)
    end

    def test_case_predicate_success_is_a
      s = 'foo'
      assert_equal String, s.case?(Array, Hash, String)
      s = Class.new(String).new
      assert_equal String, s.case?(Array, Hash, String)
    end
  end
end