Sha256: 64490330b4d2c76100826d6c39281d88dcc0b05617241e332730b4766a9fee74

Contents?: true

Size: 1.62 KB

Versions: 85

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

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

85 entries across 83 versions & 8 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/hashdiff-1.1.0/spec/hashdiff/linear_compare_array_spec.rb
cloudsmith-api-2.0.13 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.1.0/spec/hashdiff/linear_compare_array_spec.rb
cloudsmith-api-2.0.12 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.1.0/spec/hashdiff/linear_compare_array_spec.rb
cloudsmith-api-2.0.11 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.1.0/spec/hashdiff/linear_compare_array_spec.rb
cloudsmith-api-2.0.10 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.1.0/spec/hashdiff/linear_compare_array_spec.rb
cloudsmith-api-2.0.9 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.1.0/spec/hashdiff/linear_compare_array_spec.rb
cloudsmith-api-2.0.8 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.1.0/spec/hashdiff/linear_compare_array_spec.rb
hashdiff-1.1.0 spec/hashdiff/linear_compare_array_spec.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/hashdiff-1.0.1/spec/hashdiff/linear_compare_array_spec.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/hashdiff-1.0.1/spec/hashdiff/linear_compare_array_spec.rb
cloudsmith-api-2.0.7 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/linear_compare_array_spec.rb
cloudsmith-api-2.0.6 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/linear_compare_array_spec.rb
cloudsmith-api-2.0.5 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/linear_compare_array_spec.rb
cloudsmith-api-2.0.4 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/linear_compare_array_spec.rb
cloudsmith-api-2.0.3 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/linear_compare_array_spec.rb
cloudsmith-api-2.0.2 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/linear_compare_array_spec.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/hashdiff-1.0.1/spec/hashdiff/linear_compare_array_spec.rb
cloudsmith-api-2.0.1 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/linear_compare_array_spec.rb
cloudsmith-api-2.0.0 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/linear_compare_array_spec.rb
cloudsmith-api-1.142.3 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/linear_compare_array_spec.rb