File: values_at_spec.rb

package info (click to toggle)
ruby-immutable-ruby 0.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,852 kB
  • sloc: ruby: 16,556; makefile: 4
file content (33 lines) | stat: -rw-r--r-- 933 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'spec_helper'

describe Immutable::Vector do
  describe '#values_at' do
    let(:vector) { V['a', 'b', 'c'] }

    it 'accepts any number of indices, and returns a vector of items at those indices' do
      vector.values_at(0).should eql(V['a'])
      vector.values_at(1,2).should eql(V['b', 'c'])
    end

    context 'when passed invalid indices' do
      it 'fills in with nils' do
        vector.values_at(1,2,3).should  eql(V['b', 'c', nil])
        vector.values_at(-10,10).should eql(V[nil, nil])
      end
    end

    context 'when passed no arguments' do
      it 'returns an empty vector' do
        vector.values_at.should eql(V.empty)
      end
    end

    context 'from a subclass' do
      it 'returns an instance of the subclass' do
        subclass = Class.new(Immutable::Vector)
        instance = subclass.new([1,2,3])
        instance.values_at(1,2).class.should be(subclass)
      end
    end
  end
end