summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAustin Ziegler <austin@zieglers.ca>2014-05-06 00:08:02 -0400
committerAustin Ziegler <austin@zieglers.ca>2017-01-11 16:02:56 -0500
commitf82593ee76d9a05ff305840bf1efaa78f087ab2e (patch)
treebfba9c344a21afee98c70932f0e9b456f0f7ad2f
parent32727d6d0beb48672a1ee2d4a5c20bb81f7e301d (diff)
downloaddiff-lcs-spec-cleanup.tar.gz
diff-lcs 1.3 release candidate 1spec-cleanup
- Updated testing and gem infrastructure. - Cleaning up documentation. - Modernizing specs. - Silence Ruby 2.4 Fixnum deprecation warnings. Fixes #36, #38. - Ensure test dependencies are loaded. Fixes #33, #34 so that specs can be run independently. - Fix issue #1 with incorrect intuition of patch direction. Tentative fix, but the failure cases pass now.
-rw-r--r--.gitignore10
-rw-r--r--.hoerc45
-rw-r--r--.rspec1
-rw-r--r--.travis.yml33
-rw-r--r--Contributing.rdoc2
-rw-r--r--Gemfile23
-rw-r--r--History.rdoc4
-rw-r--r--Manifest.txt8
-rw-r--r--README.rdoc27
-rw-r--r--Rakefile45
-rw-r--r--diff-lcs.gemspec52
-rw-r--r--lib/diff/lcs.rb88
-rw-r--r--lib/diff/lcs/change.rb8
-rw-r--r--lib/diff/lcs/internals.rb22
-rw-r--r--lib/diff/lcs/ldiff.rb52
-rw-r--r--spec/diff_spec.rb28
-rw-r--r--spec/fixtures/ds1.csv50
-rw-r--r--spec/fixtures/ds2.csv51
-rw-r--r--spec/hunk_spec.rb34
-rw-r--r--spec/issues_spec.rb55
-rw-r--r--spec/lcs_spec.rb44
-rw-r--r--spec/ldiff_spec.rb47
-rw-r--r--spec/patch_spec.rb282
-rw-r--r--spec/sdiff_spec.rb8
-rw-r--r--spec/traverse_balanced_spec.rb16
-rw-r--r--spec/traverse_sequences_spec.rb112
26 files changed, 631 insertions, 516 deletions
diff --git a/.gitignore b/.gitignore
index 452922f..a049920 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,13 +1,10 @@
-Gemfile.lock
-spec/ldap.yml
-.rvmrc
-pkg/
*.pyc
*.rbc
*.swp
*~
.DS_Store
.rake_tasks~
+.rvmrc
.source_index
Gemfile.lock
coverage.info
@@ -15,8 +12,9 @@ coverage.vim
coverage/
doc/
html/
+pkg/
publish/
research/
+spec/ldap.yml
website/index.html
-pkg/
-publish/
+.byebug_history
diff --git a/.hoerc b/.hoerc
index 0a13543..7922c87 100644
--- a/.hoerc
+++ b/.hoerc
@@ -1,2 +1,45 @@
---
-exclude: !ruby/regexp /(tmp|swp)$|CVS|TAGS|\.(svn|git|hg|DS_Store|idea)|Gemfile\.lock|research\/|\.gemspec$/
+exclude: !ruby/regexp '/
+ \.(?:
+ tmp |
+ swp
+ )$
+ |
+ \.(?:
+ autotest |
+ byebug_history |
+ gemtest |
+ gitignore |
+ hoerc |
+ minitest.rb |
+ simplecov-prelude.rb)$
+ |
+ \.(?:
+ coveralls |
+ pullreview |
+ travis |
+ appveyor
+ )\.yml$
+ |
+ (?i:TAGS)$
+ |
+ \.(?:
+ DS_Store|
+ bundle|
+ git|
+ hg|
+ idea|
+ svn|
+ vagrant
+ )\/
+ |
+ [gG]emfile(?:\.lock)?
+ |
+ support\/
+ |
+ research\/
+ |
+ \.gemspec$
+ |
+ Vagrantfile
+ /x'
diff --git a/.rspec b/.rspec
index 7438fbe..53607ea 100644
--- a/.rspec
+++ b/.rspec
@@ -1,2 +1 @@
--colour
---format documentation
diff --git a/.travis.yml b/.travis.yml
index b54d13c..6854cfd 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,35 +1,32 @@
---
language: ruby
rvm:
- - 2.1.0
+ - 2.4.0
+ - 2.3.3
+ - 2.2.6
+ - 2.1.9
- 2.0.0
- 1.9.3
- - 1.9.2
- - ruby-head
- - jruby-19mode
- - jruby-head
- - rbx
- 1.8.7
- - jruby-18mode
- ree
+ - ruby-head
+ - jruby-19mode
matrix:
allow_failures:
- - rvm: rbx
+ - rvm: ruby-head
+ - rvm: 1.8.7
+ - rvm: ree
gemfile:
- Gemfile
before_script:
- - |
- case "${TRAVIS_RUBY_VERSION}" in
- rbx*)
- gem install psych
- gem install -v '~> 2.0' rubysl
- ;;
- esac
- - rake travis:before -t
-script: rake travis
+ - bundle exec rake travis:before -t
+script: bundle exec rake travis
after_script:
- - rake travis:after -t
+ - bundle exec rake travis:after -t
notifications:
email:
+ recipients:
+ - austin@rubyforge.org
on_success: change
on_failure: always
+sudo: false
diff --git a/Contributing.rdoc b/Contributing.rdoc
index a0f37de..4f2aa53 100644
--- a/Contributing.rdoc
+++ b/Contributing.rdoc
@@ -62,3 +62,5 @@ Thanks to everyone else who has contributed to Diff::LCS:
* Michael Granger
* Vít Ondruch
* Jon Rowe
+* Koichi Ito
+* Josef Strzibny
diff --git a/Gemfile b/Gemfile
index 174f15f..fa1f60f 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,20 +1,19 @@
# -*- ruby -*-
-# DO NOT EDIT THIS FILE. Instead, edit Rakefile, and run `rake bundler:gemfile`.
+# NOTE: This file is present to keep Travis CI happy. Edits to it will not
+# be accepted.
source "https://rubygems.org/"
+if RUBY_VERSION < '1.9'
+ gem 'rdoc', '< 4.0'
+elsif RUBY_VERSION >= '2.0'
+ if RUBY_ENGINE == 'ruby'
+ gem 'simplecov', '~> 0.7'
+ gem 'coveralls', '~> 0.7'
+ end
+end
-gem "rubyforge", ">=2.0.4", :group => [:development, :test]
-gem "rdoc", "~>4.0", :group => [:development, :test]
-gem "hoe-bundler", "~>1.2", :group => [:development, :test]
-gem "hoe-doofus", "~>1.0", :group => [:development, :test]
-gem "hoe-gemspec2", "~>1.1", :group => [:development, :test]
-gem "hoe-git", "~>1.5", :group => [:development, :test]
-gem "hoe-rubygems", "~>1.0", :group => [:development, :test]
-gem "hoe-travis", "~>1.2", :group => [:development, :test]
-gem "rake", "~>10.0", :group => [:development, :test]
-gem "rspec", "~>2.0", :group => [:development, :test]
-gem "hoe", "~>3.7", :group => [:development, :test]
+gemspec
# vim: syntax=ruby
diff --git a/History.rdoc b/History.rdoc
index 30d1d1e..2a48adb 100644
--- a/History.rdoc
+++ b/History.rdoc
@@ -123,8 +123,8 @@
* Fixed a problem reported by Mauricio Fernandez in htmldiff.
== 1.1.1 / 2004-09-25
-* Fixed bug #891:
- http://rubyforge.org/tracker/?func=detail&atid=407&aid=891&group_id=84
+* Fixed bug #891 (Set returned from patch command does not contain last equal
+ part).
* Fixed a problem with callback initialisation code (it assumed that all
callbacks passed as classes can be initialised; now, it rescues
NoMethodError in the event of private :new being called).
diff --git a/Manifest.txt b/Manifest.txt
index d078734..6873f95 100644
--- a/Manifest.txt
+++ b/Manifest.txt
@@ -1,10 +1,5 @@
-.autotest
-.gemtest
-.hoerc
.rspec
-.travis.yml
Contributing.rdoc
-Gemfile
History.rdoc
License.rdoc
Manifest.txt
@@ -28,9 +23,12 @@ lib/diff/lcs/ldiff.rb
lib/diff/lcs/string.rb
spec/change_spec.rb
spec/diff_spec.rb
+spec/fixtures/ds1.csv
+spec/fixtures/ds2.csv
spec/hunk_spec.rb
spec/issues_spec.rb
spec/lcs_spec.rb
+spec/ldiff_spec.rb
spec/patch_spec.rb
spec/sdiff_spec.rb
spec/spec_helper.rb
diff --git a/README.rdoc b/README.rdoc
index fecf267..7a3350a 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -4,8 +4,8 @@ home :: https://github.com/halostatue/diff-lcs
code :: https://github.com/halostatue/diff-lcs
bugs :: https://github.com/halostatue/diff-lcs/issues
rdoc :: http://rubydoc.info/github/halostatue/diff-lcs
-continuous integration :: {<img src="https://travis-ci.org/halostatue/diff-lcs.png" />}[https://travis-ci.org/halostatue/diff-lcs]
-test coverage :: {<img src="https://coveralls.io/repos/halostatue/diff-lcs/badge.png" alt="Coverage Status" />}[https://coveralls.io/r/halostatue/diff-lcs]
+continuous integration :: {<img src="https://travis-ci.org/halostatue/diff-lcs.svg" />}[https://travis-ci.org/halostatue/diff-lcs]
+test coverage :: {<img src="https://coveralls.io/repos/halostatue/diff-lcs/badge.svg" alt="Coverage Status" />}[https://coveralls.io/r/halostatue/diff-lcs]
== Description
@@ -13,14 +13,10 @@ Diff::LCS computes the difference between two Enumerable sequences using the
McIlroy-Hunt longest common subsequence (LCS) algorithm. It includes utilities
to create a simple HTML diff output format and a standard diff-like tool.
-This is release 1.2.4, fixing a bug introduced after diff-lcs 1.1.3 that did
-not properly prune common sequences at the beginning of a comparison set.
-Thanks to Paul Kunysch for fixing this issue.
-
-Coincident with the release of diff-lcs 1.2.3, we reported an issue with
-Rubinius in 1.9 mode
-({rubinius/rubinius#2268}[https://github.com/rubinius/rubinius/issues/2268]).
-We are happy to report that this issue has been resolved.
+This is release 1.3, providing a tentative fix to a long-standing issue related
+to incorrect detection of a patch direction. Also modernizes the gem
+infrastructure, testing infrastructure, and provides a warning-free experience
+to Ruby 2.4 users.
== Synopsis
@@ -71,12 +67,17 @@ or Array will perform best.
Diff::LCS is a port of Perl's Algorithm::Diff that uses the McIlroy-Hunt
longest common subsequence (LCS) algorithm to compute intelligent differences
between two sequenced enumerable containers. The implementation is based on
-Mario I. Wolczko's {Smalltalk version 1.2}[ftp://st.cs.uiuc.edu/pub/Smalltalk/MANCHESTER/manchester/4.0/diff.st]
+Mario I. Wolczko's
+{Smalltalk version 1.2}[ftp://st.cs.uiuc.edu/pub/Smalltalk/MANCHESTER/manchester/4.0/diff.st]
(1993) and Ned Konz's Perl version
{Algorithm::Diff 1.15}[http://search.cpan.org/~nedkonz/Algorithm-Diff-1.15/].
+Diff::LCS#sdiff and Diff::LCS#traverse_balanced were originally written for the
+Perl version by Mike Schilli.
-This library is called Diff::LCS because of an early version of Algorithm::Diff
-which was restrictively licensed.
+The algorithm is described in <em>A Fast Algorithm for Computing Longest Common
+Subsequences</em>, CACM, vol.20, no.5, pp.350-353, May 1977, with a few minor
+improvements to improve the speed. A simplified description of the algorithm,
+originally written for the Perl version, was written by Mark-Jason Dominus.
:include: Contributing.rdoc
diff --git a/Rakefile b/Rakefile
index 478ac32..4fd985e 100644
--- a/Rakefile
+++ b/Rakefile
@@ -14,27 +14,20 @@ Hoe.plugin :travis
spec = Hoe.spec 'diff-lcs' do
developer('Austin Ziegler', 'halostatue@gmail.com')
- self.need_tar = true
+ require_ruby_version '>= 1.8'
self.history_file = 'History.rdoc'
self.readme_file = 'README.rdoc'
- self.extra_rdoc_files = FileList["*.rdoc"].to_a
-
- %w(MIT Perl\ Artistic\ v2 GNU\ GPL\ v2).each { |l| self.license l }
-
- self.extra_dev_deps << ['hoe-bundler', '~> 1.2']
- self.extra_dev_deps << ['hoe-doofus', '~> 1.0']
- self.extra_dev_deps << ['hoe-gemspec2', '~> 1.1']
- self.extra_dev_deps << ['hoe-git', '~> 1.5']
- self.extra_dev_deps << ['hoe-rubygems', '~> 1.0']
- self.extra_dev_deps << ['hoe-travis', '~> 1.2']
- self.extra_dev_deps << ['rake', '~> 10.0']
- self.extra_dev_deps << ['rspec', '~> 2.0']
-
- if RUBY_VERSION >= '1.9' and (ENV['CI'] or ENV['TRAVIS'])
- self.extra_dev_deps << ['simplecov', '~> 0.8']
- self.extra_dev_deps << ['coveralls', '~> 0.7']
- end
+ self.licenses = [ 'MIT', 'Perl Artistic v2', 'GNU GPL v2' ]
+
+ extra_dev_deps << ['hoe-doofus', '~> 1.0']
+ extra_dev_deps << ['hoe-gemspec2', '~> 1.1']
+ extra_dev_deps << ['hoe-git', '~> 1.6']
+ extra_dev_deps << ['hoe-rubygems', '~> 1.0']
+ extra_dev_deps << ['hoe-travis', '~> 1.2']
+ extra_dev_deps << ['rspec', '>= 2.0', '< 4']
+ extra_dev_deps << ['rake', '>= 10.0', '< 12']
+ extra_dev_deps << ['rdoc', '>= 0']
end
unless Rake::Task.task_defined? :test
@@ -42,21 +35,23 @@ unless Rake::Task.task_defined? :test
Rake::Task['travis'].prerequisites.replace(%w(spec))
end
-if RUBY_VERSION >= '1.9'
+if RUBY_VERSION >= '2.0' && RUBY_ENGINE == 'ruby'
namespace :spec do
- desc "Submit test coverage to Coveralls"
task :coveralls do
- ENV['COVERALLS'] = 'yes'
+ if ENV['CI'] or ENV['TRAVIS']
+ ENV['COVERALLS'] = 'yes'
+ Rake::Task['spec'].execute
+ else
+ Rake::Task['spec:coverage'].execute
+ end
end
- desc "Runs test coverage. Only works Ruby 1.9+ and assumes 'simplecov' is installed."
+ desc "Runs test coverage. Only works Ruby 2.0+ and assumes 'simplecov' is installed."
task :coverage do
ENV['COVERAGE'] = 'yes'
Rake::Task['spec'].execute
end
end
- Rake::Task['travis'].prerequisites.replace(%w(spec:coveralls))
+ # Rake::Task['travis'].prerequisites.replace(%w(spec:coveralls))
end
-
-# vim: syntax=ruby
diff --git a/diff-lcs.gemspec b/diff-lcs.gemspec
index b972c34..ccc8c59 100644
--- a/diff-lcs.gemspec
+++ b/diff-lcs.gemspec
@@ -1,61 +1,59 @@
# -*- encoding: utf-8 -*-
-# stub: diff-lcs 1.3 ruby lib
+# stub: diff-lcs 1.3.0.rc1 ruby lib
Gem::Specification.new do |s|
s.name = "diff-lcs"
- s.version = "1.3"
+ s.version = "1.3.0.rc1"
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib"]
s.authors = ["Austin Ziegler"]
- s.date = "2014-04-26"
- s.description = "Diff::LCS computes the difference between two Enumerable sequences using the\nMcIlroy-Hunt longest common subsequence (LCS) algorithm. It includes utilities\nto create a simple HTML diff output format and a standard diff-like tool.\n\nThis is release 1.2.4, fixing a bug introduced after diff-lcs 1.1.3 that did\nnot properly prune common sequences at the beginning of a comparison set.\nThanks to Paul Kunysch for fixing this issue.\n\nCoincident with the release of diff-lcs 1.2.3, we reported an issue with\nRubinius in 1.9 mode\n({rubinius/rubinius#2268}[https://github.com/rubinius/rubinius/issues/2268]).\nWe are happy to report that this issue has been resolved."
+ s.date = "2017-01-11"
+ s.description = "Diff::LCS computes the difference between two Enumerable sequences using the\nMcIlroy-Hunt longest common subsequence (LCS) algorithm. It includes utilities\nto create a simple HTML diff output format and a standard diff-like tool.\n\nThis is release 1.3, providing a tentative fix to a long-standing issue related\nto incorrect detection of a patch direction. Also modernizes the gem\ninfrastructure, testing infrastructure, and provides a warning-free experience\nto Ruby 2.4 users."
s.email = ["halostatue@gmail.com"]
s.executables = ["htmldiff", "ldiff"]
- s.extra_rdoc_files = ["Contributing.rdoc", "History.rdoc", "License.rdoc", "Manifest.txt", "README.rdoc", "docs/COPYING.txt", "docs/artistic.txt", "Contributing.rdoc", "History.rdoc", "License.rdoc", "README.rdoc"]
- s.files = [".autotest", ".gemtest", ".hoerc", ".rspec", ".travis.yml", "Contributing.rdoc", "Gemfile", "History.rdoc", "License.rdoc", "Manifest.txt", "README.rdoc", "Rakefile", "autotest/discover.rb", "bin/htmldiff", "bin/ldiff", "docs/COPYING.txt", "docs/artistic.txt", "lib/diff-lcs.rb", "lib/diff/lcs.rb", "lib/diff/lcs/array.rb", "lib/diff/lcs/block.rb", "lib/diff/lcs/callbacks.rb", "lib/diff/lcs/change.rb", "lib/diff/lcs/htmldiff.rb", "lib/diff/lcs/hunk.rb", "lib/diff/lcs/internals.rb", "lib/diff/lcs/ldiff.rb", "lib/diff/lcs/string.rb", "spec/change_spec.rb", "spec/diff_spec.rb", "spec/hunk_spec.rb", "spec/issues_spec.rb", "spec/lcs_spec.rb", "spec/patch_spec.rb", "spec/sdiff_spec.rb", "spec/spec_helper.rb", "spec/traverse_balanced_spec.rb", "spec/traverse_sequences_spec.rb"]
- s.homepage = "http://halostatue.github.io/diff-lcs/"
+ s.extra_rdoc_files = ["Contributing.rdoc", "History.rdoc", "License.rdoc", "Manifest.txt", "README.rdoc", "docs/COPYING.txt", "docs/artistic.txt"]
+ s.files = [".rspec", "Contributing.rdoc", "History.rdoc", "License.rdoc", "Manifest.txt", "README.rdoc", "Rakefile", "autotest/discover.rb", "bin/htmldiff", "bin/ldiff", "docs/COPYING.txt", "docs/artistic.txt", "lib/diff-lcs.rb", "lib/diff/lcs.rb", "lib/diff/lcs/array.rb", "lib/diff/lcs/block.rb", "lib/diff/lcs/callbacks.rb", "lib/diff/lcs/change.rb", "lib/diff/lcs/htmldiff.rb", "lib/diff/lcs/hunk.rb", "lib/diff/lcs/internals.rb", "lib/diff/lcs/ldiff.rb", "lib/diff/lcs/string.rb", "spec/change_spec.rb", "spec/diff_spec.rb", "spec/fixtures/ds1.csv", "spec/fixtures/ds2.csv", "spec/hunk_spec.rb", "spec/issues_spec.rb", "spec/lcs_spec.rb", "spec/ldiff_spec.rb", "spec/patch_spec.rb", "spec/sdiff_spec.rb", "spec/spec_helper.rb", "spec/traverse_balanced_spec.rb", "spec/traverse_sequences_spec.rb"]
+ s.homepage = "https://github.com/halostatue/diff-lcs"
s.licenses = ["MIT", "Perl Artistic v2", "GNU GPL v2"]
s.rdoc_options = ["--main", "README.rdoc"]
- s.rubygems_version = "2.2.1"
+ s.required_ruby_version = Gem::Requirement.new(">= 1.8")
+ s.rubygems_version = "2.5.1"
s.summary = "Diff::LCS computes the difference between two Enumerable sequences using the McIlroy-Hunt longest common subsequence (LCS) algorithm"
if s.respond_to? :specification_version then
s.specification_version = 4
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- s.add_development_dependency(%q<rdoc>, ["~> 4.0"])
- s.add_development_dependency(%q<hoe-bundler>, ["~> 1.2"])
s.add_development_dependency(%q<hoe-doofus>, ["~> 1.0"])
s.add_development_dependency(%q<hoe-gemspec2>, ["~> 1.1"])
- s.add_development_dependency(%q<hoe-git>, ["~> 1.5"])
+ s.add_development_dependency(%q<hoe-git>, ["~> 1.6"])
s.add_development_dependency(%q<hoe-rubygems>, ["~> 1.0"])
s.add_development_dependency(%q<hoe-travis>, ["~> 1.2"])
- s.add_development_dependency(%q<rake>, ["~> 10.0"])
- s.add_development_dependency(%q<rspec>, ["~> 2.0"])
- s.add_development_dependency(%q<hoe>, ["~> 3.11"])
+ s.add_development_dependency(%q<rspec>, ["< 4", ">= 2.0"])
+ s.add_development_dependency(%q<rake>, ["< 12", ">= 10.0"])
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
+ s.add_development_dependency(%q<hoe>, ["~> 3.16"])
else
- s.add_dependency(%q<rdoc>, ["~> 4.0"])
- s.add_dependency(%q<hoe-bundler>, ["~> 1.2"])
s.add_dependency(%q<hoe-doofus>, ["~> 1.0"])
s.add_dependency(%q<hoe-gemspec2>, ["~> 1.1"])
- s.add_dependency(%q<hoe-git>, ["~> 1.5"])
+ s.add_dependency(%q<hoe-git>, ["~> 1.6"])
s.add_dependency(%q<hoe-rubygems>, ["~> 1.0"])
s.add_dependency(%q<hoe-travis>, ["~> 1.2"])
- s.add_dependency(%q<rake>, ["~> 10.0"])
- s.add_dependency(%q<rspec>, ["~> 2.0"])
- s.add_dependency(%q<hoe>, ["~> 3.11"])
+ s.add_dependency(%q<rspec>, ["< 4", ">= 2.0"])
+ s.add_dependency(%q<rake>, ["< 12", ">= 10.0"])
+ s.add_dependency(%q<rdoc>, [">= 0"])
+ s.add_dependency(%q<hoe>, ["~> 3.16"])
end
else
- s.add_dependency(%q<rdoc>, ["~> 4.0"])
- s.add_dependency(%q<hoe-bundler>, ["~> 1.2"])
s.add_dependency(%q<hoe-doofus>, ["~> 1.0"])
s.add_dependency(%q<hoe-gemspec2>, ["~> 1.1"])
- s.add_dependency(%q<hoe-git>, ["~> 1.5"])
+ s.add_dependency(%q<hoe-git>, ["~> 1.6"])
s.add_dependency(%q<hoe-rubygems>, ["~> 1.0"])
s.add_dependency(%q<hoe-travis>, ["~> 1.2"])
- s.add_dependency(%q<rake>, ["~> 10.0"])
- s.add_dependency(%q<rspec>, ["~> 2.0"])
- s.add_dependency(%q<hoe>, ["~> 3.11"])
+ s.add_dependency(%q<rspec>, ["< 4", ">= 2.0"])
+ s.add_dependency(%q<rake>, ["< 12", ">= 10.0"])
+ s.add_dependency(%q<rdoc>, [">= 0"])
+ s.add_dependency(%q<hoe>, ["~> 3.16"])
end
end
diff --git a/lib/diff/lcs.rb b/lib/diff/lcs.rb
index b51c1bc..e3bcbf0 100644
--- a/lib/diff/lcs.rb
+++ b/lib/diff/lcs.rb
@@ -1,57 +1,7 @@
# -*- ruby encoding: utf-8 -*-
module Diff; end unless defined? Diff
-# Computes "intelligent" differences between two sequenced Enumerables. This
-# is an implementation of the McIlroy-Hunt "diff" algorithm for Enumerable
-# objects that include Diffable.
-#
-# Based on Mario I. Wolczko's Smalltalk version (1.2, 1993) and Ned Konz's
-# Perl version (Algorithm::Diff 1.15).
-#
-# == Synopsis
-# require 'diff/lcs'
-#
-# seq1 = %w(a b c e h j l m n p)
-# seq2 = %w(b c d e f j k l m r s t)
-#
-# lcs = Diff::LCS.lcs(seq1, seq2)
-# diffs = Diff::LCS.diff(seq1, seq2)
-# sdiff = Diff::LCS.sdiff(seq1, seq2)
-# seq = Diff::LCS.traverse_sequences(seq1, seq2, callback_obj)
-# bal = Diff::LCS.traverse_balanced(seq1, seq2, callback_obj)
-# seq2 == Diff::LCS.patch(seq1, diffs)
-# seq2 == Diff::LCS.patch!(seq1, diffs)
-# seq1 == Diff::LCS.unpatch(seq2, diffs)
-# seq1 == Diff::LCS.unpatch!(seq2, diffs)
-# seq2 == Diff::LCS.patch(seq1, sdiff)
-# seq2 == Diff::LCS.patch!(seq1, sdiff)
-# seq1 == Diff::LCS.unpatch(seq2, sdiff)
-# seq1 == Diff::LCS.unpatch!(seq2, sdiff)
-#
-# Alternatively, objects can be extended with Diff::LCS:
-#
-# seq1.extend(Diff::LCS)
-# lcs = seq1.lcs(seq2)
-# diffs = seq1.diff(seq2)
-# sdiff = seq1.sdiff(seq2)
-# seq = seq1.traverse_sequences(seq2, callback_obj)
-# bal = seq1.traverse_balanced(seq2, callback_obj)
-# seq2 == seq1.patch(diffs)
-# seq2 == seq1.patch!(diffs)
-# seq1 == seq2.unpatch(diffs)
-# seq1 == seq2.unpatch!(diffs)
-# seq2 == seq1.patch(sdiff)
-# seq2 == seq1.patch!(sdiff)
-# seq1 == seq2.unpatch(sdiff)
-# seq1 == seq2.unpatch!(sdiff)
-#
-# Default extensions are provided for Array and String objects through the
-# use of 'diff/lcs/array' and 'diff/lcs/string'.
-#
-# == Introduction (by Mark-Jason Dominus)
-#
-# <em>The following text is from the Perl documentation. The only changes
-# have been to make the text appear better in Rdoc</em>.
+# == How Diff Works (by Mark-Jason Dominus)
#
# I once read an article written by the authors of +diff+; they said that
# they hard worked very hard on the algorithm until they found the right
@@ -98,36 +48,8 @@ module Diff; end unless defined? Diff
#
# a x b y c z p d q
# a b c a x b y c z
-#
-# == Author
-# This version is by Austin Ziegler <austin@rubyforge.org>.
-#
-# It is based on the Perl Algorithm::Diff (1.15) by Ned Konz , copyright
-# &copy; 2000&ndash;2002 and the Smalltalk diff version by Mario I.
-# Wolczko, copyright &copy; 1993. Documentation includes work by
-# Mark-Jason Dominus.
-#
-# == Licence
-# Copyright &copy; 2004&ndash;2013 Austin Ziegler
-# This program is free software; you can redistribute it and/or modify it
-# under the same terms as Ruby, or alternatively under the Perl Artistic
-# licence.
-#
-# == Credits
-# Much of the documentation is taken directly from the Perl Algorithm::Diff
-# implementation and was written originally by Mark-Jason Dominus and later
-# by Ned Konz. The basic Ruby implementation was re-ported from the
-# Smalltalk implementation, available at
-# ftp://st.cs.uiuc.edu/pub/Smalltalk/MANCHESTER/manchester/4.0/diff.st
-#
-# #sdiff and #traverse_balanced were written for the Perl version by Mike
-# Schilli <m@perlmeister.com>.
-#
-# "The algorithm is described in <em>A Fast Algorithm for Computing Longest
-# Common Subsequences</em>, CACM, vol.20, no.5, pp.350-353, May
-# 1977, with a few minor improvements to improve the speed."
module Diff::LCS
- VERSION = '1.3'
+ VERSION = '1.3.0.rc1'
end
require 'diff/lcs/callbacks'
@@ -765,7 +687,7 @@ class << Diff::LCS
ai += 1
bj += 1
end
- ai += 1
+ ai += 1
when '+'
while bj < change.position
res << (string ? src[ai, 1] : src[ai])
@@ -773,9 +695,9 @@ class << Diff::LCS
bj += 1
end
- bj += 1
+ bj += 1
- res << change.element
+ res << change.element
end
end
end
diff --git a/lib/diff/lcs/change.rb b/lib/diff/lcs/change.rb
index 3104a51..9229069 100644
--- a/lib/diff/lcs/change.rb
+++ b/lib/diff/lcs/change.rb
@@ -4,6 +4,8 @@
# addition of an element from either the old or the new sequenced
# enumerable.
class Diff::LCS::Change
+ IntClass = 1.class # Fixnum is deprecated in Ruby 2.4
+
# The only actions valid for changes are '+' (add), '-' (delete), '='
# (no change), '!' (changed), '<' (tail changes from first sequence), or
# '>' (tail changes from second sequence). The last two ('<>') are only
@@ -28,7 +30,7 @@ class Diff::LCS::Change
unless Diff::LCS::Change.valid_action?(@action)
raise "Invalid Change Action '#{@action}'"
end
- raise "Invalid Position Type" unless @position.kind_of? Fixnum
+ raise "Invalid Position Type" unless @position.kind_of? IntClass
end
def inspect
@@ -115,10 +117,10 @@ class Diff::LCS::ContextChange < Diff::LCS::Change
unless Diff::LCS::Change.valid_action?(@action)
raise "Invalid Change Action '#{@action}'"
end
- unless @old_position.nil? or @old_position.kind_of? Fixnum
+ unless @old_position.nil? or @old_position.kind_of? IntClass
raise "Invalid (Old) Position Type"
end
- unless @new_position.nil? or @new_position.kind_of? Fixnum
+ unless @new_position.nil? or @new_position.kind_of? IntClass
raise "Invalid (New) Position Type"
end
end
diff --git a/lib/diff/lcs/internals.rb b/lib/diff/lcs/internals.rb
index 9d9e3f3..17d1d06 100644
--- a/lib/diff/lcs/internals.rb
+++ b/lib/diff/lcs/internals.rb
@@ -142,8 +142,6 @@ class << Diff::LCS::Internals
# some time. This also works better with Diff::LCS::ContextChange or
# Diff::LCS::Change as its source, as an array will cause the creation
# of one of the above.
- #
- # Note: This will be deprecated as a public function in a future release.
def intuit_diff_direction(src, patchset, limit = nil)
string = src.kind_of?(String)
count = left_match = left_miss = right_match = right_miss = 0
@@ -217,19 +215,27 @@ class << Diff::LCS::Internals
no_left = (left_match == 0) && (left_miss > 0)
no_right = (right_match == 0) && (right_miss > 0)
- case [no_left, no_right]
- when [false, true]
+ case [ no_left, no_right ]
+ when [ false, true ]
:patch
- when [true, false]
+ when [ true, false ]
:unpatch
else
case left_match <=> right_match
when 1
- :patch
+ if left_miss.zero?
+ :patch
+ else
+ :unpatch
+ end
when -1
- :unpatch
+ if right_miss.zero?
+ :unpatch
+ else
+ :patch
+ end
else
- raise "The provided patchset does not appear to apply to the provided value as either source or destination value."
+ raise "The provided patchset does not appear to apply to the provided enumerable as either source or destination value."
end
end
end
diff --git a/lib/diff/lcs/ldiff.rb b/lib/diff/lcs/ldiff.rb
index 75d890f..c789f46 100644
--- a/lib/diff/lcs/ldiff.rb
+++ b/lib/diff/lcs/ldiff.rb
@@ -4,46 +4,18 @@ require 'optparse'
require 'ostruct'
require 'diff/lcs/hunk'
-# == ldiff Usage
-# ldiff [options] oldfile newfile
-#
-# -c:: Displays a context diff with 3 lines of context.
-# -C [LINES], --context [LINES]:: Displays a context diff with LINES lines of context. Default 3 lines.
-# -u:: Displays a unified diff with 3 lines of context.
-# -U [LINES], --unified [LINES]:: Displays a unified diff with LINES lines of context. Default 3 lines.
-# -e:: Creates an 'ed' script to change oldfile to newfile.
-# -f:: Creates an 'ed' script to change oldfile to newfile in reverse order.
-# -a, --text:: Treats the files as text and compares them line-by-line, even if they do not seem to be text.
-# --binary:: Treats the files as binary.
-# -q, --brief:: Reports only whether or not the files differ, not the details.
-# --help:: Shows the command-line help.
-# --version:: Shows the version of Diff::LCS.
-#
-# By default, runs produces an "old-style" diff, with output like UNIX diff.
-#
-# == Copyright
-# Copyright &copy; 2004 Austin Ziegler
-#
-# Part of Diff::LCS <http://rubyforge.org/projects/ruwiki/>
-# Austin Ziegler <diff-lcs@halostatue.ca>
-#
-# This program is free software. It may be redistributed and/or modified under
-# the terms of the GPL version 2 (or later), the Perl Artistic licence, or the
-# Ruby licence.
-module Diff::LCS::Ldiff
+module Diff::LCS::Ldiff #:nodoc:
BANNER = <<-COPYRIGHT
ldiff #{Diff::LCS::VERSION}
- Copyright 2004-2013 Austin Ziegler
+ Copyright 2004-2014 Austin Ziegler
Part of Diff::LCS.
- http://rubyforge.org/projects/ruwiki/
-
- Austin Ziegler <diff-lcs@halostatue.ca>
+ https://github.com/halostatue/diff-lcs
This program is free software. It may be redistributed and/or modified under
the terms of the GPL version 2 (or later), the Perl Artistic licence, or the
MIT licence.
- COPYRIGHT
+COPYRIGHT
end
class << Diff::LCS::Ldiff
@@ -118,13 +90,13 @@ class << Diff::LCS::Ldiff
file_length_difference = 0
if @binary.nil? or @binary
- data_old = IO::read(file_old)
- data_new = IO::read(file_new)
+ data_old = IO.read(file_old)
+ data_new = IO.read(file_new)
# Test binary status
if @binary.nil?
- old_txt = data_old[0...4096].scan(/\0/).empty?
- new_txt = data_new[0...4096].scan(/\0/).empty?
+ old_txt = data_old[0, 4096].scan(/\0/).empty?
+ new_txt = data_new[0, 4096].scan(/\0/).empty?
@binary = (not old_txt) or (not new_txt)
old_txt = new_txt = nil
end
@@ -134,8 +106,8 @@ class << Diff::LCS::Ldiff
data_new = data_new.split($/).map { |e| e.chomp }
end
else
- data_old = IO::readlines(file_old).map { |e| e.chomp }
- data_new = IO::readlines(file_new).map { |e| e.chomp }
+ data_old = IO.readlines(file_old).map { |e| e.chomp }
+ data_new = IO.readlines(file_new).map { |e| e.chomp }
end
# diff yields lots of pieces, each of which is basically a Block object
@@ -155,9 +127,9 @@ class << Diff::LCS::Ldiff
if (@format == :unified) or (@format == :context)
ft = File.stat(file_old).mtime.localtime.strftime('%Y-%m-%d %H:%M:%S.%N %z')
- puts "#{char_old} #{file_old}\t#{ft}"
+ output << "#{char_old} #{file_old}\t#{ft}\n"
ft = File.stat(file_new).mtime.localtime.strftime('%Y-%m-%d %H:%M:%S.%N %z')
- puts "#{char_new} #{file_new}\t#{ft}"
+ output << "#{char_new} #{file_new}\t#{ft}\n"
end
# Loop over hunks. If a hunk overlaps with the last hunk, join them.
diff --git a/spec/diff_spec.rb b/spec/diff_spec.rb
index 95d7b40..020ff44 100644
--- a/spec/diff_spec.rb
+++ b/spec/diff_spec.rb
@@ -2,20 +2,20 @@
require 'spec_helper'
-describe "Diff::LCS.diff" do
+describe Diff::LCS, ".diff" do
include Diff::LCS::SpecHelper::Matchers
- it "should correctly diff seq1 to seq2" do
+ it "correctly diffs seq1 to seq2" do
diff_s1_s2 = Diff::LCS.diff(seq1, seq2)
- change_diff(correct_forward_diff).should == diff_s1_s2
+ expect(change_diff(correct_forward_diff)).to eq(diff_s1_s2)
end
- it "should correctly diff seq2 to seq1" do
+ it "correctly diffs seq2 to seq1" do
diff_s2_s1 = Diff::LCS.diff(seq2, seq1)
- change_diff(correct_backward_diff).should == diff_s2_s1
+ expect(change_diff(correct_backward_diff)).to eq(diff_s2_s1)
end
- it "should correctly diff against an empty sequence" do
+ it "correctly diffs against an empty sequence" do
diff = Diff::LCS.diff(word_sequence, [])
correct_diff = [
[ [ '-', 0, 'abcd' ],
@@ -24,24 +24,24 @@ describe "Diff::LCS.diff" do
[ '-', 3, 'mnopqrstuvwxyz' ] ]
]
- change_diff(correct_diff).should == diff
+ expect(change_diff(correct_diff)).to eq(diff)
diff = Diff::LCS.diff([], word_sequence)
correct_diff.each { |hunk| hunk.each { |change| change[0] = '+' } }
- change_diff(correct_diff).should == diff
+ expect(change_diff(correct_diff)).to eq(diff)
end
- it "should correctly diff 'xx' and 'xaxb'" do
+ it "correctly diffs 'xx' and 'xaxb'" do
left = 'xx'
right = 'xaxb'
- Diff::LCS.patch(left, Diff::LCS.diff(left, right)).should == right
+ expect(Diff::LCS.patch(left, Diff::LCS.diff(left, right))).to eq(right)
end
- it "should return an empty diff with (hello, hello)" do
- Diff::LCS.diff(hello, hello).should == []
+ it "returns an empty diff with (hello, hello)" do
+ expect(Diff::LCS.diff(hello, hello)).to be_empty
end
- it "should return an empty diff with (hello_ary, hello_ary)" do
- Diff::LCS.diff(hello_ary, hello_ary).should == []
+ it "returns an empty diff with (hello_ary, hello_ary)" do
+ expect(Diff::LCS.diff(hello_ary, hello_ary)).to be_empty
end
end
diff --git a/spec/fixtures/ds1.csv b/spec/fixtures/ds1.csv
new file mode 100644
index 0000000..9ac8428
--- /dev/null
+++ b/spec/fixtures/ds1.csv
@@ -0,0 +1,50 @@
+1,3
+2,7
+3,13
+4,21
+5,31
+6,43
+7,57
+8,73
+9,91
+10,111
+11,133
+12,157
+13,183
+14,211
+15,241
+16,273
+17,307
+18,343
+19,381
+20,421
+21,463
+22,507
+23,553
+24,601
+25,651
+26,703
+27,757
+28,813
+29,871
+30,931
+31,993
+32,1057
+33,1123
+34,1191
+35,1261
+36,1333
+37,1407
+38,1483
+39,1561
+40,1641
+41,1723
+42,1807
+43,1893
+44,1981
+45,2071
+46,2163
+47,2257
+48,2353
+49,2451
+50,2500 \ No newline at end of file
diff --git a/spec/fixtures/ds2.csv b/spec/fixtures/ds2.csv
new file mode 100644
index 0000000..797de76
--- /dev/null
+++ b/spec/fixtures/ds2.csv
@@ -0,0 +1,51 @@
+ 1,3
+2,7
+3,13
+4,21
+5,31
+6,42
+7,57
+8,73
+9,91
+10,111
+11,133
+12,157
+13,183
+14,211
+15,241
+16,273
+17,307
+18,343
+19,200
+20,421
+21,463
+22,507
+23,553
+24,601
+25,651
+26,703
+27,757
+28,813
+29,871
+30,931
+31,123
+32,1057
+33,1123
+34,1000
+35,1261
+36,1333
+37,1407
+38,1483
+39,1561
+40,1641
+41,1723
+42,1807
+43,1893
+44,1981
+45,2071
+46,2163
+47,1524
+48,2353
+49,2451
+50,2500
+51,2520
diff --git a/spec/hunk_spec.rb b/spec/hunk_spec.rb
index dc6f532..0711e0d 100644
--- a/spec/hunk_spec.rb
+++ b/spec/hunk_spec.rb
@@ -2,28 +2,26 @@
require 'spec_helper'
-def h(v)
- v.to_s.bytes.to_a.map { |e| "%02x" % e }.join
-end
-
-describe "Diff::LCS::Hunk" do
- if String.method_defined?(:encoding)
+if String.method_defined?(:encoding)
+ require 'diff/lcs/hunk'
+ describe Diff::LCS::Hunk do
let(:old_data) { ["Tu avec carté {count} itém has".encode('UTF-16LE')] }
let(:new_data) { ["Tu avec carte {count} item has".encode('UTF-16LE')] }
let(:pieces) { Diff::LCS.diff old_data, new_data }
let(:hunk) { Diff::LCS::Hunk.new(old_data, new_data, pieces[0], 3, 0) }
- it 'should be able to produce a unified diff from the two pieces' do
+ it 'produces a unified diff from the two pieces' do
expected = (<<-EOD.gsub(/^\s+/,'').encode('UTF-16LE').chomp)
@@ -1,2 +1,2 @@
-Tu avec carté {count} itém has
+Tu avec carte {count} item has
EOD
- expect(hunk.diff(:unified).to_s == expected).to eql true
+
+ expect(hunk.diff(:unified)).to eq(expected)
end
- it 'should be able to produce a context diff from the two pieces' do
+ it 'produces a context diff from the two pieces' do
expected = (<<-EOD.gsub(/^\s+/,'').encode('UTF-16LE').chomp)
***************
*** 1,2 ****
@@ -32,10 +30,10 @@ describe "Diff::LCS::Hunk" do
!Tu avec carte {count} item has
EOD
- expect(hunk.diff(:context).to_s == expected).to eql true
+ expect(hunk.diff(:context)).to eq(expected)
end
- it 'should be able to produce an old diff from the two pieces' do
+ it 'produces an old diff from the two pieces' do
expected = (<<-EOD.gsub(/^ +/,'').encode('UTF-16LE').chomp)
1,2c1,2
< Tu avec carté {count} itém has
@@ -43,30 +41,32 @@ describe "Diff::LCS::Hunk" do
> Tu avec carte {count} item has
EOD
- expect(hunk.diff(:old).to_s == expected).to eql true
+
+ expect(hunk.diff(:old)).to eq(expected)
end
- it 'should be able to produce a reverse ed diff from the two pieces' do
+ it 'produces a reverse ed diff from the two pieces' do
expected = (<<-EOD.gsub(/^ +/,'').encode('UTF-16LE').chomp)
c1,2
Tu avec carte {count} item has
.
EOD
- expect(hunk.diff(:reverse_ed).to_s == expected).to eql true
+
+ expect(hunk.diff(:reverse_ed)).to eq(expected)
end
context 'with empty first data set' do
let(:old_data) { [] }
- it 'should be able to produce a unified diff' do
+ it 'produces a unified diff' do
expected = (<<-EOD.gsub(/^\s+/,'').encode('UTF-16LE').chomp)
@@ -1 +1,2 @@
+Tu avec carte {count} item has
EOD
- expect(hunk.diff(:unified).to_s == expected).to eql true
+
+ expect(hunk.diff(:unified)).to eq(expected)
end
end
-
end
end
diff --git a/spec/issues_spec.rb b/spec/issues_spec.rb
index c3d8f87..7638249 100644
--- a/spec/issues_spec.rb
+++ b/spec/issues_spec.rb
@@ -5,20 +5,45 @@ require 'spec_helper'
describe "Diff::LCS Issues" do
include Diff::LCS::SpecHelper::Matchers
- it "should not fail to provide a simple patchset (issue 1)" do
- s1, s2 = *%W(aX bXaX)
- correct_forward_diff = [
- [ [ '+', 0, 'b' ],
- [ '+', 1, 'X' ] ],
- ]
-
- diff_s1_s2 = Diff::LCS.diff(s1, s2)
- change_diff(correct_forward_diff).should == diff_s1_s2
- expect do
- Diff::LCS.patch(s1, diff_s1_s2).should == s2
- end.to_not raise_error(RuntimeError, /provided patchset/)
- expect do
- Diff::LCS.patch(s2, diff_s1_s2).should == s1
- end.to_not raise_error(RuntimeError, /provided patchset/)
+ describe 'issue #1' do
+ shared_examples 'handles simple diffs' do |s1, s2, forward_diff|
+ before do
+ @diff_s1_s2 = Diff::LCS.diff(s1, s2)
+ end
+
+ it 'creates the correct diff' do
+ expect(change_diff(forward_diff)).to eq(@diff_s1_s2)
+ end
+
+ it 'creates the correct patch s1->s2' do
+ expect(Diff::LCS.patch(s1, @diff_s1_s2)).to eq(s2)
+ end
+
+ it 'creates the correct patch s2->s1' do
+ expect(Diff::LCS.patch(s2, @diff_s1_s2)).to eq(s1)
+ end
+ end
+
+ describe 'string' do
+ it_has_behavior 'handles simple diffs', 'aX', 'bXaX', [
+ [ [ '+', 0, 'b' ],
+ [ '+', 1, 'X' ] ],
+ ]
+ it_has_behavior 'handles simple diffs', 'bXaX', 'aX', [
+ [ [ '-', 0, 'b' ],
+ [ '-', 1, 'X' ] ],
+ ]
+ end
+
+ describe 'array' do
+ it_has_behavior 'handles simple diffs', %w(a X), %w(b X a X), [
+ [ [ '+', 0, 'b' ],
+ [ '+', 1, 'X' ] ],
+ ]
+ it_has_behavior 'handles simple diffs', %w(b X a X), %w(a X), [
+ [ [ '-', 0, 'b' ],
+ [ '-', 1, 'X' ] ],
+ ]
+ end
end
end
diff --git a/spec/lcs_spec.rb b/spec/lcs_spec.rb
index 205d563..28533e3 100644
--- a/spec/lcs_spec.rb
+++ b/spec/lcs_spec.rb
@@ -2,53 +2,55 @@
require 'spec_helper'
-describe "Diff::LCS::Internals.lcs" do
+describe Diff::LCS::Internals, ".lcs" do
include Diff::LCS::SpecHelper::Matchers
- it "should return a meaningful LCS array with (seq1, seq2)" do
+ it "returns a meaningful LCS array with (seq1, seq2)" do
res = Diff::LCS::Internals.lcs(seq1, seq2)
# The result of the LCS (less the +nil+ values) must be as long as the
# correct result.
- res.compact.size.should == correct_lcs.size
- res.should correctly_map_sequence(seq1).to_other_sequence(seq2)
+ expect(res.compact.size).to eq(correct_lcs.size)
+ expect(res).to correctly_map_sequence(seq1).to_other_sequence(seq2)
# Compact these transformations and they should be the correct LCS.
x_seq1 = (0...res.size).map { |ix| res[ix] ? seq1[ix] : nil }.compact
x_seq2 = (0...res.size).map { |ix| res[ix] ? seq2[res[ix]] : nil }.compact
- x_seq1.should == correct_lcs
- x_seq2.should == correct_lcs
+ expect(x_seq1).to eq(correct_lcs)
+ expect(x_seq2).to eq(correct_lcs)
end
- it "should return all indexes with (hello, hello)" do
- Diff::LCS::Internals.lcs(hello, hello).should == (0...hello.size).to_a
+ it "returns all indexes with (hello, hello)" do
+ expect(Diff::LCS::Internals.lcs(hello, hello)).to \
+ eq((0...hello.size).to_a)
end
- it "should return all indexes with (hello_ary, hello_ary)" do
- Diff::LCS::Internals.lcs(hello_ary, hello_ary).should == (0...hello_ary.size).to_a
+ it "returns all indexes with (hello_ary, hello_ary)" do
+ expect(Diff::LCS::Internals.lcs(hello_ary, hello_ary)).to \
+ eq((0...hello_ary.size).to_a)
end
end
-describe "Diff::LCS.LCS" do
+describe Diff::LCS, ".LCS" do
include Diff::LCS::SpecHelper::Matchers
- it "should return the correct compacted values from Diff::LCS.LCS" do
+ it "returns the correct compacted values from Diff::LCS.LCS" do
res = Diff::LCS.LCS(seq1, seq2)
- res.should == correct_lcs
- res.compact.should == res
+ expect(res).to eq(correct_lcs)
+ expect(res.compact).to eq(res)
end
- it "should be transitive" do
+ it "is transitive" do
res = Diff::LCS.LCS(seq2, seq1)
- res.should == correct_lcs
- res.compact.should == res
+ expect(res).to eq(correct_lcs)
+ expect(res.compact).to eq(res)
end
- it "should return %W(h e l l o) with (hello, hello)" do
- Diff::LCS.LCS(hello, hello).should == hello.split(//)
+ it "returns %W(h e l l o) with (hello, hello)" do
+ expect(Diff::LCS.LCS(hello, hello)).to eq(hello.split(//))
end
- it "should return hello_ary with (hello_ary, hello_ary)" do
- Diff::LCS.LCS(hello_ary, hello_ary).should == hello_ary
+ it "returns hello_ary with (hello_ary, hello_ary)" do
+ expect(Diff::LCS.LCS(hello_ary, hello_ary)).to eq(hello_ary)
end
end
diff --git a/spec/ldiff_spec.rb b/spec/ldiff_spec.rb
new file mode 100644
index 0000000..ad1377f
--- /dev/null
+++ b/spec/ldiff_spec.rb
@@ -0,0 +1,47 @@
+# -*- ruby encoding: utf-8 -*-
+
+require 'spec_helper'
+
+describe "Diff::LCS.diff" do
+ include Diff::LCS::SpecHelper::Matchers
+
+ it 'correctly diffs seq1 to seq2' do
+ diff_s1_s2 = Diff::LCS.diff(seq1, seq2)
+ expect(change_diff(correct_forward_diff)).to eq(diff_s1_s2)
+ end
+
+ it 'correctly diffs seq2 to seq1' do
+ diff_s2_s1 = Diff::LCS.diff(seq2, seq1)
+ expect(change_diff(correct_backward_diff)).to eq(diff_s2_s1)
+ end
+
+ it 'correctly diffs against an empty sequence' do
+ diff = Diff::LCS.diff(word_sequence, [])
+ correct_diff = [
+ [ [ '-', 0, 'abcd' ],
+ [ '-', 1, 'efgh' ],
+ [ '-', 2, 'ijkl' ],
+ [ '-', 3, 'mnopqrstuvwxyz' ] ]
+ ]
+
+ expect(change_diff(correct_diff)).to eq(diff)
+
+ diff = Diff::LCS.diff([], word_sequence)
+ correct_diff.each { |hunk| hunk.each { |change| change[0] = '+' } }
+ expect(change_diff(correct_diff)).to eq(diff)
+ end
+
+ it "correctly diffs 'xx' and 'xaxb'" do
+ left = 'xx'
+ right = 'xaxb'
+ expect(Diff::LCS.patch(left, Diff::LCS.diff(left, right))).to eq(right)
+ end
+
+ it "returns an empty diff with (hello, hello)" do
+ expect(Diff::LCS.diff(hello, hello)).to eq([])
+ end
+
+ it "returns an empty diff with (hello_ary, hello_ary)" do
+ expect(Diff::LCS.diff(hello_ary, hello_ary)).to eq([])
+ end
+end
diff --git a/spec/patch_spec.rb b/spec/patch_spec.rb
index 0fc9160..9f1a4f1 100644
--- a/spec/patch_spec.rb
+++ b/spec/patch_spec.rb
@@ -6,33 +6,35 @@ describe "Diff::LCS.patch" do
include Diff::LCS::SpecHelper::Matchers
shared_examples "patch sequences correctly" do
- it "should correctly patch left-to-right (patch autodiscovery)" do
- Diff::LCS.patch(s1, patch_set).should == s2
+ it "correctly patches left-to-right (patch autodiscovery)" do
+ expect(Diff::LCS.patch(s1, patch_set)).to eq(s2)
end
- it "should correctly patch left-to-right (explicit patch)" do
- Diff::LCS.patch(s1, patch_set, :patch).should == s2
- Diff::LCS.patch!(s1, patch_set).should == s2
+ it "correctly patches left-to-right (explicit patch)" do
+ expect(Diff::LCS.patch(s1, patch_set, :patch)).to eq(s2)
+ expect(Diff::LCS.patch!(s1, patch_set)).to eq(s2)
end
- it "should correctly patch right-to-left (unpatch autodiscovery)" do
- Diff::LCS.patch(s2, patch_set).should == s1
+ it "correctly patches right-to-left (unpatch autodiscovery)" do
+ expect(Diff::LCS.patch(s2, patch_set)).to eq(s1)
end
- it "should correctly patch right-to-left (explicit unpatch)" do
- Diff::LCS.patch(s2, patch_set, :unpatch).should == s1
- Diff::LCS.unpatch!(s2, patch_set).should == s1
+ it "correctly patches right-to-left (explicit unpatch)" do
+ expect(Diff::LCS.patch(s2, patch_set, :unpatch)).to eq(s1)
+ expect(Diff::LCS.unpatch!(s2, patch_set)).to eq(s1)
end
end
describe "using a Diff::LCS.diff patchset" do
describe "an empty patchset returns the source" do
it "works on a string (hello)" do
- Diff::LCS::patch(hello, Diff::LCS.diff(hello, hello)).should == hello
+ diff = Diff::LCS.diff(hello, hello)
+ expect(Diff::LCS::patch(hello, diff)).to eq(hello)
end
it "works on an array %W(h e l l o)" do
- Diff::LCS::patch(hello_ary, Diff::LCS.diff(hello_ary, hello_ary)).should == hello_ary
+ diff = Diff::LCS.diff(hello_ary, hello_ary)
+ expect(Diff::LCS::patch(hello_ary, diff)).to eq(hello_ary)
end
end
@@ -102,11 +104,11 @@ describe "Diff::LCS.patch" do
describe "using a Diff::LCS.sdiff patchset" do
describe "an empty patchset returns the source" do
it "works on a string (hello)" do
- Diff::LCS::patch(hello, Diff::LCS.sdiff(hello, hello)).should == hello
+ expect(Diff::LCS::patch(hello, Diff::LCS.sdiff(hello, hello))).to eq(hello)
end
it "works on an array %W(h e l l o)" do
- Diff::LCS::patch(hello_ary, Diff::LCS.sdiff(hello_ary, hello_ary)).should == hello_ary
+ expect(Diff::LCS::patch(hello_ary, Diff::LCS.sdiff(hello_ary, hello_ary))).to eq(hello_ary)
end
end
@@ -178,122 +180,126 @@ describe "Diff::LCS.patch" do
# set. Once the bug in autodiscovery is fixed, this can be converted as
# above.
describe "fix bug 891: patchsets do not contain the last equal part" do
- before(:each) do
+ before :each do
@s1 = %w(a b c d e f g h i j k)
@s2 = %w(a b c d D e f g h i j k)
end
describe "using Diff::LCS.diff with default diff callbacks" do
- before(:each) do
+ before :each do
@patch_set_s1_s2 = Diff::LCS.diff(@s1, @s2)
@patch_set_s2_s1 = Diff::LCS.diff(@s2, @s1)
end
- it "should autodiscover s1 to s2 patches" do
+ it "autodiscovers s1 to s2 patches" do
expect do
- Diff::LCS.patch(@s1, @patch_set_s1_s2).should == @s2
- end.to_not raise_error(RuntimeError, /provided patchset/)
+ expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2)
+ end.to_not raise_error
end
- it "should autodiscover s2 to s1 patches" do
+ it "autodiscovers s2 to s1 patches" do
expect do
- Diff::LCS.patch(@s1, @patch_set_s2_s1).should == @s2
- end.to_not raise_error(RuntimeError, /provided patchset/)
+ expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2)
+ end.to_not raise_error
end
- it "should autodiscover s2 to s1 the left-to-right patches" do
- Diff::LCS.patch(@s2, @patch_set_s2_s1).should == @s1
- Diff::LCS.patch(@s2, @patch_set_s1_s2).should == @s1
+ it "autodiscovers s2 to s1 the left-to-right patches" do
+ expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1)
+ expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1)
end
- it "should correctly patch left-to-right (explicit patch)" do
- Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch).should == @s2
- Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch).should == @s1
- Diff::LCS.patch!(@s1, @patch_set_s1_s2).should == @s2
- Diff::LCS.patch!(@s2, @patch_set_s2_s1).should == @s1
+ it "correctly patches left-to-right (explicit patch)" do
+ expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2)
+ expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1)
+ expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2)
+ expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1)
end
- it "should correctly patch right-to-left (explicit unpatch)" do
- Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch).should == @s1
- Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch).should == @s2
- Diff::LCS.unpatch!(@s2, @patch_set_s1_s2).should == @s1
- Diff::LCS.unpatch!(@s1, @patch_set_s2_s1).should == @s2
+ it "correctly patches right-to-left (explicit unpatch)" do
+ expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1)
+ expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2)
+ expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1)
+ expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2)
end
end
describe "using Diff::LCS.diff with context diff callbacks" do
- before(:each) do
- @patch_set_s1_s2 = Diff::LCS.diff(@s1, @s2, Diff::LCS::ContextDiffCallbacks)
- @patch_set_s2_s1 = Diff::LCS.diff(@s2, @s1, Diff::LCS::ContextDiffCallbacks)
+ before :each do
+ @patch_set_s1_s2 = Diff::LCS.diff(@s1, @s2,
+ Diff::LCS::ContextDiffCallbacks)
+ @patch_set_s2_s1 = Diff::LCS.diff(@s2, @s1,
+ Diff::LCS::ContextDiffCallbacks)
end
- it "should autodiscover s1 to s2 patches" do
+ it "autodiscovers s1 to s2 patches" do
expect do
- Diff::LCS.patch(@s1, @patch_set_s1_s2).should == @s2
- end.to_not raise_error(RuntimeError, /provided patchset/)
+ expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2)
+ end.to_not raise_error
end
- it "should autodiscover s2 to s1 patches" do
+ it "autodiscovers s2 to s1 patches" do
expect do
- Diff::LCS.patch(@s1, @patch_set_s2_s1).should == @s2
- end.to_not raise_error(RuntimeError, /provided patchset/)
+ expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2)
+ end.to_not raise_error
end
- it "should autodiscover s2 to s1 the left-to-right patches" do
- Diff::LCS.patch(@s2, @patch_set_s2_s1).should == @s1
- Diff::LCS.patch(@s2, @patch_set_s1_s2).should == @s1
+ it "autodiscovers s2 to s1 the left-to-right patches" do
+ expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1)
+ expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1)
end
- it "should correctly patch left-to-right (explicit patch)" do
- Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch).should == @s2
- Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch).should == @s1
- Diff::LCS.patch!(@s1, @patch_set_s1_s2).should == @s2
- Diff::LCS.patch!(@s2, @patch_set_s2_s1).should == @s1
+ it "correctly patches left-to-right (explicit patch)" do
+ expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2)
+ expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1)
+ expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2)
+ expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1)
end
- it "should correctly patch right-to-left (explicit unpatch)" do
- Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch).should == @s1
- Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch).should == @s2
- Diff::LCS.unpatch!(@s2, @patch_set_s1_s2).should == @s1
- Diff::LCS.unpatch!(@s1, @patch_set_s2_s1).should == @s2
+ it "correctly patches right-to-left (explicit unpatch)" do
+ expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1)
+ expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2)
+ expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1)
+ expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2)
end
end
describe "using Diff::LCS.diff with sdiff callbacks" do
before(:each) do
- @patch_set_s1_s2 = Diff::LCS.diff(@s1, @s2, Diff::LCS::SDiffCallbacks)
- @patch_set_s2_s1 = Diff::LCS.diff(@s2, @s1, Diff::LCS::SDiffCallbacks)
+ @patch_set_s1_s2 = Diff::LCS.diff(@s1, @s2,
+ Diff::LCS::SDiffCallbacks)
+ @patch_set_s2_s1 = Diff::LCS.diff(@s2, @s1,
+ Diff::LCS::SDiffCallbacks)
end
- it "should autodiscover s1 to s2 patches" do
+ it "autodiscovers s1 to s2 patches" do
expect do
- Diff::LCS.patch(@s1, @patch_set_s1_s2).should == @s2
- end.to_not raise_error(RuntimeError, /provided patchset/)
+ expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2)
+ end.to_not raise_error
end
- it "should autodiscover s2 to s1 patches" do
+ it "autodiscovers s2 to s1 patches" do
expect do
- Diff::LCS.patch(@s1, @patch_set_s2_s1).should == @s2
- end.to_not raise_error(RuntimeError, /provided patchset/)
+ expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2)
+ end.to_not raise_error
end
- it "should autodiscover s2 to s1 the left-to-right patches" do
- Diff::LCS.patch(@s2, @patch_set_s2_s1).should == @s1
- Diff::LCS.patch(@s2, @patch_set_s1_s2).should == @s1
+ it "autodiscovers s2 to s1 the left-to-right patches" do
+ expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1)
+ expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1)
end
- it "should correctly patch left-to-right (explicit patch)" do
- Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch).should == @s2
- Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch).should == @s1
- Diff::LCS.patch!(@s1, @patch_set_s1_s2).should == @s2
- Diff::LCS.patch!(@s2, @patch_set_s2_s1).should == @s1
+ it "correctly patches left-to-right (explicit patch)" do
+ expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2)
+ expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1)
+ expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2)
+ expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1)
end
- it "should correctly patch right-to-left (explicit unpatch)" do
- Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch).should == @s1
- Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch).should == @s2
- Diff::LCS.unpatch!(@s2, @patch_set_s1_s2).should == @s1
- Diff::LCS.unpatch!(@s1, @patch_set_s2_s1).should == @s2
+ it "correctly patches right-to-left (explicit unpatch)" do
+ expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1)
+ expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2)
+ expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1)
+ expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2)
end
end
@@ -303,73 +309,75 @@ describe "Diff::LCS.patch" do
@patch_set_s2_s1 = Diff::LCS.sdiff(@s2, @s1)
end
- it "should autodiscover s1 to s2 patches" do
+ it "autodiscovers s1 to s2 patches" do
expect do
- Diff::LCS.patch(@s1, @patch_set_s1_s2).should == @s2
- end.to_not raise_error(RuntimeError, /provided patchset/)
+ expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2)
+ end.to_not raise_error
end
- it "should autodiscover s2 to s1 patches" do
+ it "autodiscovers s2 to s1 patches" do
expect do
- Diff::LCS.patch(@s1, @patch_set_s2_s1).should == @s2
- end.to_not raise_error(RuntimeError, /provided patchset/)
+ expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2)
+ end.to_not raise_error
end
- it "should autodiscover s2 to s1 the left-to-right patches" do
- Diff::LCS.patch(@s2, @patch_set_s2_s1).should == @s1
- Diff::LCS.patch(@s2, @patch_set_s1_s2).should == @s1
+ it "autodiscovers s2 to s1 the left-to-right patches" do
+ expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1)
+ expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1)
end
- it "should correctly patch left-to-right (explicit patch)", :only => true do
- Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch).should == @s2
- Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch).should == @s1
- Diff::LCS.patch!(@s1, @patch_set_s1_s2).should == @s2
- Diff::LCS.patch!(@s2, @patch_set_s2_s1).should == @s1
+ it "correctly patches left-to-right (explicit patch)" do
+ expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2)
+ expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1)
+ expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2)
+ expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1)
end
- it "should correctly patch right-to-left (explicit unpatch)" do
- Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch).should == @s1
- Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch).should == @s2
- Diff::LCS.unpatch!(@s2, @patch_set_s1_s2).should == @s1
- Diff::LCS.unpatch!(@s1, @patch_set_s2_s1).should == @s2
+ it "correctly patches right-to-left (explicit unpatch)" do
+ expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1)
+ expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2)
+ expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1)
+ expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2)
end
end
describe "using Diff::LCS.sdiff with context diff callbacks" do
before(:each) do
- @patch_set_s1_s2 = Diff::LCS.sdiff(@s1, @s2, Diff::LCS::ContextDiffCallbacks)
- @patch_set_s2_s1 = Diff::LCS.sdiff(@s2, @s1, Diff::LCS::ContextDiffCallbacks)
+ @patch_set_s1_s2 = Diff::LCS.sdiff(@s1, @s2,
+ Diff::LCS::ContextDiffCallbacks)
+ @patch_set_s2_s1 = Diff::LCS.sdiff(@s2, @s1,
+ Diff::LCS::ContextDiffCallbacks)
end
- it "should autodiscover s1 to s2 patches" do
+ it "autodiscovers s1 to s2 patches" do
expect do
- Diff::LCS.patch(@s1, @patch_set_s1_s2).should == @s2
- end.to_not raise_error(RuntimeError, /provided patchset/)
+ expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2)
+ end.to_not raise_error
end
- it "should autodiscover s2 to s1 patches" do
+ it "autodiscovers s2 to s1 patches" do
expect do
- Diff::LCS.patch(@s1, @patch_set_s2_s1).should == @s2
- end.to_not raise_error(RuntimeError, /provided patchset/)
+ expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2)
+ end.to_not raise_error
end
- it "should autodiscover s2 to s1 the left-to-right patches" do
- Diff::LCS.patch(@s2, @patch_set_s2_s1).should == @s1
- Diff::LCS.patch(@s2, @patch_set_s1_s2).should == @s1
+ it "autodiscovers s2 to s1 the left-to-right patches" do
+ expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1)
+ expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1)
end
- it "should correctly patch left-to-right (explicit patch)" do
- Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch).should == @s2
- Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch).should == @s1
- Diff::LCS.patch!(@s1, @patch_set_s1_s2).should == @s2
- Diff::LCS.patch!(@s2, @patch_set_s2_s1).should == @s1
+ it "correctly patches left-to-right (explicit patch)" do
+ expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2)
+ expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1)
+ expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2)
+ expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1)
end
- it "should correctly patch right-to-left (explicit unpatch)" do
- Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch).should == @s1
- Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch).should == @s2
- Diff::LCS.unpatch!(@s2, @patch_set_s1_s2).should == @s1
- Diff::LCS.unpatch!(@s1, @patch_set_s2_s1).should == @s2
+ it "correctly patches right-to-left (explicit unpatch)" do
+ expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1)
+ expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2)
+ expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1)
+ expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2)
end
end
@@ -379,35 +387,35 @@ describe "Diff::LCS.patch" do
@patch_set_s2_s1 = Diff::LCS.sdiff(@s2, @s1, Diff::LCS::DiffCallbacks)
end
- it "should autodiscover s1 to s2 patches" do
+ it "autodiscovers s1 to s2 patches" do
expect do
- Diff::LCS.patch(@s1, @patch_set_s1_s2).should == @s2
- end.to_not raise_error(RuntimeError, /provided patchset/)
+ expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2)
+ end.to_not raise_error
end
- it "should autodiscover s2 to s1 patches" do
+ it "autodiscovers s2 to s1 patches" do
expect do
- Diff::LCS.patch(@s1, @patch_set_s2_s1).should == @s2
- end.to_not raise_error(RuntimeError, /provided patchset/)
+ expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2)
+ end.to_not raise_error
end
- it "should autodiscover s2 to s1 the left-to-right patches" do
- Diff::LCS.patch(@s2, @patch_set_s2_s1).should == @s1
- Diff::LCS.patch(@s2, @patch_set_s1_s2).should == @s1
+ it "autodiscovers s2 to s1 the left-to-right patches" do
+ expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1)
+ expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1)
end
- it "should correctly patch left-to-right (explicit patch)" do
- Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch).should == @s2
- Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch).should == @s1
- Diff::LCS.patch!(@s1, @patch_set_s1_s2).should == @s2
- Diff::LCS.patch!(@s2, @patch_set_s2_s1).should == @s1
+ it "correctly patches left-to-right (explicit patch)" do
+ expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2)
+ expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1)
+ expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2)
+ expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1)
end
- it "should correctly patch right-to-left (explicit unpatch)" do
- Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch).should == @s1
- Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch).should == @s2
- Diff::LCS.unpatch!(@s2, @patch_set_s1_s2).should == @s1
- Diff::LCS.unpatch!(@s1, @patch_set_s2_s1).should == @s2
+ it "correctly patches right-to-left (explicit unpatch)" do
+ expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1)
+ expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2)
+ expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1)
+ expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2)
end
end
end
diff --git a/spec/sdiff_spec.rb b/spec/sdiff_spec.rb
index 7ab3bb6..d619eb4 100644
--- a/spec/sdiff_spec.rb
+++ b/spec/sdiff_spec.rb
@@ -6,12 +6,12 @@ describe "Diff::LCS.sdiff" do
include Diff::LCS::SpecHelper::Matchers
shared_examples "compare sequences correctly" do
- it "should compare s1 -> s2 correctly" do
- Diff::LCS.sdiff(s1, s2).should == context_diff(result)
+ it "compares s1 -> s2 correctly" do
+ expect(Diff::LCS.sdiff(s1, s2)).to eq(context_diff(result))
end
- it "should compare s2 -> s1 correctly" do
- Diff::LCS.sdiff(s2, s1).should == context_diff(reverse_sdiff(result))
+ it "compares s2 -> s1 correctly" do
+ expect(Diff::LCS.sdiff(s2, s1)).to eq(context_diff(reverse_sdiff(result)))
end
end
diff --git a/spec/traverse_balanced_spec.rb b/spec/traverse_balanced_spec.rb
index 63fe1eb..95e60ec 100644
--- a/spec/traverse_balanced_spec.rb
+++ b/spec/traverse_balanced_spec.rb
@@ -6,26 +6,26 @@ describe "Diff::LCS.traverse_balanced" do
include Diff::LCS::SpecHelper::Matchers
shared_examples "with a #change callback" do |s1, s2, result|
- it "should traverse s1 -> s2 correctly" do
+ it "traverses s1 -> s2 correctly" do
traversal = balanced_traversal(s1, s2, :balanced_callback)
- traversal.result.should == result
+ expect(traversal.result).to eq(result)
end
- it "should traverse s2 -> s1 correctly" do
+ it "traverses s2 -> s1 correctly" do
traversal = balanced_traversal(s2, s1, :balanced_callback)
- traversal.result.should == balanced_reverse(result)
+ expect(traversal.result).to eq(balanced_reverse(result))
end
end
shared_examples "without a #change callback" do |s1, s2, result|
- it "should traverse s1 -> s2 correctly" do
+ it "traverses s1 -> s2 correctly" do
traversal = balanced_traversal(s1, s2, :balanced_callback_no_change)
- traversal.result.should == map_to_no_change(result)
+ expect(traversal.result).to eq(map_to_no_change(result))
end
- it "should traverse s2 -> s1 correctly" do
+ it "traverses s2 -> s1 correctly" do
traversal = balanced_traversal(s2, s1, :balanced_callback_no_change)
- traversal.result.should == map_to_no_change(balanced_reverse(result))
+ expect(traversal.result).to eq(map_to_no_change(balanced_reverse(result)))
end
end
diff --git a/spec/traverse_sequences_spec.rb b/spec/traverse_sequences_spec.rb
index f4480df..1252d53 100644
--- a/spec/traverse_sequences_spec.rb
+++ b/spec/traverse_sequences_spec.rb
@@ -13,31 +13,31 @@ describe "Diff::LCS.traverse_sequences" do
Diff::LCS.traverse_sequences(seq2, seq1, @callback_s2_s1)
end
- it "should have the correct LCS result on left-matches" do
- @callback_s1_s2.matched_a.should == correct_lcs
- @callback_s2_s1.matched_a.should == correct_lcs
+ it "has the correct LCS result on left-matches" do
+ expect(@callback_s1_s2.matched_a).to eq(correct_lcs)
+ expect(@callback_s2_s1.matched_a).to eq(correct_lcs)
end
- it "should have the correct LCS result on right-matches" do
- @callback_s1_s2.matched_b.should == correct_lcs
- @callback_s2_s1.matched_b.should == correct_lcs
+ it "has the correct LCS result on right-matches" do
+ expect(@callback_s1_s2.matched_b).to eq(correct_lcs)
+ expect(@callback_s2_s1.matched_b).to eq(correct_lcs)
end
- it "should have the correct skipped sequences with the left sequence" do
- @callback_s1_s2.discards_a.should == skipped_seq1
- @callback_s2_s1.discards_a.should == skipped_seq2
+ it "has the correct skipped sequences with the left sequence" do
+ expect(@callback_s1_s2.discards_a).to eq(skipped_seq1)
+ expect(@callback_s2_s1.discards_a).to eq(skipped_seq2)
end
- it "should have the correct skipped sequences with the right sequence" do
- @callback_s1_s2.discards_b.should == skipped_seq2
- @callback_s2_s1.discards_b.should == skipped_seq1
+ it "has the correct skipped sequences with the right sequence" do
+ expect(@callback_s1_s2.discards_b).to eq(skipped_seq2)
+ expect(@callback_s2_s1.discards_b).to eq(skipped_seq1)
end
- it "should not have anything done markers from the left or right sequences" do
- @callback_s1_s2.done_a.should be_empty
- @callback_s1_s2.done_b.should be_empty
- @callback_s2_s1.done_a.should be_empty
- @callback_s2_s1.done_b.should be_empty
+ it "does not have anything done markers from the left or right sequences" do
+ expect(@callback_s1_s2.done_a).to be_empty
+ expect(@callback_s1_s2.done_b).to be_empty
+ expect(@callback_s2_s1.done_a).to be_empty
+ expect(@callback_s2_s1.done_b).to be_empty
end
end
@@ -47,25 +47,25 @@ describe "Diff::LCS.traverse_sequences" do
Diff::LCS.traverse_sequences(hello, hello, @callback)
end
- it "should have the correct LCS result on left-matches" do
- @callback.matched_a.should == hello.split(//)
+ it "has the correct LCS result on left-matches" do
+ expect(@callback.matched_a).to eq(hello.split(//))
end
- it "should have the correct LCS result on right-matches" do
- @callback.matched_b.should == hello.split(//)
+ it "has the correct LCS result on right-matches" do
+ expect(@callback.matched_b).to eq(hello.split(//))
end
- it "should have the correct skipped sequences with the left sequence", :only => true do
- @callback.discards_a.should be_empty
+ it "has the correct skipped sequences with the left sequence", :only => true do
+ expect(@callback.discards_a).to be_empty
end
- it "should have the correct skipped sequences with the right sequence" do
- @callback.discards_b.should be_empty
+ it "has the correct skipped sequences with the right sequence" do
+ expect(@callback.discards_b).to be_empty
end
- it "should not have anything done markers from the left or right sequences" do
- @callback.done_a.should be_empty
- @callback.done_b.should be_empty
+ it "does not have anything done markers from the left or right sequences" do
+ expect(@callback.done_a).to be_empty
+ expect(@callback.done_b).to be_empty
end
end
@@ -75,25 +75,25 @@ describe "Diff::LCS.traverse_sequences" do
Diff::LCS.traverse_sequences(hello_ary, hello_ary, @callback)
end
- it "should have the correct LCS result on left-matches" do
- @callback.matched_a.should == hello_ary
+ it "has the correct LCS result on left-matches" do
+ expect(@callback.matched_a).to eq(hello_ary)
end
- it "should have the correct LCS result on right-matches" do
- @callback.matched_b.should == hello_ary
+ it "has the correct LCS result on right-matches" do
+ expect(@callback.matched_b).to eq(hello_ary)
end
- it "should have the correct skipped sequences with the left sequence" do
- @callback.discards_a.should be_empty
+ it "has the correct skipped sequences with the left sequence" do
+ expect(@callback.discards_a).to be_empty
end
- it "should have the correct skipped sequences with the right sequence" do
- @callback.discards_b.should be_empty
+ it "has the correct skipped sequences with the right sequence" do
+ expect(@callback.discards_b).to be_empty
end
- it "should not have anything done markers from the left or right sequences" do
- @callback.done_a.should be_empty
- @callback.done_b.should be_empty
+ it "does not have anything done markers from the left or right sequences" do
+ expect(@callback.done_a).to be_empty
+ expect(@callback.done_b).to be_empty
end
end
end
@@ -106,34 +106,34 @@ describe "Diff::LCS.traverse_sequences" do
Diff::LCS.traverse_sequences(seq2, seq1, @callback_s2_s1)
end
- it "should have the correct LCS result on left-matches" do
- @callback_s1_s2.matched_a.should == correct_lcs
- @callback_s2_s1.matched_a.should == correct_lcs
+ it "has the correct LCS result on left-matches" do
+ expect(@callback_s1_s2.matched_a).to eq(correct_lcs)
+ expect(@callback_s2_s1.matched_a).to eq(correct_lcs)
end
- it "should have the correct LCS result on right-matches" do
- @callback_s1_s2.matched_b.should == correct_lcs
- @callback_s2_s1.matched_b.should == correct_lcs
+ it "has the correct LCS result on right-matches" do
+ expect(@callback_s1_s2.matched_b).to eq(correct_lcs)
+ expect(@callback_s2_s1.matched_b).to eq(correct_lcs)
end
- it "should have the correct skipped sequences for the left sequence" do
- @callback_s1_s2.discards_a.should == skipped_seq1
- @callback_s2_s1.discards_a.should == skipped_seq2
+ it "has the correct skipped sequences for the left sequence" do
+ expect(@callback_s1_s2.discards_a).to eq(skipped_seq1)
+ expect(@callback_s2_s1.discards_a).to eq(skipped_seq2)
end
- it "should have the correct skipped sequences for the right sequence" do
- @callback_s1_s2.discards_b.should == skipped_seq2
- @callback_s2_s1.discards_b.should == skipped_seq1
+ it "has the correct skipped sequences for the right sequence" do
+ expect(@callback_s1_s2.discards_b).to eq(skipped_seq2)
+ expect(@callback_s2_s1.discards_b).to eq(skipped_seq1)
end
- it "should have done markers differently-sized sequences" do
- @callback_s1_s2.done_a.should == [[ "p", 9, "s", 10 ]]
- @callback_s1_s2.done_b.should be_empty
+ it "has done markers differently-sized sequences" do
+ expect(@callback_s1_s2.done_a).to eq([[ "p", 9, "s", 10 ]])
+ expect(@callback_s1_s2.done_b).to be_empty
# 20110731 I don't yet understand why this particular behaviour
# isn't transitive.
- @callback_s2_s1.done_a.should be_empty
- @callback_s2_s1.done_b.should be_empty
+ expect(@callback_s2_s1.done_a).to be_empty
+ expect(@callback_s2_s1.done_b).to be_empty
end
end
end