tdiff 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,11 @@
1
+ ### 0.3.2 / 2010-11-28
2
+
3
+ * Added {TDiff#tdiff_recursive} to only handle recursively traversing
4
+ and diffing the children nodes.
5
+ * Added {TDiff::Unordered#tdiff_recursive_unordered} to only handle
6
+ recursively traversing and diffing the children nodes, without respecting
7
+ the order of the nodes.
8
+
1
9
  ### 0.3.1 / 2010-11-28
2
10
 
3
11
  * Fixed a typo in {TDiff::Unordered#tdiff_unordered}, which was causing
@@ -1,5 +1,5 @@
1
1
  name: tdiff
2
- version: 0.3.1
2
+ version: 0.3.2
3
3
  summary: Calculates the differences between two tree-like structures.
4
4
  description:
5
5
  Calculates the differences between two tree-like structures. Similar to
@@ -58,6 +58,32 @@ module TDiff
58
58
  return self
59
59
  end
60
60
 
61
+ yield ' ', self
62
+
63
+ tdiff_recursive(tree,&block)
64
+ return self
65
+ end
66
+
67
+ protected
68
+
69
+ #
70
+ # Recursively compares the differences between the children nodes.
71
+ #
72
+ # @param [#tdiff_each_child] tree
73
+ # The other tree.
74
+ #
75
+ # @yield [change, node]
76
+ # The given block will be passed the added or removed nodes.
77
+ #
78
+ # @yieldparam [' ', '+', '-'] change
79
+ # The state-change of the node.
80
+ #
81
+ # @yieldparam [Object] node
82
+ # A node from one of the two trees.
83
+ #
84
+ # @since 0.3.2
85
+ #
86
+ def tdiff_recursive(tree,&block)
61
87
  c = Hash.new { |hash,key| hash[key] = Hash.new(0) }
62
88
  x = enum_for(:tdiff_each_child,self)
63
89
  y = enum_for(:tdiff_each_child,tree)
@@ -122,9 +148,7 @@ module TDiff
122
148
  changes = nil
123
149
 
124
150
  # recurse down through unchanged nodes
125
- unchanged.each { |x,y| x.tdiff(y,&block) }
151
+ unchanged.each { |x,y| x.tdiff_recursive(y,&block) }
126
152
  unchanged = nil
127
-
128
- return self
129
153
  end
130
154
  end
@@ -15,7 +15,7 @@ module TDiff
15
15
 
16
16
  #
17
17
  # Finds the differences between `self` and another tree, not respecting
18
- # the ordering of children.
18
+ # the order of the nodes.
19
19
  #
20
20
  # @param [#tdiff_each_child] tree
21
21
  # The other tree.
@@ -44,6 +44,33 @@ module TDiff
44
44
  return self
45
45
  end
46
46
 
47
+ yield ' ', self
48
+
49
+ tdiff_recursive_unordered(tree,&block)
50
+ return self
51
+ end
52
+
53
+ protected
54
+
55
+ #
56
+ # Recursively compares the differences between the children nodes,
57
+ # without respecting the order of the nodes.
58
+ #
59
+ # @param [#tdiff_each_child] tree
60
+ # The other tree.
61
+ #
62
+ # @yield [change, node]
63
+ # The given block will be passed the added or removed nodes.
64
+ #
65
+ # @yieldparam [' ', '+', '-'] change
66
+ # The state-change of the node.
67
+ #
68
+ # @yieldparam [Object] node
69
+ # A node from one of the two trees.
70
+ #
71
+ # @since 0.3.2
72
+ #
73
+ def tdiff_recursive_unordered(tree,&block)
47
74
  x = enum_for(:tdiff_each_child,self)
48
75
  y = enum_for(:tdiff_each_child,tree)
49
76
 
@@ -79,10 +106,11 @@ module TDiff
79
106
  changes = nil
80
107
 
81
108
  # recurse down the unchanged nodes
82
- unchanged.each { |xi,yj| xi.tdiff_unordered(yj,&block) }
83
- unchanged = nil
109
+ unchanged.each do |xi,yj|
110
+ xi.tdiff_recursive_unordered(yj,&block)
111
+ end
84
112
 
85
- return self
113
+ unchanged = nil
86
114
  end
87
115
  end
88
116
  end
@@ -23,7 +23,7 @@ shared_examples_for 'TDiff' do |method|
23
23
  end
24
24
 
25
25
  it "should tell when sub-nodes are added" do
26
- changes = @tree.tdiff(@added).select { |change,node| change == '+' }
26
+ changes = @tree.send(method,@added).select { |change,node| change == '+' }
27
27
 
28
28
  changes.length.should == 1
29
29
  changes[0][0].should == '+'
@@ -31,7 +31,7 @@ shared_examples_for 'TDiff' do |method|
31
31
  end
32
32
 
33
33
  it "should tell when sub-nodes are removed" do
34
- changes = @tree.tdiff(@removed).select { |change,node| change == '-' }
34
+ changes = @tree.send(method,@removed).select { |change,node| change == '-' }
35
35
 
36
36
  changes.length.should == 1
37
37
  changes[0][0].should == '-'
@@ -11,20 +11,24 @@ describe TDiff do
11
11
  it "should detect when the order of children has changed" do
12
12
  changes = @tree.tdiff(@changed_order).to_a
13
13
 
14
- changes.length.should == 5
15
- changes[0][0].should == '-'
16
- changes[0][1].should == @tree.children[0]
14
+ changes.length.should == 6
17
15
 
18
- changes[1][0].should == ' '
19
- changes[1][1].should == @tree.children[1]
16
+ changes[0][0].should == ' '
17
+ changes[0][1].should == @tree
20
18
 
21
- changes[2][0].should == '+'
22
- changes[2][1].should == @changed_order.children[1]
19
+ changes[1][0].should == '-'
20
+ changes[1][1].should == @tree.children[0]
23
21
 
24
- changes[3][0].should == ' '
25
- changes[3][1].should == @tree.children[1].children[0]
22
+ changes[2][0].should == ' '
23
+ changes[2][1].should == @tree.children[1]
24
+
25
+ changes[3][0].should == '+'
26
+ changes[3][1].should == @changed_order.children[1]
26
27
 
27
28
  changes[4][0].should == ' '
28
- changes[4][1].should == @tree.children[1].children[1]
29
+ changes[4][1].should == @tree.children[1].children[0]
30
+
31
+ changes[5][0].should == ' '
32
+ changes[5][1].should == @tree.children[1].children[1]
29
33
  end
30
34
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 1
9
- version: 0.3.1
8
+ - 2
9
+ version: 0.3.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Postmodern