Sha256: 2070a6596ffbf581e8d9e4e3e246f0a68a88eb9c1df812e4fa9db2e77a7a2a9d

Contents?: true

Size: 1.66 KB

Versions: 25

Compression:

Stored size: 1.66 KB

Contents

require 'gorillib/diff'
require 'stringio'

module TransformLeftToRight
  attr_reader :left

  DELETE_ME = Object.new

  def display_key_header(key)
    @left_lineage << [@left, key]
    @left = @left[key]

    @right_lineage << @right
    @right = @right[key]
  end

  def only_left_key(_)
    @left = DELETE_ME
  end

  def only_right_key(key)
    @left = @right
  end

  def display_add(this, other)
    if this.nil?
      @left.insert(@ix, other)
      @ix += 1
    else
      @left.delete_at(@ix)
    end
  end

  def display_hetero(this, other)
    @ix += 1
    @left = @right
  end

  def display_noteql_items(*args)
    @in_array = true
    super(*args)
    @in_array = false
  end

  def display_noteql_atoms(this, other)
    @ix += 1
    @left = @right
  end

  def decrease_indentation
    tmp = @left
    @left,key = @left_lineage.pop

    if tmp.equal?(DELETE_ME)
      @left.delete(key)
    else
      @left[key] = tmp
    end

    @right = @right_lineage.pop
  end

  def increase_indentation() end
  def indent() end

  def display_indices(ixl, ixr)
    @ix = ixr
  end
end

class TestDrawer
  include Gorillib::DiffDrawerMethods
  include TransformLeftToRight

  def initialize this = nil, other = nil
    @left_lineage = [@left = this]
    @right_lineage = [@right = other]
    @ix = 0
  end
  
  def self.diffing_objs this, other
    diff_formatter.display_diff(this, other)
  end

  def self.diff_formatter(drawer = nil)
    Gorillib::DiffFormatter.new(stream: StringIO.new, drawer: drawer)
  end

  def self.transform_ltor this, other
    drawer = new(this, other)
    Gorillib::DiffFormatter.new(drawer: drawer).display_diff(this, other)
    drawer.left.should == other
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
ironfan-6.1.9 spec/support/dummy_diff_drawer.rb
ironfan-6.0.9 spec/support/dummy_diff_drawer.rb
ironfan-6.1.7 spec/support/dummy_diff_drawer.rb
ironfan-6.1.6 spec/support/dummy_diff_drawer.rb
ironfan-6.0.8 spec/support/dummy_diff_drawer.rb
ironfan-6.1.5 spec/support/dummy_diff_drawer.rb
ironfan-6.1.4 spec/support/dummy_diff_drawer.rb
ironfan-6.1.3 spec/support/dummy_diff_drawer.rb
ironfan-6.1.0 spec/support/dummy_diff_drawer.rb
ironfan-6.0.7 spec/support/dummy_diff_drawer.rb
ironfan-5.0.11 spec/spec_helper/dummy_diff_drawer.rb
ironfan-6.0.6 spec/support/dummy_diff_drawer.rb
ironfan-6.0.5 spec/support/dummy_diff_drawer.rb
ironfan-6.0.4 spec/support/dummy_diff_drawer.rb
ironfan-6.0.3 spec/support/dummy_diff_drawer.rb
ironfan-6.0.1 spec/support/dummy_diff_drawer.rb
ironfan-6.0.0 spec/support/dummy_diff_drawer.rb
ironfan-5.0.10 spec/spec_helper/dummy_diff_drawer.rb
ironfan-5.0.8 spec/spec_helper/dummy_diff_drawer.rb
ironfan-5.0.5 spec/spec_helper/dummy_diff_drawer.rb