Sha256: e541558a1c81b4b66add10407bb7b639c400baa3289c10eea73efabaf909287b

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require "spec_helper"

require "hamster/tuple"
require "hamster/list"

describe Hamster::List do

  describe "#split_at" do

    it "is lazy" do
      -> { Hamster.stream { fail }.split_at(1) }.should_not raise_error
    end

    [
      [[], [], []],
      [[1], [1], []],
      [[1, 2], [1, 2], []],
      [[1, 2, 3], [1, 2], [3]],
      [[1, 2, 3, 4], [1, 2], [3, 4]],
    ].each do |values, expected_prefix, expected_remainder|

      describe "on #{values.inspect}" do

        before do
          @original = Hamster.list(*values)
          @result = @original.split_at(2)
          @prefix = @result.first
          @remainder = @result.last
        end

        it "preserves the original" do
          @original.should == Hamster.list(*values)
        end

        it "returns a tuple with two items" do
          @result.is_a?(Hamster::Tuple).should == true
        end

        it "correctly identifies the matches" do
          @prefix.should == Hamster.list(*expected_prefix)
        end

        it "correctly identifies the remainder" do
          @remainder.should == Hamster.list(*expected_remainder)
        end

      end

    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hamster-1.0.1.pre.rc.1 spec/hamster/list/split_at_spec.rb