From 106d1749c965b8af857c976197814707b66cbef0 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 10:43:29 -0500 Subject: Fix issues reported by fasterer --- .fasterer.yml | 5 ++--- Gemfile | 8 ++++++-- lib/diff/lcs.rb | 2 +- lib/diff/lcs/hunk.rb | 2 +- spec/spec_helper.rb | 4 +--- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.fasterer.yml b/.fasterer.yml index 821e02d..eef484f 100644 --- a/.fasterer.yml +++ b/.fasterer.yml @@ -1,4 +1,3 @@ exclude_paths: - - lib/diff/lcs.rb # sort_vs_sort_by on priority_compare - - Rakefile # each_with_index vs while - - spec/spec_helper.rb + - research/**/* + - pkg/**/* diff --git a/Gemfile b/Gemfile index 7b9f817..b482de6 100644 --- a/Gemfile +++ b/Gemfile @@ -11,10 +11,14 @@ if RUBY_VERSION < '1.9' gem 'rdoc', '< 4' gem 'ruby-debug' -elsif RUBY_VERSION >= '2.0' +end + +if RUBY_VERSION >= '2.0' + gem 'standardrb' + gem 'fasterer' + if RUBY_ENGINE == 'ruby' gem 'simplecov', '~> 0.18' - gem 'byebug' end end diff --git a/lib/diff/lcs.rb b/lib/diff/lcs.rb index 288cfc2..234fd03 100644 --- a/lib/diff/lcs.rb +++ b/lib/diff/lcs.rb @@ -145,7 +145,7 @@ class << Diff::LCS matches = Diff::LCS::Internals.lcs(seq1, seq2) ret = [] string = seq1.kind_of? String - matches.each_with_index do |_e, i| + matches.each_index do |i| next if matches[i].nil? v = string ? seq1[i, 1] : seq1[i] diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb index 49b520e..d27b024 100644 --- a/lib/diff/lcs/hunk.rb +++ b/lib/diff/lcs/hunk.rb @@ -22,7 +22,7 @@ class Diff::LCS::Hunk end 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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 41e1f8e..79c4e45 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -355,9 +355,7 @@ module Diff::LCS::SpecHelper matcher :correctly_map_sequence do |s1| match do |actual| - actual.each_with_index { |ee, ii| - expect(ee).to be_nil_or_match_values(ii, s1, @s2) - } + actual.each_index { |ii| expect(actual[ii]).to be_nil_or_match_values(ii, s1, @s2) } end chain :to_other_sequence do |s2| -- cgit v1.2.1 From ef23b66e9a495206f2bf1cd9ce0df50d363d26ef Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 10:44:13 -0500 Subject: Add standardrb --- .standard.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .standard.yml diff --git a/.standard.yml b/.standard.yml new file mode 100644 index 0000000..4d5683c --- /dev/null +++ b/.standard.yml @@ -0,0 +1,4 @@ +parallel: true +ruby_version: 2.0 +ignore: + - 'diff-lcs.gemspec' -- cgit v1.2.1 From f85ec381137c6838600b16c353ff9dba3a05452c Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 10:44:44 -0500 Subject: standardrb --only Style/StringLiterals --fix --- Gemfile | 24 +-- Rakefile | 42 ++--- bin/htmldiff | 8 +- lib/diff-lcs.rb | 2 +- lib/diff/lcs.rb | 64 ++++---- lib/diff/lcs/array.rb | 2 +- lib/diff/lcs/block.rb | 8 +- lib/diff/lcs/callbacks.rb | 6 +- lib/diff/lcs/change.rb | 32 ++-- lib/diff/lcs/htmldiff.rb | 12 +- lib/diff/lcs/hunk.rb | 20 +-- lib/diff/lcs/internals.rb | 16 +- lib/diff/lcs/ldiff.rb | 46 +++--- spec/change_spec.rb | 48 +++--- spec/diff_spec.rb | 28 ++-- spec/hunk_spec.rb | 34 ++-- spec/issues_spec.rb | 82 +++++----- spec/lcs_spec.rb | 20 +-- spec/ldiff_spec.rb | 22 +-- spec/patch_spec.rb | 164 +++++++++---------- spec/sdiff_spec.rb | 176 ++++++++++---------- spec/spec_helper.rb | 122 +++++++------- spec/traverse_balanced_spec.rb | 346 ++++++++++++++++++++-------------------- spec/traverse_sequences_spec.rb | 58 +++---- 24 files changed, 691 insertions(+), 691 deletions(-) diff --git a/Gemfile b/Gemfile index b482de6..2840096 100644 --- a/Gemfile +++ b/Gemfile @@ -3,23 +3,23 @@ # 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 'hoe', '~> 3.20' - gem 'rake', '< 11' - gem 'rdoc', '< 4' +if RUBY_VERSION < "1.9" + gem "hoe", "~> 3.20" + gem "rake", "< 11" + gem "rdoc", "< 4" - gem 'ruby-debug' + gem "ruby-debug" end -if RUBY_VERSION >= '2.0' - gem 'standardrb' - gem 'fasterer' +if RUBY_VERSION >= "2.0" + gem "standardrb" + gem "fasterer" - if RUBY_ENGINE == 'ruby' - gem 'simplecov', '~> 0.18' - gem 'byebug' + if RUBY_ENGINE == "ruby" + gem "simplecov", "~> 0.18" + gem "byebug" end end diff --git a/Rakefile b/Rakefile index fd7ee31..18c1304 100644 --- a/Rakefile +++ b/Rakefile @@ -1,9 +1,9 @@ # frozen_string_literal: true -require 'rubygems' -require 'rspec' -require 'rspec/core/rake_task' -require 'hoe' +require "rubygems" +require "rspec" +require "rspec/core/rake_task" +require "hoe" # This is required until https://github.com/seattlerb/hoe/issues/112 is fixed class Hoe @@ -45,7 +45,7 @@ Hoe.plugin :doofus Hoe.plugin :gemspec2 Hoe.plugin :git -if RUBY_VERSION < '1.9' +if RUBY_VERSION < "1.9" class Array #:nodoc: def to_h Hash[*flatten(1)] @@ -65,22 +65,22 @@ if RUBY_VERSION < '1.9' end end -_spec = Hoe.spec 'diff-lcs' do - developer('Austin Ziegler', 'halostatue@gmail.com') +_spec = Hoe.spec "diff-lcs" do + developer("Austin Ziegler", "halostatue@gmail.com") - require_ruby_version '>= 1.8' + 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.history_file = "History.md" + self.readme_file = "README.rdoc" + self.licenses = ["MIT", "Artistic-2.0", "GPL-2.0+"] - extra_dev_deps << ['hoe-doofus', '~> 1.0'] - extra_dev_deps << ['hoe-gemspec2', '~> 1.1'] - extra_dev_deps << ['hoe-git', '~> 1.6'] - extra_dev_deps << ['hoe-rubygems', '~> 1.0'] - extra_dev_deps << ['rspec', '>= 2.0', '< 4'] - extra_dev_deps << ['rake', '>= 10.0', '< 14'] - extra_dev_deps << ['rdoc', '>= 6.3.1', '< 7'] + extra_dev_deps << ["hoe-doofus", "~> 1.0"] + extra_dev_deps << ["hoe-gemspec2", "~> 1.1"] + extra_dev_deps << ["hoe-git", "~> 1.6"] + extra_dev_deps << ["hoe-rubygems", "~> 1.0"] + extra_dev_deps << ["rspec", ">= 2.0", "< 4"] + extra_dev_deps << ["rake", ">= 10.0", "< 14"] + extra_dev_deps << ["rdoc", ">= 6.3.1", "< 7"] end desc "Run all specifications" @@ -94,12 +94,12 @@ Rake::Task["spec"].actions.uniq! { |a| a.source_location } task :default => :spec unless Rake::Task["default"].prereqs.include?("spec") task :test => :spec unless Rake::Task["test"].prereqs.include?("spec") -if RUBY_VERSION >= '2.0' && RUBY_ENGINE == 'ruby' +if RUBY_VERSION >= "2.0" && RUBY_ENGINE == "ruby" namespace :spec do desc "Runs test coverage. Only works Ruby 2.0+ and assumes 'simplecov' is installed." task :coverage do - ENV['COVERAGE'] = 'yes' - Rake::Task['spec'].execute + ENV["COVERAGE"] = "yes" + Rake::Task["spec"].execute end end end diff --git a/bin/htmldiff b/bin/htmldiff index 14114a7..bcd89d2 100755 --- a/bin/htmldiff +++ b/bin/htmldiff @@ -1,11 +1,11 @@ #! /usr/bin/env ruby -w # frozen_string_literal: true -require 'diff/lcs' -require 'diff/lcs/htmldiff' +require "diff/lcs" +require "diff/lcs/htmldiff" begin - require 'text/format' + require "text/format" rescue LoadError Diff::LCS::HTMLDiff.can_expand_tabs = false end @@ -24,7 +24,7 @@ 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 diff --git a/lib/diff-lcs.rb b/lib/diff-lcs.rb index 250392f..bc07bf9 100644 --- a/lib/diff-lcs.rb +++ b/lib/diff-lcs.rb @@ -1,3 +1,3 @@ # frozen_string_literal: true -require 'diff/lcs' +require "diff/lcs" diff --git a/lib/diff/lcs.rb b/lib/diff/lcs.rb index 234fd03..e6d817b 100644 --- a/lib/diff/lcs.rb +++ b/lib/diff/lcs.rb @@ -49,11 +49,11 @@ module Diff; end unless defined? Diff # rubocop:disable Style/Documentation # a x b y c z p d q # a b c a x b y c z module Diff::LCS - VERSION = '1.5.0' + VERSION = "1.5.0" end -require 'diff/lcs/callbacks' -require 'diff/lcs/internals' +require "diff/lcs/callbacks" +require "diff/lcs/internals" module Diff::LCS # rubocop:disable Style/Documentation # Returns an Array containing the longest common subsequence(s) between @@ -299,7 +299,7 @@ class << Diff::LCS ax = string ? seq1[ai, 1] : seq1[ai] bx = string ? seq2[bj, 1] : seq2[bj] - event = Diff::LCS::ContextChange.new('-', ai, ax, bj, bx) + event = Diff::LCS::ContextChange.new("-", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_a(event) end @@ -310,13 +310,13 @@ class << Diff::LCS break unless bj < b_line bx = string ? seq2[bj, 1] : seq2[bj] - event = Diff::LCS::ContextChange.new('+', ai, ax, bj, bx) + event = Diff::LCS::ContextChange.new("+", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_b(event) bj += 1 end bx = string ? seq2[bj, 1] : seq2[bj] - event = Diff::LCS::ContextChange.new('=', ai, ax, bj, bx) + event = Diff::LCS::ContextChange.new("=", ai, ax, bj, bx) event = yield event if block_given? callbacks.match(event) bj += 1 @@ -332,7 +332,7 @@ class << Diff::LCS 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) + event = Diff::LCS::ContextChange.new(">", (a_size - 1), ax, bj, bx) event = yield event if block_given? callbacks.finished_a(event) run_finished_a = true @@ -340,7 +340,7 @@ class << Diff::LCS ax = string ? seq1[ai, 1] : seq1[ai] loop do bx = string ? seq2[bj, 1] : seq2[bj] - event = Diff::LCS::ContextChange.new('+', ai, ax, bj, bx) + event = Diff::LCS::ContextChange.new("+", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_b(event) bj += 1 @@ -354,7 +354,7 @@ class << Diff::LCS 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) + event = Diff::LCS::ContextChange.new("<", ai, ax, (b_size - 1), bx) event = yield event if block_given? callbacks.finished_b(event) run_finished_b = true @@ -362,7 +362,7 @@ class << Diff::LCS bx = string ? seq2[bj, 1] : seq2[bj] loop do ax = string ? seq1[ai, 1] : seq1[ai] - event = Diff::LCS::ContextChange.new('-', ai, ax, bj, bx) + event = Diff::LCS::ContextChange.new("-", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_a(event) ai += 1 @@ -374,7 +374,7 @@ class << Diff::LCS if ai < a_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 = Diff::LCS::ContextChange.new("-", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_a(event) ai += 1 @@ -383,7 +383,7 @@ class << Diff::LCS 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 = Diff::LCS::ContextChange.new("+", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_b(event) bj += 1 @@ -500,29 +500,29 @@ class << Diff::LCS case [(ai < ma), (bj < mb)] when [true, true] if callbacks.respond_to?(:change) - event = Diff::LCS::ContextChange.new('!', ai, ax, bj, bx) + event = Diff::LCS::ContextChange.new("!", ai, ax, bj, bx) event = yield event if block_given? callbacks.change(event) ai += 1 else - event = Diff::LCS::ContextChange.new('-', ai, ax, bj, bx) + event = Diff::LCS::ContextChange.new("-", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_a(event) ai += 1 ax = string ? seq1[ai, 1] : seq1[ai] - event = Diff::LCS::ContextChange.new('+', ai, ax, bj, bx) + event = Diff::LCS::ContextChange.new("+", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_b(event) end bj += 1 when [true, false] - event = Diff::LCS::ContextChange.new('-', ai, ax, bj, bx) + event = Diff::LCS::ContextChange.new("-", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_a(event) ai += 1 when [false, true] - event = Diff::LCS::ContextChange.new('+', ai, ax, bj, bx) + event = Diff::LCS::ContextChange.new("+", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_b(event) bj += 1 @@ -532,7 +532,7 @@ class << Diff::LCS # Match ax = string ? seq1[ai, 1] : seq1[ai] bx = string ? seq2[bj, 1] : seq2[bj] - event = Diff::LCS::ContextChange.new('=', ai, ax, bj, bx) + event = Diff::LCS::ContextChange.new("=", ai, ax, bj, bx) event = yield event if block_given? callbacks.match(event) ai += 1 @@ -546,29 +546,29 @@ class << Diff::LCS case [(ai < a_size), (bj < b_size)] when [true, true] if callbacks.respond_to?(:change) - event = Diff::LCS::ContextChange.new('!', ai, ax, bj, bx) + event = Diff::LCS::ContextChange.new("!", ai, ax, bj, bx) event = yield event if block_given? callbacks.change(event) ai += 1 else - event = Diff::LCS::ContextChange.new('-', ai, ax, bj, bx) + event = Diff::LCS::ContextChange.new("-", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_a(event) ai += 1 ax = string ? seq1[ai, 1] : seq1[ai] - event = Diff::LCS::ContextChange.new('+', ai, ax, bj, bx) + event = Diff::LCS::ContextChange.new("+", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_b(event) end bj += 1 when [true, false] - event = Diff::LCS::ContextChange.new('-', ai, ax, bj, bx) + event = Diff::LCS::ContextChange.new("-", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_a(event) ai += 1 when [false, true] - event = Diff::LCS::ContextChange.new('+', ai, ax, bj, bx) + event = Diff::LCS::ContextChange.new("+", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_b(event) bj += 1 @@ -577,8 +577,8 @@ class << Diff::LCS end PATCH_MAP = { #:nodoc: - :patch => { '+' => '+', '-' => '-', '!' => '!', '=' => '=' }.freeze, - :unpatch => { '+' => '-', '-' => '+', '!' => '!', '=' => '=' }.freeze + :patch => { "+" => "+", "-" => "-", "!" => "!", "=" => "=" }.freeze, + :unpatch => { "+" => "-", "-" => "+", "!" => "!", "=" => "=" }.freeze }.freeze # Applies a +patchset+ to the sequence +src+ according to the +direction+ @@ -655,14 +655,14 @@ class << Diff::LCS end case action - when '-' # Remove details from the old string + when "-" # Remove details from the old string while ai < op res << (string ? src[ai, 1] : src[ai]) ai += 1 bj += 1 end ai += 1 - when '+' + when "+" while bj < np res << (string ? src[ai, 1] : src[ai]) ai += 1 @@ -671,7 +671,7 @@ class << Diff::LCS res << el bj += 1 - when '=' + when "=" # This only appears in sdiff output with the SDiff callback. # Therefore, we only need to worry about dealing with a single # element. @@ -679,7 +679,7 @@ class << Diff::LCS ai += 1 bj += 1 - when '!' + when "!" while ai < op res << (string ? src[ai, 1] : src[ai]) ai += 1 @@ -693,14 +693,14 @@ class << Diff::LCS end when Diff::LCS::Change case action - when '-' + when "-" while ai < change.position res << (string ? src[ai, 1] : src[ai]) ai += 1 bj += 1 end ai += 1 - when '+' + when "+" while bj < change.position res << (string ? src[ai, 1] : src[ai]) ai += 1 @@ -736,4 +736,4 @@ class << Diff::LCS end end -require 'diff/lcs/backports' +require "diff/lcs/backports" diff --git a/lib/diff/lcs/array.rb b/lib/diff/lcs/array.rb index 5c250f6..663918a 100644 --- a/lib/diff/lcs/array.rb +++ b/lib/diff/lcs/array.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'diff/lcs' +require "diff/lcs" class Array include Diff::LCS diff --git a/lib/diff/lcs/block.rb b/lib/diff/lcs/block.rb index 430702d..226ed6f 100644 --- a/lib/diff/lcs/block.rb +++ b/lib/diff/lcs/block.rb @@ -25,13 +25,13 @@ class Diff::LCS::Block def op case [@remove.empty?, @insert.empty?] when [false, false] - '!' + "!" when [false, true] - '-' + "-" when [true, false] - '+' + "+" else # [true, true] - '^' + "^" end end end diff --git a/lib/diff/lcs/callbacks.rb b/lib/diff/lcs/callbacks.rb index 2a7665b..c075327 100644 --- a/lib/diff/lcs/callbacks.rb +++ b/lib/diff/lcs/callbacks.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'diff/lcs/change' +require "diff/lcs/change" module Diff::LCS # rubocop:disable Style/Documentation # This callback object implements the default set of callback events, @@ -131,11 +131,11 @@ class Diff::LCS::DiffCallbacks end def discard_a(event) - @hunk << Diff::LCS::Change.new('-', event.old_position, event.old_element) + @hunk << Diff::LCS::Change.new("-", event.old_position, event.old_element) end def discard_b(event) - @hunk << Diff::LCS::Change.new('+', event.new_position, event.new_element) + @hunk << Diff::LCS::Change.new("+", event.new_position, event.new_element) end def finish_hunk diff --git a/lib/diff/lcs/change.rb b/lib/diff/lcs/change.rb index 76faf83..aa55360 100644 --- a/lib/diff/lcs/change.rb +++ b/lib/diff/lcs/change.rb @@ -28,7 +28,7 @@ class Diff::LCS::Change @action, @position, @element = *args fail "Invalid Change Action '#{@action}'" unless Diff::LCS::Change.valid_action?(@action) - fail 'Invalid Position Type' unless @position.kind_of? IntClass + fail "Invalid Position Type" unless @position.kind_of? IntClass end def inspect(*_args) @@ -49,7 +49,7 @@ class Diff::LCS::Change when 3 Diff::LCS::Change.new(*(arr[0...3])) else - fail 'Invalid change array format provided.' + fail "Invalid change array format provided." end end @@ -70,27 +70,27 @@ class Diff::LCS::Change end def adding? - @action == '+' + @action == "+" end def deleting? - @action == '-' + @action == "-" end def unchanged? - @action == '=' + @action == "=" end def changed? - @action == '!' + @action == "!" end def finished_a? - @action == '>' + @action == ">" end def finished_b? - @action == '<' + @action == "<" end end @@ -115,8 +115,8 @@ class Diff::LCS::ContextChange < Diff::LCS::Change @action, @old_position, @old_element, @new_position, @new_element = *args 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 + 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 @@ -139,15 +139,15 @@ class Diff::LCS::ContextChange < Diff::LCS::Change ea = event.to_a case ea[0] - when '-' + when "-" ea[2][1] = nil - when '<' - ea[0] = '-' + when "<" + ea[0] = "-" ea[2][1] = nil - when '+' + when "+" ea[1][1] = nil - when '>' - ea[0] = '+' + when ">" + ea[0] = "+" ea[1][1] = nil end diff --git a/lib/diff/lcs/htmldiff.rb b/lib/diff/lcs/htmldiff.rb index f12220b..41858d5 100644 --- a/lib/diff/lcs/htmldiff.rb +++ b/lib/diff/lcs/htmldiff.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'cgi' +require "cgi" # Produce a simple HTML diff view. class Diff::LCS::HTMLDiff @@ -19,13 +19,13 @@ 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 = ' ' if element.empty? + element = " " if element.empty? %Q(
#{element}
\n) end private :htmlize @@ -103,7 +103,7 @@ h1 { margin-left: 2em; } @options[:css] ||= DEFAULT_CSS.dup - @options[:title] ||= 'diff' + @options[:title] ||= "diff" end private :verify_options diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb index d27b024..2a9645d 100644 --- a/lib/diff/lcs/hunk.rb +++ b/lib/diff/lcs/hunk.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true -require 'diff/lcs/block' +require "diff/lcs/block" # A Hunk is a group of Blocks which overlap because of the context surrounding # each block. (So if we're not using context, every hunk will contain one # block.) Used in the diff program (bin/ldiff). class Diff::LCS::Hunk - OLD_DIFF_OP_ACTION = { '+' => 'a', '-' => 'd', '!' => 'c' }.freeze #:nodoc: - ED_DIFF_OP_ACTION = { '+' => 'a', '-' => 'd', '!' => 'c' }.freeze #:nodoc: + OLD_DIFF_OP_ACTION = { "+" => "a", "-" => "d", "!" => "c" }.freeze #:nodoc: + ED_DIFF_OP_ACTION = { "+" => "a", "-" => "d", "!" => "c" }.freeze #:nodoc: private_constant :OLD_DIFF_OP_ACTION, :ED_DIFF_OP_ACTION if respond_to?(:private_constant) @@ -22,7 +22,7 @@ class Diff::LCS::Hunk end 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 @@ -133,7 +133,7 @@ class Diff::LCS::Hunk # 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(_last = false) - warn 'Expecting only one block in an old diff hunk!' if @blocks.size > 1 + warn "Expecting only one block in an old diff hunk!" if @blocks.size > 1 block = @blocks[0] @@ -144,13 +144,13 @@ class Diff::LCS::Hunk # If removing anything, just print out all the remove lines in the hunk # which is just all the remove lines in the block. unless block.remove.empty? - @data_old[@start_old..@end_old].each { |e| s << encode('< ') + e.chomp + encode("\n") } + @data_old[@start_old..@end_old].each { |e| s << encode("< ") + e.chomp + encode("\n") } end - s << encode("---\n") if block.op == '!' + s << encode("---\n") if block.op == "!" unless block.insert.empty? - @data_new[@start_new..@end_new].each { |e| s << encode('> ') + e.chomp + encode("\n") } + @data_new[@start_new..@end_new].each { |e| s << encode("> ") + e.chomp + encode("\n") } end s @@ -213,7 +213,7 @@ class Diff::LCS::Hunk def context_diff(last = false) s = encode("***************\n") s << encode("*** #{context_range(:old, ',', last)} ****\n") - r = context_range(:new, ',', last) + r = context_range(:new, ",", last) if last old_missing_newline = missing_last_newline?(@data_old) @@ -269,7 +269,7 @@ class Diff::LCS::Hunk private :context_diff def ed_diff(format, _last = false) - warn 'Expecting only one block in an old diff hunk!' if @blocks.size > 1 + warn "Expecting only one block in an old diff hunk!" if @blocks.size > 1 s = if format == :reverse_ed diff --git a/lib/diff/lcs/internals.rb b/lib/diff/lcs/internals.rb index ef77667..2ed713f 100644 --- a/lib/diff/lcs/internals.rb +++ b/lib/diff/lcs/internals.rb @@ -100,7 +100,7 @@ class << Diff::LCS::Internals # the object form of same) and detection of whether the patchset represents # changes to be made. def analyze_patchset(patchset, depth = 0) - fail 'Patchset too complex' if depth > 1 + fail "Patchset too complex" if depth > 1 has_changes = false new_patchset = [] @@ -157,22 +157,22 @@ class << Diff::LCS::Internals re = string ? src[change.new_position, 1] : src[change.new_position] case change.action - when '-' # Remove details from the old string + when "-" # Remove details from the old string if le == change.old_element left_match += 1 else left_miss += 1 end - when '+' + when "+" if re == change.new_element right_match += 1 else right_miss += 1 end - when '=' + when "=" left_miss += 1 if le != change.old_element right_miss += 1 if re != change.new_element - when '!' + when "!" if le == change.old_element left_match += 1 elsif re == change.new_element @@ -189,19 +189,19 @@ class << Diff::LCS::Internals element = string ? src[change.position, 1] : src[change.position] case change.action - when '-' + when "-" if element == change.element left_match += 1 else left_miss += 1 end - when '+' + when "+" if element == change.element right_match += 1 else right_miss += 1 end - when '=' + when "=" if element != change.element left_miss += 1 right_miss += 1 diff --git a/lib/diff/lcs/ldiff.rb b/lib/diff/lcs/ldiff.rb index 17b374c..c4a60d0 100644 --- a/lib/diff/lcs/ldiff.rb +++ b/lib/diff/lcs/ldiff.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'optparse' -require 'ostruct' -require 'diff/lcs/hunk' +require "optparse" +require "ostruct" +require "diff/lcs/hunk" module Diff::LCS::Ldiff #:nodoc: BANNER = <<-COPYRIGHT @@ -28,48 +28,48 @@ class << Diff::LCS::Ldiff args.options do |o| o.banner = "Usage: #{File.basename($0)} [options] oldfile newfile" - o.separator '' + o.separator "" o.on( - '-c', '-C', '--context [LINES]', Integer, - 'Displays a context diff with LINES lines', 'of context. Default 3 lines.' + "-c", "-C", "--context [LINES]", Integer, + "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]', Integer, - 'Displays a unified diff with LINES lines', 'of context. Default 3 lines.' + "-u", "-U", "--unified [LINES]", Integer, + "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.' + "-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 + o.on_tail("--help", "Shows this text.") do error << o return 0 end - o.on_tail('--version', 'Shows the version of Diff::LCS.') do + o.on_tail("--version", "Shows the version of Diff::LCS.") do 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 @@ -87,11 +87,11 @@ class << Diff::LCS::Ldiff case @format when :context - char_old = '*' * 3 - char_new = '-' * 3 + char_old = "*" * 3 + char_new = "-" * 3 when :unified - char_old = '-' * 3 - char_new = '+' * 3 + char_old = "-" * 3 + char_new = "+" * 3 end # After we've read up to a certain point in each file, the number of @@ -129,9 +129,9 @@ class << Diff::LCS::Ldiff end if (@format == :unified) or (@format == :context) - ft = File.stat(file_old).mtime.localtime.strftime('%Y-%m-%d %H:%M:%S.000000000 %z') + ft = File.stat(file_old).mtime.localtime.strftime("%Y-%m-%d %H:%M:%S.000000000 %z") output << "#{char_old} #{file_old}\t#{ft}\n" - ft = File.stat(file_new).mtime.localtime.strftime('%Y-%m-%d %H:%M:%S.000000000 %z') + ft = File.stat(file_new).mtime.localtime.strftime("%Y-%m-%d %H:%M:%S.000000000 %z") output << "#{char_new} #{file_new}\t#{ft}\n" end diff --git a/spec/change_spec.rb b/spec/change_spec.rb index b8d3443..237f621 100644 --- a/spec/change_spec.rb +++ b/spec/change_spec.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" describe Diff::LCS::Change do - describe 'an add' do - subject { described_class.new('+', 0, 'element') } + describe "an add" do + subject { described_class.new("+", 0, "element") } it { should_not be_deleting } it { should be_adding } it { should_not be_unchanged } @@ -13,8 +13,8 @@ describe Diff::LCS::Change do it { should_not be_finished_b } end - describe 'a delete' do - subject { described_class.new('-', 0, 'element') } + describe "a delete" do + subject { described_class.new("-", 0, "element") } it { should be_deleting } it { should_not be_adding } it { should_not be_unchanged } @@ -23,8 +23,8 @@ describe Diff::LCS::Change do it { should_not be_finished_b } end - describe 'an unchanged' do - subject { described_class.new('=', 0, 'element') } + describe "an unchanged" do + subject { described_class.new("=", 0, "element") } it { should_not be_deleting } it { should_not be_adding } it { should be_unchanged } @@ -33,8 +33,8 @@ describe Diff::LCS::Change do it { should_not be_finished_b } end - describe 'a changed' do - subject { described_class.new('!', 0, 'element') } + describe "a changed" do + subject { described_class.new("!", 0, "element") } it { should_not be_deleting } it { should_not be_adding } it { should_not be_unchanged } @@ -43,8 +43,8 @@ describe Diff::LCS::Change do it { should_not be_finished_b } end - describe 'a finished_a' do - subject { described_class.new('>', 0, 'element') } + describe "a finished_a" do + subject { described_class.new(">", 0, "element") } it { should_not be_deleting } it { should_not be_adding } it { should_not be_unchanged } @@ -53,8 +53,8 @@ describe Diff::LCS::Change do it { should_not be_finished_b } end - describe 'a finished_b' do - subject { described_class.new('<', 0, 'element') } + describe "a finished_b" do + subject { described_class.new("<", 0, "element") } it { should_not be_deleting } it { should_not be_adding } it { should_not be_unchanged } @@ -63,27 +63,27 @@ describe Diff::LCS::Change do it { should be_finished_b } end - describe 'as array' do - it 'should be converted' do - action, position, element = described_class.new('!', 0, 'element') - expect(action).to eq '!' + describe "as array" do + it "should be converted" do + action, position, element = described_class.new("!", 0, "element") + expect(action).to eq "!" expect(position).to eq 0 - expect(element).to eq 'element' + expect(element).to eq "element" end end end describe Diff::LCS::ContextChange do - describe 'as array' do - it 'should be converted' do + describe "as array" do + it "should be converted" do action, (old_position, old_element), (new_position, new_element) = - described_class.new('!', 1, 'old_element', 2, 'new_element') + described_class.new("!", 1, "old_element", 2, "new_element") - expect(action).to eq '!' + expect(action).to eq "!" expect(old_position).to eq 1 - expect(old_element).to eq 'old_element' + expect(old_element).to eq "old_element" expect(new_position).to eq 2 - expect(new_element).to eq 'new_element' + expect(new_element).to eq "new_element" end end end diff --git a/spec/diff_spec.rb b/spec/diff_spec.rb index e7d632a..bd0776a 100644 --- a/spec/diff_spec.rb +++ b/spec/diff_spec.rb @@ -1,28 +1,28 @@ # frozen_string_literal: true -require 'spec_helper' +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"] ] ] @@ -30,22 +30,22 @@ describe Diff::LCS, '.diff' do diff = Diff::LCS.diff([], word_sequence) correct_diff.each do |hunk| - hunk.each do |change| change[0] = '+' end + hunk.each do |change| change[0] = "+" end end expect(change_diff(correct_diff)).to eq(diff) end it "correctly diffs 'xx' and 'xaxb'" do - left = 'xx' - right = 'xaxb' + left = "xx" + right = "xaxb" expect(Diff::LCS.patch(left, Diff::LCS.diff(left, right))).to eq(right) end - it 'returns an empty diff with (hello, hello)' do + 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 b3616bf..339f4ab 100644 --- a/spec/hunk_spec.rb +++ b/spec/hunk_spec.rb @@ -1,18 +1,18 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" if String.method_defined?(:encoding) - require 'diff/lcs/hunk' + require "diff/lcs/hunk" describe Diff::LCS::Hunk do - let(:old_data) { ['Tu a un carté avec {count} itéms'.encode('UTF-16LE')] } - let(:new_data) { ['Tu a un carte avec {count} items'.encode('UTF-16LE')] } + let(:old_data) { ["Tu a un carté avec {count} itéms".encode("UTF-16LE")] } + let(:new_data) { ["Tu a un carte avec {count} items".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 = <<-EXPECTED.gsub(/^\s+/, '').encode('UTF-16LE').chomp + it "produces a unified diff from the two pieces" do + expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp @@ -1 +1 @@ -Tu a un carté avec {count} itéms +Tu a un carte avec {count} items @@ -21,8 +21,8 @@ if String.method_defined?(:encoding) expect(hunk.diff(:unified)).to eq(expected) end - it 'produces a unified diff from the two pieces (last entry)' do - expected = <<-EXPECTED.gsub(/^\s+/, '').encode('UTF-16LE').chomp + it "produces a unified diff from the two pieces (last entry)" do + expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp @@ -1 +1 @@ -Tu a un carté avec {count} itéms +Tu a un carte avec {count} items @@ -32,8 +32,8 @@ if String.method_defined?(:encoding) expect(hunk.diff(:unified, true)).to eq(expected) end - it 'produces a context diff from the two pieces' do - expected = <<-EXPECTED.gsub(/^\s+/, '').encode('UTF-16LE').chomp + it "produces a context diff from the two pieces" do + expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp *************** *** 1 **** ! Tu a un carté avec {count} itéms @@ -44,8 +44,8 @@ if String.method_defined?(:encoding) expect(hunk.diff(:context)).to eq(expected) end - it 'produces an old diff from the two pieces' do - expected = <<-EXPECTED.gsub(/^ +/, '').encode('UTF-16LE').chomp + it "produces an old diff from the two pieces" do + expected = <<-EXPECTED.gsub(/^ +/, "").encode("UTF-16LE").chomp 1c1 < Tu a un carté avec {count} itéms --- @@ -56,8 +56,8 @@ if String.method_defined?(:encoding) expect(hunk.diff(:old)).to eq(expected) end - it 'produces a reverse ed diff from the two pieces' do - expected = <<-EXPECTED.gsub(/^ +/, '').encode('UTF-16LE').chomp + it "produces a reverse ed diff from the two pieces" do + expected = <<-EXPECTED.gsub(/^ +/, "").encode("UTF-16LE").chomp c1 Tu a un carte avec {count} items . @@ -67,11 +67,11 @@ if String.method_defined?(:encoding) expect(hunk.diff(:reverse_ed)).to eq(expected) end - context 'with empty first data set' do + context "with empty first data set" do let(:old_data) { [] } - it 'produces a unified diff' do - expected = <<-EXPECTED.gsub(/^\s+/, '').encode('UTF-16LE').chomp + it "produces a unified diff" do + expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp @@ -1 +1,2 @@ +Tu a un carte avec {count} items EXPECTED diff --git a/spec/issues_spec.rb b/spec/issues_spec.rb index ad73123..fedc3f5 100644 --- a/spec/issues_spec.rb +++ b/spec/issues_spec.rb @@ -1,73 +1,73 @@ # frozen_string_literal: true -require 'spec_helper' -require 'diff/lcs/hunk' +require "spec_helper" +require "diff/lcs/hunk" -describe 'Diff::LCS Issues' do +describe "Diff::LCS Issues" do include Diff::LCS::SpecHelper::Matchers - describe 'issue #1' do - shared_examples 'handles simple diffs' do |s1, s2, forward_diff| + describe "issue #1" do + shared_examples "handles simple diffs" do |s1, s2, forward_diff| before do @diff_s1_s2 = Diff::LCS.diff(s1, s2) end - it 'creates the correct diff' do + it "creates the correct diff" do expect(change_diff(forward_diff)).to eq(@diff_s1_s2) end - it 'creates the correct patch s1->s2' do + it "creates the correct patch s1->s2" do expect(Diff::LCS.patch(s1, @diff_s1_s2)).to eq(s2) end - it 'creates the correct patch s2->s1' do + it "creates the correct patch s2->s1" do expect(Diff::LCS.patch(s2, @diff_s1_s2)).to eq(s1) end end - describe 'string' do - it_has_behavior 'handles simple diffs', 'aX', 'bXaX', [ + 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', [ + 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), [ + 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), [ + it_has_behavior "handles simple diffs", %w(b X a X), %w(a X), [ [ - ['-', 0, 'b'], - ['-', 1, 'X'] + ["-", 0, "b"], + ["-", 1, "X"] ] ] end end - describe 'issue #57' do - it 'should fail with a correct error' do + describe "issue #57" do + it "should fail with a correct error" do expect { - actual = { :category => 'app.rack.request' } - expected = { :category => 'rack.middleware', :title => 'Anonymous Middleware' } + actual = { :category => "app.rack.request" } + expected = { :category => "rack.middleware", :title => "Anonymous Middleware" } expect(actual).to eq(expected) }.to raise_error(RSpec::Expectations::ExpectationNotMetError) end end - describe 'issue #60' do - it 'should produce unified output with correct context' do + describe "issue #60" do + it "should produce unified output with correct context" do old_data = <<-DATA_OLD.strip.split("\n").map(&:chomp) { "name": "x", @@ -96,7 +96,7 @@ describe 'Diff::LCS Issues' do end end - describe 'issue #65' do + describe "issue #65" do def diff_lines(old_lines, new_lines) file_length_difference = 0 previous_hunk = nil @@ -115,22 +115,22 @@ describe 'Diff::LCS Issues' do output.join end - it 'should not misplace the new chunk' do + it "should not misplace the new chunk" do old_data = [ - 'recipe[a::default]', 'recipe[b::default]', 'recipe[c::default]', - 'recipe[d::default]', 'recipe[e::default]', 'recipe[f::default]', - 'recipe[g::default]', 'recipe[h::default]', 'recipe[i::default]', - 'recipe[j::default]', 'recipe[k::default]', 'recipe[l::default]', - 'recipe[m::default]', 'recipe[n::default]' + "recipe[a::default]", "recipe[b::default]", "recipe[c::default]", + "recipe[d::default]", "recipe[e::default]", "recipe[f::default]", + "recipe[g::default]", "recipe[h::default]", "recipe[i::default]", + "recipe[j::default]", "recipe[k::default]", "recipe[l::default]", + "recipe[m::default]", "recipe[n::default]" ] new_data = [ - 'recipe[a::default]', 'recipe[c::default]', 'recipe[d::default]', - 'recipe[e::default]', 'recipe[f::default]', 'recipe[g::default]', - 'recipe[h::default]', 'recipe[i::default]', 'recipe[j::default]', - 'recipe[k::default]', 'recipe[l::default]', 'recipe[m::default]', - 'recipe[n::default]', 'recipe[o::new]', 'recipe[p::new]', - 'recipe[q::new]', 'recipe[r::new]' + "recipe[a::default]", "recipe[c::default]", "recipe[d::default]", + "recipe[e::default]", "recipe[f::default]", "recipe[g::default]", + "recipe[h::default]", "recipe[i::default]", "recipe[j::default]", + "recipe[k::default]", "recipe[l::default]", "recipe[m::default]", + "recipe[n::default]", "recipe[o::new]", "recipe[p::new]", + "recipe[q::new]", "recipe[r::new]" ] expect(diff_lines(old_data, new_data)).to eq(<<-EODIFF) diff --git a/spec/lcs_spec.rb b/spec/lcs_spec.rb index 94428fd..e3643dd 100644 --- a/spec/lcs_spec.rb +++ b/spec/lcs_spec.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require 'spec_helper' +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 a2468f8..e5df039 100644 --- a/spec/ldiff_spec.rb +++ b/spec/ldiff_spec.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" -RSpec.describe 'bin/ldiff' do +RSpec.describe "bin/ldiff" do include CaptureSubprocessIO fixtures = [ - { :name => 'output.diff', :left => 'aX', :right => 'bXaX' }, - { :name => 'output.diff.chef', :left => 'old-chef', :right => 'new-chef' }, - { :name => 'output.diff.chef2', :left => 'old-chef2', :right => 'new-chef2' } - ].product([nil, '-e', '-f', '-c', '-u']).map { |(fixture, flag)| + { :name => "output.diff", :left => "aX", :right => "bXaX" }, + { :name => "output.diff.chef", :left => "old-chef", :right => "new-chef" }, + { :name => "output.diff.chef2", :left => "old-chef2", :right => "new-chef2" } + ].product([nil, "-e", "-f", "-c", "-u"]).map { |(fixture, flag)| fixture = fixture.dup fixture[:flag] = flag fixture @@ -20,10 +20,10 @@ RSpec.describe 'bin/ldiff' do fixture[:flag], "spec/fixtures/#{fixture[:left]}", "spec/fixtures/#{fixture[:right]}", - '#', - '=>', + "#", + "=>", "spec/fixtures/ldiff/#{fixture[:name]}#{fixture[:flag]}" - ].join(' ') + ].join(" ") it desc do expect(run_ldiff(fixture)).to eq(read_fixture(fixture)) @@ -45,7 +45,7 @@ RSpec.describe 'bin/ldiff' do def clean_data(data, flag) data = case flag - when '-c', '-u' + when "-c", "-u" clean_output_timestamp(data) else data @@ -80,7 +80,7 @@ RSpec.describe 'bin/ldiff' do system("ruby -Ilib bin/ldiff #{flag} spec/fixtures/#{left} spec/fixtures/#{right}") end - expect(stderr).to be_empty if RUBY_VERSION >= '1.9' + expect(stderr).to be_empty if RUBY_VERSION >= "1.9" expect(stdout).not_to be_empty clean_data(stdout, flag) end diff --git a/spec/patch_spec.rb b/spec/patch_spec.rb index 11b0981..8c3a9b1 100644 --- a/spec/patch_spec.rb +++ b/spec/patch_spec.rb @@ -1,54 +1,54 @@ # frozen_string_literal: true -require 'spec_helper' +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) 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) 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 + 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 + 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) # 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,37 +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) 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) @@ -261,37 +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) 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) @@ -299,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) @@ -337,37 +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) 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) @@ -375,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 06d39d6..6816833 100644 --- a/spec/sdiff_spec.rb +++ b/spec/sdiff_spec.rb @@ -1,214 +1,214 @@ # frozen_string_literal: true -require 'spec_helper' +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 + 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 79c4e45..20f8c39 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require 'rubygems' -require 'pathname' +require "rubygems" +require "pathname" -require 'psych' if RUBY_VERSION >= '1.9' +require "psych" if RUBY_VERSION >= "1.9" -if ENV['COVERAGE'] - require 'simplecov' +if ENV["COVERAGE"] + require "simplecov" def require_do(resource) require resource @@ -17,13 +17,13 @@ if ENV['COVERAGE'] formatters = [SimpleCov::Formatter::HTMLFormatter] - require_do('simplecov-rcov') { + require_do("simplecov-rcov") { formatters << SimpleCov::Formatter::RcovFormatter } - require_do('simplecov-vim/formatter') { + require_do("simplecov-vim/formatter") { formatters << SimpleCov::Formatter::VimFormatter } - require_do('simplecov-sublime-ruby-coverage') { + require_do("simplecov-sublime-ruby-coverage") { formatters << SimpleCov::Formatter::SublimeRubyCoverageFormatter } @@ -36,7 +36,7 @@ file = Pathname.new(__FILE__).expand_path path = file.parent parent = path.parent -$:.unshift parent.join('lib') +$:.unshift parent.join("lib") module CaptureSubprocessIO def _synchronize @@ -48,9 +48,9 @@ module CaptureSubprocessIO end def _capture_subprocess_io - require 'tempfile' + require "tempfile" - captured_stdout, captured_stderr = Tempfile.new('out'), Tempfile.new('err') + captured_stdout, captured_stderr = Tempfile.new("out"), Tempfile.new("err") orig_stdout, orig_stderr = $stdout.dup, $stderr.dup $stdout.reopen captured_stdout @@ -71,11 +71,11 @@ module CaptureSubprocessIO private :_capture_subprocess_io end -require 'diff-lcs' +require "diff-lcs" module Diff::LCS::SpecHelper def hello - 'hello' + "hello" end def hello_ary @@ -109,24 +109,24 @@ module Diff::LCS::SpecHelper def correct_forward_diff [ [ - ['-', 0, 'a'] + ["-", 0, "a"] ], [ - ['+', 2, 'd'] + ["+", 2, "d"] ], [ - ['-', 4, 'h'], - ['+', 4, 'f'] + ["-", 4, "h"], + ["+", 4, "f"] ], [ - ['+', 6, 'k'] + ["+", 6, "k"] ], [ - ['-', 8, 'n'], - ['+', 9, 'r'], - ['-', 9, 'p'], - ['+', 10, 's'], - ['+', 11, 't'] + ["-", 8, "n"], + ["+", 9, "r"], + ["-", 9, "p"], + ["+", 10, "s"], + ["+", 11, "t"] ] ] end @@ -134,43 +134,43 @@ module Diff::LCS::SpecHelper def correct_backward_diff [ [ - ['+', 0, 'a'] + ["+", 0, "a"] ], [ - ['-', 2, 'd'] + ["-", 2, "d"] ], [ - ['-', 4, 'f'], - ['+', 4, 'h'] + ["-", 4, "f"], + ["+", 4, "h"] ], [ - ['-', 6, 'k'] + ["-", 6, "k"] ], [ - ['-', 9, 'r'], - ['+', 8, 'n'], - ['-', 10, 's'], - ['+', 9, 'p'], - ['-', 11, 't'] + ["-", 9, "r"], + ["+", 8, "n"], + ["-", 10, "s"], + ["+", 9, "p"], + ["-", 11, "t"] ] ] 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 @@ -178,8 +178,8 @@ module Diff::LCS::SpecHelper forward_sdiff.map { |line| line[1], line[2] = line[2], line[1] case line[0] - when '-' then line[0] = '+' - when '+' then line[0] = '-' + when "-" then line[0] = "+" + when "+" then line[0] = "-" end line } @@ -196,7 +196,7 @@ module Diff::LCS::SpecHelper def format_diffs(diffs) 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 @@ -224,10 +224,10 @@ module Diff::LCS::SpecHelper change_result.each do |line| line = [line[0], line[2], line[1]] case line[0] - when '<' - line[0] = '>' - when '>' - line[0] = '<' + when "<" + line[0] = ">" + when ">" + line[0] = "<" end new_result << line end @@ -238,9 +238,9 @@ module Diff::LCS::SpecHelper new_result = [] change_result.each do |line| case line[0] - when '!' - new_result << ['<', line[1], line[2]] - new_result << ['>', line[1] + 1, line[2]] + when "!" + new_result << ["<", line[1], line[2]] + new_result << [">", line[1] + 1, line[2]] else new_result << line end @@ -317,19 +317,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 @@ -367,6 +367,6 @@ end RSpec.configure do |conf| conf.include Diff::LCS::SpecHelper - conf.alias_it_should_behave_like_to :it_has_behavior, 'has behavior:' + conf.alias_it_should_behave_like_to :it_has_behavior, "has behavior:" conf.filter_run_excluding :broken => true end diff --git a/spec/traverse_balanced_spec.rb b/spec/traverse_balanced_spec.rb index 9ee68ea..fcbde79 100644 --- a/spec/traverse_balanced_spec.rb +++ b/spec/traverse_balanced_spec.rb @@ -1,310 +1,310 @@ # frozen_string_literal: true -require 'spec_helper' +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 = 'a b c' - s2 = '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 = 'a x y c' - s2 = '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 = 'x y c' - s2 = '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 = 'a x y z' - s2 = '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 = 'a z' - s2 = '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 = 'z a' - s2 = '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 = 'a b c' - s2 = '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 = '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 b185e1d..3bad13e 100644 --- a/spec/traverse_sequences_spec.rb +++ b/spec/traverse_sequences_spec.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require 'spec_helper' +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,32 +106,32 @@ 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, 't', 11]]) + it "has done markers differently-sized sequences" do + expect(@callback_s1_s2.done_a).to eq([["p", 9, "t", 11]]) expect(@callback_s1_s2.done_b).to be_empty expect(@callback_s2_s1.done_a).to be_empty - expect(@callback_s2_s1.done_b).to eq([['t', 11, 'p', 9]]) + expect(@callback_s2_s1.done_b).to eq([["t", 11, "p", 9]]) end end end -- cgit v1.2.1 From cb9bebb30477e815cdbe8f8460f227f0940599a1 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 10:45:50 -0500 Subject: standardrb --only Style/PercentLiteralDelimiters --fix --- Rakefile | 2 +- lib/diff/lcs/change.rb | 2 +- spec/issues_spec.rb | 4 ++-- spec/patch_spec.rb | 4 ++-- spec/sdiff_spec.rb | 42 +++++++++++++++++++++--------------------- spec/spec_helper.rb | 14 +++++++------- spec/traverse_balanced_spec.rb | 32 ++++++++++++++++---------------- 7 files changed, 50 insertions(+), 50 deletions(-) diff --git a/Rakefile b/Rakefile index 18c1304..3924134 100644 --- a/Rakefile +++ b/Rakefile @@ -85,7 +85,7 @@ end desc "Run all specifications" RSpec::Core::RakeTask.new(:spec) do |t| - rspec_dirs = %w(spec lib).join(":") + rspec_dirs = %w[spec lib].join(":") t.rspec_opts = ["-I#{rspec_dirs}"] end diff --git a/lib/diff/lcs/change.rb b/lib/diff/lcs/change.rb index aa55360..a82f3e6 100644 --- a/lib/diff/lcs/change.rb +++ b/lib/diff/lcs/change.rb @@ -10,7 +10,7 @@ class Diff::LCS::Change # (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(+ - = ! > <).freeze + VALID_ACTIONS = %w[+ - = ! > <].freeze def self.valid_action?(action) VALID_ACTIONS.include? action diff --git a/spec/issues_spec.rb b/spec/issues_spec.rb index fedc3f5..abe524e 100644 --- a/spec/issues_spec.rb +++ b/spec/issues_spec.rb @@ -41,13 +41,13 @@ describe "Diff::LCS Issues" do end describe "array" do - it_has_behavior "handles simple diffs", %w(a X), %w(b X a X), [ + it_has_behavior "handles simple diffs", %w[a X], %w[b X a X], [ [ ["+", 0, "b"], ["+", 1, "X"] ] ] - it_has_behavior "handles simple diffs", %w(b X a X), %w(a X), [ + it_has_behavior "handles simple diffs", %w[b X a X], %w[a X], [ [ ["-", 0, "b"], ["-", 1, "X"] diff --git a/spec/patch_spec.rb b/spec/patch_spec.rb index 8c3a9b1..6b9bf28 100644 --- a/spec/patch_spec.rb +++ b/spec/patch_spec.rb @@ -181,8 +181,8 @@ describe "Diff::LCS.patch" do # above. 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) # rubocop:disable Layout/SpaceInsideArrayPercentLiteral - @s2 = %w(a b c d 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 diff --git a/spec/sdiff_spec.rb b/spec/sdiff_spec.rb index 6816833..9750519 100644 --- a/spec/sdiff_spec.rb +++ b/spec/sdiff_spec.rb @@ -24,8 +24,8 @@ describe "Diff::LCS.sdiff" do end 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(:s1) { %w[abc def yyy xxx ghi jkl] } + let(:s2) { %w[abc dxf xxx ghi jkl] } let(:result) { [ ["=", [0, "abc"], [0, "abc"]], @@ -41,8 +41,8 @@ describe "Diff::LCS.sdiff" do end 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(:s1) { %w[a b c d e] } + let(:s2) { %w[a e] } let(:result) { [ ["=", [0, "a"], [0, "a"]], @@ -57,8 +57,8 @@ describe "Diff::LCS.sdiff" do end 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(:s1) { %w[a e] } + let(:s2) { %w[a b c d e] } let(:result) { [ ["=", [0, "a"], [0, "a"]], @@ -73,8 +73,8 @@ describe "Diff::LCS.sdiff" do end 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(:s1) { %w[v x a e] } + let(:s2) { %w[w y a b c d e] } let(:result) { [ ["!", [0, "v"], [0, "w"]], @@ -91,8 +91,8 @@ describe "Diff::LCS.sdiff" do end 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(:s1) { %w[x a e] } + let(:s2) { %w[a b c d e] } let(:result) { [ ["-", [0, "x"], [0, nil]], @@ -108,8 +108,8 @@ describe "Diff::LCS.sdiff" do end 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(:s1) { %w[a e] } + let(:s2) { %w[x a b c d e] } let(:result) { [ ["+", [0, nil], [0, "x"]], @@ -125,8 +125,8 @@ describe "Diff::LCS.sdiff" do end 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(:s1) { %w[a e v] } + let(:s2) { %w[x a b c d e w x] } let(:result) { [ ["+", [0, nil], [0, "x"]], @@ -144,8 +144,8 @@ describe "Diff::LCS.sdiff" do end describe "using %w() & %w(a b c)" do - let(:s1) { %w() } - let(:s2) { %w(a b c) } + let(:s1) { %w[] } + let(:s2) { %w[a b c] } let(:result) { [ ["+", [0, nil], [0, "a"]], @@ -158,8 +158,8 @@ describe "Diff::LCS.sdiff" do end describe "using %w(a b c) & %w(1)" do - let(:s1) { %w(a b c) } - let(:s2) { %w(1) } + let(:s1) { %w[a b c] } + let(:s2) { %w[1] } let(:result) { [ ["!", [0, "a"], [0, "1"]], @@ -172,8 +172,8 @@ describe "Diff::LCS.sdiff" do end describe "using %w(a b c) & %w(c)" do - let(:s1) { %w(a b c) } - let(:s2) { %w(c) } + let(:s1) { %w[a b c] } + let(:s2) { %w[c] } let(:result) { [ ["-", [0, "a"], [0, nil]], @@ -186,7 +186,7 @@ describe "Diff::LCS.sdiff" do end describe "using %w(abcd efgh ijkl mnop) & []" do - let(:s1) { %w(abcd efgh ijkl mnop) } + let(:s1) { %w[abcd efgh ijkl mnop] } let(:s2) { [] } let(:result) { [ diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 20f8c39..af5ec23 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -79,31 +79,31 @@ module Diff::LCS::SpecHelper end def hello_ary - %w(h e l l o) + %w[h e l l o] end def seq1 - %w(a b c e h j l m n p) + %w[a b c e h j l m n p] end def skipped_seq1 - %w(a h n p) + %w[a h n p] end def seq2 - %w(b c d e f j k l m r s t) + %w[b c d e f j k l m r s t] end def skipped_seq2 - %w(d f k r s t) + %w[d f k r s t] end def word_sequence - %w(abcd efgh ijkl mnopqrstuvwxyz) + %w[abcd efgh ijkl mnopqrstuvwxyz] end def correct_lcs - %w(b c e j l m) + %w[b c e j l m] end def correct_forward_diff diff --git a/spec/traverse_balanced_spec.rb b/spec/traverse_balanced_spec.rb index fcbde79..4956acf 100644 --- a/spec/traverse_balanced_spec.rb +++ b/spec/traverse_balanced_spec.rb @@ -43,7 +43,7 @@ describe "Diff::LCS.traverse_balanced" do end describe "identical array sequences %w(a b c)" do - s1 = s2 = %w(a b c) + s1 = s2 = %w[a b c] result = [ ["=", 0, 0], @@ -56,8 +56,8 @@ describe "Diff::LCS.traverse_balanced" do end describe "sequences %w(a b c) & %w(a x c)" do - s1 = %w(a b c) - s2 = %w(a x c) + s1 = %w[a b c] + s2 = %w[a x c] result = [ ["=", 0, 0], @@ -70,8 +70,8 @@ describe "Diff::LCS.traverse_balanced" do end 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) + s1 = %w[a x y c] + s2 = %w[a v w c] result = [ ["=", 0, 0], @@ -85,8 +85,8 @@ describe "Diff::LCS.traverse_balanced" do end describe "sequences %w(x y c) & %w(v w c)" do - s1 = %w(x y c) - s2 = %w(v w c) + s1 = %w[x y c] + s2 = %w[v w c] result = [ ["!", 0, 0], ["!", 1, 1], @@ -98,8 +98,8 @@ describe "Diff::LCS.traverse_balanced" do end describe "sequences %w(a x y z) & %w(b v w)" do - s1 = %w(a x y z) - s2 = %w(b v w) + s1 = %w[a x y z] + s2 = %w[b v w] result = [ ["!", 0, 0], ["!", 1, 1], @@ -112,8 +112,8 @@ describe "Diff::LCS.traverse_balanced" do end describe "sequences %w(a z) & %w(a)" do - s1 = %w(a z) - s2 = %w(a) + s1 = %w[a z] + s2 = %w[a] result = [ ["=", 0, 0], ["<", 1, 1] @@ -124,8 +124,8 @@ describe "Diff::LCS.traverse_balanced" do end describe "sequences %w(z a) & %w(a)" do - s1 = %w(z a) - s2 = %w(a) + s1 = %w[z a] + s2 = %w[a] result = [ ["<", 0, 0], ["=", 1, 0] @@ -136,8 +136,8 @@ describe "Diff::LCS.traverse_balanced" do end describe "sequences %w(a b c) & %w(x y z)" do - s1 = %w(a b c) - s2 = %w(x y z) + s1 = %w[a b c] + s2 = %w[x y z] result = [ ["!", 0, 0], ["!", 1, 1], @@ -149,7 +149,7 @@ describe "Diff::LCS.traverse_balanced" do end describe "sequences %w(abcd efgh ijkl mnoopqrstuvwxyz) & []" do - s1 = %w(abcd efgh ijkl mnopqrstuvwxyz) + s1 = %w[abcd efgh ijkl mnopqrstuvwxyz] s2 = [] result = [ ["<", 0, 0], -- cgit v1.2.1 From 089f932537a540af9c27dd03caf30eff6b4a0306 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 10:50:34 -0500 Subject: standardrb --only Layout/ExtraSpacing --fix and ignore --- lib/diff/lcs/htmldiff.rb | 6 ++--- lib/diff/lcs/hunk.rb | 8 +++---- lib/diff/lcs/internals.rb | 2 +- lib/diff/lcs/ldiff.rb | 6 ++--- spec/change_spec.rb | 52 +++++++++++++++++++++--------------------- spec/hunk_spec.rb | 4 ++-- spec/sdiff_spec.rb | 2 ++ spec/spec_helper.rb | 10 ++++++-- spec/traverse_balanced_spec.rb | 2 ++ 9 files changed, 51 insertions(+), 41 deletions(-) diff --git a/lib/diff/lcs/htmldiff.rb b/lib/diff/lcs/htmldiff.rb index 41858d5..a66c9ed 100644 --- a/lib/diff/lcs/htmldiff.rb +++ b/lib/diff/lcs/htmldiff.rb @@ -88,9 +88,9 @@ h1 { margin-left: 2em; } CSS def initialize(left, right, options = nil) - @left = left - @right = right - @options = options + @left = left + @right = right + @options = options @options = DEFAULT_OPTIONS.dup if @options.nil? end diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb index 2a9645d..3e4133d 100644 --- a/lib/diff/lcs/hunk.rb +++ b/lib/diff/lcs/hunk.rb @@ -54,8 +54,8 @@ class Diff::LCS::Hunk @start_old = a1 || (b1 - before) @start_new = b1 || (a1 + before) - @end_old = a2 || (b2 - after) - @end_new = b2 || (a2 + after) + @end_old = a2 || (b2 - after) + @end_new = b2 || (a2 + after) self.flag_context = flag_context end @@ -183,7 +183,7 @@ class Diff::LCS::Hunk @blocks.each do |block| block.remove.each do |item| - op = item.action.to_s # - + op = item.action.to_s # - offset = item.position - lo + num_added outlist[offset][0, 1] = encode(op) num_removed += 1 @@ -195,7 +195,7 @@ class Diff::LCS::Hunk end block.insert.each do |item| - op = item.action.to_s # + + op = item.action.to_s # + offset = item.position - @start_new + num_removed outlist[offset, 0] = encode(op) + @data_new[item.position].chomp num_added += 1 diff --git a/lib/diff/lcs/internals.rb b/lib/diff/lcs/internals.rb index 2ed713f..0454c8a 100644 --- a/lib/diff/lcs/internals.rb +++ b/lib/diff/lcs/internals.rb @@ -63,7 +63,7 @@ class << Diff::LCS::Internals b_matches = position_hash(b, b_start..b_finish) thresh = [] - links = [] + links = [] string = a.kind_of?(String) (a_start..a_finish).each do |i| diff --git a/lib/diff/lcs/ldiff.rb b/lib/diff/lcs/ldiff.rb index c4a60d0..2cbd704 100644 --- a/lib/diff/lcs/ldiff.rb +++ b/lib/diff/lcs/ldiff.rb @@ -34,14 +34,14 @@ class << Diff::LCS::Ldiff "Displays a context diff with LINES lines", "of context. Default 3 lines." ) do |ctx| @format = :context - @lines = ctx || 3 + @lines = ctx || 3 end o.on( "-u", "-U", "--unified [LINES]", Integer, "Displays a unified diff with LINES lines", "of context. Default 3 lines." ) do |ctx| @format = :unified - @lines = ctx || 3 + @lines = ctx || 3 end o.on("-e", "Creates an 'ed' script to change", "oldfile to newfile.") do |_ctx| @format = :ed @@ -81,7 +81,7 @@ class << Diff::LCS::Ldiff # Defaults are for old-style diff @format ||= :old - @lines ||= 0 + @lines ||= 0 file_old, file_new = *ARGV diff --git a/spec/change_spec.rb b/spec/change_spec.rb index 237f621..42533ae 100644 --- a/spec/change_spec.rb +++ b/spec/change_spec.rb @@ -5,62 +5,62 @@ require "spec_helper" describe Diff::LCS::Change do describe "an add" do subject { described_class.new("+", 0, "element") } - it { should_not be_deleting } - it { should be_adding } - it { should_not be_unchanged } - it { should_not be_changed } + it { should_not be_deleting } + it { should be_adding } + it { should_not be_unchanged } + it { should_not be_changed } it { should_not be_finished_a } it { should_not be_finished_b } end describe "a delete" do subject { described_class.new("-", 0, "element") } - it { should be_deleting } - it { should_not be_adding } - it { should_not be_unchanged } - it { should_not be_changed } + it { should be_deleting } + it { should_not be_adding } + it { should_not be_unchanged } + it { should_not be_changed } it { should_not be_finished_a } it { should_not be_finished_b } end describe "an unchanged" do subject { described_class.new("=", 0, "element") } - it { should_not be_deleting } - it { should_not be_adding } - it { should be_unchanged } - it { should_not be_changed } + it { should_not be_deleting } + it { should_not be_adding } + it { should be_unchanged } + it { should_not be_changed } it { should_not be_finished_a } it { should_not be_finished_b } end describe "a changed" do subject { described_class.new("!", 0, "element") } - it { should_not be_deleting } - it { should_not be_adding } - it { should_not be_unchanged } - it { should be_changed } + it { should_not be_deleting } + it { should_not be_adding } + it { should_not be_unchanged } + it { should be_changed } it { should_not be_finished_a } it { should_not be_finished_b } end describe "a finished_a" do subject { described_class.new(">", 0, "element") } - it { should_not be_deleting } - it { should_not be_adding } - it { should_not be_unchanged } - it { should_not be_changed } - it { should be_finished_a } + it { should_not be_deleting } + it { should_not be_adding } + it { should_not be_unchanged } + it { should_not be_changed } + it { should be_finished_a } it { should_not be_finished_b } end describe "a finished_b" do subject { described_class.new("<", 0, "element") } - it { should_not be_deleting } - it { should_not be_adding } - it { should_not be_unchanged } - it { should_not be_changed } + it { should_not be_deleting } + it { should_not be_adding } + it { should_not be_unchanged } + it { should_not be_changed } it { should_not be_finished_a } - it { should be_finished_b } + it { should be_finished_b } end describe "as array" do diff --git a/spec/hunk_spec.rb b/spec/hunk_spec.rb index 339f4ab..c52a6fd 100644 --- a/spec/hunk_spec.rb +++ b/spec/hunk_spec.rb @@ -8,8 +8,8 @@ if String.method_defined?(:encoding) describe Diff::LCS::Hunk do let(:old_data) { ["Tu a un carté avec {count} itéms".encode("UTF-16LE")] } let(:new_data) { ["Tu a un carte avec {count} items".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) } + 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 = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp diff --git a/spec/sdiff_spec.rb b/spec/sdiff_spec.rb index 9750519..aded301 100644 --- a/spec/sdiff_spec.rb +++ b/spec/sdiff_spec.rb @@ -27,6 +27,7 @@ describe "Diff::LCS.sdiff" do let(:s1) { %w[abc def yyy xxx ghi jkl] } let(:s2) { %w[abc dxf xxx ghi jkl] } let(:result) { + # standard:disable Layout/ExtraSpacing [ ["=", [0, "abc"], [0, "abc"]], ["!", [1, "def"], [1, "dxf"]], @@ -35,6 +36,7 @@ describe "Diff::LCS.sdiff" do ["=", [4, "ghi"], [3, "ghi"]], ["=", [5, "jkl"], [4, "jkl"]] ] + # standard:enable Layout/ExtraSpacing } it_has_behavior "compare sequences correctly" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index af5ec23..55a7773 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -32,8 +32,8 @@ if ENV["COVERAGE"] end end -file = Pathname.new(__FILE__).expand_path -path = file.parent +file = Pathname.new(__FILE__).expand_path +path = file.parent parent = path.parent $:.unshift parent.join("lib") @@ -107,6 +107,7 @@ module Diff::LCS::SpecHelper end def correct_forward_diff + # standard:disable Layout/ExtraSpacing [ [ ["-", 0, "a"] @@ -129,9 +130,11 @@ module Diff::LCS::SpecHelper ["+", 11, "t"] ] ] + # standard:enable Layout/ExtraSpacing end def correct_backward_diff + # standard:disable Layout/ExtraSpacing [ [ ["+", 0, "a"] @@ -154,9 +157,11 @@ module Diff::LCS::SpecHelper ["-", 11, "t"] ] ] + # standard:enable Layout/ExtraSpacing end def correct_forward_sdiff + # standard:disable Layout/ExtraSpacing [ ["-", [0, "a"], [0, nil]], ["=", [1, "b"], [0, "b"]], @@ -172,6 +177,7 @@ module Diff::LCS::SpecHelper ["!", [9, "p"], [10, "s"]], ["+", [10, nil], [11, "t"]] ] + # standard:enable Layout/ExtraSpacing end def reverse_sdiff(forward_sdiff) diff --git a/spec/traverse_balanced_spec.rb b/spec/traverse_balanced_spec.rb index 4956acf..3a3f677 100644 --- a/spec/traverse_balanced_spec.rb +++ b/spec/traverse_balanced_spec.rb @@ -272,6 +272,7 @@ describe "Diff::LCS.traverse_balanced" do describe "strings %q(abcd efgh ijkl mnopqrstuvwxyz) & %q()" do s1 = "abcd efgh ijkl mnopqrstuvwxyz" s2 = "" + # standard:disable Layout/ExtraSpacing result = [ ["<", 0, 0], ["<", 1, 0], @@ -303,6 +304,7 @@ describe "Diff::LCS.traverse_balanced" do ["<", 27, 0], ["<", 28, 0] ] + # standard:enable Layout/ExtraSpacing it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result -- cgit v1.2.1 From f5781c06b2c297caf58c97824c77f557831094a7 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 10:54:52 -0500 Subject: ignore Layout/heredocIndentation due to old Ruby --- .standard.yml | 2 ++ Rakefile | 2 ++ lib/diff/lcs/htmldiff.rb | 6 ++++++ lib/diff/lcs/ldiff.rb | 2 ++ spec/issues_spec.rb | 4 ++++ 5 files changed, 16 insertions(+) diff --git a/.standard.yml b/.standard.yml index 4d5683c..227fe7b 100644 --- a/.standard.yml +++ b/.standard.yml @@ -2,3 +2,5 @@ parallel: true ruby_version: 2.0 ignore: - 'diff-lcs.gemspec' + - 'research/**/*' + - 'pkg/**/*' diff --git a/Rakefile b/Rakefile index 3924134..f5c4f80 100644 --- a/Rakefile +++ b/Rakefile @@ -105,6 +105,7 @@ if RUBY_VERSION >= "2.0" && RUBY_ENGINE == "ruby" end task :ruby18 do + # standard:disable Layout/HeredocIndentation puts <<-MESSAGE You are starting a barebones Ruby 1.8 docker environment. You will need to do the following: @@ -117,5 +118,6 @@ do the following: Don't forget to restore your Gemfile.lock after testing. MESSAGE + # standard:enable Layout/HeredocIndentation sh "docker run -it --rm -v #{Dir.pwd}:/root/diff-lcs bellbind/docker-ruby18-rails2 bash -l" end diff --git a/lib/diff/lcs/htmldiff.rb b/lib/diff/lcs/htmldiff.rb index a66c9ed..37bbc4a 100644 --- a/lib/diff/lcs/htmldiff.rb +++ b/lib/diff/lcs/htmldiff.rb @@ -53,6 +53,7 @@ class Diff::LCS::HTMLDiff :title => nil }.freeze + # standard:disable Layout/HeredocIndentation DEFAULT_CSS = <<-CSS body { margin: 0; } .diff @@ -86,6 +87,7 @@ pre } h1 { margin-left: 2em; } CSS + # standard:enable Layout/HeredocIndentation def initialize(left, right, options = nil) @left = left @@ -123,6 +125,7 @@ h1 { margin-left: 2em; } @left.map! do |line| CGI.escapeHTML(line.chomp) end @right.map! do |line| CGI.escapeHTML(line.chomp) end + # standard:disable Layout/HeredocIndentation @options[:output] << <<-OUTPUT @@ -137,14 +140,17 @@ h1 { margin-left: 2em; } Only in New

OUTPUT + # standard:enable Layout/HeredocIndentation callbacks = Callbacks.new(@options[:output]) Diff::LCS.traverse_sequences(@left, @right, callbacks) + # standard:disable Layout/HeredocIndentation @options[:output] << <<-OUTPUT
OUTPUT + # standard:enable Layout/HeredocIndentation end end diff --git a/lib/diff/lcs/ldiff.rb b/lib/diff/lcs/ldiff.rb index 2cbd704..59625aa 100644 --- a/lib/diff/lcs/ldiff.rb +++ b/lib/diff/lcs/ldiff.rb @@ -5,6 +5,7 @@ require "ostruct" require "diff/lcs/hunk" module Diff::LCS::Ldiff #:nodoc: + # standard:disable Layout/HeredocIndentation BANNER = <<-COPYRIGHT ldiff #{Diff::LCS::VERSION} Copyright 2004-2019 Austin Ziegler @@ -16,6 +17,7 @@ ldiff #{Diff::LCS::VERSION} the terms of the GPL version 2 (or later), the Perl Artistic licence, or the MIT licence. COPYRIGHT + # standard:enable Layout/HeredocIndentation end class << Diff::LCS::Ldiff diff --git a/spec/issues_spec.rb b/spec/issues_spec.rb index abe524e..ec2abeb 100644 --- a/spec/issues_spec.rb +++ b/spec/issues_spec.rb @@ -68,6 +68,7 @@ describe "Diff::LCS Issues" do describe "issue #60" do it "should produce unified output with correct context" do + # standard:disable Layout/HeredocIndentation old_data = <<-DATA_OLD.strip.split("\n").map(&:chomp) { "name": "x", @@ -93,6 +94,7 @@ describe "Diff::LCS Issues" do + "description": "lo" } EXPECTED + # standard:enable Layout/HeredocIndentation end end @@ -133,6 +135,7 @@ describe "Diff::LCS Issues" do "recipe[q::new]", "recipe[r::new]" ] + # standard:disable Layout/HeredocIndentation expect(diff_lines(old_data, new_data)).to eq(<<-EODIFF) @@ -1,5 +1,4 @@ recipe[a::default] @@ -149,6 +152,7 @@ describe "Diff::LCS Issues" do +recipe[q::new] +recipe[r::new] EODIFF + # standard:enable Layout/HeredocIndentation end end end -- cgit v1.2.1 From 22303f04b44d97455b5c862176d2d93c02a2b2ba Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 10:58:14 -0500 Subject: Fix Style/AndOr --- lib/diff/lcs.rb | 16 ++++++++-------- lib/diff/lcs/change.rb | 4 ++-- lib/diff/lcs/hunk.rb | 2 +- lib/diff/lcs/internals.rb | 8 ++++---- lib/diff/lcs/ldiff.rb | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/diff/lcs.rb b/lib/diff/lcs.rb index e6d817b..bd0147e 100644 --- a/lib/diff/lcs.rb +++ b/lib/diff/lcs.rb @@ -326,10 +326,10 @@ class << Diff::LCS # The last entry (if any) processed was a match. +ai+ and +bj+ point just # past the last matching lines in their sequences. - while (ai < a_size) or (bj < b_size) + while (ai < a_size) || (bj < b_size) # last A? - if ai == a_size and bj < b_size - if callbacks.respond_to?(:finished_a) and !run_finished_a + if ai == a_size && bj < b_size + if callbacks.respond_to?(:finished_a) && !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) @@ -350,8 +350,8 @@ class << Diff::LCS end # last B? - if bj == b_size and ai < a_size - if callbacks.respond_to?(:finished_b) and !run_finished_b + if bj == b_size && ai < a_size + if callbacks.respond_to?(:finished_b) && !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) @@ -485,7 +485,7 @@ class << Diff::LCS # Find next match indices +ma+ and +mb+ loop do ma += 1 - break unless ma < matches.size and matches[ma].nil? + break unless ma < matches.size && matches[ma].nil? end break if ma >= matches.size # end of matches? @@ -493,7 +493,7 @@ class << Diff::LCS mb = matches[ma] # Change(seq2) - while (ai < ma) or (bj < mb) + while (ai < ma) || (bj < mb) ax = string ? seq1[ai, 1] : seq1[ai] bx = string ? seq2[bj, 1] : seq2[bj] @@ -539,7 +539,7 @@ class << Diff::LCS bj += 1 end - while (ai < a_size) or (bj < b_size) + while (ai < a_size) || (bj < b_size) ax = string ? seq1[ai, 1] : seq1[ai] bx = string ? seq2[bj, 1] : seq2[bj] diff --git a/lib/diff/lcs/change.rb b/lib/diff/lcs/change.rb index a82f3e6..f20d804 100644 --- a/lib/diff/lcs/change.rb +++ b/lib/diff/lcs/change.rb @@ -115,8 +115,8 @@ class Diff::LCS::ContextChange < Diff::LCS::Change @action, @old_position, @old_element, @new_position, @new_element = *args 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 + fail "Invalid (Old) Position Type" unless @old_position.nil? || @old_position.kind_of?(IntClass) + fail "Invalid (New) Position Type" unless @new_position.nil? || @new_position.kind_of?(IntClass) end def to_a diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb index 3e4133d..eccfc7a 100644 --- a/lib/diff/lcs/hunk.rb +++ b/lib/diff/lcs/hunk.rb @@ -70,7 +70,7 @@ class Diff::LCS::Hunk attr_accessor :flag_context # rubocop:disable Layout/EmptyLinesAroundAttributeAccessor undef :flag_context= def flag_context=(context) #:nodoc: # rubocop:disable Lint/DuplicateMethods - return if context.nil? or context.zero? + return if context.nil? || context.zero? add_start = context > @start_old ? @start_old : context diff --git a/lib/diff/lcs/internals.rb b/lib/diff/lcs/internals.rb index 0454c8a..b968917 100644 --- a/lib/diff/lcs/internals.rb +++ b/lib/diff/lcs/internals.rb @@ -45,14 +45,14 @@ class << Diff::LCS::Internals vector = [] # Collect 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) && (b_start <= b_finish) && (a[a_start] == b[b_start]) vector[a_start] = b_start a_start += 1 b_start += 1 end # 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) && (b_start <= b_finish) && (a[a_finish] == b[b_finish]) vector[a_finish] = b_finish a_finish -= 1 b_finish -= 1 @@ -75,7 +75,7 @@ class << Diff::LCS::Internals # it may have an optimization purpose # An attempt to remove it: https://github.com/halostatue/diff-lcs/pull/72 # Why it is reintroduced: https://github.com/halostatue/diff-lcs/issues/78 - if k and (thresh[k] > j) and (thresh[k - 1] < j) + if k && (thresh[k] > j) && (thresh[k - 1] < j) thresh[k] = j else k = replace_next_larger(thresh, j, k) @@ -251,7 +251,7 @@ enumerable as either source or destination value." # This operation preserves the sort order. def replace_next_larger(enum, value, last_index = nil) # Off the end? - if enum.empty? or (value > enum[-1]) + if enum.empty? || (value > enum[-1]) enum << value return enum.size - 1 end diff --git a/lib/diff/lcs/ldiff.rb b/lib/diff/lcs/ldiff.rb index 59625aa..1896203 100644 --- a/lib/diff/lcs/ldiff.rb +++ b/lib/diff/lcs/ldiff.rb @@ -130,7 +130,7 @@ class << Diff::LCS::Ldiff return 1 end - if (@format == :unified) or (@format == :context) + if (@format == :unified) || (@format == :context) ft = File.stat(file_old).mtime.localtime.strftime("%Y-%m-%d %H:%M:%S.000000000 %z") output << "#{char_old} #{file_old}\t#{ft}\n" ft = File.stat(file_new).mtime.localtime.strftime("%Y-%m-%d %H:%M:%S.000000000 %z") @@ -152,7 +152,7 @@ class << Diff::LCS::Ldiff file_length_difference = hunk.file_length_difference next unless oldhunk - next if @lines.positive? and hunk.merge(oldhunk) + next if @lines.positive? && hunk.merge(oldhunk) output << oldhunk.diff(@format) output << "\n" if @format == :unified -- cgit v1.2.1 From 5da19290c4b33f579f3b176192b7b15c151bdd00 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 11:02:38 -0500 Subject: Fix :yields: directive for rdoc --- lib/diff/lcs.rb | 10 +++++----- lib/diff/lcs/callbacks.rb | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/diff/lcs.rb b/lib/diff/lcs.rb index bd0147e..db2b03d 100644 --- a/lib/diff/lcs.rb +++ b/lib/diff/lcs.rb @@ -67,7 +67,7 @@ module Diff::LCS # rubocop:disable Style/Documentation # identically for key purposes. That is: # # O.new('a').eql?(O.new('a')) == true - def lcs(other, &block) #:yields self[i] if there are matched subsequences: + def lcs(other, &block) #:yields: self[i] if there are matched subsequences Diff::LCS.lcs(self, other, &block) end @@ -141,7 +141,7 @@ module Diff::LCS # rubocop:disable Style/Documentation end class << Diff::LCS - def lcs(seq1, seq2, &block) #:yields seq1[i] for each matched: + def lcs(seq1, seq2, &block) #:yields: seq1[i] for each matched matches = Diff::LCS::Internals.lcs(seq1, seq2) ret = [] string = seq1.kind_of? String @@ -165,7 +165,7 @@ class << Diff::LCS # Class argument is provided for +callbacks+, #diff will attempt to # 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: + def diff(seq1, seq2, callbacks = nil, &block) # :yields: diff changes diff_traversal(:diff, seq1, seq2, callbacks || Diff::LCS::DiffCallbacks, &block) end @@ -197,7 +197,7 @@ class << Diff::LCS # # insert # end # end - def sdiff(seq1, seq2, callbacks = nil, &block) #:yields diff changes: + def sdiff(seq1, seq2, callbacks = nil, &block) #:yields: diff changes diff_traversal(:sdiff, seq1, seq2, callbacks || Diff::LCS::SDiffCallbacks, &block) end @@ -282,7 +282,7 @@ class << Diff::LCS # callbacks#discard_b 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) #: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) diff --git a/lib/diff/lcs/callbacks.rb b/lib/diff/lcs/callbacks.rb index c075327..54b3686 100644 --- a/lib/diff/lcs/callbacks.rb +++ b/lib/diff/lcs/callbacks.rb @@ -107,7 +107,7 @@ class Diff::LCS::DiffCallbacks # Returns the difference set collected during the diff process. attr_reader :diffs - def initialize # :yields self: + def initialize # :yields: self @hunk = [] @diffs = [] @@ -302,7 +302,7 @@ class Diff::LCS::SDiffCallbacks # Returns the difference set collected during the diff process. attr_reader :diffs - def initialize #:yields self: + def initialize #:yields: self @diffs = [] yield self if block_given? end -- cgit v1.2.1 From 396a82c4d56bc0067c86de7cd32a4ae75f292c41 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 11:03:11 -0500 Subject: standardrb --only Layout/LeadingCommentSpace --fix --- Rakefile | 6 +++--- lib/diff/lcs.rb | 10 +++++----- lib/diff/lcs/callbacks.rb | 2 +- lib/diff/lcs/htmldiff.rb | 4 ++-- lib/diff/lcs/hunk.rb | 6 +++--- lib/diff/lcs/ldiff.rb | 10 +++++----- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Rakefile b/Rakefile index f5c4f80..9aa8d42 100644 --- a/Rakefile +++ b/Rakefile @@ -46,19 +46,19 @@ Hoe.plugin :gemspec2 Hoe.plugin :git if RUBY_VERSION < "1.9" - class Array #:nodoc: + class Array # :nodoc: def to_h Hash[*flatten(1)] end end - class Gem::Specification #:nodoc: + class Gem::Specification # :nodoc: def metadata=(*); end def default_value(*); end end - class Object #:nodoc: + class Object # :nodoc: def caller_locations(*) [] end diff --git a/lib/diff/lcs.rb b/lib/diff/lcs.rb index db2b03d..031e2d7 100644 --- a/lib/diff/lcs.rb +++ b/lib/diff/lcs.rb @@ -67,7 +67,7 @@ module Diff::LCS # rubocop:disable Style/Documentation # identically for key purposes. That is: # # O.new('a').eql?(O.new('a')) == true - def lcs(other, &block) #:yields: self[i] if there are matched subsequences + def lcs(other, &block) # :yields: self[i] if there are matched subsequences Diff::LCS.lcs(self, other, &block) end @@ -141,7 +141,7 @@ module Diff::LCS # rubocop:disable Style/Documentation end class << Diff::LCS - def lcs(seq1, seq2, &block) #:yields: seq1[i] for each matched + def lcs(seq1, seq2, &block) # :yields: seq1[i] for each matched matches = Diff::LCS::Internals.lcs(seq1, seq2) ret = [] string = seq1.kind_of? String @@ -197,7 +197,7 @@ class << Diff::LCS # # insert # end # end - def sdiff(seq1, seq2, callbacks = nil, &block) #:yields: diff changes + def sdiff(seq1, seq2, callbacks = nil, &block) # :yields: diff changes diff_traversal(:sdiff, seq1, seq2, callbacks || Diff::LCS::SDiffCallbacks, &block) end @@ -282,7 +282,7 @@ class << Diff::LCS # callbacks#discard_b 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) #: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) @@ -576,7 +576,7 @@ class << Diff::LCS end end - PATCH_MAP = { #:nodoc: + PATCH_MAP = { # :nodoc: :patch => { "+" => "+", "-" => "-", "!" => "!", "=" => "=" }.freeze, :unpatch => { "+" => "-", "-" => "+", "!" => "!", "=" => "=" }.freeze }.freeze diff --git a/lib/diff/lcs/callbacks.rb b/lib/diff/lcs/callbacks.rb index 54b3686..cdda2dd 100644 --- a/lib/diff/lcs/callbacks.rb +++ b/lib/diff/lcs/callbacks.rb @@ -302,7 +302,7 @@ class Diff::LCS::SDiffCallbacks # Returns the difference set collected during the diff process. attr_reader :diffs - def initialize #:yields: self + def initialize # :yields: self @diffs = [] yield self if block_given? end diff --git a/lib/diff/lcs/htmldiff.rb b/lib/diff/lcs/htmldiff.rb index 37bbc4a..7eab41d 100644 --- a/lib/diff/lcs/htmldiff.rb +++ b/lib/diff/lcs/htmldiff.rb @@ -5,11 +5,11 @@ require "cgi" # Produce a simple HTML diff view. class Diff::LCS::HTMLDiff class << self - attr_accessor :can_expand_tabs #:nodoc: + attr_accessor :can_expand_tabs # :nodoc: end self.can_expand_tabs = true - class Callbacks #:nodoc: + class Callbacks # :nodoc: attr_accessor :output attr_accessor :match_class attr_accessor :only_a_class diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb index eccfc7a..d886ba2 100644 --- a/lib/diff/lcs/hunk.rb +++ b/lib/diff/lcs/hunk.rb @@ -6,8 +6,8 @@ require "diff/lcs/block" # each block. (So if we're not using context, every hunk will contain one # block.) Used in the diff program (bin/ldiff). class Diff::LCS::Hunk - OLD_DIFF_OP_ACTION = { "+" => "a", "-" => "d", "!" => "c" }.freeze #:nodoc: - ED_DIFF_OP_ACTION = { "+" => "a", "-" => "d", "!" => "c" }.freeze #:nodoc: + OLD_DIFF_OP_ACTION = { "+" => "a", "-" => "d", "!" => "c" }.freeze # :nodoc: + ED_DIFF_OP_ACTION = { "+" => "a", "-" => "d", "!" => "c" }.freeze # :nodoc: private_constant :OLD_DIFF_OP_ACTION, :ED_DIFF_OP_ACTION if respond_to?(:private_constant) @@ -69,7 +69,7 @@ class Diff::LCS::Hunk # to this hunk. attr_accessor :flag_context # rubocop:disable Layout/EmptyLinesAroundAttributeAccessor undef :flag_context= - def flag_context=(context) #:nodoc: # rubocop:disable Lint/DuplicateMethods + def flag_context=(context) # :nodoc: # rubocop:disable Lint/DuplicateMethods return if context.nil? || context.zero? add_start = context > @start_old ? @start_old : context diff --git a/lib/diff/lcs/ldiff.rb b/lib/diff/lcs/ldiff.rb index 1896203..961458c 100644 --- a/lib/diff/lcs/ldiff.rb +++ b/lib/diff/lcs/ldiff.rb @@ -4,7 +4,7 @@ require "optparse" require "ostruct" require "diff/lcs/hunk" -module Diff::LCS::Ldiff #:nodoc: +module Diff::LCS::Ldiff # :nodoc: # standard:disable Layout/HeredocIndentation BANNER = <<-COPYRIGHT ldiff #{Diff::LCS::VERSION} @@ -21,11 +21,11 @@ ldiff #{Diff::LCS::VERSION} end class << Diff::LCS::Ldiff - attr_reader :format, :lines #:nodoc: - attr_reader :file_old, :file_new #:nodoc: - attr_reader :data_old, :data_new #:nodoc: + attr_reader :format, :lines # :nodoc: + 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| -- cgit v1.2.1 From 927b9b3c935f08a1611059e81b411c2ee2ff9724 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 11:13:21 -0500 Subject: Ignore Style/HashSyntax --- Rakefile | 2 ++ lib/diff/lcs.rb | 2 ++ lib/diff/lcs/htmldiff.rb | 2 ++ spec/issues_spec.rb | 2 ++ spec/ldiff_spec.rb | 2 ++ spec/spec_helper.rb | 2 ++ spec/traverse_sequences_spec.rb | 2 +- 7 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 9aa8d42..da1e041 100644 --- a/Rakefile +++ b/Rakefile @@ -91,8 +91,10 @@ end Rake::Task["spec"].actions.uniq! { |a| a.source_location } +# standard:disable Style/HashSyntax task :default => :spec unless Rake::Task["default"].prereqs.include?("spec") task :test => :spec unless Rake::Task["test"].prereqs.include?("spec") +# standard:enable Style/HashSyntax if RUBY_VERSION >= "2.0" && RUBY_ENGINE == "ruby" namespace :spec do diff --git a/lib/diff/lcs.rb b/lib/diff/lcs.rb index 031e2d7..4461af0 100644 --- a/lib/diff/lcs.rb +++ b/lib/diff/lcs.rb @@ -576,10 +576,12 @@ class << Diff::LCS end end + # standard:disable Style/HashSyntax PATCH_MAP = { # :nodoc: :patch => { "+" => "+", "-" => "-", "!" => "!", "=" => "=" }.freeze, :unpatch => { "+" => "-", "-" => "+", "!" => "!", "=" => "=" }.freeze }.freeze + # standard:enable Style/HashSyntax # Applies a +patchset+ to the sequence +src+ according to the +direction+ # (:patch or :unpatch), producing a new sequence. diff --git a/lib/diff/lcs/htmldiff.rb b/lib/diff/lcs/htmldiff.rb index 7eab41d..a57dd51 100644 --- a/lib/diff/lcs/htmldiff.rb +++ b/lib/diff/lcs/htmldiff.rb @@ -46,12 +46,14 @@ class Diff::LCS::HTMLDiff end end + # standard:disable Style/HashSyntax DEFAULT_OPTIONS = { :expand_tabs => nil, :output => nil, :css => nil, :title => nil }.freeze + # standard:enable Style/HashSyntax # standard:disable Layout/HeredocIndentation DEFAULT_CSS = <<-CSS diff --git a/spec/issues_spec.rb b/spec/issues_spec.rb index ec2abeb..26460d3 100644 --- a/spec/issues_spec.rb +++ b/spec/issues_spec.rb @@ -58,11 +58,13 @@ describe "Diff::LCS Issues" do describe "issue #57" do it "should fail with a correct error" do + # standard:disable Style/HashSyntax expect { actual = { :category => "app.rack.request" } expected = { :category => "rack.middleware", :title => "Anonymous Middleware" } expect(actual).to eq(expected) }.to raise_error(RSpec::Expectations::ExpectationNotMetError) + # standard:enable Style/HashSyntax end end diff --git a/spec/ldiff_spec.rb b/spec/ldiff_spec.rb index e5df039..4a08c43 100644 --- a/spec/ldiff_spec.rb +++ b/spec/ldiff_spec.rb @@ -5,6 +5,7 @@ require "spec_helper" RSpec.describe "bin/ldiff" do include CaptureSubprocessIO + # standard:disable Style/HashSyntax fixtures = [ { :name => "output.diff", :left => "aX", :right => "bXaX" }, { :name => "output.diff.chef", :left => "old-chef", :right => "new-chef" }, @@ -14,6 +15,7 @@ RSpec.describe "bin/ldiff" do fixture[:flag] = flag fixture } + # standard:enable Style/HashSyntax def self.test_ldiff(fixture) desc = [ diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 55a7773..acca2ef 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -374,5 +374,7 @@ end RSpec.configure do |conf| conf.include Diff::LCS::SpecHelper conf.alias_it_should_behave_like_to :it_has_behavior, "has behavior:" + # standard:disable Style/HashSyntax conf.filter_run_excluding :broken => true + # standard:enable Style/HashSyntax end diff --git a/spec/traverse_sequences_spec.rb b/spec/traverse_sequences_spec.rb index 3bad13e..ed40100 100644 --- a/spec/traverse_sequences_spec.rb +++ b/spec/traverse_sequences_spec.rb @@ -55,7 +55,7 @@ describe "Diff::LCS.traverse_sequences" 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" do expect(@callback.discards_a).to be_empty end -- cgit v1.2.1 From 99af1369a86b38585f6c63e9d50ac7040932916a Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 11:14:10 -0500 Subject: standardrb --only Style/ClassCheck --fix --- lib/diff/lcs.rb | 8 ++++---- lib/diff/lcs/change.rb | 6 +++--- lib/diff/lcs/internals.rb | 8 ++++---- spec/spec_helper.rb | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/diff/lcs.rb b/lib/diff/lcs.rb index 4461af0..2214240 100644 --- a/lib/diff/lcs.rb +++ b/lib/diff/lcs.rb @@ -144,7 +144,7 @@ class << Diff::LCS def lcs(seq1, seq2, &block) # :yields: seq1[i] for each matched matches = Diff::LCS::Internals.lcs(seq1, seq2) ret = [] - string = seq1.kind_of? String + string = seq1.is_a? String matches.each_index do |i| next if matches[i].nil? @@ -287,7 +287,7 @@ class << Diff::LCS matches = Diff::LCS::Internals.lcs(seq1, seq2) run_finished_a = run_finished_b = false - string = seq1.kind_of?(String) + string = seq1.is_a?(String) a_size = seq1.size b_size = seq2.size @@ -478,7 +478,7 @@ class << Diff::LCS b_size = seq2.size ai = bj = mb = 0 ma = -1 - string = seq1.kind_of?(String) + string = seq1.is_a?(String) # Process all the lines in the match vector. loop do @@ -629,7 +629,7 @@ class << Diff::LCS return src.respond_to?(:dup) ? src.dup : src unless has_changes - string = src.kind_of?(String) + string = src.is_a?(String) # Start with a new empty type of the source's class res = src.class.new diff --git a/lib/diff/lcs/change.rb b/lib/diff/lcs/change.rb index f20d804..cebd3af 100644 --- a/lib/diff/lcs/change.rb +++ b/lib/diff/lcs/change.rb @@ -28,7 +28,7 @@ class Diff::LCS::Change @action, @position, @element = *args fail "Invalid Change Action '#{@action}'" unless Diff::LCS::Change.valid_action?(@action) - fail "Invalid Position Type" unless @position.kind_of? IntClass + fail "Invalid Position Type" unless @position.is_a? IntClass end def inspect(*_args) @@ -115,8 +115,8 @@ class Diff::LCS::ContextChange < Diff::LCS::Change @action, @old_position, @old_element, @new_position, @new_element = *args fail "Invalid Change Action '#{@action}'" unless Diff::LCS::Change.valid_action?(@action) - fail "Invalid (Old) Position Type" unless @old_position.nil? || @old_position.kind_of?(IntClass) - fail "Invalid (New) Position Type" unless @new_position.nil? || @new_position.kind_of?(IntClass) + fail "Invalid (Old) Position Type" unless @old_position.nil? || @old_position.is_a?(IntClass) + fail "Invalid (New) Position Type" unless @new_position.nil? || @new_position.is_a?(IntClass) end def to_a diff --git a/lib/diff/lcs/internals.rb b/lib/diff/lcs/internals.rb index b968917..8a9160a 100644 --- a/lib/diff/lcs/internals.rb +++ b/lib/diff/lcs/internals.rb @@ -13,7 +13,7 @@ class << Diff::LCS if block callbacks.diffs.map do |hunk| - if hunk.kind_of? Array + if hunk.is_a? Array hunk.map { |hunk_block| block[hunk_block] } else block[hunk] @@ -64,7 +64,7 @@ class << Diff::LCS::Internals thresh = [] links = [] - string = a.kind_of?(String) + string = a.is_a?(String) (a_start..a_finish).each do |i| ai = string ? a[i, 1] : a[i] @@ -145,7 +145,7 @@ class << Diff::LCS::Internals # Diff::LCS::Change as its source, as an array will cause the creation # of one of the above. def intuit_diff_direction(src, patchset, limit = nil) - string = src.kind_of?(String) + string = src.is_a?(String) count = left_match = left_miss = right_match = right_miss = 0 patchset.each do |change| @@ -296,7 +296,7 @@ enumerable as either source or destination value." # positions it occupies in the Enumerable, optionally restricted to the # elements specified in the range of indexes specified by +interval+. def position_hash(enum, interval) - string = enum.kind_of?(String) + string = enum.is_a?(String) hash = Hash.new { |h, k| h[k] = [] } interval.each do |i| k = string ? enum[i, 1] : enum[i] diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index acca2ef..9e3fea0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -201,7 +201,7 @@ module Diff::LCS::SpecHelper def format_diffs(diffs) diffs.map { |e| - if e.kind_of?(Array) + if e.is_a?(Array) e.map { |f| f.to_a.join }.join(", ") else e.to_a.join -- cgit v1.2.1 From 63bb988f761da3fa061c9e3b5d13785477bf44c5 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 11:14:33 -0500 Subject: standardrb --only Layout/SpaceInsideHashLiteralBraces --fix --- lib/diff/lcs.rb | 4 ++-- lib/diff/lcs/hunk.rb | 4 ++-- spec/issues_spec.rb | 4 ++-- spec/ldiff_spec.rb | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/diff/lcs.rb b/lib/diff/lcs.rb index 2214240..77b508f 100644 --- a/lib/diff/lcs.rb +++ b/lib/diff/lcs.rb @@ -578,8 +578,8 @@ class << Diff::LCS # standard:disable Style/HashSyntax PATCH_MAP = { # :nodoc: - :patch => { "+" => "+", "-" => "-", "!" => "!", "=" => "=" }.freeze, - :unpatch => { "+" => "-", "-" => "+", "!" => "!", "=" => "=" }.freeze + :patch => {"+" => "+", "-" => "-", "!" => "!", "=" => "="}.freeze, + :unpatch => {"+" => "-", "-" => "+", "!" => "!", "=" => "="}.freeze }.freeze # standard:enable Style/HashSyntax diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb index d886ba2..9ff3638 100644 --- a/lib/diff/lcs/hunk.rb +++ b/lib/diff/lcs/hunk.rb @@ -6,8 +6,8 @@ require "diff/lcs/block" # each block. (So if we're not using context, every hunk will contain one # block.) Used in the diff program (bin/ldiff). class Diff::LCS::Hunk - OLD_DIFF_OP_ACTION = { "+" => "a", "-" => "d", "!" => "c" }.freeze # :nodoc: - ED_DIFF_OP_ACTION = { "+" => "a", "-" => "d", "!" => "c" }.freeze # :nodoc: + OLD_DIFF_OP_ACTION = {"+" => "a", "-" => "d", "!" => "c"}.freeze # :nodoc: + ED_DIFF_OP_ACTION = {"+" => "a", "-" => "d", "!" => "c"}.freeze # :nodoc: private_constant :OLD_DIFF_OP_ACTION, :ED_DIFF_OP_ACTION if respond_to?(:private_constant) diff --git a/spec/issues_spec.rb b/spec/issues_spec.rb index 26460d3..3451d71 100644 --- a/spec/issues_spec.rb +++ b/spec/issues_spec.rb @@ -60,8 +60,8 @@ describe "Diff::LCS Issues" do it "should fail with a correct error" do # standard:disable Style/HashSyntax expect { - actual = { :category => "app.rack.request" } - expected = { :category => "rack.middleware", :title => "Anonymous Middleware" } + actual = {:category => "app.rack.request"} + expected = {:category => "rack.middleware", :title => "Anonymous Middleware"} expect(actual).to eq(expected) }.to raise_error(RSpec::Expectations::ExpectationNotMetError) # standard:enable Style/HashSyntax diff --git a/spec/ldiff_spec.rb b/spec/ldiff_spec.rb index 4a08c43..cf89ada 100644 --- a/spec/ldiff_spec.rb +++ b/spec/ldiff_spec.rb @@ -7,9 +7,9 @@ RSpec.describe "bin/ldiff" do # standard:disable Style/HashSyntax fixtures = [ - { :name => "output.diff", :left => "aX", :right => "bXaX" }, - { :name => "output.diff.chef", :left => "old-chef", :right => "new-chef" }, - { :name => "output.diff.chef2", :left => "old-chef2", :right => "new-chef2" } + {:name => "output.diff", :left => "aX", :right => "bXaX"}, + {:name => "output.diff.chef", :left => "old-chef", :right => "new-chef"}, + {:name => "output.diff.chef2", :left => "old-chef2", :right => "new-chef2"} ].product([nil, "-e", "-f", "-c", "-u"]).map { |(fixture, flag)| fixture = fixture.dup fixture[:flag] = flag -- cgit v1.2.1 From dca29cd3a74035df6d462f7d0def64e991bc84fc Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 11:15:03 -0500 Subject: standardrb --only Style/EmptyMethod --fix --- Rakefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index da1e041..8179e81 100644 --- a/Rakefile +++ b/Rakefile @@ -53,9 +53,11 @@ if RUBY_VERSION < "1.9" end class Gem::Specification # :nodoc: - def metadata=(*); end + def metadata=(*) + end - def default_value(*); end + def default_value(*) + end end class Object # :nodoc: -- cgit v1.2.1 From 7d087cc973685105e2bc1c69dca60d719138dcbc Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 11:25:24 -0500 Subject: Clean up lint directives --- lib/diff/lcs.rb | 4 ++-- lib/diff/lcs/backports.rb | 4 ++-- lib/diff/lcs/callbacks.rb | 2 +- lib/diff/lcs/hunk.rb | 4 ++-- spec/spec_helper.rb | 8 ++------ 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/diff/lcs.rb b/lib/diff/lcs.rb index 77b508f..30385f8 100644 --- a/lib/diff/lcs.rb +++ b/lib/diff/lcs.rb @@ -1,6 +1,6 @@ # 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) # @@ -55,7 +55,7 @@ end require "diff/lcs/callbacks" require "diff/lcs/internals" -module Diff::LCS # rubocop:disable Style/Documentation +module Diff::LCS # Returns an Array containing the longest common subsequence(s) between # +self+ and +other+. See Diff::LCS#lcs. # diff --git a/lib/diff/lcs/backports.rb b/lib/diff/lcs/backports.rb index 642fc9c..3d2a768 100644 --- a/lib/diff/lcs/backports.rb +++ b/lib/diff/lcs/backports.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true unless 0.respond_to?(:positive?) - class Fixnum # rubocop:disable Lint/UnifiedInteger, Style/Documentation + class Fixnum # standard:disable Lint/UnifiedInteger def positive? - self > 0 # rubocop:disable Style/NumericPredicate + self > 0 end end end diff --git a/lib/diff/lcs/callbacks.rb b/lib/diff/lcs/callbacks.rb index cdda2dd..6fc229b 100644 --- a/lib/diff/lcs/callbacks.rb +++ b/lib/diff/lcs/callbacks.rb @@ -2,7 +2,7 @@ require "diff/lcs/change" -module Diff::LCS # rubocop:disable Style/Documentation +module Diff::LCS # 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 diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb index 9ff3638..9f596f3 100644 --- a/lib/diff/lcs/hunk.rb +++ b/lib/diff/lcs/hunk.rb @@ -67,9 +67,9 @@ class Diff::LCS::Hunk # Change the "start" and "end" fields to note that context should be added # to this hunk. - attr_accessor :flag_context # rubocop:disable Layout/EmptyLinesAroundAttributeAccessor + attr_accessor :flag_context undef :flag_context= - def flag_context=(context) # :nodoc: # rubocop:disable Lint/DuplicateMethods + def flag_context=(context) # :nodoc: # standard:disable Lint/DuplicateMethods return if context.nil? || context.zero? add_start = context > @start_old ? @start_old : context diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9e3fea0..6993912 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -106,8 +106,8 @@ module Diff::LCS::SpecHelper %w[b c e j l m] end + # standard:disable Layout/ExtraSpacing def correct_forward_diff - # standard:disable Layout/ExtraSpacing [ [ ["-", 0, "a"] @@ -130,11 +130,9 @@ module Diff::LCS::SpecHelper ["+", 11, "t"] ] ] - # standard:enable Layout/ExtraSpacing end def correct_backward_diff - # standard:disable Layout/ExtraSpacing [ [ ["+", 0, "a"] @@ -157,11 +155,9 @@ module Diff::LCS::SpecHelper ["-", 11, "t"] ] ] - # standard:enable Layout/ExtraSpacing end def correct_forward_sdiff - # standard:disable Layout/ExtraSpacing [ ["-", [0, "a"], [0, nil]], ["=", [1, "b"], [0, "b"]], @@ -177,8 +173,8 @@ module Diff::LCS::SpecHelper ["!", [9, "p"], [10, "s"]], ["+", [10, nil], [11, "t"]] ] - # standard:enable Layout/ExtraSpacing end + # standard:enable Layout/ExtraSpacing def reverse_sdiff(forward_sdiff) forward_sdiff.map { |line| -- cgit v1.2.1 From b160187f3d94f84b38faadb0726f7b0ae773d7eb Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 11:25:43 -0500 Subject: standardrb --only Style/Alias --fix --- lib/diff/lcs.rb | 4 ++-- lib/diff/lcs/change.rb | 4 ++-- lib/diff/lcs/hunk.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/diff/lcs.rb b/lib/diff/lcs.rb index 30385f8..54ef893 100644 --- a/lib/diff/lcs.rb +++ b/lib/diff/lcs.rb @@ -101,7 +101,7 @@ module Diff::LCS def patch(patchset) Diff::LCS.patch(self, patchset) end - alias unpatch patch + alias_method :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. Does no @@ -154,7 +154,7 @@ class << Diff::LCS end ret end - alias LCS lcs + alias_method :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 these diff --git a/lib/diff/lcs/change.rb b/lib/diff/lcs/change.rb index cebd3af..c86f102 100644 --- a/lib/diff/lcs/change.rb +++ b/lib/diff/lcs/change.rb @@ -39,7 +39,7 @@ class Diff::LCS::Change [@action, @position, @element] end - alias to_ary to_a + alias_method :to_ary, :to_a def self.from_a(arr) arr = arr.flatten(1) @@ -127,7 +127,7 @@ class Diff::LCS::ContextChange < Diff::LCS::Change ] end - alias to_ary to_a + alias_method :to_ary, :to_a def self.from_a(arr) Diff::LCS::Change.from_a(arr) diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb index 9f596f3..7f97a7d 100644 --- a/lib/diff/lcs/hunk.rb +++ b/lib/diff/lcs/hunk.rb @@ -102,7 +102,7 @@ class Diff::LCS::Hunk @start_new = hunk.start_new blocks.unshift(*hunk.blocks) end - alias unshift merge + alias_method :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 -- cgit v1.2.1 From a7e532ead1780f94d11bf42ac613b8428d808597 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 11:26:15 -0500 Subject: standardrb --only Style/RescueModifier --fix --- lib/diff/lcs/callbacks.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/diff/lcs/callbacks.rb b/lib/diff/lcs/callbacks.rb index 6fc229b..818c013 100644 --- a/lib/diff/lcs/callbacks.rb +++ b/lib/diff/lcs/callbacks.rb @@ -50,7 +50,11 @@ module Diff::LCS BalancedCallbacks = DefaultCallbacks def self.callbacks_for(callbacks) - callbacks.new rescue callbacks + begin + callbacks.new + rescue + callbacks + end end end -- cgit v1.2.1 From f7b3ef0aa1186f3e34c3d20684fa955cbe9fef91 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 11:28:46 -0500 Subject: standardrb --only Style/StringChars --- spec/lcs_spec.rb | 2 +- spec/traverse_sequences_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/lcs_spec.rb b/spec/lcs_spec.rb index e3643dd..c17f22f 100644 --- a/spec/lcs_spec.rb +++ b/spec/lcs_spec.rb @@ -47,7 +47,7 @@ describe Diff::LCS, ".LCS" do end it "returns %W(h e l l o) with (hello, hello)" do - expect(Diff::LCS.LCS(hello, hello)).to eq(hello.split(//)) + expect(Diff::LCS.LCS(hello, hello)).to eq(hello.chars) end it "returns hello_ary with (hello_ary, hello_ary)" do diff --git a/spec/traverse_sequences_spec.rb b/spec/traverse_sequences_spec.rb index ed40100..8e9928f 100644 --- a/spec/traverse_sequences_spec.rb +++ b/spec/traverse_sequences_spec.rb @@ -48,11 +48,11 @@ describe "Diff::LCS.traverse_sequences" do end it "has the correct LCS result on left-matches" do - expect(@callback.matched_a).to eq(hello.split(//)) + expect(@callback.matched_a).to eq(hello.chars) end it "has the correct LCS result on right-matches" do - expect(@callback.matched_b).to eq(hello.split(//)) + expect(@callback.matched_b).to eq(hello.chars) end it "has the correct skipped sequences with the left sequence" do -- cgit v1.2.1 From dce58acce9d3993b4992b2f2f7b53cdf72f9d7f8 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 11:30:59 -0500 Subject: standardrb --only Standard/BlockSingleLineBraces --fix --- lib/diff/lcs/htmldiff.rb | 8 ++++---- spec/diff_spec.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/diff/lcs/htmldiff.rb b/lib/diff/lcs/htmldiff.rb index a57dd51..325dc95 100644 --- a/lib/diff/lcs/htmldiff.rb +++ b/lib/diff/lcs/htmldiff.rb @@ -120,12 +120,12 @@ h1 { margin-left: 2em; } formatter = Text::Format.new formatter.tabstop = @options[:expand_tabs] - @left.map! do |line| formatter.expand(line.chomp) end - @right.map! do |line| formatter.expand(line.chomp) end + @left.map! { |line| formatter.expand(line.chomp) } + @right.map! { |line| formatter.expand(line.chomp) } end - @left.map! do |line| CGI.escapeHTML(line.chomp) end - @right.map! do |line| CGI.escapeHTML(line.chomp) end + @left.map! { |line| CGI.escapeHTML(line.chomp) } + @right.map! { |line| CGI.escapeHTML(line.chomp) } # standard:disable Layout/HeredocIndentation @options[:output] << <<-OUTPUT diff --git a/spec/diff_spec.rb b/spec/diff_spec.rb index bd0776a..869f098 100644 --- a/spec/diff_spec.rb +++ b/spec/diff_spec.rb @@ -30,7 +30,7 @@ describe Diff::LCS, ".diff" do diff = Diff::LCS.diff([], word_sequence) correct_diff.each do |hunk| - hunk.each do |change| change[0] = "+" end + hunk.each { |change| change[0] = "+" } end expect(change_diff(correct_diff)).to eq(diff) end -- cgit v1.2.1 From 8992d9c1c13f7852f23ef823257bcf9691049e56 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 11:31:46 -0500 Subject: standardrb --only Style/RedundantBegin --fix --- lib/diff/lcs/callbacks.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/diff/lcs/callbacks.rb b/lib/diff/lcs/callbacks.rb index 818c013..2c5a779 100644 --- a/lib/diff/lcs/callbacks.rb +++ b/lib/diff/lcs/callbacks.rb @@ -50,11 +50,9 @@ module Diff::LCS BalancedCallbacks = DefaultCallbacks def self.callbacks_for(callbacks) - begin - callbacks.new - rescue - callbacks - end + callbacks.new + rescue + callbacks end end -- cgit v1.2.1 From e5e78807564a3565a37d385b0898cd58776820f4 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 11:35:49 -0500 Subject: standardrb --only Style/StringLiteralsInInterpolation --fix and more --- lib/diff/lcs/hunk.rb | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb index 7f97a7d..8da65c2 100644 --- a/lib/diff/lcs/hunk.rb +++ b/lib/diff/lcs/hunk.rb @@ -22,7 +22,7 @@ class Diff::LCS::Hunk end 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 @@ -33,7 +33,6 @@ class Diff::LCS::Hunk @file_length_difference = after # The caller must get this manually @max_diff_size = @blocks.map { |e| e.diff_size.abs }.max - # Save the start & end of each array. If the array doesn't exist (e.g., # we're only adding items in this block), then figure out the line number # based on the line number of the other file and the current difference in @@ -140,7 +139,7 @@ class Diff::LCS::Hunk # Calculate item number range. Old diff range is just like a context # diff range, except the ranges are on one line with the action between # them. - s = encode("#{context_range(:old, ',')}#{OLD_DIFF_OP_ACTION[block.op]}#{context_range(:new, ',')}\n") + s = encode("#{context_range(:old, ",")}#{OLD_DIFF_OP_ACTION[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. unless block.remove.empty? @@ -172,7 +171,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| String.new("#{encode(' ')}#{e.chomp}") } + outlist = @data_old[lo..hi].map { |e| String.new("#{encode(" ")}#{e.chomp}") } last_block = blocks[-1] @@ -212,7 +211,7 @@ class Diff::LCS::Hunk def context_diff(last = false) s = encode("***************\n") - s << encode("*** #{context_range(:old, ',', last)} ****\n") + s << encode("*** #{context_range(:old, ",", last)} ****\n") r = context_range(:new, ",", last) if last @@ -226,7 +225,7 @@ class Diff::LCS::Hunk removes = @blocks.reject { |e| e.remove.empty? } unless removes.empty? - outlist = @data_old[lo..hi].map { |e| String.new("#{encode(' ')}#{e.chomp}") } + outlist = @data_old[lo..hi].map { |e| String.new("#{encode(" ")}#{e.chomp}") } last_block = removes[-1] @@ -248,7 +247,7 @@ class Diff::LCS::Hunk inserts = @blocks.reject { |e| e.insert.empty? } unless inserts.empty? - outlist = @data_new[lo..hi].map { |e| String.new("#{encode(' ')}#{e.chomp}") } + outlist = @data_new[lo..hi].map { |e| String.new("#{encode(" ")}#{e.chomp}") } last_block = inserts[-1] @@ -273,9 +272,9 @@ class Diff::LCS::Hunk s = if format == :reverse_ed - encode("#{ED_DIFF_OP_ACTION[@blocks[0].op]}#{context_range(:old, ',')}\n") + encode("#{ED_DIFF_OP_ACTION[@blocks[0].op]}#{context_range(:old, ",")}\n") else - encode("#{context_range(:old, ' ')}#{ED_DIFF_OP_ACTION[@blocks[0].op]}\n") + encode("#{context_range(:old, " ")}#{ED_DIFF_OP_ACTION[@blocks[0].op]}\n") end unless @blocks[0].insert.empty? -- cgit v1.2.1 From c00ef1d173c3663a3edd0adaee21cbcad7e1b3c3 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 11:37:31 -0500 Subject: standardrb --only Style/StringLiteralsInInterpolation --- lib/diff/lcs/hunk.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb index 8da65c2..2cef5ed 100644 --- a/lib/diff/lcs/hunk.rb +++ b/lib/diff/lcs/hunk.rb @@ -171,7 +171,9 @@ class Diff::LCS::Hunk # file -- don't take removed items into account. lo, hi, num_added, num_removed = @start_old, @end_old, 0, 0 + # standard:disable Performance/UnfreezeString outlist = @data_old[lo..hi].map { |e| String.new("#{encode(" ")}#{e.chomp}") } + # standard:enable Performance/UnfreezeString last_block = blocks[-1] @@ -225,7 +227,9 @@ class Diff::LCS::Hunk removes = @blocks.reject { |e| e.remove.empty? } unless removes.empty? + # standard:disable Performance/UnfreezeString outlist = @data_old[lo..hi].map { |e| String.new("#{encode(" ")}#{e.chomp}") } + # standard:enable Performance/UnfreezeString last_block = removes[-1] @@ -247,7 +251,9 @@ class Diff::LCS::Hunk inserts = @blocks.reject { |e| e.insert.empty? } unless inserts.empty? + # standard:disable Performance/UnfreezeString outlist = @data_new[lo..hi].map { |e| String.new("#{encode(" ")}#{e.chomp}") } + # standard:enable Performance/UnfreezeString last_block = inserts[-1] -- cgit v1.2.1 From e31bc57c0d863a6eb77f2c19df2dc49a1e72db67 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 11:37:49 -0500 Subject: standardrb --only Style/BarePercentLiterals --fix --- lib/diff/lcs/htmldiff.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/diff/lcs/htmldiff.rb b/lib/diff/lcs/htmldiff.rb index 325dc95..54adc2a 100644 --- a/lib/diff/lcs/htmldiff.rb +++ b/lib/diff/lcs/htmldiff.rb @@ -26,7 +26,7 @@ class Diff::LCS::HTMLDiff def htmlize(element, css_class) element = " " if element.empty? - %Q(
#{element}
\n) + %(
#{element}
\n) end private :htmlize -- cgit v1.2.1 From c0c80d43824d66052d4b7613cbbd17ba8b8e850a Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Mon, 4 Jul 2022 20:27:15 -0400 Subject: Update changelog --- History.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/History.md b/History.md index a168d7e..a108b9f 100644 --- a/History.md +++ b/History.md @@ -4,6 +4,8 @@ - Updated the CI configuration, resolving [#82][]. +- Switched to standard ruby formatting. + ## 1.5.0 / 2021-12-23 - Updated the CI configuration and monkey-patch Hoe. -- cgit v1.2.1 From 0270cb87e09dd444ad6822a777bb7999fd6f6e85 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Mon, 4 Jul 2022 20:30:28 -0400 Subject: Update codeql analysis --- .github/workflows/codeql-analysis.yml | 58 +++++++++++++++++------------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 2fe2010..a1548a1 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -9,14 +9,14 @@ # the `language` matrix defined below to confirm you have the correct set of # supported CodeQL languages. # -name: "CodeQL" +name: 'CodeQL' on: push: - branches: [ master, main ] + branches: [main] pull_request: # The branches below must be a subset of the branches above - branches: [ master, main ] + branches: [main] schedule: - cron: '28 4 * * 2' @@ -32,39 +32,39 @@ jobs: strategy: fail-fast: false matrix: - language: [ 'ruby' ] + language: ['ruby'] # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] # Learn more about CodeQL language support at https://git.io/codeql-language-support steps: - - name: Checkout repository - uses: actions/checkout@v2 + - name: Checkout repository + uses: actions/checkout@v2 - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v1 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v1 + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 - # ℹ️ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl + # ℹ️ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl - # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language + # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language - #- run: | - # make bootstrap - # make release + #- run: | + # make bootstrap + # make release - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 -- cgit v1.2.1