amp / test / test_bdiff.rb

# encoding: ascii-8bit
##################################################################
#                  Licensing Information                         #
#                                                                #
#  The following code is licensed, as standalone code, under     #
#  the Ruby License, unless otherwise directed within the code.  #
#                                                                #
#  For information on the license of this code when distributed  #
#  with and used in conjunction with the other modules in the    #
#  Amp project, please see the root-level LICENSE file.          #
#                                                                #
#  © Michael J. Edgar and Ari Brown, 2009-2010                   #
#                                                                #
##################################################################

require File.join(File.expand_path(File.dirname(__FILE__)), 'testutilities')
require File.expand_path(File.join(File.dirname(__FILE__), "../lib/amp"))

class TestBdiff < AmpTestCase
  include Amp::Diffs

  def test_create_bdiff
    input = "hi there\ni'm cool"
    output = "hi there\ni'm stupid"
    expected_output = "\000\000\000\t\000\000\000\021\000\000\000\ni'm stupid"
    assert_equal(expected_output, BinaryDiff.bdiff(input, output))
  end
  
  def test_create_bdiff
    input = "hi there\ni'm cool"
    output = "hi there\ni'm stupid"
    expected_output = "\000\000\000\t\000\000\000\021\000\000\000\ni'm stupid"
    assert_equal(expected_output, BinaryDiff.bdiff(input, output))
  end
  
  def test_another_bdiff
    input = "c913df15006c6e06504414acf8acfedd32e5875d\nmichaeledgar@michael-edgars-macbook-pro.local"+
            "\n1248396415 14400\nSTYLE.txt\n\nFirst commit."
    output = "b2a7f7ab636d1dbd06afd90f1bf287dfb92762fb\nmichaeledgar@michael-edgars-macbook-pro.local"+
             "\n1248396417 14400\ncommand.rb\ncommands/annotate.rb\ncommands/heads.rb"+
             "\ncommands/manifest.rb\ncommands/status.rb\n\nSecond commit, added commands"
    expected_output = "\x00\x00\x00\x00\x00\x00\x00)\x00\x00\x00)b2a7f7ab636d1dbd06afd90f1bf287dfb92762fb"+
                      "\n\x00\x00\x00W\x00\x00\x00r\x00\x00\x00k1248396417 14400\ncommand.rb"+
                      "\ncommands/annotate.rb\ncommands/heads.rb\ncommands/manifest.rb"+
                      "\ncommands/status.rb\n\x00\x00\x00s\x00\x00\x00\x80\x00\x00\x00\x1d"+
                      "Second commit, added commands"
    assert_equal(expected_output, BinaryDiff.bdiff(input, output))
  end
  
  def test_yet_another_bdiff
    input = "The Amp Commandments Redux:\n\t1. This is intended to genreate a conflict. "+
            "I'm out of witty stuff to put here."
    output = "\t1. This is intended to genreate a conflict. I'm out of witty stuff to put here."
    expected_output = "\x00\x00\x00\x00\x00\x00\x00\x1c\x00\x00\x00\x00"
    assert_equal(expected_output, BinaryDiff.bdiff(input, output))
  end
  
  def test_create_simple_bdiff
    input = ""
    output = "hi there\ni'm stupid"
    expected_output = "\000\000\000\000\000\000\000\000\000\000\000\x13"+output
    assert_equal expected_output, BinaryDiff.bdiff(input, output)
  end
  
  def test_mismatched_encoding_bdiff
    input = "hello©™"
    output = "hello©™"
    output.force_encoding("UTF-8") if ruby_19?
    expected_output = ""
    assert_equal expected_output, BinaryDiff.bdiff(input, output)
  end
end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.