Sha256: 98af13c17ad832d5b2cf8a952a4935fc2c9b49f0f7057a656136dfffac452bdb

Contents?: true

Size: 1.59 KB

Versions: 6

Compression:

Stored size: 1.59 KB

Contents

require 'spec_helper'

describe HashDiff::LinearCompareArray do
  it 'finds no differences between two empty arrays' do
    difference = described_class.call([], [])
    difference.should == []
  end

  it 'finds added items when the old array is empty' do
    difference = described_class.call([], %i[a b])
    difference.should == [['+', '[0]', :a], ['+', '[1]', :b]]
  end

  it 'finds removed items when the new array is empty' do
    difference = described_class.call(%i[a b], [])
    difference.should == [['-', '[1]', :b], ['-', '[0]', :a]]
  end

  it 'finds no differences between identical arrays' do
    difference = described_class.call(%i[a b], %i[a b])
    difference.should == []
  end

  it 'finds added items in an array' do
    difference = described_class.call(%i[a d], %i[a b c d])
    difference.should == [['+', '[1]', :b], ['+', '[2]', :c]]
  end

  it 'finds removed items in an array' do
    difference = described_class.call(%i[a b c d e f], %i[a d f])
    difference.should == [['-', '[4]', :e], ['-', '[2]', :c], ['-', '[1]', :b]]
  end

  it 'shows additions and deletions as changed items' do
    difference = described_class.call(%i[a b c], %i[c b a])
    difference.should == [['~', '[0]', :a, :c], ['~', '[2]', :c, :a]]
  end

  it 'shows changed items in a hash' do
    difference = described_class.call([{ a: :b }], [{ a: :c }])
    difference.should == [['~', '[0].a', :b, :c]]
  end

  it 'shows changed items and added items' do
    difference = described_class.call([{ a: 1, b: 2 }], [{ a: 2, b: 2 }, :item])
    difference.should == [['~', '[0].a', 1, 2], ['+', '[1]', :item]]
  end
end

Version data entries

6 entries across 4 versions & 2 rubygems

Version Path
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.8/spec/hash_diff/linear_compare_array_spec.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/hashdiff-0.3.8/spec/hash_diff/linear_compare_array_spec.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.8/spec/hash_diff/linear_compare_array_spec.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/hashdiff-0.3.8/spec/hash_diff/linear_compare_array_spec.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.8/spec/hash_diff/linear_compare_array_spec.rb
hashdiff-0.3.8 spec/hash_diff/linear_compare_array_spec.rb