kronk 1.2.4 → 1.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +7 -0
- data/lib/kronk.rb +1 -1
- data/lib/kronk/diff.rb +10 -1
- data/test/test_diff.rb +18 -0
- metadata +4 -4
data/History.rdoc
CHANGED
data/lib/kronk.rb
CHANGED
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
|
-
|
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:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
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-
|
18
|
+
date: 2011-03-09 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|