<commit_before>require 'slam'

class AlternativeDunk < Slam::Dunk
  include ::Slam::Alternative
end

describe AlternativeDunk do

  let(:l) { described_class.new }

  describe "#|" do
    subject { proc(&l | proc{x}) }
    let(:x) { 42 }
    example { subject.(nil).should == x }
    example { subject.(false).should == x }
    example { subject.(true).should be_true }
  end

  describe "#*" do
    subject { proc(&l.+ * proc{x}) }

    context do
      let(:x) { 42 }
      example { subject.call(1).should == x + 1 }
    end

    context do
      let(:x) { nil }
      example { subject.call(1).should == x }
    end

    context do
      let(:x) { false }
      example { subject.call(1).should == x }
    end
  end
<commit_msg>shared_examples_for にする<commit_after>require 'slam'

class AlternativeDunk < Slam::Dunk
  include ::Slam::Alternative
end

describe AlternativeDunk do

  let(:l) { described_class.new }

  describe "#|" do

    shared_examples_for "hoge" do # TODO: hoge->???
      subject { proc(&l | f) }
      example { subject .(nil)   .should == f.() }
      example { subject .(false) .should == f.() }
      example { subject .(true)  .should == true }
      example { subject .(0)     .should == 0    }
      example { subject .([])    .should == []   }
      example { subject .({})    .should == {}   }
      example { subject .("")    .should == ""   }
    end

    context "42.itself" do

      it_behaves_like "hoge" do
        let(:f) { proc{42} }
      end
    end
  end

  describe "#*" do

    shared_examples_for "pure" do
      subject { proc(&l.f * g) }
      example { subject.(r).should == r.f(g.()) }
    end

    shared_examples_for "empty" do
      subject { proc(&l.f * g) }
      example { subject.(r).should == g.() }
    end


    context do
      let(:r) { double }
      before :each do
        r.stub(:f, &:succ)
      end

      context do
        it_behaves_like "pure" do
          let(:g) { proc{42} }
        end
      end

      context do
        it_behaves_like "empty" do
          let(:g) { proc{nil} }
        end
      end

      context do
        it_behaves_like "empty" do
          let(:g) { proc{false} }
        end
      end
    end
  end

{'fraction_non_alphanumeric': 0.145578231292517, 'fraction_numerical': 0.0072562358276643995, 'mean_word_length': 1.9257294429708223, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1427456', 'n_tokens_mistral': 783, 'n_tokens_neox': 733, 'n_words': 187}