Sha256: b9f764c7e3f3a5006fc61f62292607ae8d0d570503730f7cce269c1c642931af

Contents?: true

Size: 935 Bytes

Versions: 4

Compression:

Stored size: 935 Bytes

Contents

# frozen_string_literal: true

RSpec.describe Fear::EitherPatternMatch do
  context "Right" do
    let(:matcher) do
      described_class.new do |m|
        m.right(:even?.to_proc) { |x| "#{x} is even" }
        m.right(:odd?.to_proc) { |x| "#{x} is odd" }
      end
    end

    it do
      expect(matcher.(Fear.right(4))).to eq("4 is even")
      expect(matcher.(Fear.right(3))).to eq("3 is odd")
      expect do
        matcher.(Fear.left(44))
      end.to raise_error(Fear::MatchError)
    end
  end

  context "Left" do
    let(:matcher) do
      described_class.new do |m|
        m.left(:even?.to_proc) { |x| "#{x} is even" }
        m.left(:odd?.to_proc) { |x| "#{x} is odd" }
      end
    end

    it do
      expect(matcher.(Fear.left(4))).to eq("4 is even")
      expect(matcher.(Fear.left(3))).to eq("3 is odd")
      expect do
        matcher.(Fear.right(44))
      end.to raise_error(Fear::MatchError)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fear-2.0.1 spec/fear/either_pattern_match_spec.rb
fear-2.0.0 spec/fear/either_pattern_match_spec.rb
fear-1.2.0 spec/fear/either_pattern_match_spec.rb
fear-1.1.0 spec/fear/either_pattern_match_spec.rb