diff-lcs 1.5.1 → 2.0.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +581 -0
- data/CODE_OF_CONDUCT.md +166 -0
- data/CONTRIBUTING.md +127 -0
- data/CONTRIBUTORS.md +59 -0
- data/LICENCE.md +68 -0
- data/Manifest.txt +99 -35
- data/README.md +105 -0
- data/Rakefile +107 -96
- data/SECURITY.md +36 -0
- data/integration/compare/array_diff_spec.rb +10 -0
- data/integration/compare/hash_diff_spec.rb +25 -0
- data/integration/compare/string_diff_spec.rb +10 -0
- data/integration/rspec_differ_spec.rb +26 -0
- data/integration/rspec_expectations_spec.rb +32 -0
- data/integration/runner +20 -0
- data/lib/diff/lcs/block.rb +29 -24
- data/lib/diff/lcs/callbacks.rb +240 -242
- data/lib/diff/lcs/change.rb +102 -104
- data/lib/diff/lcs/hunk.rb +110 -157
- data/lib/diff/lcs/internals.rb +92 -96
- data/lib/diff/lcs/ldiff.rb +81 -73
- data/lib/diff/lcs/version.rb +7 -0
- data/lib/diff/lcs.rb +440 -466
- data/{docs → licenses}/artistic.txt +1 -1
- data/licenses/dco.txt +34 -0
- data/spec/hunk_spec.rb +33 -46
- data/spec/issues_spec.rb +32 -32
- data/spec/lcs_spec.rb +6 -6
- data/spec/ldiff_spec.rb +27 -16
- data/spec/patch_spec.rb +1 -1
- data/spec/spec_helper.rb +98 -108
- data/test/fixtures/123_x +2 -0
- data/test/fixtures/456_x +2 -0
- data/test/fixtures/empty +0 -0
- data/test/fixtures/file1.bin +0 -0
- data/test/fixtures/file2.bin +0 -0
- data/test/fixtures/four_lines +4 -0
- data/test/fixtures/four_lines_with_missing_new_line +4 -0
- data/test/fixtures/ldiff/diff.missing_new_line1-e +1 -0
- data/test/fixtures/ldiff/diff.missing_new_line1-f +1 -0
- data/test/fixtures/ldiff/diff.missing_new_line2-e +1 -0
- data/test/fixtures/ldiff/diff.missing_new_line2-f +1 -0
- data/test/fixtures/ldiff/error.diff.chef-e +2 -0
- data/test/fixtures/ldiff/error.diff.chef-f +2 -0
- data/test/fixtures/ldiff/error.diff.missing_new_line1-e +1 -0
- data/test/fixtures/ldiff/error.diff.missing_new_line1-f +1 -0
- data/test/fixtures/ldiff/error.diff.missing_new_line2-e +1 -0
- data/test/fixtures/ldiff/error.diff.missing_new_line2-f +1 -0
- data/test/fixtures/ldiff/output.diff-c +7 -0
- data/test/fixtures/ldiff/output.diff-u +5 -0
- data/test/fixtures/ldiff/output.diff.bin1 +0 -0
- data/test/fixtures/ldiff/output.diff.bin1-c +0 -0
- data/test/fixtures/ldiff/output.diff.bin1-e +0 -0
- data/test/fixtures/ldiff/output.diff.bin1-f +0 -0
- data/test/fixtures/ldiff/output.diff.bin1-u +0 -0
- data/test/fixtures/ldiff/output.diff.bin2 +1 -0
- data/test/fixtures/ldiff/output.diff.bin2-c +1 -0
- data/test/fixtures/ldiff/output.diff.bin2-e +1 -0
- data/test/fixtures/ldiff/output.diff.bin2-f +1 -0
- data/test/fixtures/ldiff/output.diff.bin2-u +1 -0
- data/{spec → test}/fixtures/ldiff/output.diff.chef-c +2 -2
- data/test/fixtures/ldiff/output.diff.chef-u +9 -0
- data/{spec → test}/fixtures/ldiff/output.diff.chef2-c +2 -2
- data/{spec → test}/fixtures/ldiff/output.diff.chef2-u +2 -2
- data/test/fixtures/ldiff/output.diff.empty.vs.four_lines +5 -0
- data/test/fixtures/ldiff/output.diff.empty.vs.four_lines-c +9 -0
- data/test/fixtures/ldiff/output.diff.empty.vs.four_lines-e +6 -0
- data/test/fixtures/ldiff/output.diff.empty.vs.four_lines-f +6 -0
- data/test/fixtures/ldiff/output.diff.empty.vs.four_lines-u +7 -0
- data/test/fixtures/ldiff/output.diff.four_lines.vs.empty +5 -0
- data/test/fixtures/ldiff/output.diff.four_lines.vs.empty-c +9 -0
- data/test/fixtures/ldiff/output.diff.four_lines.vs.empty-e +1 -0
- data/test/fixtures/ldiff/output.diff.four_lines.vs.empty-f +1 -0
- data/test/fixtures/ldiff/output.diff.four_lines.vs.empty-u +7 -0
- data/test/fixtures/ldiff/output.diff.issue95_trailing_context +4 -0
- data/test/fixtures/ldiff/output.diff.issue95_trailing_context-c +9 -0
- data/{spec/fixtures/ldiff/output.diff-e → test/fixtures/ldiff/output.diff.issue95_trailing_context-e} +1 -1
- data/{spec/fixtures/ldiff/output.diff-f → test/fixtures/ldiff/output.diff.issue95_trailing_context-f} +1 -1
- data/test/fixtures/ldiff/output.diff.issue95_trailing_context-u +6 -0
- data/test/fixtures/ldiff/output.diff.missing_new_line1 +5 -0
- data/test/fixtures/ldiff/output.diff.missing_new_line1-c +14 -0
- data/test/fixtures/ldiff/output.diff.missing_new_line1-e +0 -0
- data/test/fixtures/ldiff/output.diff.missing_new_line1-f +0 -0
- data/test/fixtures/ldiff/output.diff.missing_new_line1-u +9 -0
- data/test/fixtures/ldiff/output.diff.missing_new_line2 +5 -0
- data/test/fixtures/ldiff/output.diff.missing_new_line2-c +14 -0
- data/test/fixtures/ldiff/output.diff.missing_new_line2-e +0 -0
- data/test/fixtures/ldiff/output.diff.missing_new_line2-f +0 -0
- data/test/fixtures/ldiff/output.diff.missing_new_line2-u +9 -0
- data/test/test_block.rb +34 -0
- data/test/test_change.rb +234 -0
- data/test/test_diff.rb +53 -0
- data/test/test_helper.rb +225 -0
- data/test/test_hunk.rb +72 -0
- data/test/test_issues.rb +168 -0
- data/test/test_lcs.rb +47 -0
- data/test/test_ldiff.rb +89 -0
- data/test/test_patch.rb +362 -0
- data/test/test_sdiff.rb +167 -0
- data/test/test_traverse_balanced.rb +322 -0
- data/test/test_traverse_sequences.rb +187 -0
- metadata +211 -103
- data/.rspec +0 -1
- data/Code-of-Conduct.md +0 -74
- data/Contributing.md +0 -121
- data/History.md +0 -431
- data/License.md +0 -41
- data/README.rdoc +0 -84
- data/bin/htmldiff +0 -35
- data/lib/diff/lcs/backports.rb +0 -9
- data/lib/diff/lcs/htmldiff.rb +0 -158
- data/spec/fixtures/ldiff/output.diff-c +0 -7
- data/spec/fixtures/ldiff/output.diff-u +0 -5
- data/spec/fixtures/ldiff/output.diff.chef-e +0 -3
- data/spec/fixtures/ldiff/output.diff.chef-f +0 -3
- data/spec/fixtures/ldiff/output.diff.chef-u +0 -9
- data/spec/fixtures/ldiff/output.diff.chef2-e +0 -7
- data/spec/fixtures/ldiff/output.diff.chef2-f +0 -7
- /data/{docs → licenses}/COPYING.txt +0 -0
- /data/{spec → test}/fixtures/aX +0 -0
- /data/{spec → test}/fixtures/bXaX +0 -0
- /data/{spec → test}/fixtures/ds1.csv +0 -0
- /data/{spec → test}/fixtures/ds2.csv +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.chef +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.chef2 +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.chef2-d +0 -0
- /data/{spec → test}/fixtures/new-chef +0 -0
- /data/{spec → test}/fixtures/new-chef2 +0 -0
- /data/{spec → test}/fixtures/old-chef +0 -0
- /data/{spec → test}/fixtures/old-chef2 +0 -0
data/lib/diff/lcs/htmldiff.rb
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "cgi"
|
|
4
|
-
|
|
5
|
-
# Produce a simple HTML diff view.
|
|
6
|
-
class Diff::LCS::HTMLDiff
|
|
7
|
-
class << self
|
|
8
|
-
attr_accessor :can_expand_tabs # :nodoc:
|
|
9
|
-
end
|
|
10
|
-
self.can_expand_tabs = true
|
|
11
|
-
|
|
12
|
-
class Callbacks # :nodoc:
|
|
13
|
-
attr_accessor :output
|
|
14
|
-
attr_accessor :match_class
|
|
15
|
-
attr_accessor :only_a_class
|
|
16
|
-
attr_accessor :only_b_class
|
|
17
|
-
|
|
18
|
-
def initialize(output, options = {})
|
|
19
|
-
@output = output
|
|
20
|
-
options ||= {}
|
|
21
|
-
|
|
22
|
-
@match_class = options[:match_class] || "match"
|
|
23
|
-
@only_a_class = options[:only_a_class] || "only_a"
|
|
24
|
-
@only_b_class = options[:only_b_class] || "only_b"
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def htmlize(element, css_class)
|
|
28
|
-
element = " " if element.empty?
|
|
29
|
-
%(<pre class="#{__send__(css_class)}">#{element}</pre>\n)
|
|
30
|
-
end
|
|
31
|
-
private :htmlize
|
|
32
|
-
|
|
33
|
-
# This will be called with both lines are the same
|
|
34
|
-
def match(event)
|
|
35
|
-
@output << htmlize(event.old_element, :match_class)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# This will be called when there is a line in A that isn't in B
|
|
39
|
-
def discard_a(event)
|
|
40
|
-
@output << htmlize(event.old_element, :only_a_class)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# This will be called when there is a line in B that isn't in A
|
|
44
|
-
def discard_b(event)
|
|
45
|
-
@output << htmlize(event.new_element, :only_b_class)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
# standard:disable Style/HashSyntax
|
|
50
|
-
DEFAULT_OPTIONS = {
|
|
51
|
-
:expand_tabs => nil,
|
|
52
|
-
:output => nil,
|
|
53
|
-
:css => nil,
|
|
54
|
-
:title => nil
|
|
55
|
-
}.freeze
|
|
56
|
-
# standard:enable Style/HashSyntax
|
|
57
|
-
|
|
58
|
-
# standard:disable Layout/HeredocIndentation
|
|
59
|
-
DEFAULT_CSS = <<-CSS
|
|
60
|
-
body { margin: 0; }
|
|
61
|
-
.diff
|
|
62
|
-
{
|
|
63
|
-
border: 1px solid black;
|
|
64
|
-
margin: 1em 2em;
|
|
65
|
-
}
|
|
66
|
-
p
|
|
67
|
-
{
|
|
68
|
-
margin-left: 2em;
|
|
69
|
-
}
|
|
70
|
-
pre
|
|
71
|
-
{
|
|
72
|
-
padding-left: 1em;
|
|
73
|
-
margin: 0;
|
|
74
|
-
font-family: Inconsolata, Consolas, Lucida, Courier, monospaced;
|
|
75
|
-
white-space: pre;
|
|
76
|
-
}
|
|
77
|
-
.match { }
|
|
78
|
-
.only_a
|
|
79
|
-
{
|
|
80
|
-
background-color: #fdd;
|
|
81
|
-
color: red;
|
|
82
|
-
text-decoration: line-through;
|
|
83
|
-
}
|
|
84
|
-
.only_b
|
|
85
|
-
{
|
|
86
|
-
background-color: #ddf;
|
|
87
|
-
color: blue;
|
|
88
|
-
border-left: 3px solid blue
|
|
89
|
-
}
|
|
90
|
-
h1 { margin-left: 2em; }
|
|
91
|
-
CSS
|
|
92
|
-
# standard:enable Layout/HeredocIndentation
|
|
93
|
-
|
|
94
|
-
def initialize(left, right, options = nil)
|
|
95
|
-
@left = left
|
|
96
|
-
@right = right
|
|
97
|
-
@options = options
|
|
98
|
-
|
|
99
|
-
@options = DEFAULT_OPTIONS.dup if @options.nil?
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def verify_options
|
|
103
|
-
@options[:expand_tabs] ||= 4
|
|
104
|
-
@options[:expand_tabs] = 4 if @options[:expand_tabs].negative?
|
|
105
|
-
|
|
106
|
-
@options[:output] ||= $stdout
|
|
107
|
-
|
|
108
|
-
@options[:css] ||= DEFAULT_CSS.dup
|
|
109
|
-
|
|
110
|
-
@options[:title] ||= "diff"
|
|
111
|
-
end
|
|
112
|
-
private :verify_options
|
|
113
|
-
|
|
114
|
-
attr_reader :options
|
|
115
|
-
|
|
116
|
-
def run
|
|
117
|
-
verify_options
|
|
118
|
-
|
|
119
|
-
if @options[:expand_tabs].positive? && self.class.can_expand_tabs
|
|
120
|
-
formatter = Text::Format.new
|
|
121
|
-
formatter.tabstop = @options[:expand_tabs]
|
|
122
|
-
|
|
123
|
-
@left.map! { |line| formatter.expand(line.chomp) }
|
|
124
|
-
@right.map! { |line| formatter.expand(line.chomp) }
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
@left.map! { |line| CGI.escapeHTML(line.chomp) }
|
|
128
|
-
@right.map! { |line| CGI.escapeHTML(line.chomp) }
|
|
129
|
-
|
|
130
|
-
# standard:disable Layout/HeredocIndentation
|
|
131
|
-
@options[:output] << <<-OUTPUT
|
|
132
|
-
<html>
|
|
133
|
-
<head>
|
|
134
|
-
<title>#{@options[:title]}</title>
|
|
135
|
-
<style type="text/css">
|
|
136
|
-
#{@options[:css]}
|
|
137
|
-
</style>
|
|
138
|
-
</head>
|
|
139
|
-
<body>
|
|
140
|
-
<h1>#{@options[:title]}</h1>
|
|
141
|
-
<p>Legend: <span class="only_a">Only in Old</span>
|
|
142
|
-
<span class="only_b">Only in New</span></p>
|
|
143
|
-
<div class="diff">
|
|
144
|
-
OUTPUT
|
|
145
|
-
# standard:enable Layout/HeredocIndentation
|
|
146
|
-
|
|
147
|
-
callbacks = Callbacks.new(@options[:output])
|
|
148
|
-
Diff::LCS.traverse_sequences(@left, @right, callbacks)
|
|
149
|
-
|
|
150
|
-
# standard:disable Layout/HeredocIndentation
|
|
151
|
-
@options[:output] << <<-OUTPUT
|
|
152
|
-
</div>
|
|
153
|
-
</body>
|
|
154
|
-
</html>
|
|
155
|
-
OUTPUT
|
|
156
|
-
# standard:enable Layout/HeredocIndentation
|
|
157
|
-
end
|
|
158
|
-
end
|
|
File without changes
|
/data/{spec → test}/fixtures/aX
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|