Sha256: 1f32acebe0f3ce69a113d52d2a2e0c2f1d7952ed0e66cb582fbb72261087137a

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

require 'hamster/list'

describe Hamster::List do

  describe "#split_at" do

    it "is lazy" do
      lambda { 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.car
          @remainder = @result.cadr
        end

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

        it "returns a list with two items" do
          @result.size.should == 2
        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

2 entries across 2 versions & 1 rubygems

Version Path
hamster-0.2.1 spec/hamster/list/split_at_spec.rb
hamster-0.2.0 spec/hamster/list/split_at_spec.rb