diffy 3.0.7 → 3.4.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of diffy might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/.travis.yml +12 -5
- data/CHANGELOG +9 -0
- data/CONTRIBUTORS +3 -0
- data/Gemfile +1 -4
- data/README.md +91 -17
- data/Rakefile +2 -0
- data/diffy.gemspec +1 -1
- data/lib/diffy.rb +1 -0
- data/lib/diffy/css.rb +17 -0
- data/lib/diffy/diff.rb +31 -18
- data/lib/diffy/format.rb +1 -1
- data/lib/diffy/html_formatter.rb +8 -4
- data/lib/diffy/split_diff.rb +49 -0
- data/lib/diffy/version.rb +1 -1
- data/spec/diffy_spec.rb +99 -1
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ce6a165c4ad246372cf5e6888ca531c55da86a43051895900df4e466cef6c940
|
4
|
+
data.tar.gz: 066c70ac2cbd41e1d34c2a9fc68f9ba9b4cc1ccea132e289638c5aeb927c0ad6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 911e04010bddf3a49726684822857ffdc1f05b62017367afef5e022f56b2eeecf618282bf40f381901bbded973c06f2273cecb1ada0292f94337cfc2690a3d4a
|
7
|
+
data.tar.gz: a41fa95586a3f16ddcc19e5f3bbd6682d492cb4b0b44b1e6c16fcbd2556cd453d931720458d842caf04610a83067fb4b4daa86eef6010aa0f9d4da9110307cbd
|
data/.travis.yml
CHANGED
@@ -1,8 +1,15 @@
|
|
1
1
|
language: ruby
|
2
|
+
sudo: false
|
3
|
+
cache: bundler
|
2
4
|
rvm:
|
3
5
|
- 1.8.7
|
4
|
-
- 1.9.
|
5
|
-
-
|
6
|
-
- 2.
|
7
|
-
- 2.
|
8
|
-
- 2.
|
6
|
+
- 1.9.3-p551
|
7
|
+
- 2.0.0-p648
|
8
|
+
- 2.1.9
|
9
|
+
- 2.2.6
|
10
|
+
- 2.3.3
|
11
|
+
- 2.4.0
|
12
|
+
- jruby-9.1.12.0
|
13
|
+
matrix:
|
14
|
+
allow_failures:
|
15
|
+
- rvm: 1.8.7
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
== 3.3.0 ==
|
2
|
+
Fix diff lines that begin with -- or ++. Thanks @dark-panda!
|
3
|
+
|
4
|
+
== 3.2.1 ==
|
5
|
+
Fix default options on alpine linux. Thanks @evgen!
|
6
|
+
|
7
|
+
== 3.1.0 ==
|
8
|
+
Side by side diffs. Thanks Runar Skaare Tveiten!
|
9
|
+
|
1
10
|
== 3.0.5 ==
|
2
11
|
Improve performance when generating html output (with inline highlighting) on
|
3
12
|
long lines. Thanks Jason Barnabe!
|
data/CONTRIBUTORS
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Diffy - Easy Diffing With Ruby [![Build Status](https://
|
1
|
+
Diffy - Easy Diffing With Ruby [![Build Status](https://travis-ci.org/samg/diffy.svg?branch=master)](https://travis-ci.org/samg/diffy)
|
2
2
|
============================
|
3
3
|
|
4
4
|
Need diffs in your ruby app? Diffy has you covered. It provides a convenient
|
@@ -24,11 +24,11 @@ A default format can be set like so:
|
|
24
24
|
Installation
|
25
25
|
------------
|
26
26
|
|
27
|
-
###on Unix
|
27
|
+
### on Unix
|
28
28
|
|
29
29
|
gem install diffy
|
30
30
|
|
31
|
-
###on Windows:
|
31
|
+
### on Windows:
|
32
32
|
|
33
33
|
1. Ensure that you have a working `diff` on your machine and in your search path.
|
34
34
|
|
@@ -126,6 +126,81 @@ There's some pretty nice css provided in `Diffy::CSS`.
|
|
126
126
|
.diff li.diff-comment { display: none; }
|
127
127
|
.diff li.diff-block-info { background: none repeat scroll 0 0 gray; }
|
128
128
|
|
129
|
+
|
130
|
+
There's also a colorblind-safe version of the pallete provided in `Diffy::CSS_COLORBLIND_1`.
|
131
|
+
|
132
|
+
|
133
|
+
Side-by-side comparisons
|
134
|
+
------------------------
|
135
|
+
|
136
|
+
Side-by-side comparisons, or split views as called by some, are supported by
|
137
|
+
using the `Diffy::SplitDiff` class. This class takes a diff returned from
|
138
|
+
`Diffy::Diff` and splits it in two parts (or two sides): left and right. The
|
139
|
+
left side represents deletions while the right side represents insertions.
|
140
|
+
|
141
|
+
The class is used as follows:
|
142
|
+
|
143
|
+
```
|
144
|
+
Diffy::SplitDiff.new(string1, string2, options = {})
|
145
|
+
```
|
146
|
+
|
147
|
+
The optional options hash is passed along to the main `Diff::Diff` class, so
|
148
|
+
all default options such as full diff output are supported. The output format
|
149
|
+
may be changed by passing the format with the options hash (see below), and all
|
150
|
+
default formats are supported.
|
151
|
+
|
152
|
+
Unlike `Diffy::Diff`, `Diffy::SplitDiff` does not use `#to_s` to output
|
153
|
+
the resulting diff. Instead, two self-explanatory methods are used to output
|
154
|
+
the diff: `#left` and `#right`. Using the earlier example, this is what they
|
155
|
+
look like in action:
|
156
|
+
|
157
|
+
```
|
158
|
+
>> puts Diffy::SplitDiff.new(string1, string2).left
|
159
|
+
-Hello how are you
|
160
|
+
I'm fine
|
161
|
+
-That's great
|
162
|
+
```
|
163
|
+
|
164
|
+
```
|
165
|
+
>> puts Diffy::SplitDiff.new(string1, string2).right
|
166
|
+
+Hello how are you?
|
167
|
+
I'm fine
|
168
|
+
+That's swell
|
169
|
+
```
|
170
|
+
|
171
|
+
### Changing the split view output format
|
172
|
+
|
173
|
+
The output format may be changed by passing the format with the options hash:
|
174
|
+
|
175
|
+
```
|
176
|
+
Diffy::SplitDiff.new(string1, string2, :format => :html)
|
177
|
+
```
|
178
|
+
|
179
|
+
This will result in the following:
|
180
|
+
|
181
|
+
```
|
182
|
+
>> puts Diffy::SplitDiff.new(string1, string2, :format => :html).left
|
183
|
+
<div class="diff">
|
184
|
+
<ul>
|
185
|
+
<li class="del"><del>Hello how are you</del></li>
|
186
|
+
<li class="unchanged"><span>I'm fine</span></li>
|
187
|
+
<li class="del"><del>That's <strong>great</strong></del></li>
|
188
|
+
</ul>
|
189
|
+
</div>
|
190
|
+
```
|
191
|
+
|
192
|
+
```
|
193
|
+
>> puts Diffy::SplitDiff.new(string1, string2, :format => :html).right
|
194
|
+
<div class="diff">
|
195
|
+
<ul>
|
196
|
+
<li class="ins"><ins>Hello how are you<strong>?</strong></ins></li>
|
197
|
+
<li class="unchanged"><span>I'm fine</span></li>
|
198
|
+
<li class="ins"><ins>That's <strong>swell</strong></ins></li>
|
199
|
+
</ul>
|
200
|
+
</div>
|
201
|
+
```
|
202
|
+
|
203
|
+
|
129
204
|
Other Diff Options
|
130
205
|
------------------
|
131
206
|
|
@@ -138,7 +213,7 @@ You can diff files instead of strings by using the `:source` option.
|
|
138
213
|
### Full Diff Output
|
139
214
|
|
140
215
|
By default Diffy removes the superfluous diff output. This is because its
|
141
|
-
default is to show the complete diff'ed file (`diff -
|
216
|
+
default is to show the complete diff'ed file (`diff -U10000` is the default).
|
142
217
|
|
143
218
|
Diffy does support full output, just use the `:include_diff_info => true`
|
144
219
|
option when initializing:
|
@@ -195,13 +270,22 @@ file).
|
|
195
270
|
### Overriding the command line options passed to diff.
|
196
271
|
|
197
272
|
You can use the `:diff` option to override the command line options that are
|
198
|
-
passed to unix diff. They default to `-
|
273
|
+
passed to unix diff. They default to `-U10000`. This option will noop if
|
199
274
|
combined with the `:context` option.
|
200
275
|
|
201
276
|
>> puts Diffy::Diff.new(" foo\nbar\n", "foo\nbar\n", :diff => "-w")
|
202
277
|
foo
|
203
278
|
bar
|
204
279
|
|
280
|
+
### `:ignore_crlf` when doing HTML compares
|
281
|
+
|
282
|
+
You can make the HTML output ignore the CRLF by passing the `:ignore_crlf` option a truthy value.
|
283
|
+
|
284
|
+
>> puts Diffy::Diff.new(" foo\nbar\n", "foo\r\nbar\r\n", ignore_crlf: true).to_s(:html)
|
285
|
+
"<div class=\"diff\"></div>"
|
286
|
+
|
287
|
+
|
288
|
+
|
205
289
|
Default Diff Options
|
206
290
|
--------------------
|
207
291
|
|
@@ -210,9 +294,9 @@ You can set the default options for new `Diffy::Diff`s using the
|
|
210
294
|
Options passed to `Diffy::Diff.new` will be merged into the default options.
|
211
295
|
|
212
296
|
>> Diffy::Diff.default_options
|
213
|
-
=> {:diff=>"-
|
297
|
+
=> {:diff=>"-U10000", :source=>"strings", :include_diff_info=>false, :include_plus_and_minus_in_html=>false}
|
214
298
|
>> Diffy::Diff.default_options.merge!(:source => 'files')
|
215
|
-
=> {:diff=>"-
|
299
|
+
=> {:diff=>"-U10000", :source=>"files", :include_diff_info=>false, :include_plus_and_minus_in_html=>false}
|
216
300
|
|
217
301
|
|
218
302
|
Custom Formats
|
@@ -240,16 +324,6 @@ deletions, and unchanged in a diff.
|
|
240
324
|
Use `#map`, `#inject`, or any of Enumerable's methods. Go crazy.
|
241
325
|
|
242
326
|
|
243
|
-
Ruby Version Compatibility
|
244
|
-
-------------------------
|
245
|
-
|
246
|
-
Support for Ruby 1.8.6 was dropped beginning at version 2.0 in order to support
|
247
|
-
the chainable enumerators available in 1.8.7 and 1.9.
|
248
|
-
|
249
|
-
If you want to use Diffy and Ruby 1.8.6 then:
|
250
|
-
|
251
|
-
$ gem install diffy -v1.1.0
|
252
|
-
|
253
327
|
Testing
|
254
328
|
------------
|
255
329
|
|
data/Rakefile
CHANGED
data/diffy.gemspec
CHANGED
data/lib/diffy.rb
CHANGED
@@ -9,4 +9,5 @@ require 'open3' unless Diffy::WINDOWS
|
|
9
9
|
require File.join(File.dirname(__FILE__), 'diffy', 'format')
|
10
10
|
require File.join(File.dirname(__FILE__), 'diffy', 'html_formatter')
|
11
11
|
require File.join(File.dirname(__FILE__), 'diffy', 'diff')
|
12
|
+
require File.join(File.dirname(__FILE__), 'diffy', 'split_diff')
|
12
13
|
require File.join(File.dirname(__FILE__), 'diffy', 'css')
|
data/lib/diffy/css.rb
CHANGED
@@ -14,4 +14,21 @@ module Diffy
|
|
14
14
|
.diff li.diff-comment { display: none; }
|
15
15
|
.diff li.diff-block-info { background: none repeat scroll 0 0 gray; }
|
16
16
|
STYLE
|
17
|
+
|
18
|
+
CSS_COLORBLIND_1 = <<-STYLE
|
19
|
+
.diff{overflow:auto;}
|
20
|
+
.diff ul{background:#fff;overflow:auto;font-size:13px;list-style:none;margin:0;padding:0;display:table;width:100%;}
|
21
|
+
.diff del, .diff ins{display:block;text-decoration:none;}
|
22
|
+
.diff li{padding:0; display:table-row;margin: 0;height:1em;}
|
23
|
+
.diff li.ins{background:#ddf; color:#008}
|
24
|
+
.diff li.del{background:#fee; color:#b00}
|
25
|
+
.diff li:hover{background:#ffc}
|
26
|
+
/* try 'whitespace:pre;' if you don't want lines to wrap */
|
27
|
+
.diff del, .diff ins, .diff span{white-space:pre-wrap;font-family:courier;}
|
28
|
+
.diff del strong{font-weight:normal;background:#fcc;}
|
29
|
+
.diff ins strong{font-weight:normal;background:#99f;}
|
30
|
+
.diff li.diff-comment { display: none; }
|
31
|
+
.diff li.diff-block-info { background: none repeat scroll 0 0 gray; }
|
32
|
+
STYLE
|
33
|
+
|
17
34
|
end
|
data/lib/diffy/diff.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Diffy
|
2
2
|
class Diff
|
3
3
|
ORIGINAL_DEFAULT_OPTIONS = {
|
4
|
-
:diff => '-
|
4
|
+
:diff => '-U10000',
|
5
5
|
:source => 'strings',
|
6
6
|
:include_diff_info => false,
|
7
7
|
:include_plus_and_minus_in_html => false,
|
@@ -12,7 +12,7 @@ module Diffy
|
|
12
12
|
class << self
|
13
13
|
attr_writer :default_format
|
14
14
|
def default_format
|
15
|
-
@default_format
|
15
|
+
@default_format ||= :text
|
16
16
|
end
|
17
17
|
|
18
18
|
# default options passed to new Diff objects
|
@@ -23,7 +23,7 @@ module Diffy
|
|
23
23
|
|
24
24
|
end
|
25
25
|
include Enumerable
|
26
|
-
attr_reader :string1, :string2, :options
|
26
|
+
attr_reader :string1, :string2, :options
|
27
27
|
|
28
28
|
# supported options
|
29
29
|
# +:diff+:: A cli options string passed to diff
|
@@ -42,7 +42,7 @@ module Diffy
|
|
42
42
|
|
43
43
|
def diff
|
44
44
|
@diff ||= begin
|
45
|
-
paths = case options[:source]
|
45
|
+
@paths = case options[:source]
|
46
46
|
when 'strings'
|
47
47
|
[tempfile(string1), tempfile(string2)]
|
48
48
|
when 'files'
|
@@ -51,10 +51,10 @@ module Diffy
|
|
51
51
|
|
52
52
|
if WINDOWS
|
53
53
|
# don't use open3 on windows
|
54
|
-
cmd = sprintf '"%s" %s %s', diff_bin, diff_options.join(' '), paths.map { |s| %("#{s}") }.join(' ')
|
54
|
+
cmd = sprintf '"%s" %s %s', diff_bin, diff_options.join(' '), @paths.map { |s| %("#{s}") }.join(' ')
|
55
55
|
diff = `#{cmd}`
|
56
56
|
else
|
57
|
-
diff = Open3.popen3(diff_bin, *(diff_options + paths)) { |i, o, e| o.read }
|
57
|
+
diff = Open3.popen3(diff_bin, *(diff_options + @paths)) { |i, o, e| o.read }
|
58
58
|
end
|
59
59
|
diff.force_encoding('ASCII-8BIT') if diff.respond_to?(:valid_encoding?) && !diff.valid_encoding?
|
60
60
|
if diff =~ /\A\s*\Z/ && !options[:allow_empty_diff]
|
@@ -67,24 +67,37 @@ module Diffy
|
|
67
67
|
end
|
68
68
|
ensure
|
69
69
|
# unlink the tempfiles explicitly now that the diff is generated
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
70
|
+
if defined? @tempfiles # to avoid Ruby warnings about undefined ins var.
|
71
|
+
Array(@tempfiles).each do |t|
|
72
|
+
begin
|
73
|
+
# check that the path is not nil and file still exists.
|
74
|
+
# REE seems to be very agressive with when it magically removes
|
75
|
+
# tempfiles
|
76
|
+
t.unlink if t.path && File.exist?(t.path)
|
77
|
+
rescue => e
|
78
|
+
warn "#{e.class}: #{e}"
|
79
|
+
warn e.backtrace.join("\n")
|
80
|
+
end
|
79
81
|
end
|
80
82
|
end
|
81
83
|
end
|
82
84
|
|
83
85
|
def each
|
84
86
|
lines = case @options[:include_diff_info]
|
85
|
-
when false
|
86
|
-
|
87
|
+
when false
|
88
|
+
# this "primes" the diff and sets up the paths we'll reference below.
|
89
|
+
diff
|
90
|
+
|
91
|
+
# caching this regexp improves the performance of the loop by a
|
92
|
+
# considerable amount.
|
93
|
+
regexp = /^(--- "?#{@paths[0]}"?|\+\+\+ "?#{@paths[1]}"?|@@|\\\\)/
|
94
|
+
|
95
|
+
diff.split("\n").reject{|x| x =~ regexp }.map {|line| line + "\n" }
|
96
|
+
|
97
|
+
when true
|
98
|
+
diff.split("\n").map {|line| line + "\n" }
|
87
99
|
end
|
100
|
+
|
88
101
|
if block_given?
|
89
102
|
lines.each{|line| yield line}
|
90
103
|
else
|
@@ -161,7 +174,7 @@ module Diffy
|
|
161
174
|
|
162
175
|
# options pass to diff program
|
163
176
|
def diff_options
|
164
|
-
Array(options[:context] ? "-U
|
177
|
+
Array(options[:context] ? "-U#{options[:context]}" : options[:diff])
|
165
178
|
end
|
166
179
|
|
167
180
|
end
|
data/lib/diffy/format.rb
CHANGED
data/lib/diffy/html_formatter.rb
CHANGED
@@ -90,10 +90,14 @@ module Diffy
|
|
90
90
|
|
91
91
|
def split_characters(chunk)
|
92
92
|
chunk.gsub(/^./, '').each_line.map do |line|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
93
|
+
if @options[:ignore_crlf]
|
94
|
+
(line.chomp.split('') + ['\n']).map{|chr| ERB::Util.h(chr) }
|
95
|
+
else
|
96
|
+
chars = line.sub(/([\r\n]$)/, '').split('')
|
97
|
+
# add escaped newlines
|
98
|
+
chars << '\n'
|
99
|
+
chars.map{|chr| ERB::Util.h(chr) }
|
100
|
+
end
|
97
101
|
end.flatten.join("\n") + "\n"
|
98
102
|
end
|
99
103
|
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Diffy
|
2
|
+
class SplitDiff
|
3
|
+
def initialize(left, right, options = {})
|
4
|
+
@format = options[:format] || Diffy::Diff.default_format
|
5
|
+
|
6
|
+
formats = Format.instance_methods(false).map { |x| x.to_s }
|
7
|
+
unless formats.include?(@format.to_s)
|
8
|
+
fail ArgumentError, "Format #{format.inspect} is not a valid format"
|
9
|
+
end
|
10
|
+
|
11
|
+
@diff = Diffy::Diff.new(left, right, options).to_s(@format)
|
12
|
+
@left_diff, @right_diff = split
|
13
|
+
end
|
14
|
+
|
15
|
+
%w(left right).each do |direction|
|
16
|
+
define_method direction do
|
17
|
+
instance_variable_get("@#{direction}_diff")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def split
|
24
|
+
[split_left, split_right]
|
25
|
+
end
|
26
|
+
|
27
|
+
def split_left
|
28
|
+
case @format
|
29
|
+
when :color
|
30
|
+
@diff.gsub(/\033\[32m\+(.*)\033\[0m\n/, '')
|
31
|
+
when :html, :html_simple
|
32
|
+
@diff.gsub(%r{\s+<li class="ins"><ins>(.*)</ins></li>}, '')
|
33
|
+
when :text
|
34
|
+
@diff.gsub(/^\+(.*)\n/, '')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def split_right
|
39
|
+
case @format
|
40
|
+
when :color
|
41
|
+
@diff.gsub(/\033\[31m\-(.*)\033\[0m\n/, '')
|
42
|
+
when :html, :html_simple
|
43
|
+
@diff.gsub(%r{\s+<li class="del"><del>(.*)</del></li>}, '')
|
44
|
+
when :text
|
45
|
+
@diff.gsub(/^-(.*)\n/, '')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/diffy/version.rb
CHANGED
data/spec/diffy_spec.rb
CHANGED
@@ -115,7 +115,7 @@ describe Diffy::Diff do
|
|
115
115
|
describe "handling temp files" do
|
116
116
|
it "should unlink tempfiles after generating the diff" do
|
117
117
|
before_tmpfiles = Dir.entries(Dir.tmpdir)
|
118
|
-
|
118
|
+
::Diffy::Diff.new("a", "b").to_s
|
119
119
|
after_tmpfiles = Dir.entries(Dir.tmpdir)
|
120
120
|
expect(before_tmpfiles).to match_array(after_tmpfiles)
|
121
121
|
end
|
@@ -503,6 +503,13 @@ baz
|
|
503
503
|
expect(@diff.to_s(:html)).to eq(html)
|
504
504
|
end
|
505
505
|
|
506
|
+
it "should treat unix vs windows newlines as same if option :ignore_crlf" do
|
507
|
+
@diff = Diffy::Diff.new("one\ntwo\nthree\n", "one\r\ntwo\r\nthree\r\n",
|
508
|
+
ignore_crlf: true)
|
509
|
+
empty_diff = "<div class=\"diff\"></div>"
|
510
|
+
expect(@diff.to_s(:html)).to eq(empty_diff)
|
511
|
+
end
|
512
|
+
|
506
513
|
describe 'with lines that include \n' do
|
507
514
|
before do
|
508
515
|
string1 = 'a\nb'"\n"
|
@@ -585,6 +592,97 @@ baz
|
|
585
592
|
line
|
586
593
|
end).to eq([" foo\n", " bar\n", "+baz\n"])
|
587
594
|
end
|
595
|
+
|
596
|
+
it "should handle lines that begin with --" do
|
597
|
+
string1 = "a a\n-- b\nc c\n"
|
598
|
+
string2 = "a a\nb b\nc c\n"
|
599
|
+
|
600
|
+
expect(Diffy::Diff.new(string1, string2).to_s).to eq <<-DIFF
|
601
|
+
a a
|
602
|
+
--- b
|
603
|
+
+b b
|
604
|
+
c c
|
605
|
+
DIFF
|
606
|
+
end
|
607
|
+
|
608
|
+
it "should handle lines that begin with ++" do
|
609
|
+
string1 = "a a\nb b\nc c\n"
|
610
|
+
string2 = "a a\n++ b\nc c\n"
|
611
|
+
|
612
|
+
expect(Diffy::Diff.new(string1, string2).to_s).to eq <<-DIFF
|
613
|
+
a a
|
614
|
+
-b b
|
615
|
+
+++ b
|
616
|
+
c c
|
617
|
+
DIFF
|
618
|
+
end
|
619
|
+
end
|
620
|
+
end
|
621
|
+
|
622
|
+
describe Diffy::SplitDiff do
|
623
|
+
before do
|
624
|
+
::Diffy::Diff.default_options.merge!(:diff => '-U10000')
|
625
|
+
end
|
626
|
+
|
627
|
+
it "should fail with invalid format" do
|
628
|
+
expected_fail = expect do
|
629
|
+
Diffy::SplitDiff.new("lorem\n", "ipsum\n", :format => :fail)
|
630
|
+
end
|
631
|
+
expected_fail.to raise_error(ArgumentError)
|
632
|
+
end
|
633
|
+
|
634
|
+
describe "#left" do
|
635
|
+
it "should only highlight deletions" do
|
636
|
+
string1 = "lorem\nipsum\ndolor\nsit amet\n"
|
637
|
+
string2 = "lorem\nipsumdolor\nsit amet\n"
|
638
|
+
expect(Diffy::SplitDiff.new(string1, string2).left).to eq <<-TEXT
|
639
|
+
lorem
|
640
|
+
-ipsum
|
641
|
+
-dolor
|
642
|
+
sit amet
|
643
|
+
TEXT
|
644
|
+
end
|
645
|
+
|
646
|
+
it "should also format left diff as html" do
|
647
|
+
string1 = "lorem\nipsum\ndolor\nsit amet\n"
|
648
|
+
string2 = "lorem\nipsumdolor\nsit amet\n"
|
649
|
+
expect(Diffy::SplitDiff.new(string1, string2, :format => :html).left).to eq <<-HTML
|
650
|
+
<div class="diff">
|
651
|
+
<ul>
|
652
|
+
<li class="unchanged"><span>lorem</span></li>
|
653
|
+
<li class="del"><del>ipsum<strong></strong></del></li>
|
654
|
+
<li class="del"><del><strong></strong>dolor</del></li>
|
655
|
+
<li class="unchanged"><span>sit amet</span></li>
|
656
|
+
</ul>
|
657
|
+
</div>
|
658
|
+
HTML
|
659
|
+
end
|
660
|
+
end
|
661
|
+
|
662
|
+
describe "#right" do
|
663
|
+
it "should only highlight insertions" do
|
664
|
+
string1 = "lorem\nipsum\ndolor\nsit amet\n"
|
665
|
+
string2 = "lorem\nipsumdolor\nsit amet\n"
|
666
|
+
expect(Diffy::SplitDiff.new(string1, string2).right).to eq <<-TEXT
|
667
|
+
lorem
|
668
|
+
+ipsumdolor
|
669
|
+
sit amet
|
670
|
+
TEXT
|
671
|
+
end
|
672
|
+
|
673
|
+
it "should also format right diff as html" do
|
674
|
+
string1 = "lorem\nipsum\ndolor\nsit amet\n"
|
675
|
+
string2 = "lorem\nipsumdolor\nsit amet\n"
|
676
|
+
expect(Diffy::SplitDiff.new(string1, string2, :format => :html).right).to eq <<-HTML
|
677
|
+
<div class="diff">
|
678
|
+
<ul>
|
679
|
+
<li class="unchanged"><span>lorem</span></li>
|
680
|
+
<li class="ins"><ins>ipsumdolor</ins></li>
|
681
|
+
<li class="unchanged"><span>sit amet</span></li>
|
682
|
+
</ul>
|
683
|
+
</div>
|
684
|
+
HTML
|
685
|
+
end
|
588
686
|
end
|
589
687
|
end
|
590
688
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diffy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Goldstein
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
description: Convenient diffing in ruby
|
42
42
|
email:
|
43
43
|
- sgrock@gmail.org
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- lib/diffy/diff.rb
|
61
61
|
- lib/diffy/format.rb
|
62
62
|
- lib/diffy/html_formatter.rb
|
63
|
+
- lib/diffy/split_diff.rb
|
63
64
|
- lib/diffy/version.rb
|
64
65
|
- spec/demo_app.rb
|
65
66
|
- spec/diffy_spec.rb
|
@@ -67,7 +68,7 @@ homepage: http://github.com/samg/diffy
|
|
67
68
|
licenses:
|
68
69
|
- MIT
|
69
70
|
metadata: {}
|
70
|
-
post_install_message:
|
71
|
+
post_install_message:
|
71
72
|
rdoc_options: []
|
72
73
|
require_paths:
|
73
74
|
- lib
|
@@ -82,9 +83,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
83
|
- !ruby/object:Gem::Version
|
83
84
|
version: '0'
|
84
85
|
requirements: []
|
85
|
-
|
86
|
-
|
87
|
-
signing_key:
|
86
|
+
rubygems_version: 3.0.6
|
87
|
+
signing_key:
|
88
88
|
specification_version: 4
|
89
89
|
summary: A convenient way to diff string in ruby
|
90
90
|
test_files:
|