File: compact_spec.rb

package info (click to toggle)
ruby-hamster 3.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,932 kB
  • sloc: ruby: 16,915; makefile: 4
file content (30 lines) | stat: -rw-r--r-- 749 bytes parent folder | download | duplicates (2)
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
require "spec_helper"
require "hamster/vector"

describe Hamster::Vector do
  describe "#compact" do
    it "returns a new Vector with all nils removed" do
      V[1, nil, 2, nil].compact.should eql(V[1, 2])
      V[1, 2, 3].compact.should eql(V[1, 2, 3])
      V[nil].compact.should eql(V.empty)
    end

    context "on an empty vector" do
      it "returns self" do
        V.empty.compact.should be(V.empty)
      end
    end

    it "doesn't remove false" do
      V[false].compact.should eql(V[false])
    end

    context "from a subclass" do
      it "returns an instance of the subclass" do
        subclass = Class.new(V)
        instance = subclass[1, nil, 2]
        instance.compact.class.should be(subclass)
      end
    end
  end
end