diff 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/Rakefile +1 -1
- data/diff.gemspec +1 -1
- data/lib/emaildiff.rb +44 -5
- data/test/test_emailcases.rb +9 -0
- data/test/test_emaildiff.rb +3 -5
- metadata +2 -2
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/Rakefile
CHANGED
data/diff.gemspec
CHANGED
data/lib/emaildiff.rb
CHANGED
@@ -1,11 +1,50 @@
|
|
1
1
|
require 'diff'
|
2
2
|
|
3
|
+
class EmailDiff < Diff
|
4
|
+
GREATER = 62
|
5
|
+
|
6
|
+
attr_reader :orig_a, :orig_b
|
7
|
+
|
8
|
+
def initialize(diffs_or_a, b = nil, isstring = nil)
|
9
|
+
if b.nil?
|
10
|
+
@diffs = diffs_or_a
|
11
|
+
@isstring = isstring
|
12
|
+
super
|
13
|
+
else
|
14
|
+
@diffs = []
|
15
|
+
@curdiffs = []
|
16
|
+
strip_a = striplines(diffs_or_a)
|
17
|
+
strip_b = striplines(b)
|
18
|
+
makediff(strip_a, strip_b)
|
19
|
+
@orig_a = diffs_or_a
|
20
|
+
@orig_b = b
|
21
|
+
@difftype = diffs_or_a.class
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def striplines(ary)
|
26
|
+
newary= ary.dup
|
27
|
+
newary.each_with_index { |item,index|
|
28
|
+
if item.class == String
|
29
|
+
item = item.dup
|
30
|
+
item.strip
|
31
|
+
while item[0] == GREATER
|
32
|
+
item.slice!(0)
|
33
|
+
item.strip
|
34
|
+
newary[index] = item
|
35
|
+
end
|
36
|
+
end
|
37
|
+
}
|
38
|
+
return newary
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
3
42
|
module HTMLCollapsable
|
4
43
|
def diff(b)
|
5
44
|
Diff.new(self, b)
|
6
45
|
end
|
7
46
|
|
8
|
-
def
|
47
|
+
def patch(diff,starttoken,endtoken)
|
9
48
|
newary = nil
|
10
49
|
if diff.difftype == String
|
11
50
|
newary = diff.difftype.new('')
|
@@ -24,7 +63,7 @@ module HTMLCollapsable
|
|
24
63
|
end
|
25
64
|
newary << starttoken if quoted == 1
|
26
65
|
while ai < mod[1]
|
27
|
-
newary <<
|
66
|
+
newary << diff.orig_a[ai]
|
28
67
|
ai += 1
|
29
68
|
bi += 1
|
30
69
|
end
|
@@ -36,12 +75,12 @@ module HTMLCollapsable
|
|
36
75
|
end
|
37
76
|
newary << starttoken if quoted == 1
|
38
77
|
while bi < mod[1]
|
39
|
-
newary <<
|
78
|
+
newary << diff.orig_a[ai]
|
40
79
|
ai += 1
|
41
80
|
bi += 1
|
42
81
|
end
|
43
82
|
newary << endtoken if quoted == 1
|
44
|
-
newary << mod[
|
83
|
+
newary << diff.orig_b[mod[1]]
|
45
84
|
bi += 1
|
46
85
|
else
|
47
86
|
raise "Unknown diff action"
|
@@ -54,7 +93,7 @@ module HTMLCollapsable
|
|
54
93
|
end
|
55
94
|
newary << starttoken if quoted == 1
|
56
95
|
while ai < self.length
|
57
|
-
newary <<
|
96
|
+
newary << diff.orig_a[ai]
|
58
97
|
ai += 1
|
59
98
|
bi += 1
|
60
99
|
end
|
data/test/test_emailcases.rb
CHANGED
@@ -1,4 +1,13 @@
|
|
1
1
|
module DiffArrayTests
|
2
|
+
def test_array_quoted
|
3
|
+
difftest ["1","2","3"], [">1",">2",">3","4"], [888,">1",">2",">3",999,"4"]
|
4
|
+
difftest ["1","2","3"], [">1",">2",">3","4","5"], [888,">1",">2",">3",999,"4","5"]
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_array_quoted
|
8
|
+
difftest ["1","2","3"], [">1",">2",">3","4"], [888,">1",">2",">3",999,"4"]
|
9
|
+
difftest ["1"," > 2"," > 3"], [">1","> > 2","> > 3","4","5"], [888,">1","> > 2","> > 3",999,"4","5"]
|
10
|
+
end
|
2
11
|
|
3
12
|
def test_array_append
|
4
13
|
difftest [1,2,3], [1,2,3,4], [888,1,2,3,999,4]
|
data/test/test_emaildiff.rb
CHANGED
@@ -8,19 +8,17 @@ require 'test_emailcases'
|
|
8
8
|
class EmailDiffTest < RUNIT::TestCase
|
9
9
|
|
10
10
|
include DiffArrayTests
|
11
|
-
|
12
11
|
def difftest(a, b, c)
|
13
12
|
#puts "old string:"
|
14
13
|
#puts a
|
15
14
|
#puts "new string:"
|
16
15
|
#puts b
|
17
|
-
diff =
|
18
|
-
d = a.
|
16
|
+
diff = EmailDiff.new(a, b)
|
17
|
+
d = a.patch(diff,888,999)
|
19
18
|
#puts "result:"
|
20
|
-
#puts
|
19
|
+
#puts d
|
21
20
|
assert_equal(c,d)
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
25
|
-
|
26
24
|
RUNIT::CUI::TestRunner.run(EmailDiffTest.suite)
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|