Sha256: 72a9cc5f236c65c72109ed623ec1daa451602b991b979e12e5acdba80688d41b

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

RSpec.describe "Fear::Extractor::IdentifiedMatcher" do
  let(:parser) { Fear::Extractor::GrammarParser.new }
  let(:matcher) { parser.parse(pattern).to_matcher }

  describe "#defined_at?" do
    subject { matcher }

    let(:pattern) { "array @ [1, *tail]" }

    it { is_expected.to be_defined_at([1, 2]) }
    it { is_expected.not_to be_defined_at("foo") }
    it { is_expected.not_to be_defined_at([2, 1]) }
  end

  describe "#call" do
    subject { matcher.(other) }

    context "defined" do
      let(:other) { [1, 2] }
      let(:pattern) { "array @ [1, *tail]" }

      it { is_expected.to eq(array: [1, 2], tail: [2]) }
    end
  end

  describe "#failure_reason" do
    subject { matcher.failure_reason(other) }

    let(:pattern) { "array @ [1, *tail]" }

    context "match integer" do
      let(:other) { [1, 2] }

      it { is_expected.to eq(Fear.none) }
    end

    context "does not match float" do
      let(:other) { [2, 2] }

      it { is_expected.to eq(Fear.some(<<~ERROR.strip)) }
        Expected `2` to match:
        array @ [1, *tail]
        ~~~~~~~~~^
      ERROR
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fear-1.2.0 spec/fear/extractor/identified_matcher_spec.rb
fear-1.1.0 spec/fear/extractor/identified_matcher_spec.rb