diff 0.3.2 → 0.3.3

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.
data.tar.gz.sig CHANGED
Binary file
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('diff','0.3.2') do |s|
5
+ Echoe.new('diff','0.3.3') do |s|
6
6
  s.description = "Diff Algorithm Implementation"
7
7
  s.url = "http://users.cybercity.dk/~dsl8950/ruby/diff.html"
8
8
  s.author = "Wayne Walter"
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{diff}
5
- s.version = "0.3.2"
5
+ s.version = "0.3.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Wayne Walter"]
@@ -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 collapse(diff,starttoken,endtoken)
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 << self[ai]
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 << self[ai]
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[2]
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 << self[ai]
96
+ newary << diff.orig_a[ai]
58
97
  ai += 1
59
98
  bi += 1
60
99
  end
@@ -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]
@@ -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 = Diff.new(a, b)
18
- d = a.collapse(diff,888,999)
16
+ diff = EmailDiff.new(a, b)
17
+ d = a.patch(diff,888,999)
19
18
  #puts "result:"
20
- #puts c
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
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 2
9
- version: 0.3.2
8
+ - 3
9
+ version: 0.3.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Wayne Walter
metadata.gz.sig CHANGED
Binary file