summaryrefslogtreecommitdiff
path: root/test/csv/test_patterns.rb
blob: 881f03a3a4ae5ec9c578a2cb6f4743fdd8f8c905 (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
# frozen_string_literal: true

require_relative "helper"

class TestCSVPatternMatching < Test::Unit::TestCase

  def test_hash
    case CSV::Row.new(%i{A B C}, [1, 2, 3])
    in B: b, C: c
      assert_equal([2, 3], [b, c])
    end
  end

  def test_hash_rest
    case CSV::Row.new(%i{A B C}, [1, 2, 3])
    in B: b, **rest
      assert_equal([2, { A: 1, C: 3 }], [b, rest])
    end
  end

  def test_array
    case CSV::Row.new(%i{A B C}, [1, 2, 3])
    in *, matched
      assert_equal(3, matched)
    end
  end
end