docdiff 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/.gitignore +6 -0
  2. data/.travis.yml +7 -0
  3. data/Gemfile +17 -0
  4. data/Guardfile +8 -0
  5. data/Makefile +108 -0
  6. data/Rakefile +17 -0
  7. data/bin/docdiff +179 -0
  8. data/devutil/JIS0208.TXT +6952 -0
  9. data/devutil/char_by_charclass.rb +23 -0
  10. data/devutil/charclass_by_char.rb +21 -0
  11. data/devutil/jis0208.rb +343 -0
  12. data/devutil/testjis0208.rb +38 -0
  13. data/docdiff.conf.example +22 -0
  14. data/docdiff.gemspec +23 -0
  15. data/docdiffwebui.cgi +176 -0
  16. data/docdiffwebui.html +123 -0
  17. data/img/docdiff-screenshot-format-html-digest-firefox.png +0 -0
  18. data/img/docdiff-screenshot-format-html-firefox.png +0 -0
  19. data/img/docdiff-screenshot-format-tty-cmdexe-en.png +0 -0
  20. data/img/docdiff-screenshot-format-tty-cmdexe-ja.png +0 -0
  21. data/img/docdiff-screenshot-format-tty-rxvtunicode-en.png +0 -0
  22. data/img/docdiff-screenshot-format-tty-rxvtunicode-ja.png +0 -0
  23. data/img/docdiff-screenshot-format-tty-xterm-en.png +0 -0
  24. data/img/docdiff-screenshot-format-tty-xterm-ja.png +0 -0
  25. data/img/docdiff-screenshot-resolution-linewordchar-xterm.png +0 -0
  26. data/index.html +181 -0
  27. data/langfilter.rb +14 -0
  28. data/lib/doc_diff.rb +170 -0
  29. data/lib/docdiff.rb +7 -0
  30. data/lib/docdiff/charstring.rb +579 -0
  31. data/lib/docdiff/diff.rb +217 -0
  32. data/lib/docdiff/diff/contours.rb +382 -0
  33. data/lib/docdiff/diff/editscript.rb +148 -0
  34. data/lib/docdiff/diff/rcsdiff.rb +107 -0
  35. data/lib/docdiff/diff/shortestpath.rb +93 -0
  36. data/lib/docdiff/diff/speculative.rb +40 -0
  37. data/lib/docdiff/diff/subsequence.rb +39 -0
  38. data/lib/docdiff/diff/unidiff.rb +124 -0
  39. data/lib/docdiff/difference.rb +92 -0
  40. data/lib/docdiff/document.rb +127 -0
  41. data/lib/docdiff/encoding/en_ascii.rb +97 -0
  42. data/lib/docdiff/encoding/ja_eucjp.rb +269 -0
  43. data/lib/docdiff/encoding/ja_sjis.rb +260 -0
  44. data/lib/docdiff/encoding/ja_utf8.rb +6974 -0
  45. data/lib/docdiff/version.rb +3 -0
  46. data/lib/docdiff/view.rb +476 -0
  47. data/lib/viewdiff.rb +375 -0
  48. data/readme.html +713 -0
  49. data/sample/01.en.ascii.cr +1 -0
  50. data/sample/01.en.ascii.crlf +2 -0
  51. data/sample/01.en.ascii.lf +2 -0
  52. data/sample/01.ja.eucjp.lf +2 -0
  53. data/sample/01.ja.sjis.cr +1 -0
  54. data/sample/01.ja.sjis.crlf +2 -0
  55. data/sample/01.ja.utf8.crlf +2 -0
  56. data/sample/02.en.ascii.cr +1 -0
  57. data/sample/02.en.ascii.crlf +2 -0
  58. data/sample/02.en.ascii.lf +2 -0
  59. data/sample/02.ja.eucjp.lf +2 -0
  60. data/sample/02.ja.sjis.cr +1 -0
  61. data/sample/02.ja.sjis.crlf +2 -0
  62. data/sample/02.ja.utf8.crlf +2 -0
  63. data/sample/humpty_dumpty01.ascii.lf +4 -0
  64. data/sample/humpty_dumpty02.ascii.lf +4 -0
  65. data/test/charstring_test.rb +1008 -0
  66. data/test/diff_test.rb +36 -0
  67. data/test/difference_test.rb +64 -0
  68. data/test/docdiff_test.rb +193 -0
  69. data/test/document_test.rb +626 -0
  70. data/test/test_helper.rb +7 -0
  71. data/test/view_test.rb +570 -0
  72. data/test/viewdiff_test.rb +908 -0
  73. metadata +129 -0
@@ -0,0 +1,908 @@
1
+ #!/usr/bin/ruby
2
+ # -*- coding: euc-jp; -*-
3
+ require 'test/unit'
4
+ require 'viewdiff'
5
+
6
+ class TC_Document < Test::Unit::TestCase
7
+
8
+ def setup()
9
+ @classic_diff = <<END
10
+ diff --text sample/1/a.en.ascii.lf sample/2/a.en.ascii.lf
11
+ 1d0
12
+ < a
13
+ 3,4d1
14
+ < c
15
+ < d
16
+ 6a4
17
+ > 0
18
+ 7a6,7
19
+ > 1
20
+ > 2
21
+ 9c9
22
+ < i
23
+ ---
24
+ > 3
25
+ 11c11,12
26
+ < k
27
+ ---
28
+ > 4
29
+ > 5
30
+ 13,14c14,15
31
+ < m
32
+ < n
33
+ ---
34
+ > 6
35
+ > 7
36
+ 22d22
37
+ < v
38
+ 23a24,25
39
+ > 8
40
+ > 9
41
+ 25c27,28
42
+ < y
43
+ ---
44
+ > A
45
+ > B
46
+ diff --text sample/1/b.en.ascii.lf sample/2/b.en.ascii.lf
47
+ 1c1,8
48
+ < a
49
+ ---
50
+ > @
51
+ > <
52
+ > >
53
+ > -
54
+ > +
55
+ > *
56
+ > !
57
+ >
58
+ 9a17,19
59
+ > +
60
+ >
61
+ >
62
+ 17d26
63
+ < q
64
+ 24c33
65
+ < x
66
+ ---
67
+ > *
68
+ 26c35
69
+ < z
70
+ ---
71
+ > z
72
+
73
+ END
74
+ @context_diff = <<END
75
+ diff -c --text sample/1/a.en.ascii.lf sample/2/a.en.ascii.lf
76
+ *** sample/1/a.en.ascii.lf Tue Aug 30 07:07:45 2005
77
+ --- sample/2/a.en.ascii.lf Tue Aug 30 07:33:51 2005
78
+ ***************
79
+ *** 1,17 ****
80
+ - a
81
+ b
82
+ - c
83
+ - d
84
+ e
85
+ f
86
+ g
87
+ h
88
+ ! i
89
+ j
90
+ ! k
91
+ l
92
+ ! m
93
+ ! n
94
+ o
95
+ p
96
+ q
97
+ --- 1,18 ----
98
+ b
99
+ e
100
+ f
101
+ + 0
102
+ g
103
+ + 1
104
+ + 2
105
+ h
106
+ ! 3
107
+ j
108
+ ! 4
109
+ ! 5
110
+ l
111
+ ! 6
112
+ ! 7
113
+ o
114
+ p
115
+ q
116
+ ***************
117
+ *** 19,26 ****
118
+ s
119
+ t
120
+ u
121
+ - v
122
+ w
123
+ x
124
+ ! y
125
+ z
126
+ --- 20,29 ----
127
+ s
128
+ t
129
+ u
130
+ w
131
+ + 8
132
+ + 9
133
+ x
134
+ ! A
135
+ ! B
136
+ z
137
+ diff -c --text sample/1/b.en.ascii.lf sample/2/b.en.ascii.lf
138
+ *** sample/1/b.en.ascii.lf Tue Aug 30 07:31:52 2005
139
+ --- sample/2/b.en.ascii.lf Tue Aug 30 07:41:01 2005
140
+ ***************
141
+ *** 1,4 ****
142
+ ! a
143
+ b
144
+ c
145
+ d
146
+ --- 1,11 ----
147
+ ! @
148
+ ! <
149
+ ! >
150
+ ! -
151
+ ! +
152
+ ! *
153
+ ! !
154
+ !
155
+ b
156
+ c
157
+ d
158
+ ***************
159
+ *** 7,12 ****
160
+ --- 14,22 ----
161
+ g
162
+ h
163
+ i
164
+ + +
165
+ +
166
+ +
167
+ j
168
+ k
169
+ l
170
+ ***************
171
+ *** 14,26 ****
172
+ n
173
+ o
174
+ p
175
+ - q
176
+ r
177
+ s
178
+ t
179
+ u
180
+ v
181
+ w
182
+ ! x
183
+ y
184
+ ! z
185
+ --- 24,35 ----
186
+ n
187
+ o
188
+ p
189
+ r
190
+ s
191
+ t
192
+ u
193
+ v
194
+ w
195
+ ! *
196
+ y
197
+ ! z
198
+
199
+ END
200
+ @context_diff_short = <<END
201
+ diff -c --text sample/1/a.en.ascii.lf sample/2/a.en.ascii.lf
202
+ *** sample/1/a.en.ascii.lf Tue Aug 30 07:07:45 2005
203
+ --- sample/2/a.en.ascii.lf Tue Aug 30 07:33:51 2005
204
+ ***************
205
+ *** 19,26 ****
206
+ s
207
+ t
208
+ u
209
+ - v
210
+ w
211
+ x
212
+ ! y
213
+ z
214
+ --- 20,29 ----
215
+ s
216
+ t
217
+ u
218
+ w
219
+ + 8
220
+ + 9
221
+ x
222
+ ! A
223
+ ! B
224
+ z
225
+
226
+ END
227
+ @unified_diff = <<END
228
+ diff -u --text sample/1/a.en.ascii.lf sample/2/a.en.ascii.lf
229
+ --- sample/1/a.en.ascii.lf 2005-08-30 07:07:45.000000000 +0900
230
+ +++ sample/2/a.en.ascii.lf 2005-08-30 07:33:51.000000000 +0900
231
+ @@ -1,17 +1,18 @@
232
+ -a
233
+ b
234
+ -c
235
+ -d
236
+ e
237
+ f
238
+ +0
239
+ g
240
+ +1
241
+ +2
242
+ h
243
+ -i
244
+ +3
245
+ j
246
+ -k
247
+ +4
248
+ +5
249
+ l
250
+ -m
251
+ -n
252
+ +6
253
+ +7
254
+ o
255
+ p
256
+ q
257
+ @@ -19,8 +20,10 @@
258
+ s
259
+ t
260
+ u
261
+ -v
262
+ w
263
+ +8
264
+ +9
265
+ x
266
+ -y
267
+ +A
268
+ +B
269
+ z
270
+ diff -u --text sample/1/b.en.ascii.lf sample/2/b.en.ascii.lf
271
+ --- sample/1/b.en.ascii.lf 2005-08-30 07:31:52.000000000 +0900
272
+ +++ sample/2/b.en.ascii.lf 2005-08-30 07:41:01.000000000 +0900
273
+ @@ -1,4 +1,11 @@
274
+ -a
275
+ +@
276
+ +<
277
+ +>
278
+ +-
279
+ ++
280
+ +*
281
+ +!
282
+ +
283
+ b
284
+ c
285
+ d
286
+ @@ -7,6 +14,9 @@
287
+ g
288
+ h
289
+ i
290
+ ++
291
+ +
292
+ +
293
+ j
294
+ k
295
+ l
296
+ @@ -14,13 +24,12 @@
297
+ n
298
+ o
299
+ p
300
+ -q
301
+ r
302
+ s
303
+ t
304
+ u
305
+ v
306
+ w
307
+ -x
308
+ +*
309
+ y
310
+ -z
311
+ +z
312
+
313
+ END
314
+ end
315
+
316
+ def test_guess_diff_type_classic()
317
+ expected = "classic"
318
+ result = DiffFile.new(@classic_diff).guess_diff_type(@classic_diff)
319
+ assert_equal(expected, result)
320
+ end
321
+ def test_guess_diff_type_context()
322
+ expected = "context"
323
+ result = DiffFile.new(@context_diff).guess_diff_type(@context_diff)
324
+ assert_equal(expected, result)
325
+ end
326
+ def test_guess_diff_type_unified()
327
+ expected = "unified"
328
+ result = DiffFile.new(@unified_diff).guess_diff_type(@unified_diff)
329
+ assert_equal(expected, result)
330
+ end
331
+ def test_guess_diff_type_unknown()
332
+ expected = "unknown"
333
+ result = DiffFile.new(@unified_diff).guess_diff_type("")
334
+ assert_equal(expected, result)
335
+ end
336
+
337
+ def test_difffile_src()
338
+ expected = @classic_diff
339
+ result = DiffFile.new(@classic_diff).src
340
+ assert_equal(expected, result)
341
+ end
342
+
343
+ def test_scan_text_for_diffs_simplified()
344
+ expected = 12
345
+ result = scan_text_for_diffs(@classic_diff + @context_diff + @unified_diff).size
346
+ assert_equal(expected, result)
347
+ end
348
+
349
+ def test_scan_text_for_diffs()
350
+ expected = [
351
+ "diff file1 file2\n",
352
+ "1d0\n< a\n6a4\n> 0\n7a6,7\n> 1\n> 2\n9c9\n< i\n---\n> 3\n",
353
+ "diff -o f3 f4\n",
354
+ "26c35\n< z\n---\n> z\n No newline at end of file\n",
355
+ "lorem insum\n",
356
+ "diff -o f1 f2\n",
357
+ "*** f1 blah\n--- f2 blab\n***************\n*** 1,17 ****\n- a\n b\n p\n q\n--- 1,18 ----\n b\n e\n f\n+ 0\n g\n+ 1\n+ 2\n h\n***************\n*** 19,26 ****\n w\n x\n! y\n z\n--- 20,29 ----\n x\n! A\n! B\n z\n No newline at end of file\n",
358
+ "diff f3 f4\n",
359
+ "*** f3 foo\n--- f4 bar\n***************\n*** 7,12 ****\n--- 14,22 ----\n g\n h\n i\n+ +\n+\n+\n j\n k\n l\n",
360
+ "\n",
361
+ "foo\n\n",
362
+ "diff -o\n",
363
+ "--- f1 foo\n+++ f2 bar\n@@ -19,8 +20,10 @@\n s\n t\n u\n-v\n w\n+8\n+9\n x\n-y\n+A\n+B\n z\n",
364
+ "diff -o\n",
365
+ "--- f3\n+++ f4\n@@ -7,6 +14,9 @@\n g\n h\n i\n++\n+\n+\n j\n k\n l\n@@ -14,13 +24,12 @@\n y\n-z\n+z\n No newline at end of file"
366
+ ]
367
+ result = scan_text_for_diffs("diff file1 file2
368
+ 1d0
369
+ < a
370
+ 6a4
371
+ > 0
372
+ 7a6,7
373
+ > 1
374
+ > 2
375
+ 9c9
376
+ < i
377
+ ---
378
+ > 3
379
+ diff -o f3 f4
380
+ 26c35
381
+ < z
382
+ ---
383
+ > z
384
+
385
+ lorem insum
386
+ diff -o f1 f2
387
+ *** f1 blah
388
+ --- f2 blab
389
+ ***************
390
+ *** 1,17 ****
391
+ - a
392
+ b
393
+ p
394
+ q
395
+ --- 1,18 ----
396
+ b
397
+ e
398
+ f
399
+ + 0
400
+ g
401
+ + 1
402
+ + 2
403
+ h
404
+ ***************
405
+ *** 19,26 ****
406
+ w
407
+ x
408
+ ! y
409
+ z
410
+ --- 20,29 ----
411
+ x
412
+ ! A
413
+ ! B
414
+ z
415
+
416
+ diff f3 f4
417
+ *** f3 foo
418
+ --- f4 bar
419
+ ***************
420
+ *** 7,12 ****
421
+ --- 14,22 ----
422
+ g
423
+ h
424
+ i
425
+ + +
426
+ +
427
+ +
428
+ j
429
+ k
430
+ l
431
+
432
+ foo
433
+
434
+ diff -o
435
+ --- f1 foo
436
+ +++ f2 bar
437
+ @@ -19,8 +20,10 @@
438
+ s
439
+ t
440
+ u
441
+ -v
442
+ w
443
+ +8
444
+ +9
445
+ x
446
+ -y
447
+ +A
448
+ +B
449
+ z
450
+ diff -o
451
+ --- f3
452
+ +++ f4
453
+ @@ -7,6 +14,9 @@
454
+ g
455
+ h
456
+ i
457
+ ++
458
+ +
459
+ +
460
+ j
461
+ k
462
+ l
463
+ @@ -14,13 +24,12 @@
464
+ y
465
+ -z
466
+ +z
467
+ ")
468
+ assert_equal(expected, result)
469
+ end
470
+
471
+ def test_anatomize_classic()
472
+ expected = [
473
+ [:common_elt_elt, ["diff --text sample/1/a.en.ascii.lf sample/2/a.en.ascii.lf\n"], ["diff --text sample/1/a.en.ascii.lf sample/2/a.en.ascii.lf\n"]],
474
+ [:common_elt_elt, ["1d0", "\n"], ["1d0", "\n"]],
475
+ [:del_elt, ["< ", "a", "\n"], nil],
476
+ [:common_elt_elt, ["3,4d1", "\n"], ["3,4d1", "\n"]],
477
+ [:del_elt, ["< ", "c", "\n", "< ", "d", "\n"], nil],
478
+ [:common_elt_elt, ["6a4", "\n"], ["6a4", "\n"]],
479
+ [:add_elt, nil, ["> ", "0", "\n"]],
480
+ [:common_elt_elt, ["7a6,7", "\n"], ["7a6,7", "\n"]],
481
+ [:add_elt, nil, ["> ", "1", "\n", "> ", "2", "\n"]],
482
+ [:common_elt_elt, ["9c9", "\n"], ["9c9", "\n"]],
483
+ [:change_elt, ["< ", "i"], nil],
484
+ [:common_elt_elt, ["\n"], ["\n"]],
485
+ [:common_elt_elt, ["---", "\n"], ["---", "\n"]],
486
+ [:change_elt, nil, ["> ", "3"]],
487
+ [:common_elt_elt, ["\n"], ["\n"]],
488
+ [:common_elt_elt, ["11c11,12", "\n"], ["11c11,12", "\n"]],
489
+ [:change_elt, ["< ", "k"], nil],
490
+ [:common_elt_elt, ["\n"], ["\n"]],
491
+ [:common_elt_elt, ["---", "\n"], ["---", "\n"]],
492
+ [:change_elt, nil, ["> ", "4", "\n", "> ", "5"]],
493
+ [:common_elt_elt, ["\n"], ["\n"]],
494
+ [:common_elt_elt, ["13,14c14,15", "\n"], ["13,14c14,15", "\n"]],
495
+ [:change_elt, ["< ", "m"], nil],
496
+ [:common_elt_elt, ["\n"], ["\n"]],
497
+ [:change_elt, ["< ", "n"], nil],
498
+ [:common_elt_elt, ["\n"], ["\n"]],
499
+ [:common_elt_elt, ["---", "\n"], ["---", "\n"]],
500
+ [:change_elt, nil, ["> ", "6"]],
501
+ [:common_elt_elt, ["\n"], ["\n"]],
502
+ [:change_elt, nil, ["> ", "7"]],
503
+ [:common_elt_elt, ["\n"], ["\n"]],
504
+ [:common_elt_elt, ["22d22", "\n"], ["22d22", "\n"]],
505
+ [:del_elt, ["< ", "v", "\n"], nil],
506
+ [:common_elt_elt, ["23a24,25", "\n"], ["23a24,25", "\n"]],
507
+ [:add_elt, nil, ["> ", "8", "\n", "> ", "9", "\n"]],
508
+ [:common_elt_elt, ["25c27,28", "\n"], ["25c27,28", "\n"]],
509
+ [:change_elt, ["< ", "y"], nil],
510
+ [:common_elt_elt, ["\n"], ["\n"]],
511
+ [:common_elt_elt, ["---", "\n"], ["---", "\n"]],
512
+ [:change_elt, nil, ["> ", "A", "\n", "> ", "B"]],
513
+ [:common_elt_elt, ["\n"], ["\n"]],
514
+ [:common_elt_elt, ["diff --text sample/1/b.en.ascii.lf sample/2/b.en.ascii.lf\n"], ["diff --text sample/1/b.en.ascii.lf sample/2/b.en.ascii.lf\n"]],
515
+ [:common_elt_elt, ["1c1,8", "\n"], ["1c1,8", "\n"]],
516
+ [:change_elt, ["< ", "a"], nil],
517
+ [:common_elt_elt, ["\n"], ["\n"]],
518
+ [:common_elt_elt, ["---", "\n"], ["---", "\n"]],
519
+ [:change_elt, nil, ["> ", "@", "\n", "> ", "<", "\n", "> ", ">", "\n", "> ", "-", "\n", "> ", "+", "\n", "> ", "*", "\n", "> ", "!", "\n", ">"]],
520
+ [:common_elt_elt, ["\n"], ["\n"]],
521
+ [:common_elt_elt, ["9a17,19", "\n"], ["9a17,19", "\n"]],
522
+ [:add_elt, nil, ["> ", "+", "\n", ">", "\n", ">", "\n"]],
523
+ [:common_elt_elt, ["17d26", "\n"], ["17d26", "\n"]],
524
+ [:del_elt, ["< ", "q", "\n"], nil],
525
+ [:common_elt_elt, ["24c33", "\n"], ["24c33", "\n"]],
526
+ [:change_elt, ["< ", "x"], nil],
527
+ [:common_elt_elt, ["\n"], ["\n"]],
528
+ [:common_elt_elt, ["---", "\n"], ["---", "\n"]],
529
+ [:change_elt, nil, ["> ", "*"]],
530
+ [:common_elt_elt, ["\n"], ["\n"]],
531
+ [:common_elt_elt, ["26c35", "\n"], ["26c35", "\n"]],
532
+ [:change_elt, ["< "], nil],
533
+ [:common_elt_elt, ["z", "\n"], ["z", "\n"]],
534
+ [:common_elt_elt, ["---", "\n"], ["---", "\n"]],
535
+ [:change_elt, nil, ["> "]],
536
+ [:common_elt_elt, ["z", "\n"], ["z", "\n"]],
537
+ [:common_elt_elt, [" No newline at end of file\n"], [" No newline at end of file\n"]]
538
+ ]
539
+ result = anatomize_classic(@classic_diff)
540
+ assert_equal(expected, result)
541
+ end
542
+
543
+ def test_anatomize_classic_hunk()
544
+ expected = [
545
+ [:common_elt_elt, ["9c9", "\n"], ["9c9", "\n"]],
546
+ [:change_elt, ["< ", "i"], nil],
547
+ [:common_elt_elt, ["\n"], ["\n"]],
548
+ [:common_elt_elt, ["---", "\n"], ["---", "\n"]],
549
+ [:change_elt, nil, ["> ", "3"]],
550
+ [:common_elt_elt, ["\n"], ["\n"]],
551
+ ]
552
+ result = anatomize_classic_hunk("9c9\n< i\n---\n> 3\n", "US-ASCII", "LF")
553
+ assert_equal(expected, result)
554
+ end
555
+
556
+ def test_anatomize_context()
557
+ expected = [
558
+ [:common_elt_elt, ["diff ", "-c ", "--text ", "1a ", "2a", "\n"], ["diff ", "-c ", "--text ", "1a ", "2a", "\n"]],
559
+ [:common_elt_elt, ["*** ", "1a", "\n"], ["*** ", "1a", "\n"]],
560
+ [:common_elt_elt, ["--- ", "2a", "\n"], ["--- ", "2a", "\n"]],
561
+ [:common_elt_elt, ["***************", "\n"], ["***************", "\n"]],
562
+ [:common_elt_elt, ["*** ", "1,17 ", "****", "\n"], ["*** ", "1,17 ", "****", "\n"]],
563
+ [:del_elt, ["- ", "a", "\n"], nil],
564
+ [:common_elt_elt, [" ", "b", "\n"], [" ", "b", "\n"]],
565
+ [:common_elt_elt, ["--- ", "1,18 ", "----", "\n"], ["--- ", "1,18 ", "----", "\n"]],
566
+ [:common_elt_elt, [" ", "b", "\n"], [" ", "b", "\n"]],
567
+ [:common_elt_elt, ["***************", "\n"], ["***************", "\n"]],
568
+ [:common_elt_elt, ["*** ", "19,26 ", "****", "\n"], ["*** ", "19,26 ", "****", "\n"]],
569
+ [:common_elt_elt, ["! "], ["! "]],
570
+ [:change_elt, ["v"], nil],
571
+ [:common_elt_elt, ["\n"], ["\n"]],
572
+ [:common_elt_elt, ["--- ", "20,29 ", "----", "\n"], ["--- ", "20,29 ", "----", "\n"]],
573
+ [:common_elt_elt, ["! "], ["! "]],
574
+ [:change_elt, nil, ["8"]],
575
+ [:common_elt_elt, ["\n"], ["\n"]],
576
+ [:common_elt_elt, ["diff ", "-c ", "--text ", "1b ", "2b", "\n"], ["diff ", "-c ", "--text ", "1b ", "2b", "\n"]],
577
+ [:common_elt_elt, ["*** ", "1b", "\n"], ["*** ", "1b", "\n"]],
578
+ [:common_elt_elt, ["--- ", "2b", "\n"], ["--- ", "2b", "\n"]],
579
+ [:common_elt_elt, ["***************", "\n"], ["***************", "\n"]],
580
+ [:common_elt_elt, ["*** ", "7,12 ", "****", "\n"], ["*** ", "7,12 ", "****", "\n"]],
581
+ [:common_elt_elt, ["--- ", "14,22 ", "----", "\n"], ["--- ", "14,22 ", "----", "\n"]],
582
+ [:add_elt, nil, ["+ ", "g", "\n"]]
583
+ ]
584
+ result = anatomize_context("diff -c --text 1a 2a
585
+ *** 1a
586
+ --- 2a
587
+ ***************
588
+ *** 1,17 ****
589
+ - a
590
+ b
591
+ --- 1,18 ----
592
+ b
593
+ ***************
594
+ *** 19,26 ****
595
+ ! v
596
+ --- 20,29 ----
597
+ ! 8
598
+ diff -c --text 1b 2b
599
+ *** 1b
600
+ --- 2b
601
+ ***************
602
+ *** 7,12 ****
603
+ --- 14,22 ----
604
+ + g
605
+ ")
606
+ assert_equal(expected, result)
607
+ end
608
+
609
+ def test_anatomize_context_hunk()
610
+ expected = [
611
+ [:common_elt_elt, ["***************", "\n"], ["***************", "\n"]],
612
+ [:common_elt_elt, ["*** ", "19,26 ", "****", "\n"], ["*** ", "19,26 ", "****", "\n"]],
613
+ [:common_elt_elt, [" ", "s", "\n ", "t", "\n ", "u", "\n"], [" ", "s", "\n ", "t", "\n ", "u", "\n"]],
614
+ [:del_elt, ["- ", "v", "\n"], nil],
615
+ [:common_elt_elt, [" ", "w", "\n ", "x", "\n"], [" ", "w", "\n ", "x", "\n"]],
616
+ [:common_elt_elt, ["! "], ["! "]],
617
+ [:change_elt, ["y"], nil],
618
+ [:common_elt_elt, ["\n"], ["\n"]],
619
+ [:common_elt_elt, [" ", "z", "\n"], [" ", "z", "\n"]],
620
+ [:common_elt_elt, ["--- ", "20,29 ", "----", "\n"], ["--- ", "20,29 ", "----", "\n"]],
621
+ [:common_elt_elt, [" ", "s", "\n ", "t", "\n ", "u", "\n ", "w", "\n"], [" ", "s", "\n ", "t", "\n ", "u", "\n ", "w", "\n"]],
622
+ [:add_elt, nil, ["+ ", "8", "\n", "+ ", "9", "\n"]],
623
+ [:common_elt_elt, [" ", "x", "\n"], [" ", "x", "\n"]],
624
+ [:common_elt_elt, ["! "], ["! "]],
625
+ [:change_elt, nil, ["A", "\n", "! ", "B"]], # <= this should be :change_elt !
626
+ [:common_elt_elt, ["\n"], ["\n"]],
627
+ [:common_elt_elt, [" ", "z", "\n"], [" ", "z", "\n"]],
628
+ ]
629
+ result = anatomize_context_hunk("***************
630
+ *** 19,26 ****
631
+ s
632
+ t
633
+ u
634
+ - v
635
+ w
636
+ x
637
+ ! y
638
+ z
639
+ --- 20,29 ----
640
+ s
641
+ t
642
+ u
643
+ w
644
+ + 8
645
+ + 9
646
+ x
647
+ ! A
648
+ ! B
649
+ z
650
+ ", "US-ASCII", "LF")
651
+ assert_equal(expected, result)
652
+ end
653
+
654
+ def test_anatomize_context_hunk_scanbodies()
655
+ expected = [
656
+ [
657
+ [:common_elt_elt, [" ", "w", "\n"], [" ", "w", "\n"]],
658
+ [:common_elt_elt, ["! "], ["! "]],
659
+ [:change_elt, ["x"], nil],
660
+ [:common_elt_elt, ["\n"], ["\n"]],
661
+ [:common_elt_elt, [" ", "y", "\n"], [" ", "y", "\n"]]
662
+ ],
663
+ [
664
+ [:common_elt_elt, [" ", "w", "\n"], [" ", "w", "\n"]],
665
+ [:common_elt_elt, ["! "], ["! "]],
666
+ [:change_elt, nil, ["*"]],
667
+ [:common_elt_elt, ["\n"], ["\n"]],
668
+ [:common_elt_elt, [" ", "y", "\n"], [" ", "y", "\n"]]
669
+ ]
670
+ ]
671
+ result = anatomize_context_hunk_scanbodies(" w
672
+ ! x
673
+ y
674
+ ", " w
675
+ ! *
676
+ y
677
+ ", "US-ASCII", "LF")
678
+ assert_equal(expected, result)
679
+ end
680
+
681
+ def test_anatomize_context_hunk_scanbodies_lackformer()
682
+ expected = [
683
+ [
684
+ ],
685
+ [
686
+ [:common_elt_elt, [" ", "a", "\n"], [" ", "a", "\n"]],
687
+ [:add_elt, nil, ["+ ", "x", "\n"]],
688
+ [:common_elt_elt, [" ", "b", "\n"], [" ", "b", "\n"]]
689
+ ]
690
+ ]
691
+ result = anatomize_context_hunk_scanbodies(""," a\n+ x\n b\n", "US-ASCII", "LF")
692
+ assert_equal(expected, result)
693
+ end
694
+
695
+ def test_anatomize_unified_hunk()
696
+ expected = [
697
+ [:common_elt_elt, ["@@ ", "-19,8 ", "+20,10 ", "@@", "\n"], ["@@ ", "-19,8 ", "+20,10 ", "@@", "\n"]],
698
+ [:common_elt_elt, [" ", "s", "\n ", "t", "\n ", "u", "\n"], [" ", "s", "\n ", "t", "\n ", "u", "\n"]],
699
+ [:del_elt, ["-v", "\n"], nil],
700
+ [:common_elt_elt, [" ", "w", "\n"], [" ", "w", "\n"]],
701
+ [:add_elt, nil, ["+8", "\n", "+9", "\n"]],
702
+ [:common_elt_elt, [" ", "x", "\n"], [" ", "x", "\n"]],
703
+ [:change_elt, ["-y"], nil],
704
+ [:change_elt, nil, ["+A", "\n", "+B"]],
705
+ [:common_elt_elt, ["\n"], ["\n"]],
706
+ [:common_elt_elt, [" ", "z", "\n"], [" ", "z", "\n"]]
707
+ ]
708
+ result = anatomize_unified_hunk("@@ -19,8 +20,10 @@
709
+ s
710
+ t
711
+ u
712
+ -v
713
+ w
714
+ +8
715
+ +9
716
+ x
717
+ -y
718
+ +A
719
+ +B
720
+ z
721
+ ", "US-ASCII", "LF")
722
+ assert_equal(expected, result)
723
+ end
724
+
725
+ def test_anatomize_unified()
726
+ expected =
727
+ [[:common_elt_elt,
728
+ ["diff ",
729
+ "-u ",
730
+ "--text ",
731
+ "sample/1/a.en.ascii.lf ",
732
+ "sample/2/a.en.ascii.lf",
733
+ "\n",
734
+ "--- ",
735
+ "sample/1/a.en.ascii.lf ",
736
+ " ",
737
+ "2005-08-30 ",
738
+ "07:07:45.000000000 ",
739
+ "+0900",
740
+ "\n",
741
+ "+++ ",
742
+ "sample/2/a.en.ascii.lf ",
743
+ " ",
744
+ "2005-08-30 ",
745
+ "07:33:51.000000000 ",
746
+ "+0900",
747
+ "\n"],
748
+ ["diff ",
749
+ "-u ",
750
+ "--text ",
751
+ "sample/1/a.en.ascii.lf ",
752
+ "sample/2/a.en.ascii.lf",
753
+ "\n",
754
+ "--- ",
755
+ "sample/1/a.en.ascii.lf ",
756
+ " ",
757
+ "2005-08-30 ",
758
+ "07:07:45.000000000 ",
759
+ "+0900",
760
+ "\n",
761
+ "+++ ",
762
+ "sample/2/a.en.ascii.lf ",
763
+ " ",
764
+ "2005-08-30 ",
765
+ "07:33:51.000000000 ",
766
+ "+0900",
767
+ "\n"]],
768
+ [:common_elt_elt,
769
+ ["@@ ", "-1,17 ", "+1,18 ", "@@", "\n"],
770
+ ["@@ ", "-1,17 ", "+1,18 ", "@@", "\n"]],
771
+ [:del_elt, ["-a", "\n"], nil],
772
+ [:common_elt_elt, [" ", "b", "\n"], [" ", "b", "\n"]],
773
+ [:common_elt_elt, ["-c", "\n"], ["-c", "\n"]],
774
+ [:common_elt_elt, ["-d", "\n"], ["-d", "\n"]],
775
+ [:common_elt_elt, [" ", "e", "\n"], [" ", "e", "\n"]],
776
+ [:common_elt_elt, [" ", "f", "\n"], [" ", "f", "\n"]],
777
+ [:common_elt_elt, ["+0", "\n"], ["+0", "\n"]],
778
+ [:common_elt_elt, [" ", "g", "\n"], [" ", "g", "\n"]],
779
+ [:common_elt_elt, ["+1", "\n"], ["+1", "\n"]],
780
+ [:common_elt_elt, ["+2", "\n"], ["+2", "\n"]],
781
+ [:common_elt_elt, [" ", "h", "\n"], [" ", "h", "\n"]],
782
+ [:common_elt_elt, ["-i", "\n"], ["-i", "\n"]],
783
+ [:common_elt_elt, ["+3", "\n"], ["+3", "\n"]],
784
+ [:common_elt_elt, [" ", "j", "\n"], [" ", "j", "\n"]],
785
+ [:common_elt_elt, ["-k", "\n"], ["-k", "\n"]],
786
+ [:common_elt_elt, ["+4", "\n"], ["+4", "\n"]],
787
+ [:common_elt_elt, ["+5", "\n"], ["+5", "\n"]],
788
+ [:common_elt_elt, [" ", "l", "\n"], [" ", "l", "\n"]],
789
+ [:common_elt_elt, ["-m", "\n"], ["-m", "\n"]],
790
+ [:common_elt_elt, ["-n", "\n"], ["-n", "\n"]],
791
+ [:common_elt_elt, ["+6", "\n"], ["+6", "\n"]],
792
+ [:common_elt_elt, ["+7", "\n"], ["+7", "\n"]],
793
+ [:common_elt_elt, [" ", "o", "\n"], [" ", "o", "\n"]],
794
+ [:common_elt_elt, [" ", "p", "\n"], [" ", "p", "\n"]],
795
+ [:common_elt_elt, [" ", "q", "\n"], [" ", "q", "\n"]],
796
+ [:common_elt_elt,
797
+ ["@@ ", "-19,8 ", "+20,10 ", "@@", "\n"],
798
+ ["@@ ", "-19,8 ", "+20,10 ", "@@", "\n"]],
799
+ [:common_elt_elt,
800
+ [" ", "s", "\n ", "t", "\n ", "u", "\n"],
801
+ [" ", "s", "\n ", "t", "\n ", "u", "\n"]],
802
+ [:common_elt_elt, ["-v", "\n"], ["-v", "\n"]],
803
+ [:common_elt_elt, [" ", "w", "\n"], [" ", "w", "\n"]],
804
+ [:common_elt_elt, ["+8", "\n"], ["+8", "\n"]],
805
+ [:common_elt_elt, ["+9", "\n"], ["+9", "\n"]],
806
+ [:common_elt_elt, [" ", "x", "\n"], [" ", "x", "\n"]],
807
+ [:common_elt_elt, ["-y", "\n"], ["-y", "\n"]],
808
+ [:common_elt_elt, ["+A", "\n"], ["+A", "\n"]],
809
+ [:common_elt_elt, ["+B", "\n"], ["+B", "\n"]],
810
+ [:common_elt_elt, [" ", "z"], [" ", "z"]],
811
+ [:common_elt_elt,
812
+ ["diff ",
813
+ "-u ",
814
+ "--text ",
815
+ "sample/1/b.en.ascii.lf ",
816
+ "sample/2/b.en.ascii.lf",
817
+ "\n",
818
+ "--- ",
819
+ "sample/1/b.en.ascii.lf ",
820
+ " ",
821
+ "2005-08-30 ",
822
+ "07:31:52.000000000 ",
823
+ "+0900",
824
+ "\n",
825
+ "+++ ",
826
+ "sample/2/b.en.ascii.lf ",
827
+ " ",
828
+ "2005-08-30 ",
829
+ "07:41:01.000000000 ",
830
+ "+0900",
831
+ "\n"],
832
+ ["diff ",
833
+ "-u ",
834
+ "--text ",
835
+ "sample/1/b.en.ascii.lf ",
836
+ "sample/2/b.en.ascii.lf",
837
+ "\n",
838
+ "--- ",
839
+ "sample/1/b.en.ascii.lf ",
840
+ " ",
841
+ "2005-08-30 ",
842
+ "07:31:52.000000000 ",
843
+ "+0900",
844
+ "\n",
845
+ "+++ ",
846
+ "sample/2/b.en.ascii.lf ",
847
+ " ",
848
+ "2005-08-30 ",
849
+ "07:41:01.000000000 ",
850
+ "+0900",
851
+ "\n"]],
852
+ [:common_elt_elt,
853
+ ["@@ ", "-1,4 ", "+1,11 ", "@@", "\n"],
854
+ ["@@ ", "-1,4 ", "+1,11 ", "@@", "\n"]],
855
+ [:del_elt, ["-a", "\n"], nil],
856
+ [:common_elt_elt, ["+@", "\n"], ["+@", "\n"]],
857
+ [:common_elt_elt, ["+<", "\n"], ["+<", "\n"]],
858
+ [:common_elt_elt, ["+>", "\n"], ["+>", "\n"]],
859
+ [:common_elt_elt, ["+-", "\n"], ["+-", "\n"]],
860
+ [:common_elt_elt, ["++", "\n"], ["++", "\n"]],
861
+ [:common_elt_elt, ["+*", "\n"], ["+*", "\n"]],
862
+ [:common_elt_elt, ["+!", "\n"], ["+!", "\n"]],
863
+ [:common_elt_elt, ["+", "\n"], ["+", "\n"]],
864
+ [:common_elt_elt, [" ", "b", "\n"], [" ", "b", "\n"]],
865
+ [:common_elt_elt, [" ", "c", "\n"], [" ", "c", "\n"]],
866
+ [:common_elt_elt, [" ", "d", "\n"], [" ", "d", "\n"]],
867
+ [:common_elt_elt,
868
+ ["@@ ", "-7,6 ", "+14,9 ", "@@", "\n"],
869
+ ["@@ ", "-7,6 ", "+14,9 ", "@@", "\n"]],
870
+ [:common_elt_elt,
871
+ [" ", "g", "\n ", "h", "\n ", "i", "\n"],
872
+ [" ", "g", "\n ", "h", "\n ", "i", "\n"]],
873
+ [:common_elt_elt, ["++", "\n"], ["++", "\n"]],
874
+ [:common_elt_elt, ["+", "\n"], ["+", "\n"]],
875
+ [:common_elt_elt, ["+", "\n"], ["+", "\n"]],
876
+ [:common_elt_elt, [" ", "j", "\n"], [" ", "j", "\n"]],
877
+ [:common_elt_elt, [" ", "k", "\n"], [" ", "k", "\n"]],
878
+ [:common_elt_elt, [" ", "l", "\n"], [" ", "l", "\n"]],
879
+ [:common_elt_elt,
880
+ ["@@ ", "-14,13 ", "+24,12 ", "@@", "\n"],
881
+ ["@@ ", "-14,13 ", "+24,12 ", "@@", "\n"]],
882
+ [:common_elt_elt,
883
+ [" ", "n", "\n ", "o", "\n ", "p", "\n"],
884
+ [" ", "n", "\n ", "o", "\n ", "p", "\n"]],
885
+ [:common_elt_elt, ["-q", "\n"], ["-q", "\n"]],
886
+ [:common_elt_elt, [" ", "r", "\n"], [" ", "r", "\n"]],
887
+ [:common_elt_elt, [" ", "s", "\n"], [" ", "s", "\n"]],
888
+ [:common_elt_elt, [" ", "t", "\n"], [" ", "t", "\n"]],
889
+ [:common_elt_elt, [" ", "u", "\n"], [" ", "u", "\n"]],
890
+ [:common_elt_elt, [" ", "v", "\n"], [" ", "v", "\n"]],
891
+ [:common_elt_elt, [" ", "w", "\n"], [" ", "w", "\n"]],
892
+ [:common_elt_elt, ["-x", "\n"], ["-x", "\n"]],
893
+ [:common_elt_elt, ["+*", "\n"], ["+*", "\n"]],
894
+ [:common_elt_elt, [" ", "y", "\n"], [" ", "y", "\n"]],
895
+ [:common_elt_elt, ["-z", "\n"], ["-z", "\n"]],
896
+ [:common_elt_elt, ["+z", "\n"], ["+z", "\n"]],
897
+ [:common_elt_elt,
898
+ [" ", "No ", "newline ", "at ", "end ", "of ", "file", "\n"],
899
+ [" ", "No ", "newline ", "at ", "end ", "of ", "file", "\n"]]]
900
+ result = anatomize_unified(@unified_diff)
901
+ assert_equal(expected, result)
902
+ end
903
+
904
+ def teardown()
905
+ #
906
+ end
907
+
908
+ end