summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore10
-rw-r--r--.hoerc45
-rw-r--r--.rspec1
-rw-r--r--.travis.yml33
-rw-r--r--Code-of-Conduct.md74
-rw-r--r--Contributing.md83
-rw-r--r--Contributing.rdoc64
-rw-r--r--Gemfile23
-rw-r--r--History.md220
-rw-r--r--History.rdoc163
-rw-r--r--License.md (renamed from License.rdoc)0
-rw-r--r--Manifest.txt15
-rw-r--r--README.rdoc27
-rw-r--r--Rakefile47
-rw-r--r--diff-lcs.gemspec46
-rw-r--r--lib/diff/lcs.rb86
-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/spec_helper.rb4
-rw-r--r--spec/traverse_balanced_spec.rb16
-rw-r--r--spec/traverse_sequences_spec.rb112
31 files changed, 1007 insertions, 743 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/Code-of-Conduct.md b/Code-of-Conduct.md
new file mode 100644
index 0000000..d05f4bc
--- /dev/null
+++ b/Code-of-Conduct.md
@@ -0,0 +1,74 @@
+# Contributor Covenant Code of Conduct
+
+## Our Pledge
+
+In the interest of fostering an open and welcoming environment, we as
+contributors and maintainers pledge to making participation in our project and
+our community a harassment-free experience for everyone, regardless of age, body
+size, disability, ethnicity, gender identity and expression, level of experience,
+nationality, personal appearance, race, religion, or sexual identity and
+orientation.
+
+## Our Standards
+
+Examples of behavior that contributes to creating a positive environment
+include:
+
+* Using welcoming and inclusive language
+* Being respectful of differing viewpoints and experiences
+* Gracefully accepting constructive criticism
+* Focusing on what is best for the community
+* Showing empathy towards other community members
+
+Examples of unacceptable behavior by participants include:
+
+* The use of sexualized language or imagery and unwelcome sexual attention or
+advances
+* Trolling, insulting/derogatory comments, and personal or political attacks
+* Public or private harassment
+* Publishing others' private information, such as a physical or electronic
+ address, without explicit permission
+* Other conduct which could reasonably be considered inappropriate in a
+ professional setting
+
+## Our Responsibilities
+
+Project maintainers are responsible for clarifying the standards of acceptable
+behavior and are expected to take appropriate and fair corrective action in
+response to any instances of unacceptable behavior.
+
+Project maintainers have the right and responsibility to remove, edit, or
+reject comments, commits, code, wiki edits, issues, and other contributions
+that are not aligned to this Code of Conduct, or to ban temporarily or
+permanently any contributor for other behaviors that they deem inappropriate,
+threatening, offensive, or harmful.
+
+## Scope
+
+This Code of Conduct applies both within project spaces and in public spaces
+when an individual is representing the project or its community. Examples of
+representing a project or community include using an official project e-mail
+address, posting via an official social media account, or acting as an appointed
+representative at an online or offline event. Representation of a project may be
+further defined and clarified by project maintainers.
+
+## Enforcement
+
+Instances of abusive, harassing, or otherwise unacceptable behavior may be
+reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
+complaints will be reviewed and investigated and will result in a response that
+is deemed necessary and appropriate to the circumstances. The project team is
+obligated to maintain confidentiality with regard to the reporter of an incident.
+Further details of specific enforcement policies may be posted separately.
+
+Project maintainers who do not follow or enforce the Code of Conduct in good
+faith may face temporary or permanent repercussions as determined by other
+members of the project's leadership.
+
+## Attribution
+
+This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
+available at [http://contributor-covenant.org/version/1/4][version]
+
+[homepage]: http://contributor-covenant.org
+[version]: http://contributor-covenant.org/version/1/4/
diff --git a/Contributing.md b/Contributing.md
new file mode 100644
index 0000000..3eb81ee
--- /dev/null
+++ b/Contributing.md
@@ -0,0 +1,83 @@
+## Contributing
+
+I value any contribution to Diff::LCS you can provide: a bug report, a feature
+request, or code contributions. Code contributions to Diff::LCS are especially
+<del>welcome</del>encouraged. Because Diff::LCS is a complex codebase, there
+are a few guidelines:
+
+* Code changes *will not* be accepted without tests. The test suite is
+ written with [RSpec][].
+* Match my coding style.
+* Use a thoughtfully-named topic branch that contains your change. Rebase
+ your commits into logical chunks as necessary.
+* Use [quality commit messages][].
+* Do not change the version number; when your patch is accepted and a release
+ is made, the version will be updated at that point.
+* Submit a GitHub pull request with your changes.
+* New or changed behaviours require appropriate documentation.
+
+### Test Dependencies
+
+Diff::LCS uses Ryan Davis’s [Hoe][] to manage the release process, and it adds
+a number of rake tasks. You will mostly be interested in:
+
+ $ rake
+
+which runs the tests the same way that:
+
+ $ rake spec
+ $ rake travis
+
+will do.
+
+To assist with the installation of the development dependencies, I have
+provided a Gemfile pointing to the (generated) `diff-lcs.gemspec` file. This
+will permit you to do:
+
+ $ bundle install
+
+to get the development dependencies. If you aleady have `hoe` installed, you
+can accomplish the same thing with:
+
+ $ rake newb
+
+This task will install any missing dependencies, run the tests/specs, and
+generate the RDoc.
+
+You can run tests with code coverage analysis by running:
+
+ $ rake spec:coverage
+
+### Workflow
+
+Here's the most direct way to get your work merged into the project:
+
+* Fork the project.
+* Clone down your fork (`git clone git://github.com/<username>/diff-lcs.git`).
+* Create a topic branch to contain your change (`git checkout -b
+ my_awesome_feature`).
+* Hack away, add tests. Not necessarily in that order.
+* Make sure everything still passes by running `rake`.
+* If necessary, rebase your commits into logical chunks, without errors.
+* Push the branch up (`git push origin my_awesome_feature`).
+* Create a pull request against halostatue/diff-lcs and describe what your
+ change does and the why you think it should be merged.
+
+### Contributors
+
+* Austin Ziegler created Diff::LCS.
+
+Thanks to everyone else who has contributed to Diff::LCS:
+
+* Kenichi Kamiya
+* Michael Granger
+* Vít Ondruch
+* Jon Rowe
+* Koichi Ito
+* Josef Strzibny
+* Josh Bronson
+* Mark Friedgan
+
+[Rspec]: http://rspec.info/documentation/
+[quality commit messages]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
+[Hoe]: https://github.com/seattlerb/hoe
diff --git a/Contributing.rdoc b/Contributing.rdoc
deleted file mode 100644
index a0f37de..0000000
--- a/Contributing.rdoc
+++ /dev/null
@@ -1,64 +0,0 @@
-== Contributing
-
-I value any contribution to Diff::LCS you can provide: a bug report, a feature
-request, or code contributions.
-
-Code contributions to Diff::LCS are especially <del>welcome</del>encouraged.
-Because Diff::LCS is a complex codebase, there are a few guidelines:
-
-* Changes <strong>will not</strong> be accepted without tests.
-* The test suite is written with RSpec.‡
-* Match my coding style.
-* Use a thoughtfully-named topic branch that contains your change. Rebase your
- commits into logical chunks as necessary.
-* Use {quality commit messages}[http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html].
-* Do not change the version number; when your patch is accepted and a release
- is made, the version will be updated at that point.
-* Submit a GitHub pull request with your changes.
-* New features require new documentation.
-
-=== Test Dependencies
-
-To run the test suite, you will need to install the development dependencies
-for Diff::LCS. If you have Bundler, you can accomplish this easily:
-
- $ bundle install
-
-Diff::LCS uses Ryan Davis’s excellent {Hoe}[https://github.com/seattlerb/hoe]
-to manage the release process, and it adds a number of rake tasks. You will
-mostly be interested in:
-
- $ rake
-
-which runs the tests the same way that:
-
- $ rake spec
- $ rake test
- $ rake travis
-
-will do.
-
-=== Workflow
-
-Here's the most direct way to get your work merged into the project:
-
-* Fork the project.
-* Clone down your fork (+git clone git://github.com/<username>/diff-lcs.git+).
-* Create a topic branch to contain your change (+git checkout -b my\_awesome\_feature+).
-* Hack away, add tests. Not necessarily in that order.
-* Make sure everything still passes by running `rake`.
-* If necessary, rebase your commits into logical chunks, without errors.
-* Push the branch up (+git push origin my\_awesome\_feature+).
-* Create a pull request against halostatue/diff-lcs and describe what your
- change does and the why you think it should be merged.
-
-=== Contributors
-
-* Austin Ziegler created Diff::LCS.
-
-Thanks to everyone else who has contributed to Diff::LCS:
-
-* Kenichi Kamiya
-* Michael Granger
-* Vít Ondruch
-* Jon Rowe
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.md b/History.md
new file mode 100644
index 0000000..0db6448
--- /dev/null
+++ b/History.md
@@ -0,0 +1,220 @@
+## 1.3 / 2017-01-18
+
+* Bugs fixed:
+
+ * Fixed an error for bin/ldiff --version. Fixes [issue #21][].
+ * Force Diff::LCS::Change and Diff::LCS::ContextChange to only perform
+ equality comparisons against themselves. Provided by Kevin Mook in
+ [pull request #29][].
+ * Fix tab expansion in htmldiff, provided by Mark Friedgan in
+ [pull request #25][].
+ * Silence Ruby 2.4 Fixnum deprecation warnings. Fixxues [issue #38][] and
+ [pull request#36][].
+ * Ensure that test dependencies are loaded properly. Fixes [issue #33][]
+ and [pull request #34][].
+ * Fix [issue #1][] with incorrect intuition of patch direction. Tentative
+ fix, but the previous failure cases pass now.
+
+* Tooling changes:
+
+ * Added SimpleCov and Coveralls support.
+ * Change the homepage (temporarily) to the GitHub repo.
+ * Updated testing and gem infrastructure.
+ * Modernized the specs.
+
+* Cleaned up documentation.
+
+* Added a Code of Conduct.
+
+## 1.2.5 / 2013-11-08
+
+* Bugs fixed:
+
+ * Comparing arrays flattened them too far, especially with
+ Diff::LCS.sdiff. Fixed by Josh Bronson in [pull request #23][].
+
+## 1.2.4 / 2013-04-20
+
+* Bugs fixed:
+
+ * A bug was introduced after 1.1.3 when pruning common sequences at the
+ start of comparison. Paul Kunysch (@pck) fixed this in
+ [pull request #18][]. Thanks!
+
+ * The Rubinius (1.9 mode) bug in [rubinius/rubinius#2268][] has been
+ fixed by the Rubinius team two days after it was filed. Thanks for
+ fixing this so quickly!
+
+* Switching to Raggi's hoe-gemspec2 for gemspec generation.
+
+## 1.2.3 / 2013-04-11
+
+* Bugs Fixed:
+
+ * The new encoding detection for diff output generation (added in 1.2.2)
+ introduced a bug if the left side of the comparison was the empty set.
+ Originally found in [rspec/rspec-expectations#238][] and
+ [rspec/rspec-expectations#239][]. Jon Rowe developed a reasonable
+ heuristic (left side, right side, empty string literal) to avoid this
+ bug.
+ * There is a known issue with Rubinius in 1.9 mode reported in
+ [rubinius/rubinius#2268][] and demonstrated in the Travis CI builds.
+ For all other tested platforms, diff-lcs is considered stable. As soon
+ as a suitably small test-case can be created for the Rubinius team to
+ examine, this will be added to the Rubinius issue around this.
+
+## 1.2.2 / 2013-03-30
+
+* Bugs Fixed:
+
+ * Diff::LCS::Hunk could not properly generate a difference for comparison
+ sets that are not US-ASCII-compatible because of the use of literal
+ regular expressions and strings. Jon Rowe found this in
+ [rspec/rspec-expectations#219][] and provided a first pass
+ implementation in [pull request #15][]. I've reworked it because of
+ test failures in Rubinius when running in Ruby 1.9 mode. This coerces
+ the added values to the encoding of the old dataset (as determined by
+ the first piece of the old dataset).
+ * Adding Travis CI testing for Ruby 2.0.
+
+## 1.2.1 / 2013-02-09
+
+* Bugs Fixed:
+
+ * As seen in [rspec/rspec-expectations#200][], the release of
+ Diff::LCS 1.2 introduced an unnecessary public API change to
+ Diff::LCS::Hunk (see the change at
+ [rspec/rspec-expectations@3d6fc82c][] for details). The new method name
+ (and behaviour) is more correct, but I should not have renamed the
+ function or should have at least provided an alias. This release
+ restores Diff::LCS::Hunk#unshift as an alias to #merge. Note that the
+ old #unshift behaviour was incorrect and will not be restored.
+
+## 1.2.0 / 2013-01-21
+
+* Minor Enhancements:
+
+ * Added special case handling for Diff::LCS.patch so that it handles
+ patches that are empty or contain no changes.
+ * Added two new methods (#patch\_me and #unpatch\_me) to the includable
+ module.
+
+* Bugs Fixed:
+
+ * Fixed [issue #1][] patch direction detection.
+ * Resolved [issue #2][] by handling `string[string.size, 1]` properly (it
+ returns `""` not `nil`).
+ * Michael Granger (ged) fixed an implementation error in
+ Diff::LCS::Change and added specs in [pull request #8][]. Thanks!
+ * Made the code auto-testable.
+ * Vít Ondruch (voxik) provided the latest version of the GPL2 license
+ file in [pull request #10][]. Thanks!
+ * Fixed a documentation issue with the includable versions of #patch! and
+ #unpatch! where they implied that they would replace the original
+ value. Given that Diff::LCS.patch always returns a copy, the
+ documentation was incorrect and has been corrected. To provide the
+ behaviour that was originally documented, two new methods were added to
+ provide this behaviour. Found by scooter-dangle in [issue #12][].
+ Thanks!
+
+* Code Style Changes:
+
+ * Removed trailing spaces.
+ * Calling class methods using `.` instead of `::`.
+ * Vít Ondruch (voxik) removed unnecessary shebangs in [pull request #9][].
+ Thanks!
+ * Kenichi Kamiya (kachick) removed some warnings of an unused variable in
+ lucky [pull request #13][]. Thanks!
+ * Embarked on a major refactoring to make the files a little more
+ manageable and understand the code on a deeper level.
+ * Adding to http://travis-ci.org.
+
+## 1.1.3 / 2011-08-27
+
+* Converted to 'hoe' for release.
+* Converted tests to RSpec 2.
+* Extracted the body of htmldiff into a class available from
+ diff/lcs/htmldiff.
+* Migrated development and issue tracking to GitHub.
+* Bugs fixed:
+
+ * Eliminated the explicit use of RubyGems in both bin/htmldiff and
+ bin/ldiff. Resolves [issue #4][].
+ * Eliminated Ruby warnings. Resolves [issue #3][].
+
+## 1.1.2 / 2004-10-20
+
+* Fixed a problem reported by Mauricio Fernandez in htmldiff.
+
+## 1.1.1 / 2004-09-25
+
+* 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).
+* Modified the non-initialisable callbacks to have a private #new method.
+* Moved ldiff core code to Diff::LCS::Ldiff (diff/lcs/ldiff.rb).
+
+## 1.1.0 / -
+
+* Eliminated the need for Diff::LCS::Event and removed it.
+* Added a contextual diff callback, Diff::LCS::ContextDiffCallback.
+* Implemented patching/unpatching for standard Diff callback output formats
+ with both #diff and #sdiff.
+* Extensive documentation changes.
+
+## 1.0.4
+
+* Fixed a problem with bin/ldiff output, especially for unified format.
+ Newlines that should have been present weren't.
+* Changed the .tar.gz installer to generate Windows batch files if ones do
+ not exist already. Removed the existing batch files as they didn't work.
+
+## 1.0.3
+
+* Fixed a problem with #traverse\_sequences where the first difference from
+ the left sequence might not be appropriately captured.
+
+## 1.0.2
+
+* Fixed an issue with ldiff not working because actions were changed from
+ symbols to strings.
+
+## 1.0.1
+
+* Minor modifications to the gemspec, the README.
+* Renamed the diff program to ldiff (as well as the companion batch file) so
+ as to not collide with the standard diff program.
+* Fixed issues with RubyGems. Requires RubyGems > 0.6.1 or >= 0.6.1 with the
+ latest CVS version.
+
+## 1.0
+
+* Initial release based mostly on Perl's Algorithm::Diff.
+
+[rubinius/rubinius#2268]: https://github.com/rubinius/rubinius/issues/2268
+[rspec/rspec-expectations#239]: https://github.com/rspec/rspec-expectations/issues/239
+[rspec/rspec-expectations#238]: https://github.com/rspec/rspec-expectations/issues/238
+[rspec/rspec-expectations#219]: https://github.com/rspec/rspec-expectations/issues/219
+[rspec/rspec-expectations@3d6fc82c]: https://github.com/rspec/rspec-expectations/commit/3d6fc82c
+[rspec/rspec-expectations#200]: https://github.com/rspec/rspec-expectations/pull/200
+[pull request #36]: https://github.com/halostatue/diff-lcs/pull/36
+[pull request #34]: https://github.com/halostatue/diff-lcs/pull/34
+[pull request #29]: https://github.com/halostatue/diff-lcs/pull/29
+[pull request #25]: https://github.com/halostatue/diff-lcs/pull/25
+[pull request #23]: https://github.com/halostatue/diff-lcs/pull/23
+[pull request #18]: https://github.com/halostatue/diff-lcs/pull/18
+[pull request #15]: https://github.com/halostatue/diff-lcs/pull/15
+[pull request #13]: https://github.com/halostatue/diff-lcs/pull/13
+[pull request #10]: https://github.com/halostatue/diff-lcs/pull/10
+[pull request #9]: https://github.com/halostatue/diff-lcs/pull/9
+[pull request #8]: https://github.com/halostatue/diff-lcs/pull/8
+[issue #38]: https://github.com/halostatue/diff-lcs/issues/38
+[issue #33]: https://github.com/halostatue/diff-lcs/issues/33
+[issue #21]: https://github.com/halostatue/diff-lcs/issues/21
+[issue #12]: https://github.com/halostatue/diff-lcs/issues/12
+[issue #4]: https://github.com/halostatue/diff-lcs/issues/4
+[issue #3]: https://github.com/halostatue/diff-lcs/issues/3
+[issue #2]: https://github.com/halostatue/diff-lcs/issues/2
+[issue #1]: https://github.com/halostatue/diff-lcs/issues/1
diff --git a/History.rdoc b/History.rdoc
deleted file mode 100644
index 30d1d1e..0000000
--- a/History.rdoc
+++ /dev/null
@@ -1,163 +0,0 @@
-== 1.3 / 2014-MM-DD
-
-* Bugs fixed:
- * Fixed an error for bin/ldiff --version.
- * Force Diff::LCS::Change and Diff::LCS::ContextChange to only perform
- equality comparisons against themselves.
-
-* Tooling changes:
- * Added SimpleCov and Coveralls support.
- * Change the homepage (temporarily) to the GitHub repo.
-
-== 1.2.5 / 2013-11-08
-
-* Bugs fixed:
- * Comparing arrays flattened them too far, especially with Diff::LCS.sdiff.
- https://github.com/halostatue/diff-lcs/pull/23
-
-== 1.2.4 / 2013-04-20
-
-* Bugs fixed:
- * A bug was introduced after 1.1.3 when pruning common sequences at the start
- of comparison. Paul Kunysch (@pck) fixed this in pull request 18. Thanks!
- https://github.com/halostatue/diff-lcs/pull/18
-* The Rubinius (1.9 mode) bug in rubinius/rubinius#2268 has been fixed by the
- Rubinius team two days after it was filed. Thanks for fixing this so quickly!
- https://github.com/rubinius/rubinius/issues/2268
-* Switching to Raggi's hoe-gemspec2 for gemspec generation.
-
-== 1.2.3 / 2013-04-11
-
-* Bugs Fixed:
- * The new encoding detection for diff output generation (added in 1.2.2)
- introduced a bug if the left side of the comparison was the empty set.
- Originally found in rspec/rspec-expectations#238 and
- rspec/rspec-expectations#239. Jon Rowe developed a reasonable heuristic
- (left side, right side, empty string literal) to avoid this bug.
- https://github.com/rspec/rspec-expectations/pull/238
- https://github.com/rspec/rspec-expectations/pull/239
-* There is a known issue with Rubinius in 1.9 mode reported in
- rubinius/rubinius#2268 and demonstrated in the Travis CI builds. For all
- other tested platforms, diff-lcs is considered stable. As soon as a suitably
- small test-case can be created for the Rubinius team to examine, this will be
- added to the Rubinius issue around this.
- https://github.com/rubinius/rubinius/issues/2268
- https://travis-ci.org/halostatue/diff-lcs/jobs/6241195
-
-== 1.2.2 / 2013-03-30
-
-* Bugs Fixed:
- * Diff::LCS::Hunk could not properly generate a difference for comparison
- sets that are not US-ASCII-compatible because of the use of literal regular
- expressions and strings. Jon Rowe (JonRowe) found this in
- rspec/rspec-expectations#219 and provided a first pass implementation in
- diff-lcs#15. I've reworked it because of test failures in Rubinius when
- running in Ruby 1.9 mode. This coerces the added values to the encoding of
- the old dataset (as determined by the first piece of the old dataset).
- https://github.com/rspec/rspec-expectations/issues/219
- https://github.com/halostatue/diff-lcs/pull/15
-* Adding Travis CI testing for Ruby 2.0.
-
-== 1.2.1 / 2013-02-09
-
-* Bugs Fixed:
- * As seen in https://github.com/rspec/rspec-expectations/pull/200, the
- release of Diff::LCS 1.2 introduced an unnecessary public API change to
- Diff::LCS::Hunk (see the change at
- https://github.com/rspec/rspec-expectations/commit/3d6fc82c for details).
- The new method name (and behaviour) is more correct, but I should not have
- renamed the function or should have at least provided an alias. This
- release restores Diff::LCS::Hunk#unshift as an alias to
- #merge. Note that the old #unshift behaviour was incorrect and will not be
- restored.
-
-== 1.2.0 / 2013-01-21
-* Minor Enhancements:
- * Added special case handling for Diff::LCS.patch so that it handles patches
- that are empty or contain no changes.
- * Added two new methods (#patch\_me and #unpatch\_me) to the includable
- module.
-* Bugs Fixed:
- * Fixed issue #1 patch direction detection.
- https://github.com/halostatue/diff-lcs/issues/1
- * Resolved issue #2 by handling string[string.size, 1] properly (it returns
- "" not nil). https://github.com/halostatue/diff-lcs/issues/2
- * Michael Granger (ged) fixed an implementation error in Diff::LCS::Change
- and added specs in pull request #8. Thanks!
- https://github.com/halostatue/diff-lcs/issues/8
- * Made the code auto-testable.
- * Vít Ondruch (voxik) provided the latest version of the GPL2 license file in
- pull request #10. Thanks! https://github.com/halostatue/diff-lcs/issues/10
- * Fixed a documentation issue with the includable versions of #patch! and
- #unpatch! where they implied that they would replace the original value.
- Given that Diff::LCS.patch always returns a copy, the documentation was
- incorrect and has been corrected. To provide the behaviour that was
- originally documented, two new methods were added to provide this
- behaviour. Found by scooter-dangle in issue #12. Thanks!
- https://github.com/halostatue/diff-lcs/issues/12
-* Code Style Changes:
- * Removed trailing spaces.
- * Calling class methods using '.' instead of '::'.
- * Vít Ondruch (voxik) removed unnecessary shebangs in pull request #9.
- Thanks! https://github.com/halostatue/diff-lcs/issues/9
- * Kenichi Kamiya (kachick) removed some warnings of an unused variable in
- lucky pull request #13. https://github.com/halostatue/diff-lcs/issues/13
- Thanks!
- * Embarked on a major refactoring to make the files a little more manageable
- and understand the code on a deeper level.
- * Adding to http://travis-ci.org.
-
-== 1.1.3 / 2011-08-27
-* Converted to 'hoe' for release.
-* Converted tests to RSpec 2.
-* Extracted the body of htmldiff into a class available from
- diff/lcs/htmldiff.
-* Migrated development and issue tracking to GitHub.
-* Bugs fixed:
- - Eliminated the explicit use of RubyGems in both bin/htmldiff and bin/ldiff.
- Resolves issue 4 (https://github.com/halostatue/diff-lcs/issues/4).
- - Eliminated Ruby warnings. Resolves issue 3
- (https://github.com/halostatue/diff-lcs/issues/3).
-
-== 1.1.2 / 2004-10-20
-* 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 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).
-* Modified the non-initialisable callbacks to have a private #new method.
-* Moved ldiff core code to Diff::LCS::Ldiff (diff/lcs/ldiff.rb).
-
-== 1.1.0 / -
-* Eliminated the need for Diff::LCS::Event and removed it.
-* Added a contextual diff callback, Diff::LCS::ContextDiffCallback.
-* Implemented patching/unpatching for standard Diff callback output formats
- with both #diff and #sdiff.
-* Extensive documentation changes.
-
-== 1.0.4 / -
-* Fixed a problem with bin/ldiff output, especially for unified format.
- Newlines that should have been present weren't.
-* Changed the .tar.gz installer to generate Windows batch files if ones do not
- exist already. Removed the existing batch files as they didn't work.
-
-== 1.0.3 / -
-* Fixed a problem with #traverse\_sequences where the first difference from the
- left sequence might not be appropriately captured.
-
-== 1.0.2 / -
-* Fixed an issue with ldiff not working because actions were changed from
- symbols to strings.
-
-== 1.0.1 / -
-* Minor modifications to the gemspec, the README.
-* Renamed the diff program to ldiff (as well as the companion batch file) so as
- to not collide with the standard diff program.
-* Fixed issues with RubyGems. Requires RubyGems > 0.6.1 or >= 0.6.1 with the
- latest CVS version.
-
-== 1.0 / -
-* Initial release based mostly on Perl's Algorithm::Diff.
diff --git a/License.rdoc b/License.md
index 63b763d..63b763d 100644
--- a/License.rdoc
+++ b/License.md
diff --git a/Manifest.txt b/Manifest.txt
index d078734..955bec0 100644
--- a/Manifest.txt
+++ b/Manifest.txt
@@ -1,12 +1,8 @@
-.autotest
-.gemtest
-.hoerc
.rspec
-.travis.yml
-Contributing.rdoc
-Gemfile
-History.rdoc
-License.rdoc
+Code-of-Conduct.md
+Contributing.md
+History.md
+License.md
Manifest.txt
README.rdoc
Rakefile
@@ -28,9 +24,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..b971c84 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.history_file = 'History.md'
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..f5e4195 100644
--- a/diff-lcs.gemspec
+++ b/diff-lcs.gemspec
@@ -8,54 +8,52 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") 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-18"
+ 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 = ["Code-of-Conduct.md", "Contributing.md", "History.md", "License.md", "Manifest.txt", "README.rdoc", "docs/COPYING.txt", "docs/artistic.txt"]
+ s.files = [".rspec", "Code-of-Conduct.md", "Contributing.md", "History.md", "License.md", "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..34ddf0f 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,34 +48,6 @@ 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'
end
@@ -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/spec_helper.rb b/spec/spec_helper.rb
index 48bec6f..27298c4 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -296,14 +296,14 @@ module Diff::LCS::SpecHelper
matcher :be_nil_or_match_values do |ii, s1, s2|
match do |ee|
- ee.should satisfy { |vee| vee.nil? || s1[ii] == s2[ee] }
+ expect(ee).to(satisfy { |vee| vee.nil? || s1[ii] == s2[ee] })
end
end
matcher :correctly_map_sequence do |s1|
match do |actual|
actual.each_with_index { |ee, ii|
- ee.should be_nil_or_match_values(ii, s1, @s2)
+ expect(ee).to be_nil_or_match_values(ii, s1, @s2)
}
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