docdiff 0.6.1 → 0.6.2

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