Sha256: 159b2f17530e933a50a477cf889cd124751117a49b6d05fedb85511d1417c1e8

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

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

describe 'Pair' do

  it 'should return the first item: first/key' do
    expect(pair(1, 2).first).to eq(1)
    expect(pair(1, 2).key).to eq(1)
  end

  it 'should return the second item: second/value' do
    expect(pair(1, 2).second).to eq(2)
    expect(pair(1, 2).value).to eq(2)
  end

  it 'should return sequence of values' do
    expect(pair(1, 2).values).to eq(sequence(1, 2))
  end

  it 'should convert to string' do
    expect(pair('apples', 2).to_s).to eq({'apples' => '2'})
  end

  it 'should convert to a sequence of pairs from a map' do
    expect(Pair.from_map({apples: '10'}).to_a).to eq(sequence(pair(:apples, '10')).to_a)
    expect(Pair.from_map({:one => 1, :two => 2}).to_a).to eq(sequence(pair(:one,1),pair(:two,2)).to_a)
  end

  it 'should convert a pair to a map' do
    expect(pair(1, 2).to_map).to eq({1 => 2})
  end

  it 'should convert to int' do
    expect(pair('1', '2').to_i).to eq({1 => 2})
  end

  it 'should convert to float' do
    expect(pair('1', '2').to_f).to eq({1.0 => 2.0})
  end

  it 'should support each' do
    expect(pair(1,2).each{|x| x }).to eq([1,2])
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
totally_lazy-0.0.20 spec/pair_spec.rb
totally_lazy-0.0.19 spec/pair_spec.rb
totally_lazy-0.0.18 spec/pair_spec.rb