diff-lcs 1.3 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +5 -5
  2. data/Contributing.md +86 -48
  3. data/History.md +370 -159
  4. data/License.md +6 -4
  5. data/Manifest.txt +23 -1
  6. data/README.rdoc +10 -10
  7. data/Rakefile +109 -36
  8. data/bin/htmldiff +9 -6
  9. data/bin/ldiff +4 -1
  10. data/lib/diff/lcs/array.rb +2 -2
  11. data/lib/diff/lcs/backports.rb +9 -0
  12. data/lib/diff/lcs/block.rb +5 -5
  13. data/lib/diff/lcs/callbacks.rb +22 -17
  14. data/lib/diff/lcs/change.rb +42 -49
  15. data/lib/diff/lcs/htmldiff.rb +21 -12
  16. data/lib/diff/lcs/hunk.rb +160 -73
  17. data/lib/diff/lcs/internals.rb +57 -56
  18. data/lib/diff/lcs/ldiff.rb +63 -57
  19. data/lib/diff/lcs/string.rb +1 -1
  20. data/lib/diff/lcs.rb +226 -210
  21. data/lib/diff-lcs.rb +2 -2
  22. data/spec/change_spec.rb +58 -34
  23. data/spec/diff_spec.rb +13 -9
  24. data/spec/fixtures/aX +1 -0
  25. data/spec/fixtures/bXaX +1 -0
  26. data/spec/fixtures/ldiff/output.diff +4 -0
  27. data/spec/fixtures/ldiff/output.diff-c +7 -0
  28. data/spec/fixtures/ldiff/output.diff-e +3 -0
  29. data/spec/fixtures/ldiff/output.diff-f +3 -0
  30. data/spec/fixtures/ldiff/output.diff-u +5 -0
  31. data/spec/fixtures/ldiff/output.diff.chef +4 -0
  32. data/spec/fixtures/ldiff/output.diff.chef-c +15 -0
  33. data/spec/fixtures/ldiff/output.diff.chef-e +3 -0
  34. data/spec/fixtures/ldiff/output.diff.chef-f +3 -0
  35. data/spec/fixtures/ldiff/output.diff.chef-u +9 -0
  36. data/spec/fixtures/ldiff/output.diff.chef2 +7 -0
  37. data/spec/fixtures/ldiff/output.diff.chef2-c +20 -0
  38. data/spec/fixtures/ldiff/output.diff.chef2-d +7 -0
  39. data/spec/fixtures/ldiff/output.diff.chef2-e +7 -0
  40. data/spec/fixtures/ldiff/output.diff.chef2-f +7 -0
  41. data/spec/fixtures/ldiff/output.diff.chef2-u +16 -0
  42. data/spec/fixtures/new-chef +4 -0
  43. data/spec/fixtures/new-chef2 +17 -0
  44. data/spec/fixtures/old-chef +4 -0
  45. data/spec/fixtures/old-chef2 +14 -0
  46. data/spec/hunk_spec.rb +48 -37
  47. data/spec/issues_spec.rb +132 -21
  48. data/spec/lcs_spec.rb +3 -3
  49. data/spec/ldiff_spec.rb +74 -32
  50. data/spec/patch_spec.rb +14 -20
  51. data/spec/sdiff_spec.rb +83 -81
  52. data/spec/spec_helper.rb +146 -91
  53. data/spec/traverse_balanced_spec.rb +138 -136
  54. data/spec/traverse_sequences_spec.rb +7 -9
  55. metadata +76 -48
  56. data/autotest/discover.rb +0 -1
data/spec/sdiff_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
- # -*- ruby encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  describe "Diff::LCS.sdiff" do
6
6
  include Diff::LCS::SpecHelper::Matchers
@@ -24,32 +24,34 @@ describe "Diff::LCS.sdiff" do
24
24
  end
25
25
 
26
26
  describe "using %w(abc def yyy xxx ghi jkl) & %w(abc dxf xxx ghi jkl)" do
27
- let(:s1) { %w(abc def yyy xxx ghi jkl) }
28
- let(:s2) { %w(abc dxf xxx ghi jkl) }
27
+ let(:s1) { %w[abc def yyy xxx ghi jkl] }
28
+ let(:s2) { %w[abc dxf xxx ghi jkl] }
29
29
  let(:result) {
30
+ # standard:disable Layout/ExtraSpacing
30
31
  [
31
- [ '=', [ 0, 'abc' ], [ 0, 'abc' ] ],
32
- [ '!', [ 1, 'def' ], [ 1, 'dxf' ] ],
33
- [ '-', [ 2, 'yyy' ], [ 2, nil ] ],
34
- [ '=', [ 3, 'xxx' ], [ 2, 'xxx' ] ],
35
- [ '=', [ 4, 'ghi' ], [ 3, 'ghi' ] ],
36
- [ '=', [ 5, 'jkl' ], [ 4, 'jkl' ] ]
32
+ ["=", [0, "abc"], [0, "abc"]],
33
+ ["!", [1, "def"], [1, "dxf"]],
34
+ ["-", [2, "yyy"], [2, nil]],
35
+ ["=", [3, "xxx"], [2, "xxx"]],
36
+ ["=", [4, "ghi"], [3, "ghi"]],
37
+ ["=", [5, "jkl"], [4, "jkl"]]
37
38
  ]
39
+ # standard:enable Layout/ExtraSpacing
38
40
  }
39
41
 
40
42
  it_has_behavior "compare sequences correctly"
41
43
  end
42
44
 
43
45
  describe "using %w(a b c d e) & %w(a e)" do
44
- let(:s1) { %w(a b c d e) }
45
- let(:s2) { %w(a e) }
46
+ let(:s1) { %w[a b c d e] }
47
+ let(:s2) { %w[a e] }
46
48
  let(:result) {
47
49
  [
48
- [ '=', [ 0, 'a' ], [ 0, 'a' ] ],
49
- [ '-', [ 1, 'b' ], [ 1, nil ] ],
50
- [ '-', [ 2, 'c' ], [ 1, nil ] ],
51
- [ '-', [ 3, 'd' ], [ 1, nil ] ],
52
- [ '=', [ 4, 'e' ], [ 1, 'e' ] ]
50
+ ["=", [0, "a"], [0, "a"]],
51
+ ["-", [1, "b"], [1, nil]],
52
+ ["-", [2, "c"], [1, nil]],
53
+ ["-", [3, "d"], [1, nil]],
54
+ ["=", [4, "e"], [1, "e"]]
53
55
  ]
54
56
  }
55
57
 
@@ -57,15 +59,15 @@ describe "Diff::LCS.sdiff" do
57
59
  end
58
60
 
59
61
  describe "using %w(a e) & %w(a b c d e)" do
60
- let(:s1) { %w(a e) }
61
- let(:s2) { %w(a b c d e) }
62
+ let(:s1) { %w[a e] }
63
+ let(:s2) { %w[a b c d e] }
62
64
  let(:result) {
63
65
  [
64
- [ '=', [ 0, 'a' ], [ 0, 'a' ] ],
65
- [ '+', [ 1, nil ], [ 1, 'b' ] ],
66
- [ '+', [ 1, nil ], [ 2, 'c' ] ],
67
- [ '+', [ 1, nil ], [ 3, 'd' ] ],
68
- [ '=', [ 1, 'e' ], [ 4, 'e' ] ]
66
+ ["=", [0, "a"], [0, "a"]],
67
+ ["+", [1, nil], [1, "b"]],
68
+ ["+", [1, nil], [2, "c"]],
69
+ ["+", [1, nil], [3, "d"]],
70
+ ["=", [1, "e"], [4, "e"]]
69
71
  ]
70
72
  }
71
73
 
@@ -73,17 +75,17 @@ describe "Diff::LCS.sdiff" do
73
75
  end
74
76
 
75
77
  describe "using %w(v x a e) & %w(w y a b c d e)" do
76
- let(:s1) { %w(v x a e) }
77
- let(:s2) { %w(w y a b c d e) }
78
+ let(:s1) { %w[v x a e] }
79
+ let(:s2) { %w[w y a b c d e] }
78
80
  let(:result) {
79
81
  [
80
- [ '!', [ 0, 'v' ], [ 0, 'w' ] ],
81
- [ '!', [ 1, 'x' ], [ 1, 'y' ] ],
82
- [ '=', [ 2, 'a' ], [ 2, 'a' ] ],
83
- [ '+', [ 3, nil ], [ 3, 'b' ] ],
84
- [ '+', [ 3, nil ], [ 4, 'c' ] ],
85
- [ '+', [ 3, nil ], [ 5, 'd' ] ],
86
- [ '=', [ 3, 'e' ], [ 6, 'e' ] ]
82
+ ["!", [0, "v"], [0, "w"]],
83
+ ["!", [1, "x"], [1, "y"]],
84
+ ["=", [2, "a"], [2, "a"]],
85
+ ["+", [3, nil], [3, "b"]],
86
+ ["+", [3, nil], [4, "c"]],
87
+ ["+", [3, nil], [5, "d"]],
88
+ ["=", [3, "e"], [6, "e"]]
87
89
  ]
88
90
  }
89
91
 
@@ -91,16 +93,16 @@ describe "Diff::LCS.sdiff" do
91
93
  end
92
94
 
93
95
  describe "using %w(x a e) & %w(a b c d e)" do
94
- let(:s1) { %w(x a e) }
95
- let(:s2) { %w(a b c d e) }
96
+ let(:s1) { %w[x a e] }
97
+ let(:s2) { %w[a b c d e] }
96
98
  let(:result) {
97
99
  [
98
- [ '-', [ 0, 'x' ], [ 0, nil ] ],
99
- [ '=', [ 1, 'a' ], [ 0, 'a' ] ],
100
- [ '+', [ 2, nil ], [ 1, 'b' ] ],
101
- [ '+', [ 2, nil ], [ 2, 'c' ] ],
102
- [ '+', [ 2, nil ], [ 3, 'd' ] ],
103
- [ '=', [ 2, 'e' ], [ 4, 'e' ] ]
100
+ ["-", [0, "x"], [0, nil]],
101
+ ["=", [1, "a"], [0, "a"]],
102
+ ["+", [2, nil], [1, "b"]],
103
+ ["+", [2, nil], [2, "c"]],
104
+ ["+", [2, nil], [3, "d"]],
105
+ ["=", [2, "e"], [4, "e"]]
104
106
  ]
105
107
  }
106
108
 
@@ -108,16 +110,16 @@ describe "Diff::LCS.sdiff" do
108
110
  end
109
111
 
110
112
  describe "using %w(a e) & %w(x a b c d e)" do
111
- let(:s1) { %w(a e) }
112
- let(:s2) { %w(x a b c d e) }
113
+ let(:s1) { %w[a e] }
114
+ let(:s2) { %w[x a b c d e] }
113
115
  let(:result) {
114
116
  [
115
- [ '+', [ 0, nil ], [ 0, 'x' ] ],
116
- [ '=', [ 0, 'a' ], [ 1, 'a' ] ],
117
- [ '+', [ 1, nil ], [ 2, 'b' ] ],
118
- [ '+', [ 1, nil ], [ 3, 'c' ] ],
119
- [ '+', [ 1, nil ], [ 4, 'd' ] ],
120
- [ '=', [ 1, 'e' ], [ 5, 'e' ] ]
117
+ ["+", [0, nil], [0, "x"]],
118
+ ["=", [0, "a"], [1, "a"]],
119
+ ["+", [1, nil], [2, "b"]],
120
+ ["+", [1, nil], [3, "c"]],
121
+ ["+", [1, nil], [4, "d"]],
122
+ ["=", [1, "e"], [5, "e"]]
121
123
  ]
122
124
  }
123
125
 
@@ -125,18 +127,18 @@ describe "Diff::LCS.sdiff" do
125
127
  end
126
128
 
127
129
  describe "using %w(a e v) & %w(x a b c d e w x)" do
128
- let(:s1) { %w(a e v) }
129
- let(:s2) { %w(x a b c d e w x) }
130
+ let(:s1) { %w[a e v] }
131
+ let(:s2) { %w[x a b c d e w x] }
130
132
  let(:result) {
131
133
  [
132
- [ '+', [ 0, nil ], [ 0, 'x' ] ],
133
- [ '=', [ 0, 'a' ], [ 1, 'a' ] ],
134
- [ '+', [ 1, nil ], [ 2, 'b' ] ],
135
- [ '+', [ 1, nil ], [ 3, 'c' ] ],
136
- [ '+', [ 1, nil ], [ 4, 'd' ] ],
137
- [ '=', [ 1, 'e' ], [ 5, 'e' ] ],
138
- [ '!', [ 2, 'v' ], [ 6, 'w' ] ],
139
- [ '+', [ 3, nil ], [ 7, 'x' ] ]
134
+ ["+", [0, nil], [0, "x"]],
135
+ ["=", [0, "a"], [1, "a"]],
136
+ ["+", [1, nil], [2, "b"]],
137
+ ["+", [1, nil], [3, "c"]],
138
+ ["+", [1, nil], [4, "d"]],
139
+ ["=", [1, "e"], [5, "e"]],
140
+ ["!", [2, "v"], [6, "w"]],
141
+ ["+", [3, nil], [7, "x"]]
140
142
  ]
141
143
  }
142
144
 
@@ -144,13 +146,13 @@ describe "Diff::LCS.sdiff" do
144
146
  end
145
147
 
146
148
  describe "using %w() & %w(a b c)" do
147
- let(:s1) { %w() }
148
- let(:s2) { %w(a b c) }
149
+ let(:s1) { %w[] }
150
+ let(:s2) { %w[a b c] }
149
151
  let(:result) {
150
152
  [
151
- [ '+', [ 0, nil ], [ 0, 'a' ] ],
152
- [ '+', [ 0, nil ], [ 1, 'b' ] ],
153
- [ '+', [ 0, nil ], [ 2, 'c' ] ]
153
+ ["+", [0, nil], [0, "a"]],
154
+ ["+", [0, nil], [1, "b"]],
155
+ ["+", [0, nil], [2, "c"]]
154
156
  ]
155
157
  }
156
158
 
@@ -158,13 +160,13 @@ describe "Diff::LCS.sdiff" do
158
160
  end
159
161
 
160
162
  describe "using %w(a b c) & %w(1)" do
161
- let(:s1) { %w(a b c) }
162
- let(:s2) { %w(1) }
163
+ let(:s1) { %w[a b c] }
164
+ let(:s2) { %w[1] }
163
165
  let(:result) {
164
166
  [
165
- [ '!', [ 0, 'a' ], [ 0, '1' ] ],
166
- [ '-', [ 1, 'b' ], [ 1, nil ] ],
167
- [ '-', [ 2, 'c' ], [ 1, nil ] ]
167
+ ["!", [0, "a"], [0, "1"]],
168
+ ["-", [1, "b"], [1, nil]],
169
+ ["-", [2, "c"], [1, nil]]
168
170
  ]
169
171
  }
170
172
 
@@ -172,13 +174,13 @@ describe "Diff::LCS.sdiff" do
172
174
  end
173
175
 
174
176
  describe "using %w(a b c) & %w(c)" do
175
- let(:s1) { %w(a b c) }
176
- let(:s2) { %w(c) }
177
+ let(:s1) { %w[a b c] }
178
+ let(:s2) { %w[c] }
177
179
  let(:result) {
178
180
  [
179
- [ '-', [ 0, 'a' ], [ 0, nil ] ],
180
- [ '-', [ 1, 'b' ], [ 0, nil ] ],
181
- [ '=', [ 2, 'c' ], [ 0, 'c' ] ]
181
+ ["-", [0, "a"], [0, nil]],
182
+ ["-", [1, "b"], [0, nil]],
183
+ ["=", [2, "c"], [0, "c"]]
182
184
  ]
183
185
  }
184
186
 
@@ -186,14 +188,14 @@ describe "Diff::LCS.sdiff" do
186
188
  end
187
189
 
188
190
  describe "using %w(abcd efgh ijkl mnop) & []" do
189
- let(:s1) { %w(abcd efgh ijkl mnop) }
191
+ let(:s1) { %w[abcd efgh ijkl mnop] }
190
192
  let(:s2) { [] }
191
193
  let(:result) {
192
194
  [
193
- [ '-', [ 0, 'abcd' ], [ 0, nil ] ],
194
- [ '-', [ 1, 'efgh' ], [ 0, nil ] ],
195
- [ '-', [ 2, 'ijkl' ], [ 0, nil ] ],
196
- [ '-', [ 3, 'mnop' ], [ 0, nil ] ]
195
+ ["-", [0, "abcd"], [0, nil]],
196
+ ["-", [1, "efgh"], [0, nil]],
197
+ ["-", [2, "ijkl"], [0, nil]],
198
+ ["-", [3, "mnop"], [0, nil]]
197
199
  ]
198
200
  }
199
201
 
@@ -201,11 +203,11 @@ describe "Diff::LCS.sdiff" do
201
203
  end
202
204
 
203
205
  describe "using [[1,2]] & []" do
204
- let(:s1) { [ [ 1, 2 ] ] }
206
+ let(:s1) { [[1, 2]] }
205
207
  let(:s2) { [] }
206
208
  let(:result) {
207
209
  [
208
- [ '-', [ 0, [ 1, 2 ] ], [ 0, nil ] ]
210
+ ["-", [0, [1, 2]], [0, nil]]
209
211
  ]
210
212
  }
211
213
 
data/spec/spec_helper.rb CHANGED
@@ -1,46 +1,77 @@
1
- # -*- ruby encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
2
 
3
- require 'rubygems'
4
- require 'pathname'
5
- require 'psych'
3
+ require "rubygems"
4
+ require "pathname"
6
5
 
7
- if ENV['COVERALLS']
8
- require 'coveralls'
9
- Coveralls.wear!
10
- elsif ENV['COVERAGE']
11
- require 'simplecov'
6
+ require "psych" if RUBY_VERSION >= "1.9"
12
7
 
13
- def require_do(resource, &block)
8
+ if ENV["COVERAGE"]
9
+ require "simplecov"
10
+
11
+ def require_do(resource)
14
12
  require resource
15
- block.call
13
+ yield if block_given?
16
14
  rescue LoadError
17
15
  nil
18
16
  end
19
17
 
20
- formatters = [ SimpleCov::Formatter::HTMLFormatter ]
18
+ formatters = [SimpleCov::Formatter::HTMLFormatter]
21
19
 
22
- require_do('simplecov-rcov') {
20
+ require_do("simplecov-rcov") {
23
21
  formatters << SimpleCov::Formatter::RcovFormatter
24
22
  }
25
- require_do('simplecov-vim/formatter') {
23
+ require_do("simplecov-vim/formatter") {
26
24
  formatters << SimpleCov::Formatter::VimFormatter
27
25
  }
28
- require_do('simplecov-sublime-ruby-coverage') {
26
+ require_do("simplecov-sublime-ruby-coverage") {
29
27
  formatters << SimpleCov::Formatter::SublimeRubyCoverageFormatter
30
28
  }
31
29
 
32
30
  SimpleCov.start do
33
- formatter SimpleCov::Formatter::MultiFormatter[*formatters]
31
+ formatter SimpleCov::Formatter::MultiFormatter.new(formatters)
34
32
  end
35
33
  end
36
34
 
37
- file = Pathname.new(__FILE__).expand_path
38
- path = file.parent
35
+ file = Pathname.new(__FILE__).expand_path
36
+ path = file.parent
39
37
  parent = path.parent
40
38
 
41
- $:.unshift parent.join('lib')
39
+ $:.unshift parent.join("lib")
40
+
41
+ module CaptureSubprocessIO
42
+ def _synchronize
43
+ yield
44
+ end
45
+
46
+ def capture_subprocess_io
47
+ _synchronize { _capture_subprocess_io { yield } }
48
+ end
49
+
50
+ def _capture_subprocess_io
51
+ require "tempfile"
52
+
53
+ captured_stdout, captured_stderr = Tempfile.new("out"), Tempfile.new("err")
54
+
55
+ orig_stdout, orig_stderr = $stdout.dup, $stderr.dup
56
+ $stdout.reopen captured_stdout
57
+ $stderr.reopen captured_stderr
58
+
59
+ yield
60
+
61
+ $stdout.rewind
62
+ $stderr.rewind
63
+
64
+ [captured_stdout.read, captured_stderr.read]
65
+ ensure
66
+ captured_stdout.unlink
67
+ captured_stderr.unlink
68
+ $stdout.reopen orig_stdout
69
+ $stderr.reopen orig_stderr
70
+ end
71
+ private :_capture_subprocess_io
72
+ end
42
73
 
43
- require 'diff-lcs'
74
+ require "diff-lcs"
44
75
 
45
76
  module Diff::LCS::SpecHelper
46
77
  def hello
@@ -48,88 +79,109 @@ module Diff::LCS::SpecHelper
48
79
  end
49
80
 
50
81
  def hello_ary
51
- %W(h e l l o)
82
+ %w[h e l l o]
52
83
  end
53
84
 
54
85
  def seq1
55
- %w(a b c e h j l m n p)
86
+ %w[a b c e h j l m n p]
56
87
  end
57
88
 
58
89
  def skipped_seq1
59
- %w(a h n p)
90
+ %w[a h n p]
60
91
  end
61
92
 
62
93
  def seq2
63
- %w(b c d e f j k l m r s t)
94
+ %w[b c d e f j k l m r s t]
64
95
  end
65
96
 
66
97
  def skipped_seq2
67
- %w(d f k r s t)
98
+ %w[d f k r s t]
68
99
  end
69
100
 
70
101
  def word_sequence
71
- %w(abcd efgh ijkl mnopqrstuvwxyz)
102
+ %w[abcd efgh ijkl mnopqrstuvwxyz]
72
103
  end
73
104
 
74
105
  def correct_lcs
75
- %w(b c e j l m)
106
+ %w[b c e j l m]
76
107
  end
77
108
 
109
+ # standard:disable Layout/ExtraSpacing
78
110
  def correct_forward_diff
79
111
  [
80
- [ [ '-', 0, 'a' ] ],
81
- [ [ '+', 2, 'd' ] ],
82
- [ [ '-', 4, 'h' ],
83
- [ '+', 4, 'f' ] ],
84
- [ [ '+', 6, 'k' ] ],
85
- [ [ '-', 8, 'n' ],
86
- [ '-', 9, 'p' ],
87
- [ '+', 9, 'r' ],
88
- [ '+', 10, 's' ],
89
- [ '+', 11, 't' ] ]
112
+ [
113
+ ["-", 0, "a"]
114
+ ],
115
+ [
116
+ ["+", 2, "d"]
117
+ ],
118
+ [
119
+ ["-", 4, "h"],
120
+ ["+", 4, "f"]
121
+ ],
122
+ [
123
+ ["+", 6, "k"]
124
+ ],
125
+ [
126
+ ["-", 8, "n"],
127
+ ["+", 9, "r"],
128
+ ["-", 9, "p"],
129
+ ["+", 10, "s"],
130
+ ["+", 11, "t"]
131
+ ]
90
132
  ]
91
133
  end
92
134
 
93
135
  def correct_backward_diff
94
136
  [
95
- [ [ '+', 0, 'a' ] ],
96
- [ [ '-', 2, 'd' ] ],
97
- [ [ '-', 4, 'f' ],
98
- [ '+', 4, 'h' ] ],
99
- [ [ '-', 6, 'k' ] ],
100
137
  [
101
- [ '-', 9, 'r' ],
102
- [ '-', 10, 's' ],
103
- [ '+', 8, 'n' ],
104
- [ '-', 11, 't' ],
105
- [ '+', 9, 'p' ] ]
138
+ ["+", 0, "a"]
139
+ ],
140
+ [
141
+ ["-", 2, "d"]
142
+ ],
143
+ [
144
+ ["-", 4, "f"],
145
+ ["+", 4, "h"]
146
+ ],
147
+ [
148
+ ["-", 6, "k"]
149
+ ],
150
+ [
151
+ ["-", 9, "r"],
152
+ ["+", 8, "n"],
153
+ ["-", 10, "s"],
154
+ ["+", 9, "p"],
155
+ ["-", 11, "t"]
156
+ ]
106
157
  ]
107
158
  end
108
159
 
109
160
  def correct_forward_sdiff
110
161
  [
111
- [ '-', [ 0, 'a' ], [ 0, nil ] ],
112
- [ '=', [ 1, 'b' ], [ 0, 'b' ] ],
113
- [ '=', [ 2, 'c' ], [ 1, 'c' ] ],
114
- [ '+', [ 3, nil ], [ 2, 'd' ] ],
115
- [ '=', [ 3, 'e' ], [ 3, 'e' ] ],
116
- [ '!', [ 4, 'h' ], [ 4, 'f' ] ],
117
- [ '=', [ 5, 'j' ], [ 5, 'j' ] ],
118
- [ '+', [ 6, nil ], [ 6, 'k' ] ],
119
- [ '=', [ 6, 'l' ], [ 7, 'l' ] ],
120
- [ '=', [ 7, 'm' ], [ 8, 'm' ] ],
121
- [ '!', [ 8, 'n' ], [ 9, 'r' ] ],
122
- [ '!', [ 9, 'p' ], [ 10, 's' ] ],
123
- [ '+', [ 10, nil ], [ 11, 't' ] ]
162
+ ["-", [0, "a"], [0, nil]],
163
+ ["=", [1, "b"], [0, "b"]],
164
+ ["=", [2, "c"], [1, "c"]],
165
+ ["+", [3, nil], [2, "d"]],
166
+ ["=", [3, "e"], [3, "e"]],
167
+ ["!", [4, "h"], [4, "f"]],
168
+ ["=", [5, "j"], [5, "j"]],
169
+ ["+", [6, nil], [6, "k"]],
170
+ ["=", [6, "l"], [7, "l"]],
171
+ ["=", [7, "m"], [8, "m"]],
172
+ ["!", [8, "n"], [9, "r"]],
173
+ ["!", [9, "p"], [10, "s"]],
174
+ ["+", [10, nil], [11, "t"]]
124
175
  ]
125
176
  end
177
+ # standard:enable Layout/ExtraSpacing
126
178
 
127
179
  def reverse_sdiff(forward_sdiff)
128
180
  forward_sdiff.map { |line|
129
181
  line[1], line[2] = line[2], line[1]
130
182
  case line[0]
131
- when '-' then line[0] = '+'
132
- when '+' then line[0] = '-'
183
+ when "-" then line[0] = "+"
184
+ when "+" then line[0] = "-"
133
185
  end
134
186
  line
135
187
  }
@@ -144,13 +196,13 @@ module Diff::LCS::SpecHelper
144
196
  end
145
197
 
146
198
  def format_diffs(diffs)
147
- diffs.map do |e|
148
- if e.kind_of?(Array)
199
+ diffs.map { |e|
200
+ if e.is_a?(Array)
149
201
  e.map { |f| f.to_a.join }.join(", ")
150
202
  else
151
203
  e.to_a.join
152
204
  end
153
- end.join("\n")
205
+ }.join("\n")
154
206
  end
155
207
 
156
208
  def map_diffs(diffs, klass = Diff::LCS::ContextChange)
@@ -171,30 +223,30 @@ module Diff::LCS::SpecHelper
171
223
 
172
224
  def balanced_reverse(change_result)
173
225
  new_result = []
174
- change_result.each { |line|
175
- line = [ line[0], line[2], line[1] ]
226
+ change_result.each do |line|
227
+ line = [line[0], line[2], line[1]]
176
228
  case line[0]
177
- when '<'
178
- line[0] = '>'
179
- when '>'
180
- line[0] = '<'
229
+ when "<"
230
+ line[0] = ">"
231
+ when ">"
232
+ line[0] = "<"
181
233
  end
182
234
  new_result << line
183
- }
184
- new_result.sort_by { |line| [ line[1], line[2] ] }
235
+ end
236
+ new_result.sort_by { |line| [line[1], line[2]] }
185
237
  end
186
238
 
187
239
  def map_to_no_change(change_result)
188
240
  new_result = []
189
- change_result.each { |line|
241
+ change_result.each do |line|
190
242
  case line[0]
191
- when '!'
192
- new_result << [ '<', line[1], line[2] ]
193
- new_result << [ '>', line[1] + 1, line[2] ]
243
+ when "!"
244
+ new_result << ["<", line[1], line[2]]
245
+ new_result << [">", line[1] + 1, line[2]]
194
246
  else
195
247
  new_result << line
196
248
  end
197
- }
249
+ end
198
250
  new_result
199
251
  end
200
252
 
@@ -231,14 +283,17 @@ module Diff::LCS::SpecHelper
231
283
  end
232
284
 
233
285
  def finished_a(event)
234
- @done_a << [event.old_element, event.old_position,
235
- event.new_element, event.new_position]
286
+ @done_a << [
287
+ event.old_element, event.old_position,
288
+ event.new_element, event.new_position
289
+ ]
236
290
  end
237
291
 
238
292
  def finished_b(event)
239
- p "called #finished_b"
240
- @done_b << [event.old_element, event.old_position,
241
- event.new_element, event.new_position]
293
+ @done_b << [
294
+ event.old_element, event.old_position,
295
+ event.new_element, event.new_position
296
+ ]
242
297
  end
243
298
  end
244
299
  callbacks.reset
@@ -264,19 +319,19 @@ module Diff::LCS::SpecHelper
264
319
  end
265
320
 
266
321
  def match(event)
267
- @result << [ "=", event.old_position, event.new_position ]
322
+ @result << ["=", event.old_position, event.new_position]
268
323
  end
269
324
 
270
325
  def discard_a(event)
271
- @result << [ "<", event.old_position, event.new_position ]
326
+ @result << ["<", event.old_position, event.new_position]
272
327
  end
273
328
 
274
329
  def discard_b(event)
275
- @result << [ ">", event.old_position, event.new_position ]
330
+ @result << [">", event.old_position, event.new_position]
276
331
  end
277
332
 
278
333
  def change(event)
279
- @result << [ "!", event.old_position, event.new_position ]
334
+ @result << ["!", event.old_position, event.new_position]
280
335
  end
281
336
  end
282
337
  cb.reset
@@ -302,9 +357,7 @@ module Diff::LCS::SpecHelper
302
357
 
303
358
  matcher :correctly_map_sequence do |s1|
304
359
  match do |actual|
305
- actual.each_with_index { |ee, ii|
306
- expect(ee).to be_nil_or_match_values(ii, s1, @s2)
307
- }
360
+ actual.each_index { |ii| expect(actual[ii]).to be_nil_or_match_values(ii, s1, @s2) }
308
361
  end
309
362
 
310
363
  chain :to_other_sequence do |s2|
@@ -316,6 +369,8 @@ end
316
369
 
317
370
  RSpec.configure do |conf|
318
371
  conf.include Diff::LCS::SpecHelper
319
- conf.alias_it_should_behave_like_to :it_has_behavior, 'has behavior:'
372
+ conf.alias_it_should_behave_like_to :it_has_behavior, "has behavior:"
373
+ # standard:disable Style/HashSyntax
320
374
  conf.filter_run_excluding :broken => true
375
+ # standard:enable Style/HashSyntax
321
376
  end