kronk 1.2.4 → 1.2.5

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/History.rdoc CHANGED
@@ -1,3 +1,10 @@
1
+ === 1.2.5 / 2011-03-09
2
+
3
+ * Bugfixes:
4
+
5
+ * Small fix to the diff functionality.
6
+ Swapping left and right would not always yeild the same behavior.
7
+
1
8
  === 1.2.4 / 2011-03-04
2
9
 
3
10
  * Enhancements:
data/lib/kronk.rb CHANGED
@@ -11,7 +11,7 @@ require 'yaml'
11
11
  class Kronk
12
12
 
13
13
  # This gem's version.
14
- VERSION = '1.2.4'
14
+ VERSION = '1.2.5'
15
15
 
16
16
 
17
17
  ##
data/lib/kronk/diff.rb CHANGED
@@ -205,7 +205,8 @@ class Kronk
205
205
  match1 = arr1.index item2
206
206
  match2 = arr2.index item1
207
207
 
208
- if match1
208
+
209
+ if use_left?(match1, match2)
209
210
  diff_ary.concat diff_match(item1, match1, arr1, 0, sub_diff)
210
211
  sub_diff = nil
211
212
 
@@ -226,6 +227,14 @@ class Kronk
226
227
  end
227
228
 
228
229
 
230
+ ##
231
+ # Check if the index on the left should be used.
232
+
233
+ def use_left? index1, index2
234
+ index1 && (index2.nil? || index1 < index2)
235
+ end
236
+
237
+
229
238
  ##
230
239
  # Create a diff from a match.
231
240
 
data/test/test_diff.rb CHANGED
@@ -291,6 +291,24 @@ STR
291
291
  end
292
292
 
293
293
 
294
+ def test_create_diff_smallest_match
295
+ str1 = "line1\nline right\nline4\nline4\nline5\nline6\nline2\nline7"
296
+ str2 = "line1\nline left\nline2\nline3\nline4\nline5"
297
+
298
+ expected = [
299
+ "line1",
300
+ [["line right"], ["line left", "line2", "line3"]],
301
+ "line4",
302
+ [["line4"], []],
303
+ "line5",
304
+ [["line6", "line2", "line7"], []]
305
+ ]
306
+
307
+ diff = Kronk::Diff.new str1, str2
308
+ assert_equal expected, diff.create_diff
309
+ end
310
+
311
+
294
312
  def test_count
295
313
  assert_equal 4, @diff.count
296
314
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kronk
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 4
10
- version: 1.2.4
9
+ - 5
10
+ version: 1.2.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeremie Castagna
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-04 00:00:00 -08:00
18
+ date: 2011-03-09 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency