summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAustin Ziegler <austin@zieglers.ca>2019-01-27 00:15:29 -0500
committerAustin Ziegler <austin@zieglers.ca>2019-01-27 11:08:38 -0500
commitf07a49b67dcc1e2bad21d7c8f476af0df9e52151 (patch)
tree532caf445578eacb98ae84da344d2e879c8c3c6d
parent07ed577eba341f0ff0d7eebf4c1c2cc23083cba7 (diff)
downloaddiff-lcs-rubocop.tar.gz
Applied Rubocop rules that I likerubocop
- Other linting configuration also applied. - Soft-deprecating versions older than 2.3.
-rw-r--r--.autotest4
-rw-r--r--.fasterer.yml4
-rw-r--r--.hoerc56
-rw-r--r--.rubocop.yml120
-rw-r--r--.travis.yml28
-rw-r--r--Gemfile10
-rw-r--r--History.md5
-rw-r--r--Rakefile6
-rw-r--r--autotest/discover.rb4
-rwxr-xr-xbin/htmldiff11
-rwxr-xr-xbin/ldiff5
-rw-r--r--diff-lcs.gemspec86
-rw-r--r--lib/diff-lcs.rb2
-rw-r--r--lib/diff/lcs.rb82
-rw-r--r--lib/diff/lcs/array.rb2
-rw-r--r--lib/diff/lcs/block.rb2
-rw-r--r--lib/diff/lcs/callbacks.rb23
-rw-r--r--lib/diff/lcs/change.rb65
-rw-r--r--lib/diff/lcs/htmldiff.rb33
-rw-r--r--lib/diff/lcs/hunk.rb99
-rw-r--r--lib/diff/lcs/internals.rb59
-rw-r--r--lib/diff/lcs/ldiff.rb49
-rw-r--r--lib/diff/lcs/string.rb2
-rw-r--r--spec/change_spec.rb14
-rw-r--r--spec/diff_spec.rb28
-rw-r--r--spec/hunk_spec.rb26
-rw-r--r--spec/issues_spec.rb28
-rw-r--r--spec/lcs_spec.rb20
-rw-r--r--spec/ldiff_spec.rb22
-rw-r--r--spec/patch_spec.rb192
-rw-r--r--spec/sdiff_spec.rb178
-rw-r--r--spec/spec_helper.rb141
-rw-r--r--spec/traverse_balanced_spec.rb346
-rw-r--r--spec/traverse_sequences_spec.rb56
34 files changed, 990 insertions, 818 deletions
diff --git a/.autotest b/.autotest
index 1236395..0857ef3 100644
--- a/.autotest
+++ b/.autotest
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'rubygems'
-# vim: syntax=ruby
+# vim: ft=ruby
diff --git a/.fasterer.yml b/.fasterer.yml
new file mode 100644
index 0000000..821e02d
--- /dev/null
+++ b/.fasterer.yml
@@ -0,0 +1,4 @@
+exclude_paths:
+ - lib/diff/lcs.rb # sort_vs_sort_by on priority_compare
+ - Rakefile # each_with_index vs while
+ - spec/spec_helper.rb
diff --git a/.hoerc b/.hoerc
index 7922c87..1d8fb44 100644
--- a/.hoerc
+++ b/.hoerc
@@ -1,30 +1,11 @@
---
exclude: !ruby/regexp '/
\.(?:
- tmp |
- swp
- )$
+ 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|
@@ -35,11 +16,36 @@ exclude: !ruby/regexp '/
|
[gG]emfile(?:\.lock)?
|
- support\/
+ (?:
+ support |
+ research
+ )\/
|
- research\/
+ \.(?:
+ appveyor |
+ coveralls |
+ fasterer |
+ pullreview |
+ rubocop.* |
+ travis |
+ unused
+ )\.yml$
+ |
+ (?i:TAGS)$
+ |
+ \.(?:
+ DS_Store |
+ autotest |
+ byebug_history |
+ gemtest |
+ gitattributes |
+ gitignore |
+ hoerc |
+ minitest.rb |
+ simplecov-prelude.rb
+ )$
|
\.gemspec$
|
- Vagrantfile
+ ^Vagrantfile$
/x'
diff --git a/.rubocop.yml b/.rubocop.yml
new file mode 100644
index 0000000..de2cbc6
--- /dev/null
+++ b/.rubocop.yml
@@ -0,0 +1,120 @@
+---
+AllCops:
+ DisplayCopNames: true
+ DisplayStyleGuide: true
+ ExtraDetails: true
+ Exclude:
+ - diff-lcs.gemspec
+ - research/**/*
+
+Layout/AlignParameters:
+ EnforcedStyle: with_fixed_indentation
+
+Layout/DotPosition:
+ EnforcedStyle: trailing
+
+Layout/ExtraSpacing:
+ Exclude:
+ - spec/**/*
+
+Layout/MultilineMethodCallIndentation:
+ EnforcedStyle: indented
+
+Metrics/LineLength:
+ Max: 110
+
+Naming/FileName:
+ Exclude:
+ - lib/diff-lcs.rb
+
+Naming/MemoizedInstanceVariableName:
+ Exclude: []
+
+Naming/UncommunicativeMethodParamName:
+ Exclude:
+ - lib/diff/lcs/internals.rb
+ - spec/spec_helper.rb
+
+Naming/VariableNumber:
+ Exclude: []
+
+Performance/Caller:
+ Exclude: []
+
+Security/MarshalLoad:
+ Exclude: []
+
+Security/YAMLLoad:
+ Exclude: []
+
+Style/BlockDelimiters:
+ EnforcedStyle: semantic
+ ProceduralMethods:
+ - trace
+ - assert_raises
+ - spec
+ FunctionalMethods:
+ - let
+ - subject
+ - add_discovery
+ - require_do
+ - it
+ IgnoredMethods:
+ - expect
+
+Style/Documentation:
+ Exclude:
+ - lib/diff/lcs/array.rb
+ - lib/diff/lcs/string.rb
+ - spec/spec_helper.rb
+
+# Until there is a hard drop of Ruby 1.8
+Style/HashSyntax:
+ Enabled: false
+
+Style/PercentLiteralDelimiters:
+ PreferredDelimiters:
+ default: ()
+ '%i': '()'
+ '%I': '()'
+ '%r': '{}'
+ '%w': '()'
+ '%W': '()'
+
+Style/RescueModifier:
+ Enabled: false
+
+Style/RescueStandardError:
+ EnforcedStyle: implicit
+
+Style/SignalException:
+ EnforcedStyle: semantic
+
+Layout/IndentHeredoc: { Enabled: false }
+Metrics/AbcSize: { Enabled: false }
+Metrics/BlockLength: { Enabled: false }
+Metrics/BlockNesting: { Enabled: false }
+Metrics/ClassLength: { Enabled: false }
+Metrics/CyclomaticComplexity: { Enabled: false }
+Metrics/MethodLength: { Enabled: false}
+Metrics/ModuleLength: { Enabled: false}
+Metrics/PerceivedComplexity: { Enabled: false }
+Style/AccessModifierDeclarations: { Enabled: false }
+Style/AndOr: { Enabled: false }
+Style/AsciiComments: { Enabled: false }
+Style/BarePercentLiterals: { Enabled: false }
+Style/ClassAndModuleChildren: { Enabled: false }
+Style/ClassCheck: { Enabled: false }
+Style/CommentedKeyword: { Enabled: false }
+Style/DoubleNegation: { Enabled: false }
+Style/EmptyMethod: { Enabled: false }
+Style/ExpandPathArguments: { Enabled: false }
+Style/FormatString: { Enabled: false }
+Style/FormatStringToken: { Enabled: false }
+Style/MultilineBlockChain: { Enabled: false }
+Style/ParallelAssignment: { Enabled: false }
+Style/SafeNavigation: { Enabled: false }
+Style/SpecialGlobalVars: { Enabled: false }
+Style/SymbolArray: { Enabled: false }
+Style/SymbolProc: { Enabled: false }
+Style/WordArray: { Enabled: false }
diff --git a/.travis.yml b/.travis.yml
index 03e800e..deafbb8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,22 +1,20 @@
---
language: ruby
rvm:
- - 2.5.0
- - 2.4.3
- - 2.3.6
- - 2.2.9
- - 2.1.10
- - 2.0.0
- - 1.9.3
- - 1.8.7
- - ree
+ - 2.6.0
+ - 2.5.3
+ - 2.4.5
+ - 2.3.8
+ - jruby-9.2.5.0
+ - jruby-9.1.17.0
+ - jruby-9.0.5.0
+ - jruby-head
- ruby-head
- - jruby-19mode
matrix:
allow_failures:
+ - rvm: jruby-head
- rvm: ruby-head
- - rvm: 1.8.7
- - rvm: ree
+ fast_finish: true
gemfile:
- Gemfile
before_script:
@@ -24,10 +22,4 @@ before_script:
script: bundle exec rake travis
after_script:
- bundle exec rake travis:after -t
-notifications:
- email:
- recipients:
- - austin@rubyforge.org
- on_success: change
- on_failure: always
sudo: false
diff --git a/Gemfile b/Gemfile
index b5a72e4..ccc6276 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,20 +1,20 @@
-# -*- ruby -*-
+# frozen_string_literal: true
# NOTE: This file is present to keep Travis CI happy. Edits to it will not
# be accepted.
-source "https://rubygems.org/"
+source 'https://rubygems.org/'
if RUBY_VERSION < '1.9'
- gem 'rdoc', '< 4'
gem 'rake', '< 11'
+ gem 'rdoc', '< 4'
elsif RUBY_VERSION >= '2.0'
if RUBY_ENGINE == 'ruby'
- gem 'simplecov', '~> 0.7'
gem 'coveralls', '~> 0.7'
+ gem 'simplecov', '~> 0.7'
end
end
gemspec
-# vim: syntax=ruby
+# vim: ft=ruby
diff --git a/History.md b/History.md
index 0db6448..36e976e 100644
--- a/History.md
+++ b/History.md
@@ -1,3 +1,8 @@
+## 1.NEXT / 2019-MM-DD
+
+* Ruby versions lower than 2.3 are soft-deprecated and will not be run as part
+ of the CI process any longer.
+
## 1.3 / 2017-01-18
* Bugs fixed:
diff --git a/Rakefile b/Rakefile
index ab244ac..24edf0c 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,4 +1,4 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
require 'rubygems'
require 'rspec'
@@ -11,14 +11,14 @@ Hoe.plugin :gemspec2
Hoe.plugin :git
Hoe.plugin :travis
-spec = Hoe.spec 'diff-lcs' do
+_spec = Hoe.spec 'diff-lcs' do
developer('Austin Ziegler', 'halostatue@gmail.com')
require_ruby_version '>= 1.8'
self.history_file = 'History.md'
self.readme_file = 'README.rdoc'
- self.licenses = [ 'MIT', 'Artistic-2.0', 'GPL-2.0+' ]
+ self.licenses = ['MIT', 'Artistic-2.0', 'GPL-2.0+']
extra_dev_deps << ['hoe-doofus', '~> 1.0']
extra_dev_deps << ['hoe-gemspec2', '~> 1.1']
diff --git a/autotest/discover.rb b/autotest/discover.rb
index cd6892c..0ac9c8a 100644
--- a/autotest/discover.rb
+++ b/autotest/discover.rb
@@ -1 +1,3 @@
-Autotest.add_discovery { "rspec2" }
+# frozen_string_literal: true
+
+Autotest.add_discovery { 'rspec2' }
diff --git a/bin/htmldiff b/bin/htmldiff
index 1e4efe7..14114a7 100755
--- a/bin/htmldiff
+++ b/bin/htmldiff
@@ -1,4 +1,5 @@
-#!ruby -w
+#! /usr/bin/env ruby -w
+# frozen_string_literal: true
require 'diff/lcs'
require 'diff/lcs/htmldiff'
@@ -10,8 +11,8 @@ rescue LoadError
end
if ARGV.size < 2 or ARGV.size > 3
- $stderr.puts "usage: #{File.basename($0)} old new [output.html]"
- $stderr.puts " #{File.basename($0)} old new > output.html"
+ warn "usage: #{File.basename($0)} old new [output.html]"
+ warn " #{File.basename($0)} old new > output.html"
exit 127
end
@@ -23,10 +24,12 @@ options = { :title => "diff #{ARGV[0]} #{ARGV[1]}" }
htmldiff = Diff::LCS::HTMLDiff.new(left, right, options)
if ARGV[2]
- File.open(ARGV[2], "w") do |f|
+ File.open(ARGV[2], 'w') do |f|
htmldiff.options[:output] = f
htmldiff.run
end
else
htmldiff.run
end
+
+# vim: ft=ruby
diff --git a/bin/ldiff b/bin/ldiff
index a9b876f..f4734f5 100755
--- a/bin/ldiff
+++ b/bin/ldiff
@@ -1,6 +1,9 @@
-#!ruby -w
+#! /usr/bin/env ruby -w
+# frozen_string_literal: true
require 'diff/lcs'
require 'diff/lcs/ldiff'
exit Diff::LCS::Ldiff.run(ARGV)
+
+# vim: ft=ruby
diff --git a/diff-lcs.gemspec b/diff-lcs.gemspec
index 4c2c516..6ca6cad 100644
--- a/diff-lcs.gemspec
+++ b/diff-lcs.gemspec
@@ -2,58 +2,58 @@
# stub: diff-lcs 1.3 ruby lib
Gem::Specification.new do |s|
- s.name = "diff-lcs"
+ s.name = "diff-lcs".freeze
s.version = "1.3"
- 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 = "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 = ["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", "Artistic-2.0", "GPL-2.0+"]
- s.rdoc_options = ["--main", "README.rdoc"]
- 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"
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
+ s.require_paths = ["lib".freeze]
+ s.authors = ["Austin Ziegler".freeze]
+ s.date = "2019-01-27"
+ 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.".freeze
+ s.email = ["halostatue@gmail.com".freeze]
+ s.executables = ["htmldiff".freeze, "ldiff".freeze]
+ s.extra_rdoc_files = ["Code-of-Conduct.md".freeze, "Contributing.md".freeze, "History.md".freeze, "License.md".freeze, "Manifest.txt".freeze, "README.rdoc".freeze, "docs/COPYING.txt".freeze, "docs/artistic.txt".freeze]
+ s.files = [".rspec".freeze, "Code-of-Conduct.md".freeze, "Contributing.md".freeze, "History.md".freeze, "License.md".freeze, "Manifest.txt".freeze, "README.rdoc".freeze, "Rakefile".freeze, "autotest/discover.rb".freeze, "bin/htmldiff".freeze, "bin/ldiff".freeze, "docs/COPYING.txt".freeze, "docs/artistic.txt".freeze, "lib/diff-lcs.rb".freeze, "lib/diff/lcs.rb".freeze, "lib/diff/lcs/array.rb".freeze, "lib/diff/lcs/block.rb".freeze, "lib/diff/lcs/callbacks.rb".freeze, "lib/diff/lcs/change.rb".freeze, "lib/diff/lcs/htmldiff.rb".freeze, "lib/diff/lcs/hunk.rb".freeze, "lib/diff/lcs/internals.rb".freeze, "lib/diff/lcs/ldiff.rb".freeze, "lib/diff/lcs/string.rb".freeze, "spec/change_spec.rb".freeze, "spec/diff_spec.rb".freeze, "spec/fixtures/ds1.csv".freeze, "spec/fixtures/ds2.csv".freeze, "spec/hunk_spec.rb".freeze, "spec/issues_spec.rb".freeze, "spec/lcs_spec.rb".freeze, "spec/ldiff_spec.rb".freeze, "spec/patch_spec.rb".freeze, "spec/sdiff_spec.rb".freeze, "spec/spec_helper.rb".freeze, "spec/traverse_balanced_spec.rb".freeze, "spec/traverse_sequences_spec.rb".freeze]
+ s.homepage = "https://github.com/halostatue/diff-lcs".freeze
+ s.licenses = ["MIT".freeze, "Artistic-2.0".freeze, "GPL-2.0+".freeze]
+ s.rdoc_options = ["--main".freeze, "README.rdoc".freeze]
+ s.required_ruby_version = Gem::Requirement.new(">= 1.8".freeze)
+ s.rubygems_version = "2.7.7".freeze
+ s.summary = "Diff::LCS computes the difference between two Enumerable sequences using the McIlroy-Hunt longest common subsequence (LCS) algorithm".freeze
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<hoe-doofus>, ["~> 1.0"])
- s.add_development_dependency(%q<hoe-gemspec2>, ["~> 1.1"])
- 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<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"])
+ s.add_development_dependency(%q<hoe-doofus>.freeze, ["~> 1.0"])
+ s.add_development_dependency(%q<hoe-gemspec2>.freeze, ["~> 1.1"])
+ s.add_development_dependency(%q<hoe-git>.freeze, ["~> 1.6"])
+ s.add_development_dependency(%q<hoe-rubygems>.freeze, ["~> 1.0"])
+ s.add_development_dependency(%q<hoe-travis>.freeze, ["~> 1.2"])
+ s.add_development_dependency(%q<rspec>.freeze, ["< 4", ">= 2.0"])
+ s.add_development_dependency(%q<rake>.freeze, ["< 12", ">= 10.0"])
+ s.add_development_dependency(%q<rdoc>.freeze, [">= 0"])
+ s.add_development_dependency(%q<hoe>.freeze, ["~> 3.17"])
else
- s.add_dependency(%q<hoe-doofus>, ["~> 1.0"])
- s.add_dependency(%q<hoe-gemspec2>, ["~> 1.1"])
- 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<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"])
+ s.add_dependency(%q<hoe-doofus>.freeze, ["~> 1.0"])
+ s.add_dependency(%q<hoe-gemspec2>.freeze, ["~> 1.1"])
+ s.add_dependency(%q<hoe-git>.freeze, ["~> 1.6"])
+ s.add_dependency(%q<hoe-rubygems>.freeze, ["~> 1.0"])
+ s.add_dependency(%q<hoe-travis>.freeze, ["~> 1.2"])
+ s.add_dependency(%q<rspec>.freeze, ["< 4", ">= 2.0"])
+ s.add_dependency(%q<rake>.freeze, ["< 12", ">= 10.0"])
+ s.add_dependency(%q<rdoc>.freeze, [">= 0"])
+ s.add_dependency(%q<hoe>.freeze, ["~> 3.17"])
end
else
- s.add_dependency(%q<hoe-doofus>, ["~> 1.0"])
- s.add_dependency(%q<hoe-gemspec2>, ["~> 1.1"])
- 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<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"])
+ s.add_dependency(%q<hoe-doofus>.freeze, ["~> 1.0"])
+ s.add_dependency(%q<hoe-gemspec2>.freeze, ["~> 1.1"])
+ s.add_dependency(%q<hoe-git>.freeze, ["~> 1.6"])
+ s.add_dependency(%q<hoe-rubygems>.freeze, ["~> 1.0"])
+ s.add_dependency(%q<hoe-travis>.freeze, ["~> 1.2"])
+ s.add_dependency(%q<rspec>.freeze, ["< 4", ">= 2.0"])
+ s.add_dependency(%q<rake>.freeze, ["< 12", ">= 10.0"])
+ s.add_dependency(%q<rdoc>.freeze, [">= 0"])
+ s.add_dependency(%q<hoe>.freeze, ["~> 3.17"])
end
end
diff --git a/lib/diff-lcs.rb b/lib/diff-lcs.rb
index 10d6e8a..250392f 100644
--- a/lib/diff-lcs.rb
+++ b/lib/diff-lcs.rb
@@ -1,3 +1,3 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
require 'diff/lcs'
diff --git a/lib/diff/lcs.rb b/lib/diff/lcs.rb
index 34ddf0f..bfafc14 100644
--- a/lib/diff/lcs.rb
+++ b/lib/diff/lcs.rb
@@ -1,6 +1,7 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
+
+module Diff; end unless defined? Diff # rubocop:disable Style/Documentation
-module Diff; end unless defined? Diff
# == How Diff Works (by Mark-Jason Dominus)
#
# I once read an article written by the authors of +diff+; they said that
@@ -55,7 +56,7 @@ end
require 'diff/lcs/callbacks'
require 'diff/lcs/internals'
-module Diff::LCS
+module Diff::LCS # rubocop:disable Style/Documentation
# Returns an Array containing the longest common subsequence(s) between
# +self+ and +other+. See Diff::LCS#LCS.
#
@@ -97,7 +98,7 @@ module Diff::LCS
def patch(patchset)
Diff::LCS.patch(self, patchset)
end
- alias_method :unpatch, :patch
+ alias unpatch patch
# Attempts to patch +self+ with the provided +patchset+. A new sequence
# based on +self+ and the +patchset+ will be created. See Diff::LCS#patch.
@@ -142,16 +143,16 @@ class << Diff::LCS
matches = Diff::LCS::Internals.lcs(seq1, seq2)
ret = []
string = seq1.kind_of? String
- matches.each_with_index do |e, i|
- unless matches[i].nil?
- v = string ? seq1[i, 1] : seq1[i]
- v = block[v] if block
- ret << v
- end
+ matches.each_with_index do |_e, i|
+ next if matches[i].nil?
+
+ v = string ? seq1[i, 1] : seq1[i]
+ v = block[v] if block
+ ret << v
end
ret
end
- alias_method :LCS, :lcs
+ alias LCS lcs
# #diff computes the smallest set of additions and deletions necessary to
# turn the first sequence into the second, and returns a description of
@@ -163,8 +164,7 @@ class << Diff::LCS
# initialise it. If the +callbacks+ object (possibly initialised) responds
# to #finish, it will be called.
def diff(seq1, seq2, callbacks = nil, &block) # :yields diff changes:
- diff_traversal(:diff, seq1, seq2, callbacks || Diff::LCS::DiffCallbacks,
- &block)
+ diff_traversal(:diff, seq1, seq2, callbacks || Diff::LCS::DiffCallbacks, &block)
end
# #sdiff computes all necessary components to show two sequences and their
@@ -182,8 +182,7 @@ class << Diff::LCS
# initialise it. If the +callbacks+ object (possibly initialised) responds
# to #finish, it will be called.
def sdiff(seq1, seq2, callbacks = nil, &block) #:yields diff changes:
- diff_traversal(:sdiff, seq1, seq2, callbacks || Diff::LCS::SDiffCallbacks,
- &block)
+ diff_traversal(:sdiff, seq1, seq2, callbacks || Diff::LCS::SDiffCallbacks, &block)
end
# #traverse_sequences is the most general facility provided by this
@@ -267,7 +266,7 @@ class << Diff::LCS
# <tt>callbacks#discard_b</tt> will be called after the end of the
# sequence is reached, if +a+ has not yet reached the end of +A+ or +b+
# has not yet reached the end of +B+.
- def traverse_sequences(seq1, seq2, callbacks = Diff::LCS::SequenceCallbacks, &block) #:yields change events:
+ def traverse_sequences(seq1, seq2, callbacks = Diff::LCS::SequenceCallbacks) #:yields change events:
callbacks ||= Diff::LCS::SequenceCallbacks
matches = Diff::LCS::Internals.lcs(seq1, seq2)
@@ -293,6 +292,7 @@ class << Diff::LCS
else
loop do
break unless bj < b_line
+
bx = string ? seq2[bj, 1] : seq2[bj]
event = Diff::LCS::ContextChange.new('+', i, ax, bj, bx)
event = yield event if block_given?
@@ -314,7 +314,7 @@ class << Diff::LCS
while (ai < a_size) or (bj < b_size)
# last A?
if ai == a_size and bj < b_size
- if callbacks.respond_to?(:finished_a) and not run_finished_a
+ if callbacks.respond_to?(:finished_a) and !run_finished_a
ax = string ? seq1[-1, 1] : seq1[-1]
bx = string ? seq2[bj, 1] : seq2[bj]
event = Diff::LCS::ContextChange.new('>', (a_size - 1), ax, bj, bx)
@@ -336,7 +336,7 @@ class << Diff::LCS
# last B?
if bj == b_size and ai < a_size
- if callbacks.respond_to?(:finished_b) and not run_finished_b
+ if callbacks.respond_to?(:finished_b) and !run_finished_b
ax = string ? seq1[ai, 1] : seq1[ai]
bx = string ? seq2[-1, 1] : seq2[-1]
event = Diff::LCS::ContextChange.new('<', ai, ax, (b_size - 1), bx)
@@ -365,14 +365,14 @@ class << Diff::LCS
ai += 1
end
- if bj < b_size
- ax = string ? seq1[ai, 1] : seq1[ai]
- bx = string ? seq2[bj, 1] : seq2[bj]
- event = Diff::LCS::ContextChange.new('+', ai, ax, bj, bx)
- event = yield event if block_given?
- callbacks.discard_b(event)
- bj += 1
- end
+ next unless bj < b_size
+
+ ax = string ? seq1[ai, 1] : seq1[ai]
+ bx = string ? seq2[bj, 1] : seq2[bj]
+ event = Diff::LCS::ContextChange.new('+', ai, ax, bj, bx)
+ event = yield event if block_given?
+ callbacks.discard_b(event)
+ bj += 1
end
end
@@ -475,6 +475,7 @@ class << Diff::LCS
end
break if ma >= matches.size # end of matches?
+
mb = matches[ma]
# Change(seq2)
@@ -489,7 +490,6 @@ class << Diff::LCS
event = yield event if block_given?
callbacks.change(event)
ai += 1
- bj += 1
else
event = Diff::LCS::ContextChange.new('-', ai, ax, bj, bx)
event = yield event if block_given?
@@ -499,8 +499,9 @@ class << Diff::LCS
event = Diff::LCS::ContextChange.new('+', ai, ax, bj, bx)
event = yield event if block_given?
callbacks.discard_b(event)
- bj += 1
end
+
+ bj += 1
when [true, false]
event = Diff::LCS::ContextChange.new('-', ai, ax, bj, bx)
event = yield event if block_given?
@@ -535,7 +536,6 @@ class << Diff::LCS
event = yield event if block_given?
callbacks.change(event)
ai += 1
- bj += 1
else
event = Diff::LCS::ContextChange.new('-', ai, ax, bj, bx)
event = yield event if block_given?
@@ -545,8 +545,9 @@ class << Diff::LCS
event = Diff::LCS::ContextChange.new('+', ai, ax, bj, bx)
event = yield event if block_given?
callbacks.discard_b(event)
- bj += 1
end
+
+ bj += 1
when [true, false]
event = Diff::LCS::ContextChange.new('-', ai, ax, bj, bx)
event = yield event if block_given?
@@ -562,9 +563,9 @@ class << Diff::LCS
end
PATCH_MAP = { #:nodoc:
- :patch => { '+' => '+', '-' => '-', '!' => '!', '=' => '=' },
- :unpatch => { '+' => '-', '-' => '+', '!' => '!', '=' => '=' }
- }
+ :patch => { '+' => '+', '-' => '-', '!' => '!', '=' => '=' }.freeze,
+ :unpatch => { '+' => '-', '-' => '+', '!' => '!', '=' => '=' }.freeze
+ }.freeze
# Applies a +patchset+ to the sequence +src+ according to the +direction+
# (<tt>:patch</tt> or <tt>:unpatch</tt>), producing a new sequence.
@@ -610,10 +611,7 @@ class << Diff::LCS
# Normalize the patchset.
has_changes, patchset = Diff::LCS::Internals.analyze_patchset(patchset)
- if not has_changes
- return src.dup if src.respond_to? :dup
- return src
- end
+ return src.respond_to?(:dup) ? src.dup : src unless has_changes
string = src.kind_of?(String)
# Start with a new empty type of the source's class
@@ -657,8 +655,8 @@ class << Diff::LCS
bj += 1
end
- res << el
- bj += 1
+ res << el
+ bj += 1
when '='
# This only appears in sdiff output with the SDiff callback.
# Therefore, we only need to worry about dealing with a single
@@ -674,10 +672,10 @@ class << Diff::LCS
bj += 1
end
- bj += 1
- ai += 1
+ bj += 1
+ ai += 1
- res << el
+ res << el
end
when Diff::LCS::Change
case action
diff --git a/lib/diff/lcs/array.rb b/lib/diff/lcs/array.rb
index 1acd8c9..5c250f6 100644
--- a/lib/diff/lcs/array.rb
+++ b/lib/diff/lcs/array.rb
@@ -1,4 +1,4 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
require 'diff/lcs'
diff --git a/lib/diff/lcs/block.rb b/lib/diff/lcs/block.rb
index 8518727..430702d 100644
--- a/lib/diff/lcs/block.rb
+++ b/lib/diff/lcs/block.rb
@@ -1,4 +1,4 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
# A block is an operation removing, adding, or changing a group of items.
# Basically, this is just a list of changes, where each change adds or
diff --git a/lib/diff/lcs/callbacks.rb b/lib/diff/lcs/callbacks.rb
index 8eec5fc..93c860d 100644
--- a/lib/diff/lcs/callbacks.rb
+++ b/lib/diff/lcs/callbacks.rb
@@ -1,8 +1,8 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
require 'diff/lcs/change'
-module Diff::LCS
+module Diff::LCS # rubocop:disable Style/Documentation
# This callback object implements the default set of callback events,
# which only returns the event itself. Note that #finished_a and
# #finished_b are not implemented -- I haven't yet figured out where they
@@ -17,14 +17,17 @@ module Diff::LCS
def match(event)
event
end
+
# Called when the old value is discarded in favour of the new value.
def discard_a(event)
event
end
+
# Called when the new value is discarded in favour of the old value.
def discard_b(event)
event
end
+
# Called when both the old and new values have changed.
def change(event)
event
@@ -108,12 +111,12 @@ class Diff::LCS::DiffCallbacks
@hunk = []
@diffs = []
- if block_given?
- begin
- yield self
- ensure
- self.finish
- end
+ return unless block_given?
+
+ begin
+ yield self
+ ensure
+ finish
end
end
@@ -123,7 +126,7 @@ class Diff::LCS::DiffCallbacks
finish_hunk
end
- def match(event)
+ def match(_event)
finish_hunk
end
@@ -241,7 +244,7 @@ end
# will compute and display the necessary components to show two sequences
# and their minimized differences side by side, just like the Unix utility
# +sdiff+.
-#
+#
# same same
# before | after
# old < -
diff --git a/lib/diff/lcs/change.rb b/lib/diff/lcs/change.rb
index 9229069..75e1f84 100644
--- a/lib/diff/lcs/change.rb
+++ b/lib/diff/lcs/change.rb
@@ -1,16 +1,16 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
# Represents a simplistic (non-contextual) change. Represents the removal or
# 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
+ IntClass = 1.class # Fixnum is deprecated in Ruby 2.4 # rubocop:disable Naming/ConstantName
# 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
# found with Diff::LCS::diff and Diff::LCS::sdiff.
- VALID_ACTIONS = %W(+ - = ! > <)
+ VALID_ACTIONS = %w(+ - = ! > <).freeze
def self.valid_action?(action)
VALID_ACTIONS.include? action
@@ -27,18 +27,16 @@ class Diff::LCS::Change
def initialize(*args)
@action, @position, @element = *args
- unless Diff::LCS::Change.valid_action?(@action)
- raise "Invalid Change Action '#{@action}'"
- end
- raise "Invalid Position Type" unless @position.kind_of? IntClass
+ fail "Invalid Change Action '#{@action}'" unless Diff::LCS::Change.valid_action?(@action)
+ fail 'Invalid Position Type' unless @position.kind_of? IntClass
end
- def inspect
- to_a.inspect
+ def inspect(*_args)
+ "#<#{self.class}: #{to_a.inspect}>"
end
def to_a
- [ @action, @position, @element ]
+ [@action, @position, @element]
end
def self.from_a(arr)
@@ -49,7 +47,7 @@ class Diff::LCS::Change
when 3
Diff::LCS::Change.new(*(arr[0...3]))
else
- raise "Invalid change array format provided."
+ fail 'Invalid change array format provided.'
end
end
@@ -57,15 +55,15 @@ class Diff::LCS::Change
def ==(other)
(self.class == other.class) and
- (self.action == other.action) and
- (self.position == other.position) and
- (self.element == other.element)
+ (action == other.action) and
+ (position == other.position) and
+ (element == other.element)
end
def <=>(other)
- r = self.action <=> other.action
- r = self.position <=> other.position if r.zero?
- r = self.element <=> other.element if r.zero?
+ r = action <=> other.action
+ r = position <=> other.position if r.zero?
+ r = element <=> other.element if r.zero?
r
end
@@ -114,28 +112,19 @@ class Diff::LCS::ContextChange < Diff::LCS::Change
def initialize(*args)
@action, @old_position, @old_element, @new_position, @new_element = *args
- unless Diff::LCS::Change.valid_action?(@action)
- raise "Invalid Change Action '#{@action}'"
- end
- 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? IntClass
- raise "Invalid (New) Position Type"
- end
+ fail "Invalid Change Action '#{@action}'" unless Diff::LCS::Change.valid_action?(@action)
+ fail 'Invalid (Old) Position Type' unless @old_position.nil? or @old_position.kind_of? IntClass
+ fail 'Invalid (New) Position Type' unless @new_position.nil? or @new_position.kind_of? IntClass
end
def to_a
- [ @action,
- [ @old_position, @old_element ],
- [ @new_position, @new_element ]
+ [
+ @action,
+ [@old_position, @old_element],
+ [@new_position, @new_element]
]
end
- def inspect(*args)
- to_a.inspect
- end
-
def self.from_a(arr)
Diff::LCS::Change.from_a(arr)
end
@@ -163,11 +152,11 @@ class Diff::LCS::ContextChange < Diff::LCS::Change
def ==(other)
(self.class == other.class) and
- (@action == other.action) and
- (@old_position == other.old_position) and
- (@new_position == other.new_position) and
- (@old_element == other.old_element) and
- (@new_element == other.new_element)
+ (@action == other.action) and
+ (@old_position == other.old_position) and
+ (@new_position == other.new_position) and
+ (@old_element == other.old_element) and
+ (@new_element == other.new_element)
end
def <=>(other)
diff --git a/lib/diff/lcs/htmldiff.rb b/lib/diff/lcs/htmldiff.rb
index 8b79994..f12220b 100644
--- a/lib/diff/lcs/htmldiff.rb
+++ b/lib/diff/lcs/htmldiff.rb
@@ -1,14 +1,15 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
require 'cgi'
+# Produce a simple HTML diff view.
class Diff::LCS::HTMLDiff
class << self
attr_accessor :can_expand_tabs #:nodoc:
end
self.can_expand_tabs = true
- class Callbacks
+ class Callbacks #:nodoc:
attr_accessor :output
attr_accessor :match_class
attr_accessor :only_a_class
@@ -18,14 +19,14 @@ class Diff::LCS::HTMLDiff
@output = output
options ||= {}
- @match_class = options[:match_class] || "match"
- @only_a_class = options[:only_a_class] || "only_a"
- @only_b_class = options[:only_b_class] || "only_b"
+ @match_class = options[:match_class] || 'match'
+ @only_a_class = options[:only_a_class] || 'only_a'
+ @only_b_class = options[:only_b_class] || 'only_b'
end
def htmlize(element, css_class)
- element = "&nbsp;" if element.empty?
- %Q|<pre class="#{__send__(css_class)}">#{element}</pre>\n|
+ element = '&nbsp;' if element.empty?
+ %Q(<pre class="#{__send__(css_class)}">#{element}</pre>\n)
end
private :htmlize
@@ -49,8 +50,8 @@ class Diff::LCS::HTMLDiff
:expand_tabs => nil,
:output => nil,
:css => nil,
- :title => nil,
- }
+ :title => nil
+ }.freeze
DEFAULT_CSS = <<-CSS
body { margin: 0; }
@@ -96,13 +97,13 @@ h1 { margin-left: 2em; }
def verify_options
@options[:expand_tabs] ||= 4
- @options[:expand_tabs] = 4 if @options[:expand_tabs] < 0
+ @options[:expand_tabs] = 4 if @options[:expand_tabs].negative?
@options[:output] ||= $stdout
@options[:css] ||= DEFAULT_CSS.dup
- @options[:title] ||= "diff"
+ @options[:title] ||= 'diff'
end
private :verify_options
@@ -111,16 +112,16 @@ h1 { margin-left: 2em; }
def run
verify_options
- if @options[:expand_tabs] > 0 && self.class.can_expand_tabs
+ if @options[:expand_tabs].positive? && self.class.can_expand_tabs
formatter = Text::Format.new
formatter.tabstop = @options[:expand_tabs]
- @left.map! { |line| formatter.expand(line.chomp) }
- @right.map! { |line| formatter.expand(line.chomp) }
+ @left.map! do |line| formatter.expand(line.chomp) end
+ @right.map! do |line| formatter.expand(line.chomp) end
end
- @left.map! { |line| CGI.escapeHTML(line.chomp) }
- @right.map! { |line| CGI.escapeHTML(line.chomp) }
+ @left.map! do |line| CGI.escapeHTML(line.chomp) end
+ @right.map! do |line| CGI.escapeHTML(line.chomp) end
@options[:output] << <<-OUTPUT
<html>
diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb
index 05c3fb6..58a68db 100644
--- a/lib/diff/lcs/hunk.rb
+++ b/lib/diff/lcs/hunk.rb
@@ -1,4 +1,4 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
require 'diff/lcs/block'
@@ -10,9 +10,9 @@ class Diff::LCS::Hunk
# the piece of data.
def initialize(data_old, data_new, piece, flag_context, file_length_difference)
# At first, a hunk will have just one Block in it
- @blocks = [ Diff::LCS::Block.new(piece) ]
+ @blocks = [Diff::LCS::Block.new(piece)]
if String.method_defined?(:encoding)
- @preferred_data_encoding = data_old.fetch(0, data_new.fetch(0,'') ).encoding
+ @preferred_data_encoding = data_old.fetch(0, data_new.fetch(0, '')).encoding
end
@data_old = data_old
@data_new = data_new
@@ -55,19 +55,21 @@ class Diff::LCS::Hunk
# Change the "start" and "end" fields to note that context should be added
# to this hunk.
attr_accessor :flag_context
- undef :flag_context=;
- def flag_context=(context) #:nodoc:
+ undef :flag_context=
+ def flag_context=(context) #:nodoc: # rubocop:disable Lint/DuplicateMethods
return if context.nil? or context.zero?
- add_start = (context > @start_old) ? @start_old : context
+ add_start = context > @start_old ? @start_old : context
@start_old -= add_start
@start_new -= add_start
- if (@end_old + context) > @data_old.size
- add_end = @data_old.size - @end_old
- else
- add_end = context
- end
+ add_end =
+ if (@end_old + context) > @data_old.size
+ @data_old.size - @end_old
+ else
+ context
+ end
+
@end_old += add_end
@end_new += add_end
end
@@ -76,15 +78,13 @@ class Diff::LCS::Hunk
# a truthy value so that if there is no overlap, you can know the merge
# was skipped.
def merge(hunk)
- if overlaps?(hunk)
- @start_old = hunk.start_old
- @start_new = hunk.start_new
- blocks.unshift(*hunk.blocks)
- else
- nil
- end
+ return unless overlaps?(hunk)
+
+ @start_old = hunk.start_old
+ @start_new = hunk.start_new
+ blocks.unshift(*hunk.blocks)
end
- alias_method :unshift, :merge
+ alias unshift merge
# Determines whether there is an overlap between this hunk and the
# provided hunk. This will be true if the difference between the two hunks
@@ -108,15 +108,15 @@ class Diff::LCS::Hunk
when :reverse_ed, :ed_finish
ed_diff(format)
else
- raise "Unknown diff format #{format}."
+ fail "Unknown diff format #{format}."
end
end
# Note that an old diff can't have any context. Therefore, we know that
# there's only one block in the hunk.
def old_diff
- warn "Expecting only one block in an old diff hunk!" if @blocks.size > 1
- op_act = { "+" => 'a', "-" => 'd', "!" => "c" }
+ warn 'Expecting only one block in an old diff hunk!' if @blocks.size > 1
+ op_act = { '+' => 'a', '-' => 'd', '!' => 'c' }
block = @blocks[0]
@@ -126,9 +126,16 @@ class Diff::LCS::Hunk
s = encode("#{context_range(:old)}#{op_act[block.op]}#{context_range(:new)}\n")
# If removing anything, just print out all the remove lines in the hunk
# which is just all the remove lines in the block.
- @data_old[@start_old .. @end_old].each { |e| s << encode("< ") + e + encode("\n") } unless block.remove.empty?
- s << encode("---\n") if block.op == "!"
- @data_new[@start_new .. @end_new].each { |e| s << encode("> ") + e + encode("\n") } unless block.insert.empty?
+ unless block.remove.empty?
+ @data_old[@start_old..@end_old].each { |e| s << encode('< ') + e + encode("\n") }
+ end
+
+ s << encode("---\n") if block.op == '!'
+
+ unless block.insert.empty?
+ @data_new[@start_new..@end_new].each { |e| s << encode('> ') + e + encode("\n") }
+ end
+
s
end
private :old_diff
@@ -148,7 +155,7 @@ class Diff::LCS::Hunk
# file -- don't take removed items into account.
lo, hi, num_added, num_removed = @start_old, @end_old, 0, 0
- outlist = @data_old[lo .. hi].map { |e| e.insert(0, encode(' ')) }
+ outlist = @data_old[lo..hi].map { |e| e.insert(0, encode(' ')) }
@blocks.each do |block|
block.remove.each do |item|
@@ -177,9 +184,9 @@ class Diff::LCS::Hunk
# Print out file 1 part for each block in context diff format if there
# are any blocks that remove items
lo, hi = @start_old, @end_old
- removes = @blocks.select { |e| not e.remove.empty? }
+ removes = @blocks.reject { |e| e.remove.empty? }
if removes
- outlist = @data_old[lo .. hi].map { |e| e.insert(0, encode(' ')) }
+ outlist = @data_old[lo..hi].map { |e| e.insert(0, encode(' ')) }
removes.each do |block|
block.remove.each do |item|
@@ -191,9 +198,9 @@ class Diff::LCS::Hunk
s << encode("\n--- #{r} ----\n")
lo, hi = @start_new, @end_new
- inserts = @blocks.select { |e| not e.insert.empty? }
+ inserts = @blocks.reject { |e| e.insert.empty? }
if inserts
- outlist = @data_new[lo .. hi].collect { |e| e.insert(0, encode(' ')) }
+ outlist = @data_new[lo..hi].collect { |e| e.insert(0, encode(' ')) }
inserts.each do |block|
block.insert.each do |item|
outlist[item.position - lo][0, 1] = encode(block.op) # + or !
@@ -206,17 +213,18 @@ class Diff::LCS::Hunk
private :context_diff
def ed_diff(format)
- op_act = { "+" => 'a', "-" => 'd', "!" => "c" }
- warn "Expecting only one block in an old diff hunk!" if @blocks.size > 1
-
- if format == :reverse_ed
- s = encode("#{op_act[@blocks[0].op]}#{context_range(:old)}\n")
- else
- s = encode("#{context_range(:old, ' ')}#{op_act[@blocks[0].op]}\n")
- end
+ op_act = { '+' => 'a', '-' => 'd', '!' => 'c' }
+ warn 'Expecting only one block in an old diff hunk!' if @blocks.size > 1
+
+ s =
+ if format == :reverse_ed
+ encode("#{op_act[@blocks[0].op]}#{context_range(:old)}\n")
+ else
+ encode("#{context_range(:old, ' ')}#{op_act[@blocks[0].op]}\n")
+ end
unless @blocks[0].insert.empty?
- @data_new[@start_new .. @end_new].each { |e| s << e + encode("\n") }
+ @data_new[@start_new..@end_new].each do |e| s << e + encode("\n") end
s << encode(".\n")
end
s
@@ -225,7 +233,7 @@ class Diff::LCS::Hunk
# Generate a range of item numbers to print. Only print 1 number if the
# range has only one item in it. Otherwise, it's 'start,end'
- def context_range(mode, op = ',')
+ def context_range(mode, op = ',') # rubocop:disable Naming/UncommunicativeMethodParamName
case mode
when :old
s, e = (@start_old + 1), (@end_old + 1)
@@ -233,7 +241,7 @@ class Diff::LCS::Hunk
s, e = (@start_new + 1), (@end_new + 1)
end
- (s < e) ? "#{s}#{op}#{e}" : "#{e}"
+ s < e ? "#{s}#{op}#{e}" : e.to_s
end
private :context_range
@@ -249,8 +257,8 @@ class Diff::LCS::Hunk
end
length = e - s + 1
- first = (length < 2) ? e : s # "strange, but correct"
- (length == 1) ? "#{first}" : "#{first},#{length}"
+ first = length < 2 ? e : s # "strange, but correct"
+ length == 1 ? first.to_s : "#{first},#{length}"
end
private :unified_range
@@ -263,10 +271,11 @@ class Diff::LCS::Hunk
args.map { |arg| arg.encode(string.encoding) }
end
else
- def encode(literal, target_encoding = nil)
+ def encode(literal, _target_encoding = nil)
literal
end
- def encode_as(string, *args)
+
+ def encode_as(_string, *args)
args
end
end
diff --git a/lib/diff/lcs/internals.rb b/lib/diff/lcs/internals.rb
index 17d1d06..c3360d5 100644
--- a/lib/diff/lcs/internals.rb
+++ b/lib/diff/lcs/internals.rb
@@ -1,4 +1,4 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
class << Diff::LCS
def diff_traversal(method, seq1, seq2, callbacks, &block)
@@ -45,8 +45,7 @@ class << Diff::LCS::Internals
vector = []
# Prune off any common elements at the beginning...
- while ((a_start <= a_finish) and (b_start <= b_finish) and
- (a[a_start] == b[b_start]))
+ while (a_start <= a_finish) and (b_start <= b_finish) and (a[a_start] == b[b_start])
vector[a_start] = b_start
a_start += 1
b_start += 1
@@ -54,8 +53,7 @@ class << Diff::LCS::Internals
b_start = a_start
# Now the end...
- while ((a_start <= a_finish) and (b_start <= b_finish) and
- (a[a_finish] == b[b_finish]))
+ while (a_start <= a_finish) and (b_start <= b_finish) and (a[a_finish] == b[b_finish])
vector[a_finish] = b_finish
a_finish -= 1
b_finish -= 1
@@ -68,7 +66,7 @@ class << Diff::LCS::Internals
links = []
string = a.kind_of?(String)
- (a_start .. a_finish).each do |i|
+ (a_start..a_finish).each do |i|
ai = string ? a[i, 1] : a[i]
bm = b_matches[ai]
k = nil
@@ -78,13 +76,13 @@ class << Diff::LCS::Internals
else
k = replace_next_larger(thresh, j, k)
end
- links[k] = [ (k > 0) ? links[k - 1] : nil, i, j ] unless k.nil?
+ links[k] = [k.positive? ? links[k - 1] : nil, i, j] unless k.nil?
end
end
unless thresh.empty?
link = links[thresh.size - 1]
- while not link.nil?
+ until link.nil?
vector[link[1]] = link[2]
link = link[0]
end
@@ -98,7 +96,7 @@ class << Diff::LCS::Internals
# Diff::LCS::Change objects to the object form of same) and detection of
# whether the patchset represents changes to be made.
def analyze_patchset(patchset, depth = 0)
- raise "Patchset too complex" if depth > 1
+ fail 'Patchset too complex' if depth > 1
has_changes = false
@@ -110,7 +108,7 @@ class << Diff::LCS::Internals
# ]
# ]
- patchset = patchset.map do |hunk|
+ patchset = patchset.map { |hunk|
case hunk
when Diff::LCS::Change
has_changes ||= !hunk.unchanged?
@@ -128,11 +126,11 @@ class << Diff::LCS::Internals
hunk.flatten
end
else
- raise ArgumentError, "Cannot normalise a hunk of class #{hunk.class}."
+ fail ArgumentError, "Cannot normalise a hunk of class #{hunk.class}."
end
- end
+ }
- [ has_changes, patchset.flatten(1) ]
+ [has_changes, patchset.flatten(1)]
end
# Examine the patchset and the source to see in which direction the
@@ -173,13 +171,11 @@ class << Diff::LCS::Internals
when '!'
if le == change.old_element
left_match += 1
+ elsif re == change.new_element
+ right_match += 1
else
- if re == change.new_element
- right_match += 1
- else
- left_miss += 1
- right_miss += 1
- end
+ left_miss += 1
+ right_miss += 1
end
end
when Diff::LCS::Change
@@ -209,16 +205,16 @@ class << Diff::LCS::Internals
end
end
- break if (not limit.nil?) && (count > limit)
+ break if !limit.nil? && (count > limit)
end
- no_left = (left_match == 0) && (left_miss > 0)
- no_right = (right_match == 0) && (right_miss > 0)
+ no_left = left_match.zero? && left_miss.positive?
+ no_right = right_match.zero? && right_miss.positive?
- 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
@@ -235,7 +231,8 @@ class << Diff::LCS::Internals
:patch
end
else
- raise "The provided patchset does not appear to apply to the provided enumerable as either source or destination value."
+ fail "The provided patchset does not appear to apply to the provided \
+enumerable as either source or destination value."
end
end
end
@@ -258,14 +255,14 @@ class << Diff::LCS::Internals
# Binary search for the insertion point
last_index ||= enum.size
first_index = 0
- while (first_index <= last_index)
+ while first_index <= last_index
i = (first_index + last_index) >> 1
found = enum[i]
- if value == found
- return nil
- elsif value > found
+ return nil if value == found
+
+ if value > found
first_index = i + 1
else
last_index = i - 1
@@ -275,7 +272,7 @@ class << Diff::LCS::Internals
# The insertion point is in first_index; overwrite the next larger
# value.
enum[first_index] = value
- return first_index
+ first_index
end
private :replace_next_larger
diff --git a/lib/diff/lcs/ldiff.rb b/lib/diff/lcs/ldiff.rb
index c789f46..d385f72 100644
--- a/lib/diff/lcs/ldiff.rb
+++ b/lib/diff/lcs/ldiff.rb
@@ -1,4 +1,4 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
require 'optparse'
require 'ostruct'
@@ -7,7 +7,7 @@ require 'diff/lcs/hunk'
module Diff::LCS::Ldiff #:nodoc:
BANNER = <<-COPYRIGHT
ldiff #{Diff::LCS::VERSION}
- Copyright 2004-2014 Austin Ziegler
+ Copyright 2004-2019 Austin Ziegler
Part of Diff::LCS.
https://github.com/halostatue/diff-lcs
@@ -15,7 +15,7 @@ ldiff #{Diff::LCS::VERSION}
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
@@ -23,33 +23,42 @@ class << Diff::LCS::Ldiff
attr_reader :file_old, :file_new #:nodoc:
attr_reader :data_old, :data_new #:nodoc:
- def run(args, input = $stdin, output = $stdout, error = $stderr) #:nodoc:
+ def run(args, _input = $stdin, output = $stdout, error = $stderr) #:nodoc:
@binary = nil
args.options do |o|
o.banner = "Usage: #{File.basename($0)} [options] oldfile newfile"
- o.separator ""
- o.on('-c', '-C', '--context [LINES]', Numeric, 'Displays a context diff with LINES lines', 'of context. Default 3 lines.') do |ctx|
+ o.separator ''
+ o.on(
+ '-c', '-C', '--context [LINES]', Numeric,
+ 'Displays a context diff with LINES lines', 'of context. Default 3 lines.'
+ ) do |ctx|
@format = :context
@lines = ctx || 3
end
- o.on('-u', '-U', '--unified [LINES]', Numeric, 'Displays a unified diff with LINES lines', 'of context. Default 3 lines.') do |ctx|
+ o.on(
+ '-u', '-U', '--unified [LINES]', Numeric,
+ 'Displays a unified diff with LINES lines', 'of context. Default 3 lines.'
+ ) do |ctx|
@format = :unified
@lines = ctx || 3
end
- o.on('-e', 'Creates an \'ed\' script to change', 'oldfile to newfile.') do |ctx|
+ o.on('-e', 'Creates an \'ed\' script to change', 'oldfile to newfile.') do |_ctx|
@format = :ed
end
- o.on('-f', 'Creates an \'ed\' script to change', 'oldfile to newfile in reverse order.') do |ctx|
+ o.on('-f', 'Creates an \'ed\' script to change', 'oldfile to newfile in reverse order.') do |_ctx|
@format = :reverse_ed
end
- o.on('-a', '--text', 'Treat the files as text and compare them', 'line-by-line, even if they do not seem', 'to be text.') do |txt|
+ o.on(
+ '-a', '--text',
+ 'Treat the files as text and compare them', 'line-by-line, even if they do not seem', 'to be text.'
+ ) do |_txt|
@binary = false
end
- o.on('--binary', 'Treats the files as binary.') do |bin|
+ o.on('--binary', 'Treats the files as binary.') do |_bin|
@binary = true
end
- o.on('-q', '--brief', 'Report only whether or not the files', 'differ, not the details.') do |ctx|
+ o.on('-q', '--brief', 'Report only whether or not the files', 'differ, not the details.') do |_ctx|
@format = :report
end
o.on_tail('--help', 'Shows this text.') do
@@ -60,7 +69,7 @@ class << Diff::LCS::Ldiff
error << Diff::LCS::Ldiff::BANNER
return 0
end
- o.on_tail ""
+ o.on_tail ''
o.on_tail 'By default, runs produces an "old-style" diff, with output like UNIX diff.'
o.parse!
end
@@ -97,8 +106,7 @@ class << Diff::LCS::Ldiff
if @binary.nil?
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
+ @binary = !old_txt or !new_txt
end
unless @binary
@@ -143,12 +151,11 @@ class << Diff::LCS::Ldiff
diffs.each do |piece|
begin
- hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, @lines,
- file_length_difference)
+ hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, @lines, file_length_difference)
file_length_difference = hunk.file_length_difference
next unless oldhunk
- next if (@lines > 0) and hunk.merge(oldhunk)
+ next if @lines.postive? and hunk.merge(oldhunk)
output << oldhunk.diff(@format) << "\n"
ensure
@@ -158,10 +165,8 @@ class << Diff::LCS::Ldiff
output << oldhunk.diff(@format) << "\n"
- if @format == :ed
- output.reverse_each { |e| real_output << e.diff(:ed_finish) }
- end
+ output.reverse_each { |e| real_output << e.diff(:ed_finish) } if @format == :ed
- return 1
+ 1
end
end
diff --git a/lib/diff/lcs/string.rb b/lib/diff/lcs/string.rb
index 8545bcf..9ab32e9 100644
--- a/lib/diff/lcs/string.rb
+++ b/lib/diff/lcs/string.rb
@@ -1,4 +1,4 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
class String
include Diff::LCS
diff --git a/spec/change_spec.rb b/spec/change_spec.rb
index dfe385f..b5ad0cb 100644
--- a/spec/change_spec.rb
+++ b/spec/change_spec.rb
@@ -1,9 +1,9 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
require 'spec_helper'
describe Diff::LCS::Change do
- describe "an add" do
+ describe 'an add' do
subject { described_class.new('+', 0, 'element') }
it { should_not be_deleting }
it { should be_adding }
@@ -13,7 +13,7 @@ describe Diff::LCS::Change do
it { should_not be_finished_b }
end
- describe "a delete" do
+ describe 'a delete' do
subject { described_class.new('-', 0, 'element') }
it { should be_deleting }
it { should_not be_adding }
@@ -23,7 +23,7 @@ describe Diff::LCS::Change do
it { should_not be_finished_b }
end
- describe "an unchanged" do
+ describe 'an unchanged' do
subject { described_class.new('=', 0, 'element') }
it { should_not be_deleting }
it { should_not be_adding }
@@ -33,7 +33,7 @@ describe Diff::LCS::Change do
it { should_not be_finished_b }
end
- describe "a changed" do
+ describe 'a changed' do
subject { described_class.new('!', 0, 'element') }
it { should_not be_deleting }
it { should_not be_adding }
@@ -43,7 +43,7 @@ describe Diff::LCS::Change do
it { should_not be_finished_b }
end
- describe "a finished_a" do
+ describe 'a finished_a' do
subject { described_class.new('>', 0, 'element') }
it { should_not be_deleting }
it { should_not be_adding }
@@ -53,7 +53,7 @@ describe Diff::LCS::Change do
it { should_not be_finished_b }
end
- describe "a finished_b" do
+ describe 'a finished_b' do
subject { described_class.new('<', 0, 'element') }
it { should_not be_deleting }
it { should_not be_adding }
diff --git a/spec/diff_spec.rb b/spec/diff_spec.rb
index 020ff44..e7d632a 100644
--- a/spec/diff_spec.rb
+++ b/spec/diff_spec.rb
@@ -1,33 +1,37 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
require 'spec_helper'
-describe Diff::LCS, ".diff" do
+describe Diff::LCS, '.diff' do
include Diff::LCS::SpecHelper::Matchers
- it "correctly diffs seq1 to seq2" do
+ 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
+ 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
+ it 'correctly diffs against an empty sequence' do
diff = Diff::LCS.diff(word_sequence, [])
correct_diff = [
- [ [ '-', 0, 'abcd' ],
- [ '-', 1, 'efgh' ],
- [ '-', 2, 'ijkl' ],
- [ '-', 3, 'mnopqrstuvwxyz' ] ]
+ [
+ ['-', 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] = '+' } }
+ correct_diff.each do |hunk|
+ hunk.each do |change| change[0] = '+' end
+ end
expect(change_diff(correct_diff)).to eq(diff)
end
@@ -37,11 +41,11 @@ describe Diff::LCS, ".diff" do
expect(Diff::LCS.patch(left, Diff::LCS.diff(left, right))).to eq(right)
end
- it "returns an empty diff with (hello, hello)" do
+ it 'returns an empty diff with (hello, hello)' do
expect(Diff::LCS.diff(hello, hello)).to be_empty
end
- it "returns an empty diff with (hello_ary, hello_ary)" do
+ 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/hunk_spec.rb b/spec/hunk_spec.rb
index 0711e0d..5a45072 100644
--- a/spec/hunk_spec.rb
+++ b/spec/hunk_spec.rb
@@ -1,4 +1,4 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
require 'spec_helper'
@@ -6,52 +6,52 @@ 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(: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 'produces a unified diff from the two pieces' do
- expected = (<<-EOD.gsub(/^\s+/,'').encode('UTF-16LE').chomp)
+ expected = <<-EXPECTED.gsub(/^\s+/, '').encode('UTF-16LE').chomp
@@ -1,2 +1,2 @@
-Tu avec carté {count} itém has
+Tu avec carte {count} item has
- EOD
+ EXPECTED
expect(hunk.diff(:unified)).to eq(expected)
end
it 'produces a context diff from the two pieces' do
- expected = (<<-EOD.gsub(/^\s+/,'').encode('UTF-16LE').chomp)
+ expected = <<-EXPECTED.gsub(/^\s+/, '').encode('UTF-16LE').chomp
***************
*** 1,2 ****
!Tu avec carté {count} itém has
--- 1,2 ----
!Tu avec carte {count} item has
- EOD
+ EXPECTED
expect(hunk.diff(:context)).to eq(expected)
end
it 'produces an old diff from the two pieces' do
- expected = (<<-EOD.gsub(/^ +/,'').encode('UTF-16LE').chomp)
+ expected = <<-EXPECTED.gsub(/^ +/, '').encode('UTF-16LE').chomp
1,2c1,2
< Tu avec carté {count} itém has
---
> Tu avec carte {count} item has
- EOD
+ EXPECTED
expect(hunk.diff(:old)).to eq(expected)
end
it 'produces a reverse ed diff from the two pieces' do
- expected = (<<-EOD.gsub(/^ +/,'').encode('UTF-16LE').chomp)
+ expected = <<-EXPECTED.gsub(/^ +/, '').encode('UTF-16LE').chomp
c1,2
Tu avec carte {count} item has
.
- EOD
+ EXPECTED
expect(hunk.diff(:reverse_ed)).to eq(expected)
end
@@ -60,10 +60,10 @@ if String.method_defined?(:encoding)
let(:old_data) { [] }
it 'produces a unified diff' do
- expected = (<<-EOD.gsub(/^\s+/,'').encode('UTF-16LE').chomp)
+ expected = <<-EXPECTED.gsub(/^\s+/, '').encode('UTF-16LE').chomp
@@ -1 +1,2 @@
+Tu avec carte {count} item has
- EOD
+ EXPECTED
expect(hunk.diff(:unified)).to eq(expected)
end
diff --git a/spec/issues_spec.rb b/spec/issues_spec.rb
index 7638249..79ddd0b 100644
--- a/spec/issues_spec.rb
+++ b/spec/issues_spec.rb
@@ -1,8 +1,8 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
require 'spec_helper'
-describe "Diff::LCS Issues" do
+describe 'Diff::LCS Issues' do
include Diff::LCS::SpecHelper::Matchers
describe 'issue #1' do
@@ -26,23 +26,31 @@ describe "Diff::LCS Issues" do
describe 'string' do
it_has_behavior 'handles simple diffs', 'aX', 'bXaX', [
- [ [ '+', 0, 'b' ],
- [ '+', 1, 'X' ] ],
+ [
+ ['+', 0, 'b'],
+ ['+', 1, 'X']
+ ]
]
it_has_behavior 'handles simple diffs', 'bXaX', 'aX', [
- [ [ '-', 0, 'b' ],
- [ '-', 1, 'X' ] ],
+ [
+ ['-', 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' ] ],
+ [
+ ['+', 0, 'b'],
+ ['+', 1, 'X']
+ ]
]
it_has_behavior 'handles simple diffs', %w(b X a X), %w(a X), [
- [ [ '-', 0, 'b' ],
- [ '-', 1, 'X' ] ],
+ [
+ ['-', 0, 'b'],
+ ['-', 1, 'X']
+ ]
]
end
end
diff --git a/spec/lcs_spec.rb b/spec/lcs_spec.rb
index 28533e3..94428fd 100644
--- a/spec/lcs_spec.rb
+++ b/spec/lcs_spec.rb
@@ -1,11 +1,11 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
require 'spec_helper'
-describe Diff::LCS::Internals, ".lcs" do
+describe Diff::LCS::Internals, '.lcs' do
include Diff::LCS::SpecHelper::Matchers
- it "returns 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.
@@ -20,37 +20,37 @@ describe Diff::LCS::Internals, ".lcs" do
expect(x_seq2).to eq(correct_lcs)
end
- it "returns all indexes with (hello, hello)" do
+ it 'returns all indexes with (hello, hello)' do
expect(Diff::LCS::Internals.lcs(hello, hello)).to \
eq((0...hello.size).to_a)
end
- it "returns all indexes with (hello_ary, hello_ary)" do
+ 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 "returns 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)
expect(res).to eq(correct_lcs)
expect(res.compact).to eq(res)
end
- it "is transitive" do
+ it 'is transitive' do
res = Diff::LCS.LCS(seq2, seq1)
expect(res).to eq(correct_lcs)
expect(res.compact).to eq(res)
end
- it "returns %W(h e l l o) with (hello, hello)" do
+ it 'returns %W(h e l l o) with (hello, hello)' do
expect(Diff::LCS.LCS(hello, hello)).to eq(hello.split(//))
end
- it "returns hello_ary with (hello_ary, hello_ary)" do
+ 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
index ad1377f..113c0dd 100644
--- a/spec/ldiff_spec.rb
+++ b/spec/ldiff_spec.rb
@@ -1,8 +1,8 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
require 'spec_helper'
-describe "Diff::LCS.diff" do
+describe 'Diff::LCS.diff' do
include Diff::LCS::SpecHelper::Matchers
it 'correctly diffs seq1 to seq2' do
@@ -18,16 +18,20 @@ describe "Diff::LCS.diff" do
it 'correctly diffs against an empty sequence' do
diff = Diff::LCS.diff(word_sequence, [])
correct_diff = [
- [ [ '-', 0, 'abcd' ],
- [ '-', 1, 'efgh' ],
- [ '-', 2, 'ijkl' ],
- [ '-', 3, 'mnopqrstuvwxyz' ] ]
+ [
+ ['-', 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] = '+' } }
+ correct_diff.each do |hunk|
+ hunk.each do |change| change[0] = '+' end
+ end
expect(change_diff(correct_diff)).to eq(diff)
end
@@ -37,11 +41,11 @@ describe "Diff::LCS.diff" do
expect(Diff::LCS.patch(left, Diff::LCS.diff(left, right))).to eq(right)
end
- it "returns an empty diff with (hello, hello)" do
+ 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
+ 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 9f1a4f1..11b0981 100644
--- a/spec/patch_spec.rb
+++ b/spec/patch_spec.rb
@@ -1,54 +1,54 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
require 'spec_helper'
-describe "Diff::LCS.patch" do
+describe 'Diff::LCS.patch' do
include Diff::LCS::SpecHelper::Matchers
- shared_examples "patch sequences correctly" do
- it "correctly patches left-to-right (patch autodiscovery)" do
+ shared_examples 'patch sequences correctly' do
+ it 'correctly patches left-to-right (patch autodiscovery)' do
expect(Diff::LCS.patch(s1, patch_set)).to eq(s2)
end
- it "correctly patches left-to-right (explicit patch)" do
+ 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 "correctly patches right-to-left (unpatch autodiscovery)" do
+ it 'correctly patches right-to-left (unpatch autodiscovery)' do
expect(Diff::LCS.patch(s2, patch_set)).to eq(s1)
end
- it "correctly patches right-to-left (explicit unpatch)" do
+ 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
+ describe 'using a Diff::LCS.diff patchset' do
+ describe 'an empty patchset returns the source' do
+ it 'works on a string (hello)' do
diff = Diff::LCS.diff(hello, hello)
- expect(Diff::LCS::patch(hello, diff)).to eq(hello)
+ expect(Diff::LCS.patch(hello, diff)).to eq(hello)
end
- it "works on an array %W(h e l l o)" do
+ it 'works on an array %W(h e l l o)' do
diff = Diff::LCS.diff(hello_ary, hello_ary)
- expect(Diff::LCS::patch(hello_ary, diff)).to eq(hello_ary)
+ expect(Diff::LCS.patch(hello_ary, diff)).to eq(hello_ary)
end
end
- describe "with default diff callbacks (DiffCallbacks)" do
- describe "forward (s1 -> s2)" do
- it_has_behavior "patch sequences correctly" do
+ describe 'with default diff callbacks (DiffCallbacks)' do
+ describe 'forward (s1 -> s2)' do
+ it_has_behavior 'patch sequences correctly' do
let(:s1) { seq1 }
let(:s2) { seq2 }
let(:patch_set) { Diff::LCS.diff(seq1, seq2) }
end
end
- describe "reverse (s2 -> s1)" do
- it_has_behavior "patch sequences correctly" do
+ describe 'reverse (s2 -> s1)' do
+ it_has_behavior 'patch sequences correctly' do
let(:s1) { seq2 }
let(:s2) { seq1 }
let(:patch_set) { Diff::LCS.diff(seq2, seq1) }
@@ -56,9 +56,9 @@ describe "Diff::LCS.patch" do
end
end
- describe "with context diff callbacks (ContextDiffCallbacks)" do
- describe "forward (s1 -> s2)" do
- it_has_behavior "patch sequences correctly" do
+ describe 'with context diff callbacks (ContextDiffCallbacks)' do
+ describe 'forward (s1 -> s2)' do
+ it_has_behavior 'patch sequences correctly' do
let(:s1) { seq1 }
let(:s2) { seq2 }
let(:patch_set) {
@@ -67,8 +67,8 @@ describe "Diff::LCS.patch" do
end
end
- describe "reverse (s2 -> s1)" do
- it_has_behavior "patch sequences correctly" do
+ describe 'reverse (s2 -> s1)' do
+ it_has_behavior 'patch sequences correctly' do
let(:s1) { seq2 }
let(:s2) { seq1 }
let(:patch_set) {
@@ -78,9 +78,9 @@ describe "Diff::LCS.patch" do
end
end
- describe "with sdiff callbacks (SDiffCallbacks)" do
- describe "forward (s1 -> s2)" do
- it_has_behavior "patch sequences correctly" do
+ describe 'with sdiff callbacks (SDiffCallbacks)' do
+ describe 'forward (s1 -> s2)' do
+ it_has_behavior 'patch sequences correctly' do
let(:s1) { seq1 }
let(:s2) { seq2 }
let(:patch_set) {
@@ -89,8 +89,8 @@ describe "Diff::LCS.patch" do
end
end
- describe "reverse (s2 -> s1)" do
- it_has_behavior "patch sequences correctly" do
+ describe 'reverse (s2 -> s1)' do
+ it_has_behavior 'patch sequences correctly' do
let(:s1) { seq2 }
let(:s2) { seq1 }
let(:patch_set) {
@@ -101,20 +101,20 @@ describe "Diff::LCS.patch" do
end
end
- describe "using a Diff::LCS.sdiff patchset" do
- describe "an empty patchset returns the source" do
- it "works on a string (hello)" do
- expect(Diff::LCS::patch(hello, Diff::LCS.sdiff(hello, hello))).to eq(hello)
+ describe 'using a Diff::LCS.sdiff patchset' do
+ describe 'an empty patchset returns the source' do
+ it 'works on a string (hello)' do
+ 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
- expect(Diff::LCS::patch(hello_ary, Diff::LCS.sdiff(hello_ary, hello_ary))).to eq(hello_ary)
+ it 'works on an array %W(h e l l o)' do
+ expect(Diff::LCS.patch(hello_ary, Diff::LCS.sdiff(hello_ary, hello_ary))).to eq(hello_ary)
end
end
- describe "with default diff callbacks (DiffCallbacks)" do
- describe "forward (s1 -> s2)" do
- it_has_behavior "patch sequences correctly" do
+ describe 'with default diff callbacks (DiffCallbacks)' do
+ describe 'forward (s1 -> s2)' do
+ it_has_behavior 'patch sequences correctly' do
let(:s1) { seq1 }
let(:s2) { seq2 }
let(:patch_set) {
@@ -123,8 +123,8 @@ describe "Diff::LCS.patch" do
end
end
- describe "reverse (s2 -> s1)" do
- it_has_behavior "patch sequences correctly" do
+ describe 'reverse (s2 -> s1)' do
+ it_has_behavior 'patch sequences correctly' do
let(:s1) { seq2 }
let(:s2) { seq1 }
let(:patch_set) {
@@ -134,9 +134,9 @@ describe "Diff::LCS.patch" do
end
end
- describe "with context diff callbacks (DiffCallbacks)" do
- describe "forward (s1 -> s2)" do
- it_has_behavior "patch sequences correctly" do
+ describe 'with context diff callbacks (DiffCallbacks)' do
+ describe 'forward (s1 -> s2)' do
+ it_has_behavior 'patch sequences correctly' do
let(:s1) { seq1 }
let(:s2) { seq2 }
let(:patch_set) {
@@ -145,8 +145,8 @@ describe "Diff::LCS.patch" do
end
end
- describe "reverse (s2 -> s1)" do
- it_has_behavior "patch sequences correctly" do
+ describe 'reverse (s2 -> s1)' do
+ it_has_behavior 'patch sequences correctly' do
let(:s1) { seq2 }
let(:s2) { seq1 }
let(:patch_set) {
@@ -156,17 +156,17 @@ describe "Diff::LCS.patch" do
end
end
- describe "with sdiff callbacks (SDiffCallbacks)" do
- describe "forward (s1 -> s2)" do
- it_has_behavior "patch sequences correctly" do
+ describe 'with sdiff callbacks (SDiffCallbacks)' do
+ describe 'forward (s1 -> s2)' do
+ it_has_behavior 'patch sequences correctly' do
let(:s1) { seq1 }
let(:s2) { seq2 }
let(:patch_set) { Diff::LCS.sdiff(seq1, seq2) }
end
end
- describe "reverse (s2 -> s1)" do
- it_has_behavior "patch sequences correctly" do
+ describe 'reverse (s2 -> s1)' do
+ it_has_behavior 'patch sequences correctly' do
let(:s1) { seq2 }
let(:s2) { seq1 }
let(:patch_set) { Diff::LCS.sdiff(seq2, seq1) }
@@ -179,43 +179,43 @@ describe "Diff::LCS.patch" do
# to s2 patches"), this cannot use the "patch sequences correctly" shared
# 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
+ describe 'fix bug 891: patchsets do not contain the last equal part' do
before :each do
- @s1 = %w(a b c d e f g h i j k)
+ @s1 = %w(a b c d e f g h i j k) # rubocop:disable Layout/SpaceInsideArrayPercentLiteral
@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
+ describe 'using Diff::LCS.diff with default diff callbacks' do
before :each do
@patch_set_s1_s2 = Diff::LCS.diff(@s1, @s2)
@patch_set_s2_s1 = Diff::LCS.diff(@s2, @s1)
end
- it "autodiscovers s1 to s2 patches" do
+ it 'autodiscovers s1 to s2 patches' do
expect do
expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2)
end.to_not raise_error
end
- it "autodiscovers s2 to s1 patches" do
+ it 'autodiscovers s2 to s1 patches' do
expect do
expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2)
end.to_not raise_error
end
- it "autodiscovers s2 to s1 the left-to-right patches" do
+ 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 "correctly patches left-to-right (explicit patch)" do
+ 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 "correctly patches right-to-left (explicit unpatch)" do
+ 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)
@@ -223,39 +223,37 @@ describe "Diff::LCS.patch" do
end
end
- describe "using Diff::LCS.diff with context diff callbacks" do
+ 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)
+ @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 "autodiscovers s1 to s2 patches" do
+ it 'autodiscovers s1 to s2 patches' do
expect do
expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2)
end.to_not raise_error
end
- it "autodiscovers s2 to s1 patches" do
+ it 'autodiscovers s2 to s1 patches' do
expect do
expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2)
end.to_not raise_error
end
- it "autodiscovers s2 to s1 the left-to-right patches" do
+ 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 "correctly patches left-to-right (explicit patch)" do
+ 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 "correctly patches right-to-left (explicit unpatch)" do
+ 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)
@@ -263,39 +261,37 @@ describe "Diff::LCS.patch" do
end
end
- describe "using Diff::LCS.diff with sdiff callbacks" do
+ 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 "autodiscovers s1 to s2 patches" do
+ it 'autodiscovers s1 to s2 patches' do
expect do
expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2)
end.to_not raise_error
end
- it "autodiscovers s2 to s1 patches" do
+ it 'autodiscovers s2 to s1 patches' do
expect do
expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2)
end.to_not raise_error
end
- it "autodiscovers s2 to s1 the left-to-right patches" do
+ 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 "correctly patches left-to-right (explicit patch)" do
+ 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 "correctly patches right-to-left (explicit unpatch)" do
+ 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)
@@ -303,37 +299,37 @@ describe "Diff::LCS.patch" do
end
end
- describe "using Diff::LCS.sdiff with default sdiff callbacks" do
+ describe 'using Diff::LCS.sdiff with default sdiff callbacks' do
before(:each) do
@patch_set_s1_s2 = Diff::LCS.sdiff(@s1, @s2)
@patch_set_s2_s1 = Diff::LCS.sdiff(@s2, @s1)
end
- it "autodiscovers s1 to s2 patches" do
+ it 'autodiscovers s1 to s2 patches' do
expect do
expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2)
end.to_not raise_error
end
- it "autodiscovers s2 to s1 patches" do
+ it 'autodiscovers s2 to s1 patches' do
expect do
expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2)
end.to_not raise_error
end
- it "autodiscovers s2 to s1 the left-to-right patches" do
+ 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 "correctly patches left-to-right (explicit patch)" do
+ 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 "correctly patches right-to-left (explicit unpatch)" do
+ 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)
@@ -341,39 +337,37 @@ describe "Diff::LCS.patch" do
end
end
- describe "using Diff::LCS.sdiff with context diff callbacks" do
+ 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 "autodiscovers s1 to s2 patches" do
+ it 'autodiscovers s1 to s2 patches' do
expect do
expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2)
end.to_not raise_error
end
- it "autodiscovers s2 to s1 patches" do
+ it 'autodiscovers s2 to s1 patches' do
expect do
expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2)
end.to_not raise_error
end
- it "autodiscovers s2 to s1 the left-to-right patches" do
+ 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 "correctly patches left-to-right (explicit patch)" do
+ 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 "correctly patches right-to-left (explicit unpatch)" do
+ 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)
@@ -381,37 +375,37 @@ describe "Diff::LCS.patch" do
end
end
- describe "using Diff::LCS.sdiff with default diff callbacks" do
+ describe 'using Diff::LCS.sdiff with default diff callbacks' do
before(:each) do
@patch_set_s1_s2 = Diff::LCS.sdiff(@s1, @s2, Diff::LCS::DiffCallbacks)
@patch_set_s2_s1 = Diff::LCS.sdiff(@s2, @s1, Diff::LCS::DiffCallbacks)
end
- it "autodiscovers s1 to s2 patches" do
+ it 'autodiscovers s1 to s2 patches' do
expect do
expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2)
end.to_not raise_error
end
- it "autodiscovers s2 to s1 patches" do
+ it 'autodiscovers s2 to s1 patches' do
expect do
expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2)
end.to_not raise_error
end
- it "autodiscovers s2 to s1 the left-to-right patches" do
+ 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 "correctly patches left-to-right (explicit patch)" do
+ 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 "correctly patches right-to-left (explicit unpatch)" do
+ 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)
diff --git a/spec/sdiff_spec.rb b/spec/sdiff_spec.rb
index d619eb4..06d39d6 100644
--- a/spec/sdiff_spec.rb
+++ b/spec/sdiff_spec.rb
@@ -1,214 +1,214 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
require 'spec_helper'
-describe "Diff::LCS.sdiff" do
+describe 'Diff::LCS.sdiff' do
include Diff::LCS::SpecHelper::Matchers
- shared_examples "compare sequences correctly" do
- it "compares s1 -> s2 correctly" do
+ shared_examples 'compare sequences correctly' do
+ it 'compares s1 -> s2 correctly' do
expect(Diff::LCS.sdiff(s1, s2)).to eq(context_diff(result))
end
- it "compares s2 -> s1 correctly" do
+ it 'compares s2 -> s1 correctly' do
expect(Diff::LCS.sdiff(s2, s1)).to eq(context_diff(reverse_sdiff(result)))
end
end
- describe "using seq1 & seq2" do
+ describe 'using seq1 & seq2' do
let(:s1) { seq1 }
let(:s2) { seq2 }
let(:result) { correct_forward_sdiff }
- it_has_behavior "compare sequences correctly"
+ it_has_behavior 'compare sequences correctly'
end
- describe "using %w(abc def yyy xxx ghi jkl) & %w(abc dxf xxx ghi jkl)" do
+ describe 'using %w(abc def yyy xxx ghi jkl) & %w(abc dxf xxx ghi jkl)' do
let(:s1) { %w(abc def yyy xxx ghi jkl) }
let(:s2) { %w(abc dxf xxx ghi jkl) }
let(:result) {
[
- [ '=', [ 0, 'abc' ], [ 0, 'abc' ] ],
- [ '!', [ 1, 'def' ], [ 1, 'dxf' ] ],
- [ '-', [ 2, 'yyy' ], [ 2, nil ] ],
- [ '=', [ 3, 'xxx' ], [ 2, 'xxx' ] ],
- [ '=', [ 4, 'ghi' ], [ 3, 'ghi' ] ],
- [ '=', [ 5, 'jkl' ], [ 4, 'jkl' ] ]
+ ['=', [0, 'abc'], [0, 'abc']],
+ ['!', [1, 'def'], [1, 'dxf']],
+ ['-', [2, 'yyy'], [2, nil]],
+ ['=', [3, 'xxx'], [2, 'xxx']],
+ ['=', [4, 'ghi'], [3, 'ghi']],
+ ['=', [5, 'jkl'], [4, 'jkl']]
]
}
- it_has_behavior "compare sequences correctly"
+ it_has_behavior 'compare sequences correctly'
end
- describe "using %w(a b c d e) & %w(a e)" do
+ describe 'using %w(a b c d e) & %w(a e)' do
let(:s1) { %w(a b c d e) }
let(:s2) { %w(a e) }
let(:result) {
[
- [ '=', [ 0, 'a' ], [ 0, 'a' ] ],
- [ '-', [ 1, 'b' ], [ 1, nil ] ],
- [ '-', [ 2, 'c' ], [ 1, nil ] ],
- [ '-', [ 3, 'd' ], [ 1, nil ] ],
- [ '=', [ 4, 'e' ], [ 1, 'e' ] ]
+ ['=', [0, 'a'], [0, 'a']],
+ ['-', [1, 'b'], [1, nil]],
+ ['-', [2, 'c'], [1, nil]],
+ ['-', [3, 'd'], [1, nil]],
+ ['=', [4, 'e'], [1, 'e']]
]
}
- it_has_behavior "compare sequences correctly"
+ it_has_behavior 'compare sequences correctly'
end
- describe "using %w(a e) & %w(a b c d e)" do
+ describe 'using %w(a e) & %w(a b c d e)' do
let(:s1) { %w(a e) }
let(:s2) { %w(a b c d e) }
let(:result) {
[
- [ '=', [ 0, 'a' ], [ 0, 'a' ] ],
- [ '+', [ 1, nil ], [ 1, 'b' ] ],
- [ '+', [ 1, nil ], [ 2, 'c' ] ],
- [ '+', [ 1, nil ], [ 3, 'd' ] ],
- [ '=', [ 1, 'e' ], [ 4, 'e' ] ]
+ ['=', [0, 'a'], [0, 'a']],
+ ['+', [1, nil], [1, 'b']],
+ ['+', [1, nil], [2, 'c']],
+ ['+', [1, nil], [3, 'd']],
+ ['=', [1, 'e'], [4, 'e']]
]
}
- it_has_behavior "compare sequences correctly"
+ it_has_behavior 'compare sequences correctly'
end
- describe "using %w(v x a e) & %w(w y a b c d e)" do
+ describe 'using %w(v x a e) & %w(w y a b c d e)' do
let(:s1) { %w(v x a e) }
let(:s2) { %w(w y a b c d e) }
let(:result) {
[
- [ '!', [ 0, 'v' ], [ 0, 'w' ] ],
- [ '!', [ 1, 'x' ], [ 1, 'y' ] ],
- [ '=', [ 2, 'a' ], [ 2, 'a' ] ],
- [ '+', [ 3, nil ], [ 3, 'b' ] ],
- [ '+', [ 3, nil ], [ 4, 'c' ] ],
- [ '+', [ 3, nil ], [ 5, 'd' ] ],
- [ '=', [ 3, 'e' ], [ 6, 'e' ] ]
+ ['!', [0, 'v'], [0, 'w']],
+ ['!', [1, 'x'], [1, 'y']],
+ ['=', [2, 'a'], [2, 'a']],
+ ['+', [3, nil], [3, 'b']],
+ ['+', [3, nil], [4, 'c']],
+ ['+', [3, nil], [5, 'd']],
+ ['=', [3, 'e'], [6, 'e']]
]
}
- it_has_behavior "compare sequences correctly"
+ it_has_behavior 'compare sequences correctly'
end
- describe "using %w(x a e) & %w(a b c d e)" do
+ describe 'using %w(x a e) & %w(a b c d e)' do
let(:s1) { %w(x a e) }
let(:s2) { %w(a b c d e) }
let(:result) {
[
- [ '-', [ 0, 'x' ], [ 0, nil ] ],
- [ '=', [ 1, 'a' ], [ 0, 'a' ] ],
- [ '+', [ 2, nil ], [ 1, 'b' ] ],
- [ '+', [ 2, nil ], [ 2, 'c' ] ],
- [ '+', [ 2, nil ], [ 3, 'd' ] ],
- [ '=', [ 2, 'e' ], [ 4, 'e' ] ]
+ ['-', [0, 'x'], [0, nil]],
+ ['=', [1, 'a'], [0, 'a']],
+ ['+', [2, nil], [1, 'b']],
+ ['+', [2, nil], [2, 'c']],
+ ['+', [2, nil], [3, 'd']],
+ ['=', [2, 'e'], [4, 'e']]
]
}
- it_has_behavior "compare sequences correctly"
+ it_has_behavior 'compare sequences correctly'
end
- describe "using %w(a e) & %w(x a b c d e)" do
+ describe 'using %w(a e) & %w(x a b c d e)' do
let(:s1) { %w(a e) }
let(:s2) { %w(x a b c d e) }
let(:result) {
[
- [ '+', [ 0, nil ], [ 0, 'x' ] ],
- [ '=', [ 0, 'a' ], [ 1, 'a' ] ],
- [ '+', [ 1, nil ], [ 2, 'b' ] ],
- [ '+', [ 1, nil ], [ 3, 'c' ] ],
- [ '+', [ 1, nil ], [ 4, 'd' ] ],
- [ '=', [ 1, 'e' ], [ 5, 'e' ] ]
+ ['+', [0, nil], [0, 'x']],
+ ['=', [0, 'a'], [1, 'a']],
+ ['+', [1, nil], [2, 'b']],
+ ['+', [1, nil], [3, 'c']],
+ ['+', [1, nil], [4, 'd']],
+ ['=', [1, 'e'], [5, 'e']]
]
}
- it_has_behavior "compare sequences correctly"
+ it_has_behavior 'compare sequences correctly'
end
- describe "using %w(a e v) & %w(x a b c d e w x)" do
+ describe 'using %w(a e v) & %w(x a b c d e w x)' do
let(:s1) { %w(a e v) }
let(:s2) { %w(x a b c d e w x) }
let(:result) {
[
- [ '+', [ 0, nil ], [ 0, 'x' ] ],
- [ '=', [ 0, 'a' ], [ 1, 'a' ] ],
- [ '+', [ 1, nil ], [ 2, 'b' ] ],
- [ '+', [ 1, nil ], [ 3, 'c' ] ],
- [ '+', [ 1, nil ], [ 4, 'd' ] ],
- [ '=', [ 1, 'e' ], [ 5, 'e' ] ],
- [ '!', [ 2, 'v' ], [ 6, 'w' ] ],
- [ '+', [ 3, nil ], [ 7, 'x' ] ]
+ ['+', [0, nil], [0, 'x']],
+ ['=', [0, 'a'], [1, 'a']],
+ ['+', [1, nil], [2, 'b']],
+ ['+', [1, nil], [3, 'c']],
+ ['+', [1, nil], [4, 'd']],
+ ['=', [1, 'e'], [5, 'e']],
+ ['!', [2, 'v'], [6, 'w']],
+ ['+', [3, nil], [7, 'x']]
]
}
- it_has_behavior "compare sequences correctly"
+ it_has_behavior 'compare sequences correctly'
end
- describe "using %w() & %w(a b c)" do
+ describe 'using %w() & %w(a b c)' do
let(:s1) { %w() }
let(:s2) { %w(a b c) }
let(:result) {
[
- [ '+', [ 0, nil ], [ 0, 'a' ] ],
- [ '+', [ 0, nil ], [ 1, 'b' ] ],
- [ '+', [ 0, nil ], [ 2, 'c' ] ]
+ ['+', [0, nil], [0, 'a']],
+ ['+', [0, nil], [1, 'b']],
+ ['+', [0, nil], [2, 'c']]
]
}
- it_has_behavior "compare sequences correctly"
+ it_has_behavior 'compare sequences correctly'
end
- describe "using %w(a b c) & %w(1)" do
+ describe 'using %w(a b c) & %w(1)' do
let(:s1) { %w(a b c) }
let(:s2) { %w(1) }
let(:result) {
[
- [ '!', [ 0, 'a' ], [ 0, '1' ] ],
- [ '-', [ 1, 'b' ], [ 1, nil ] ],
- [ '-', [ 2, 'c' ], [ 1, nil ] ]
+ ['!', [0, 'a'], [0, '1']],
+ ['-', [1, 'b'], [1, nil]],
+ ['-', [2, 'c'], [1, nil]]
]
}
- it_has_behavior "compare sequences correctly"
+ it_has_behavior 'compare sequences correctly'
end
- describe "using %w(a b c) & %w(c)" do
+ describe 'using %w(a b c) & %w(c)' do
let(:s1) { %w(a b c) }
let(:s2) { %w(c) }
let(:result) {
[
- [ '-', [ 0, 'a' ], [ 0, nil ] ],
- [ '-', [ 1, 'b' ], [ 0, nil ] ],
- [ '=', [ 2, 'c' ], [ 0, 'c' ] ]
+ ['-', [0, 'a'], [0, nil]],
+ ['-', [1, 'b'], [0, nil]],
+ ['=', [2, 'c'], [0, 'c']]
]
}
- it_has_behavior "compare sequences correctly"
+ it_has_behavior 'compare sequences correctly'
end
- describe "using %w(abcd efgh ijkl mnop) & []" do
+ describe 'using %w(abcd efgh ijkl mnop) & []' do
let(:s1) { %w(abcd efgh ijkl mnop) }
let(:s2) { [] }
let(:result) {
[
- [ '-', [ 0, 'abcd' ], [ 0, nil ] ],
- [ '-', [ 1, 'efgh' ], [ 0, nil ] ],
- [ '-', [ 2, 'ijkl' ], [ 0, nil ] ],
- [ '-', [ 3, 'mnop' ], [ 0, nil ] ]
+ ['-', [0, 'abcd'], [0, nil]],
+ ['-', [1, 'efgh'], [0, nil]],
+ ['-', [2, 'ijkl'], [0, nil]],
+ ['-', [3, 'mnop'], [0, nil]]
]
}
- it_has_behavior "compare sequences correctly"
+ it_has_behavior 'compare sequences correctly'
end
- describe "using [[1,2]] & []" do
- let(:s1) { [ [ 1, 2 ] ] }
+ describe 'using [[1,2]] & []' do
+ let(:s1) { [[1, 2]] }
let(:s2) { [] }
let(:result) {
[
- [ '-', [ 0, [ 1, 2 ] ], [ 0, nil ] ]
+ ['-', [0, [1, 2]], [0, nil]]
]
}
- it_has_behavior "compare sequences correctly"
+ it_has_behavior 'compare sequences correctly'
end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 27298c4..4899c49 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,4 +1,4 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
require 'rubygems'
require 'pathname'
@@ -10,14 +10,14 @@ if ENV['COVERALLS']
elsif ENV['COVERAGE']
require 'simplecov'
- def require_do(resource, &block)
+ def require_do(resource)
require resource
- block.call
+ yield if block_given?
rescue LoadError
nil
end
- formatters = [ SimpleCov::Formatter::HTMLFormatter ]
+ formatters = [SimpleCov::Formatter::HTMLFormatter]
require_do('simplecov-rcov') {
formatters << SimpleCov::Formatter::RcovFormatter
@@ -44,11 +44,11 @@ require 'diff-lcs'
module Diff::LCS::SpecHelper
def hello
- "hello"
+ 'hello'
end
def hello_ary
- %W(h e l l o)
+ %w(h e l l o)
end
def seq1
@@ -77,50 +77,69 @@ module Diff::LCS::SpecHelper
def correct_forward_diff
[
- [ [ '-', 0, 'a' ] ],
- [ [ '+', 2, 'd' ] ],
- [ [ '-', 4, 'h' ],
- [ '+', 4, 'f' ] ],
- [ [ '+', 6, 'k' ] ],
- [ [ '-', 8, 'n' ],
- [ '-', 9, 'p' ],
- [ '+', 9, 'r' ],
- [ '+', 10, 's' ],
- [ '+', 11, 't' ] ]
+ [
+ ['-', 0, 'a']
+ ],
+ [
+ ['+', 2, 'd']
+ ],
+ [
+ ['-', 4, 'h'],
+ ['+', 4, 'f']
+ ],
+ [
+ ['+', 6, 'k']
+ ],
+ [
+ ['-', 8, 'n'],
+ ['-', 9, 'p'],
+ ['+', 9, 'r'],
+ ['+', 10, 's'],
+ ['+', 11, 't']
+ ]
]
end
def correct_backward_diff
[
- [ [ '+', 0, 'a' ] ],
- [ [ '-', 2, 'd' ] ],
- [ [ '-', 4, 'f' ],
- [ '+', 4, 'h' ] ],
- [ [ '-', 6, 'k' ] ],
[
- [ '-', 9, 'r' ],
- [ '-', 10, 's' ],
- [ '+', 8, 'n' ],
- [ '-', 11, 't' ],
- [ '+', 9, 'p' ] ]
+ ['+', 0, 'a']
+ ],
+ [
+ ['-', 2, 'd']
+ ],
+ [
+ ['-', 4, 'f'],
+ ['+', 4, 'h']
+ ],
+ [
+ ['-', 6, 'k']
+ ],
+ [
+ ['-', 9, 'r'],
+ ['-', 10, 's'],
+ ['+', 8, 'n'],
+ ['-', 11, 't'],
+ ['+', 9, 'p']
+ ]
]
end
def correct_forward_sdiff
[
- [ '-', [ 0, 'a' ], [ 0, nil ] ],
- [ '=', [ 1, 'b' ], [ 0, 'b' ] ],
- [ '=', [ 2, 'c' ], [ 1, 'c' ] ],
- [ '+', [ 3, nil ], [ 2, 'd' ] ],
- [ '=', [ 3, 'e' ], [ 3, 'e' ] ],
- [ '!', [ 4, 'h' ], [ 4, 'f' ] ],
- [ '=', [ 5, 'j' ], [ 5, 'j' ] ],
- [ '+', [ 6, nil ], [ 6, 'k' ] ],
- [ '=', [ 6, 'l' ], [ 7, 'l' ] ],
- [ '=', [ 7, 'm' ], [ 8, 'm' ] ],
- [ '!', [ 8, 'n' ], [ 9, 'r' ] ],
- [ '!', [ 9, 'p' ], [ 10, 's' ] ],
- [ '+', [ 10, nil ], [ 11, 't' ] ]
+ ['-', [0, 'a'], [0, nil]],
+ ['=', [1, 'b'], [0, 'b']],
+ ['=', [2, 'c'], [1, 'c']],
+ ['+', [3, nil], [2, 'd']],
+ ['=', [3, 'e'], [3, 'e']],
+ ['!', [4, 'h'], [4, 'f']],
+ ['=', [5, 'j'], [5, 'j']],
+ ['+', [6, nil], [6, 'k']],
+ ['=', [6, 'l'], [7, 'l']],
+ ['=', [7, 'm'], [8, 'm']],
+ ['!', [8, 'n'], [9, 'r']],
+ ['!', [9, 'p'], [10, 's']],
+ ['+', [10, nil], [11, 't']]
]
end
@@ -144,13 +163,13 @@ module Diff::LCS::SpecHelper
end
def format_diffs(diffs)
- diffs.map do |e|
+ diffs.map { |e|
if e.kind_of?(Array)
- e.map { |f| f.to_a.join }.join(", ")
+ e.map { |f| f.to_a.join }.join(', ')
else
e.to_a.join
end
- end.join("\n")
+ }.join("\n")
end
def map_diffs(diffs, klass = Diff::LCS::ContextChange)
@@ -171,8 +190,8 @@ module Diff::LCS::SpecHelper
def balanced_reverse(change_result)
new_result = []
- change_result.each { |line|
- line = [ line[0], line[2], line[1] ]
+ change_result.each do |line|
+ line = [line[0], line[2], line[1]]
case line[0]
when '<'
line[0] = '>'
@@ -180,21 +199,21 @@ module Diff::LCS::SpecHelper
line[0] = '<'
end
new_result << line
- }
- new_result.sort_by { |line| [ line[1], line[2] ] }
+ end
+ new_result.sort_by { |line| [line[1], line[2]] }
end
def map_to_no_change(change_result)
new_result = []
- change_result.each { |line|
+ change_result.each do |line|
case line[0]
when '!'
- new_result << [ '<', line[1], line[2] ]
- new_result << [ '>', line[1] + 1, line[2] ]
+ new_result << ['<', line[1], line[2]]
+ new_result << ['>', line[1] + 1, line[2]]
else
new_result << line
end
- }
+ end
new_result
end
@@ -231,14 +250,18 @@ module Diff::LCS::SpecHelper
end
def finished_a(event)
- @done_a << [event.old_element, event.old_position,
- event.new_element, event.new_position]
+ @done_a << [
+ event.old_element, event.old_position,
+ event.new_element, event.new_position
+ ]
end
def finished_b(event)
- p "called #finished_b"
- @done_b << [event.old_element, event.old_position,
- event.new_element, event.new_position]
+ p 'called #finished_b'
+ @done_b << [
+ event.old_element, event.old_position,
+ event.new_element, event.new_position
+ ]
end
end
callbacks.reset
@@ -264,19 +287,19 @@ module Diff::LCS::SpecHelper
end
def match(event)
- @result << [ "=", event.old_position, event.new_position ]
+ @result << ['=', event.old_position, event.new_position]
end
def discard_a(event)
- @result << [ "<", event.old_position, event.new_position ]
+ @result << ['<', event.old_position, event.new_position]
end
def discard_b(event)
- @result << [ ">", event.old_position, event.new_position ]
+ @result << ['>', event.old_position, event.new_position]
end
def change(event)
- @result << [ "!", event.old_position, event.new_position ]
+ @result << ['!', event.old_position, event.new_position]
end
end
cb.reset
diff --git a/spec/traverse_balanced_spec.rb b/spec/traverse_balanced_spec.rb
index 95e60ec..9ee68ea 100644
--- a/spec/traverse_balanced_spec.rb
+++ b/spec/traverse_balanced_spec.rb
@@ -1,310 +1,310 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
require 'spec_helper'
-describe "Diff::LCS.traverse_balanced" do
+describe 'Diff::LCS.traverse_balanced' do
include Diff::LCS::SpecHelper::Matchers
- shared_examples "with a #change callback" do |s1, s2, result|
- it "traverses s1 -> s2 correctly" do
+ shared_examples 'with a #change callback' do |s1, s2, result|
+ it 'traverses s1 -> s2 correctly' do
traversal = balanced_traversal(s1, s2, :balanced_callback)
expect(traversal.result).to eq(result)
end
- it "traverses s2 -> s1 correctly" do
+ it 'traverses s2 -> s1 correctly' do
traversal = balanced_traversal(s2, s1, :balanced_callback)
expect(traversal.result).to eq(balanced_reverse(result))
end
end
- shared_examples "without a #change callback" do |s1, s2, result|
- it "traverses s1 -> s2 correctly" do
+ shared_examples 'without a #change callback' do |s1, s2, result|
+ it 'traverses s1 -> s2 correctly' do
traversal = balanced_traversal(s1, s2, :balanced_callback_no_change)
expect(traversal.result).to eq(map_to_no_change(result))
end
- it "traverses s2 -> s1 correctly" do
+ it 'traverses s2 -> s1 correctly' do
traversal = balanced_traversal(s2, s1, :balanced_callback_no_change)
expect(traversal.result).to eq(map_to_no_change(balanced_reverse(result)))
end
end
describe "identical string sequences ('abc')" do
- s1 = s2 = "abc"
+ s1 = s2 = 'abc'
result = [
- [ '=', 0, 0 ],
- [ '=', 1, 1 ],
- [ '=', 2, 2 ]
+ ['=', 0, 0],
+ ['=', 1, 1],
+ ['=', 2, 2]
]
- it_has_behavior "with a #change callback", s1, s2, result
- it_has_behavior "without a #change callback", s1, s2, result
+ it_has_behavior 'with a #change callback', s1, s2, result
+ it_has_behavior 'without a #change callback', s1, s2, result
end
- describe "identical array sequences %w(a b c)" do
+ describe 'identical array sequences %w(a b c)' do
s1 = s2 = %w(a b c)
result = [
- [ '=', 0, 0 ],
- [ '=', 1, 1 ],
- [ '=', 2, 2 ]
+ ['=', 0, 0],
+ ['=', 1, 1],
+ ['=', 2, 2]
]
- it_has_behavior "with a #change callback", s1, s2, result
- it_has_behavior "without a #change callback", s1, s2, result
+ it_has_behavior 'with a #change callback', s1, s2, result
+ it_has_behavior 'without a #change callback', s1, s2, result
end
- describe "sequences %w(a b c) & %w(a x c)" do
+ describe 'sequences %w(a b c) & %w(a x c)' do
s1 = %w(a b c)
s2 = %w(a x c)
result = [
- [ '=', 0, 0 ],
- [ '!', 1, 1 ],
- [ '=', 2, 2 ]
+ ['=', 0, 0],
+ ['!', 1, 1],
+ ['=', 2, 2]
]
- it_has_behavior "with a #change callback", s1, s2, result
- it_has_behavior "without a #change callback", s1, s2, result
+ it_has_behavior 'with a #change callback', s1, s2, result
+ it_has_behavior 'without a #change callback', s1, s2, result
end
- describe "sequences %w(a x y c) & %w(a v w c)" do
+ describe 'sequences %w(a x y c) & %w(a v w c)' do
s1 = %w(a x y c)
s2 = %w(a v w c)
result = [
- [ '=', 0, 0 ],
- [ '!', 1, 1 ],
- [ '!', 2, 2 ],
- [ '=', 3, 3 ]
+ ['=', 0, 0],
+ ['!', 1, 1],
+ ['!', 2, 2],
+ ['=', 3, 3]
]
- it_has_behavior "with a #change callback", s1, s2, result
- it_has_behavior "without a #change callback", s1, s2, result
+ it_has_behavior 'with a #change callback', s1, s2, result
+ it_has_behavior 'without a #change callback', s1, s2, result
end
- describe "sequences %w(x y c) & %w(v w c)" do
+ describe 'sequences %w(x y c) & %w(v w c)' do
s1 = %w(x y c)
s2 = %w(v w c)
result = [
- [ '!', 0, 0 ],
- [ '!', 1, 1 ],
- [ '=', 2, 2 ]
+ ['!', 0, 0],
+ ['!', 1, 1],
+ ['=', 2, 2]
]
- it_has_behavior "with a #change callback", s1, s2, result
- it_has_behavior "without a #change callback", s1, s2, result
+ it_has_behavior 'with a #change callback', s1, s2, result
+ it_has_behavior 'without a #change callback', s1, s2, result
end
- describe "sequences %w(a x y z) & %w(b v w)" do
+ describe 'sequences %w(a x y z) & %w(b v w)' do
s1 = %w(a x y z)
s2 = %w(b v w)
result = [
- [ '!', 0, 0 ],
- [ '!', 1, 1 ],
- [ '!', 2, 2 ],
- [ '<', 3, 3 ]
+ ['!', 0, 0],
+ ['!', 1, 1],
+ ['!', 2, 2],
+ ['<', 3, 3]
]
- it_has_behavior "with a #change callback", s1, s2, result
- it_has_behavior "without a #change callback", s1, s2, result
+ it_has_behavior 'with a #change callback', s1, s2, result
+ it_has_behavior 'without a #change callback', s1, s2, result
end
- describe "sequences %w(a z) & %w(a)" do
+ describe 'sequences %w(a z) & %w(a)' do
s1 = %w(a z)
s2 = %w(a)
result = [
- [ '=', 0, 0 ],
- [ '<', 1, 1 ]
+ ['=', 0, 0],
+ ['<', 1, 1]
]
- it_has_behavior "with a #change callback", s1, s2, result
- it_has_behavior "without a #change callback", s1, s2, result
+ it_has_behavior 'with a #change callback', s1, s2, result
+ it_has_behavior 'without a #change callback', s1, s2, result
end
- describe "sequences %w(z a) & %w(a)" do
+ describe 'sequences %w(z a) & %w(a)' do
s1 = %w(z a)
s2 = %w(a)
result = [
- [ '<', 0, 0 ],
- [ '=', 1, 0 ]
+ ['<', 0, 0],
+ ['=', 1, 0]
]
- it_has_behavior "with a #change callback", s1, s2, result
- it_has_behavior "without a #change callback", s1, s2, result
+ it_has_behavior 'with a #change callback', s1, s2, result
+ it_has_behavior 'without a #change callback', s1, s2, result
end
- describe "sequences %w(a b c) & %w(x y z)" do
+ describe 'sequences %w(a b c) & %w(x y z)' do
s1 = %w(a b c)
s2 = %w(x y z)
result = [
- [ '!', 0, 0 ],
- [ '!', 1, 1 ],
- [ '!', 2, 2 ]
+ ['!', 0, 0],
+ ['!', 1, 1],
+ ['!', 2, 2]
]
- it_has_behavior "with a #change callback", s1, s2, result
- it_has_behavior "without a #change callback", s1, s2, result
+ it_has_behavior 'with a #change callback', s1, s2, result
+ it_has_behavior 'without a #change callback', s1, s2, result
end
- describe "sequences %w(abcd efgh ijkl mnoopqrstuvwxyz) & []" do
+ describe 'sequences %w(abcd efgh ijkl mnoopqrstuvwxyz) & []' do
s1 = %w(abcd efgh ijkl mnopqrstuvwxyz)
s2 = []
result = [
- [ '<', 0, 0 ],
- [ '<', 1, 0 ],
- [ '<', 2, 0 ],
- [ '<', 3, 0 ]
+ ['<', 0, 0],
+ ['<', 1, 0],
+ ['<', 2, 0],
+ ['<', 3, 0]
]
- it_has_behavior "with a #change callback", s1, s2, result
- it_has_behavior "without a #change callback", s1, s2, result
+ it_has_behavior 'with a #change callback', s1, s2, result
+ it_has_behavior 'without a #change callback', s1, s2, result
end
- describe "strings %Q(a b c) & %Q(a x c)" do
- s1 = %Q(a b c)
- s2 = %Q(a x c)
+ describe 'strings %q(a b c) & %q(a x c)' do
+ s1 = 'a b c'
+ s2 = 'a x c'
result = [
- [ '=', 0, 0 ],
- [ '=', 1, 1 ],
- [ '!', 2, 2 ],
- [ '=', 3, 3 ],
- [ '=', 4, 4 ]
+ ['=', 0, 0],
+ ['=', 1, 1],
+ ['!', 2, 2],
+ ['=', 3, 3],
+ ['=', 4, 4]
]
- it_has_behavior "with a #change callback", s1, s2, result
- it_has_behavior "without a #change callback", s1, s2, result
+ it_has_behavior 'with a #change callback', s1, s2, result
+ it_has_behavior 'without a #change callback', s1, s2, result
end
- describe "strings %Q(a x y c) & %Q(a v w c)" do
- s1 = %Q(a x y c)
- s2 = %Q(a v w c)
+ describe 'strings %q(a x y c) & %q(a v w c)' do
+ s1 = 'a x y c'
+ s2 = 'a v w c'
result = [
- [ '=', 0, 0 ],
- [ '=', 1, 1 ],
- [ '!', 2, 2 ],
- [ '=', 3, 3 ],
- [ '!', 4, 4 ],
- [ '=', 5, 5 ],
- [ '=', 6, 6 ]
+ ['=', 0, 0],
+ ['=', 1, 1],
+ ['!', 2, 2],
+ ['=', 3, 3],
+ ['!', 4, 4],
+ ['=', 5, 5],
+ ['=', 6, 6]
]
- it_has_behavior "with a #change callback", s1, s2, result
- it_has_behavior "without a #change callback", s1, s2, result
+ it_has_behavior 'with a #change callback', s1, s2, result
+ it_has_behavior 'without a #change callback', s1, s2, result
end
- describe "strings %Q(x y c) & %Q(v w c)" do
- s1 = %Q(x y c)
- s2 = %Q(v w c)
+ describe 'strings %q(x y c) & %q(v w c)' do
+ s1 = 'x y c'
+ s2 = 'v w c'
result = [
- [ '!', 0, 0 ],
- [ '=', 1, 1 ],
- [ '!', 2, 2 ],
- [ '=', 3, 3 ],
- [ '=', 4, 4 ]
+ ['!', 0, 0],
+ ['=', 1, 1],
+ ['!', 2, 2],
+ ['=', 3, 3],
+ ['=', 4, 4]
]
- it_has_behavior "with a #change callback", s1, s2, result
- it_has_behavior "without a #change callback", s1, s2, result
+ it_has_behavior 'with a #change callback', s1, s2, result
+ it_has_behavior 'without a #change callback', s1, s2, result
end
- describe "strings %Q(a x y z) & %Q(b v w)" do
- s1 = %Q(a x y z)
- s2 = %Q(b v w)
+ describe 'strings %q(a x y z) & %q(b v w)' do
+ s1 = 'a x y z'
+ s2 = 'b v w'
result = [
- [ '!', 0, 0 ],
- [ '=', 1, 1 ],
- [ '!', 2, 2 ],
- [ '=', 3, 3 ],
- [ '!', 4, 4 ],
- [ '<', 5, 5 ],
- [ '<', 6, 5 ]
+ ['!', 0, 0],
+ ['=', 1, 1],
+ ['!', 2, 2],
+ ['=', 3, 3],
+ ['!', 4, 4],
+ ['<', 5, 5],
+ ['<', 6, 5]
]
- it_has_behavior "with a #change callback", s1, s2, result
- it_has_behavior "without a #change callback", s1, s2, result
+ it_has_behavior 'with a #change callback', s1, s2, result
+ it_has_behavior 'without a #change callback', s1, s2, result
end
- describe "strings %Q(a z) & %Q(a)" do
- s1 = %Q(a z)
- s2 = %Q(a)
+ describe 'strings %q(a z) & %q(a)' do
+ s1 = 'a z'
+ s2 = 'a'
result = [
- [ '=', 0, 0 ],
- [ '<', 1, 1 ],
- [ '<', 2, 1 ]
+ ['=', 0, 0],
+ ['<', 1, 1],
+ ['<', 2, 1]
]
- it_has_behavior "with a #change callback", s1, s2, result
- it_has_behavior "without a #change callback", s1, s2, result
+ it_has_behavior 'with a #change callback', s1, s2, result
+ it_has_behavior 'without a #change callback', s1, s2, result
end
- describe "strings %Q(z a) & %Q(a)" do
- s1 = %Q(z a)
- s2 = %Q(a)
+ describe 'strings %q(z a) & %q(a)' do
+ s1 = 'z a'
+ s2 = 'a'
result = [
- [ '<', 0, 0 ],
- [ '<', 1, 0 ],
- [ '=', 2, 0 ]
+ ['<', 0, 0],
+ ['<', 1, 0],
+ ['=', 2, 0]
]
- it_has_behavior "with a #change callback", s1, s2, result
- it_has_behavior "without a #change callback", s1, s2, result
+ it_has_behavior 'with a #change callback', s1, s2, result
+ it_has_behavior 'without a #change callback', s1, s2, result
end
- describe "strings %Q(a b c) & %Q(x y z)" do
- s1 = %Q(a b c)
- s2 = %Q(x y z)
+ describe 'strings %q(a b c) & %q(x y z)' do
+ s1 = 'a b c'
+ s2 = 'x y z'
result = [
- [ '!', 0, 0 ],
- [ '=', 1, 1 ],
- [ '!', 2, 2 ],
- [ '=', 3, 3 ],
- [ '!', 4, 4 ]
+ ['!', 0, 0],
+ ['=', 1, 1],
+ ['!', 2, 2],
+ ['=', 3, 3],
+ ['!', 4, 4]
]
- it_has_behavior "with a #change callback", s1, s2, result
- it_has_behavior "without a #change callback", s1, s2, result
+ it_has_behavior 'with a #change callback', s1, s2, result
+ it_has_behavior 'without a #change callback', s1, s2, result
end
- describe "strings %Q(abcd efgh ijkl mnopqrstuvwxyz) & %Q()" do
- s1 = %Q(abcd efgh ijkl mnopqrstuvwxyz)
- s2 = ""
+ describe 'strings %q(abcd efgh ijkl mnopqrstuvwxyz) & %q()' do
+ s1 = 'abcd efgh ijkl mnopqrstuvwxyz'
+ s2 = ''
result = [
- [ '<', 0, 0 ],
- [ '<', 1, 0 ],
- [ '<', 2, 0 ],
- [ '<', 3, 0 ],
- [ '<', 4, 0 ],
- [ '<', 5, 0 ],
- [ '<', 6, 0 ],
- [ '<', 7, 0 ],
- [ '<', 8, 0 ],
- [ '<', 9, 0 ],
- [ '<', 10, 0 ],
- [ '<', 11, 0 ],
- [ '<', 12, 0 ],
- [ '<', 13, 0 ],
- [ '<', 14, 0 ],
- [ '<', 15, 0 ],
- [ '<', 16, 0 ],
- [ '<', 17, 0 ],
- [ '<', 18, 0 ],
- [ '<', 19, 0 ],
- [ '<', 20, 0 ],
- [ '<', 21, 0 ],
- [ '<', 22, 0 ],
- [ '<', 23, 0 ],
- [ '<', 24, 0 ],
- [ '<', 25, 0 ],
- [ '<', 26, 0 ],
- [ '<', 27, 0 ],
- [ '<', 28, 0 ],
+ ['<', 0, 0],
+ ['<', 1, 0],
+ ['<', 2, 0],
+ ['<', 3, 0],
+ ['<', 4, 0],
+ ['<', 5, 0],
+ ['<', 6, 0],
+ ['<', 7, 0],
+ ['<', 8, 0],
+ ['<', 9, 0],
+ ['<', 10, 0],
+ ['<', 11, 0],
+ ['<', 12, 0],
+ ['<', 13, 0],
+ ['<', 14, 0],
+ ['<', 15, 0],
+ ['<', 16, 0],
+ ['<', 17, 0],
+ ['<', 18, 0],
+ ['<', 19, 0],
+ ['<', 20, 0],
+ ['<', 21, 0],
+ ['<', 22, 0],
+ ['<', 23, 0],
+ ['<', 24, 0],
+ ['<', 25, 0],
+ ['<', 26, 0],
+ ['<', 27, 0],
+ ['<', 28, 0]
]
- it_has_behavior "with a #change callback", s1, s2, result
- it_has_behavior "without a #change callback", s1, s2, result
+ it_has_behavior 'with a #change callback', s1, s2, result
+ it_has_behavior 'without a #change callback', s1, s2, result
end
end
diff --git a/spec/traverse_sequences_spec.rb b/spec/traverse_sequences_spec.rb
index 1252d53..ea7a129 100644
--- a/spec/traverse_sequences_spec.rb
+++ b/spec/traverse_sequences_spec.rb
@@ -1,10 +1,10 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
require 'spec_helper'
-describe "Diff::LCS.traverse_sequences" do
- describe "callback with no finishers" do
- describe "over (seq1, seq2)" do
+describe 'Diff::LCS.traverse_sequences' do
+ describe 'callback with no finishers' do
+ describe 'over (seq1, seq2)' do
before(:each) do
@callback_s1_s2 = simple_callback_no_finishers
Diff::LCS.traverse_sequences(seq1, seq2, @callback_s1_s2)
@@ -13,27 +13,27 @@ describe "Diff::LCS.traverse_sequences" do
Diff::LCS.traverse_sequences(seq2, seq1, @callback_s2_s1)
end
- it "has the correct LCS result on left-matches" do
+ 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 "has the correct LCS result on right-matches" do
+ 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 "has the correct skipped sequences with the left sequence" do
+ 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 "has the correct skipped sequences with the right sequence" do
+ 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 "does not have anything done markers from the left or right sequences" do
+ 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
@@ -41,64 +41,64 @@ describe "Diff::LCS.traverse_sequences" do
end
end
- describe "over (hello, hello)" do
+ describe 'over (hello, hello)' do
before(:each) do
@callback = simple_callback_no_finishers
Diff::LCS.traverse_sequences(hello, hello, @callback)
end
- it "has the correct LCS result on left-matches" do
+ it 'has the correct LCS result on left-matches' do
expect(@callback.matched_a).to eq(hello.split(//))
end
- it "has the correct LCS result on right-matches" do
+ it 'has the correct LCS result on right-matches' do
expect(@callback.matched_b).to eq(hello.split(//))
end
- it "has the correct skipped sequences with the left sequence", :only => true do
+ it 'has the correct skipped sequences with the left sequence', :only => true do
expect(@callback.discards_a).to be_empty
end
- it "has the correct skipped sequences with the right sequence" do
+ it 'has the correct skipped sequences with the right sequence' do
expect(@callback.discards_b).to be_empty
end
- it "does not have anything done markers from the left or right sequences" do
+ 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
- describe "over (hello_ary, hello_ary)" do
+ describe 'over (hello_ary, hello_ary)' do
before(:each) do
@callback = simple_callback_no_finishers
Diff::LCS.traverse_sequences(hello_ary, hello_ary, @callback)
end
- it "has the correct LCS result on left-matches" do
+ it 'has the correct LCS result on left-matches' do
expect(@callback.matched_a).to eq(hello_ary)
end
- it "has the correct LCS result on right-matches" do
+ it 'has the correct LCS result on right-matches' do
expect(@callback.matched_b).to eq(hello_ary)
end
- it "has the correct skipped sequences with the left sequence" do
+ it 'has the correct skipped sequences with the left sequence' do
expect(@callback.discards_a).to be_empty
end
- it "has the correct skipped sequences with the right sequence" do
+ it 'has the correct skipped sequences with the right sequence' do
expect(@callback.discards_b).to be_empty
end
- it "does not have anything done markers from the left or right sequences" do
+ 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
- describe "callback with finisher" do
+ describe 'callback with finisher' do
before(:each) do
@callback_s1_s2 = simple_callback
Diff::LCS.traverse_sequences(seq1, seq2, @callback_s1_s2)
@@ -106,28 +106,28 @@ describe "Diff::LCS.traverse_sequences" do
Diff::LCS.traverse_sequences(seq2, seq1, @callback_s2_s1)
end
- it "has the correct LCS result on left-matches" do
+ 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 "has the correct LCS result on right-matches" do
+ 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 "has the correct skipped sequences for the left sequence" do
+ 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 "has the correct skipped sequences for the right sequence" do
+ 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 "has done markers differently-sized sequences" do
- expect(@callback_s1_s2.done_a).to eq([[ "p", 9, "s", 10 ]])
+ 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