forked from chipsalliance/verible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff_test.cc
814 lines (789 loc) · 21.2 KB
/
diff_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
// Copyright 2017-2020 The Verible Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "common/strings/diff.h"
#include <initializer_list>
#include <sstream>
#include "absl/strings/string_view.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
namespace diff {
// Print functions copied from external_libs/editscript_test.cc
std::ostream& operator<<(std::ostream& out, Operation operation) {
switch (operation) {
case Operation::EQUALS:
return (out << "EQUALS");
case Operation::DELETE:
return (out << "DELETE");
case Operation::INSERT:
return (out << "INSERT");
}
return out;
}
std::ostream& operator<<(std::ostream& out, const diff::Edit& edit) {
out << "{" << edit.operation << ",[" << edit.start << "," << edit.end << ")}";
return out;
}
std::ostream& operator<<(std::ostream& out, const Edits& edits) {
out << "Edits{";
std::string outer_delim = "";
for (auto& edit : edits) {
out << outer_delim << edit;
outer_delim = ",";
}
out << "};";
return out;
}
} // namespace diff
namespace verible {
namespace {
using diff::Edits;
using diff::Operation;
using ::testing::ElementsAreArray;
struct DiffTestCase {
absl::string_view before;
absl::string_view after;
absl::string_view expected;
};
TEST(LineDiffsTest, Various) {
constexpr DiffTestCase kTestCases[] = {
{"", "", ""},
{"", " ", "+ \n"},
{" ", "", "- \n"},
{" ", " ", " \n"},
{"", "\n", "+\n"},
{"\n", "", "-\n"},
{"\n", "\n", " \n"},
{"\n\n", "\n", " \n-\n"},
{"\n", "\n\n", " \n+\n"},
{"foo\nbar", "foo\nBar", // missing end \n
" foo\n"
"-bar\n"
"+Bar\n"},
{"foo\nbar\n", "foo\nBar\n", // with end \n
" foo\n"
"-bar\n"
"+Bar\n"},
{"foo\nbar\n", "Foo\nbar\n", // with end \n
"-foo\n"
"+Foo\n"
" bar\n"},
{"foo\nbar\n", "Foo\nBar\n", // both lines changed
"-foo\n"
"-bar\n"
"+Foo\n"
"+Bar\n"},
{"foo\nbar", "foo\nbar\n", // end \n added
" foo\n"
"-bar\n"
"+bar\n"},
{"frodo\nsam\nmerry\npippin\n", //
"frodo\nmerry\npippin\n", //
" frodo\n"
"-sam\n"
" merry\n"
" pippin\n"},
{"frodo\nsam\nmerry\npippin\n", //
"frodo\nmerry\ngandalf\npippin\n", //
" frodo\n"
"-sam\n"
" merry\n"
"+gandalf\n"
" pippin\n"},
};
for (const auto& test : kTestCases) {
const LineDiffs line_diffs(test.before, test.after);
std::ostringstream stream;
stream << line_diffs;
EXPECT_EQ(stream.str(), test.expected) << "\bbefore:\n"
<< test.before << "\nafter:\n"
<< test.after;
}
}
struct AddedLineNumbersTestCase {
Edits edits;
LineNumberSet expected_line_numbers;
};
TEST(DiffEditsToAddedLineNumbersTest, Various) {
const AddedLineNumbersTestCase kTestCases[] = {
{{}, //
{}},
{{{Operation::DELETE, 0, 3}}, //
{}},
{{{Operation::EQUALS, 1, 4}}, //
{}},
{{{Operation::INSERT, 2, 5}}, //
{{3, 6}}},
{{{Operation::EQUALS, 0, 2}, //
{Operation::DELETE, 2, 7}, //
{Operation::INSERT, 2, 4}, //
{Operation::EQUALS, 7, 9}}, //
{{3, 5}}},
{{{Operation::EQUALS, 0, 2}, //
{Operation::DELETE, 2, 7}, //
{Operation::INSERT, 2, 4}, //
{Operation::EQUALS, 7, 9}, //
{Operation::INSERT, 6, 11}}, //
{{3, 5}, {7, 12}}},
};
for (const auto& test : kTestCases) {
EXPECT_EQ(DiffEditsToAddedLineNumbers(test.edits),
test.expected_line_numbers);
}
}
// Represents an Edit operation over a number of elements.
struct RelativeEdit {
Operation operation;
int64_t size;
};
// Construct a well-formed sequence of Edits with consistent and contiguous
// start/end ranges given a sequence of RelativeEdits.
// Rationale: it is much easier to reason about relative-sized edit ranges
// and absolute indices when hand-crafting test cases.
//
// Example:
// RelativeEdits:
// {Operation::EQUALS, 2},
// {Operation::DELETE, 3},
// {Operation::INSERT, 4},
// {Operation::EQUALS, 5},
//
// starting at indices 0 for both sequences,
// translates into diff::Edit's (absolute indices):
// {Operation::EQUALS, 0, 2}, // both files start at 0 for 2 lines
// {Operation::DELETE, 2, 5}, // 3 lines [2,5) of old sequence deleted
// {Operation::INSERT, 2, 6}, // 4 lines [2,6) of new sequence added
// {Operation::EQUALS, 5, 10}, // both files advance 5 lines in common
//
// See MakeDiffEditsTest below for examples.
//
// (This is currently well-suited for a test-only library, but
// could eventually become a crucial piece of future diff-to-patch-library.)
diff::Edits MakeDiffEdits(const std::vector<RelativeEdit>& relative_edits,
int64_t old_index = 0, int64_t new_index = 0) {
diff::Edits edits;
for (const RelativeEdit& edit : relative_edits) {
if (!edits.empty() && edits.back().operation == edit.operation) {
// same type as previous operation, just combine them.
edits.back().end += edit.size;
continue;
}
switch (edit.operation) {
case Operation::EQUALS: {
const int64_t old_end = old_index + edit.size;
edits.push_back(diff::Edit{edit.operation, old_index, old_end});
old_index = old_end;
new_index += edit.size;
break;
}
case Operation::INSERT: {
const int64_t new_end = new_index + edit.size;
edits.push_back(diff::Edit{edit.operation, new_index, new_end});
new_index = new_end;
break;
}
case Operation::DELETE: {
const int64_t old_end = old_index + edit.size;
edits.push_back(diff::Edit{edit.operation, old_index, old_end});
old_index = old_end;
break;
}
}
}
return edits;
}
struct MakeDiffEditsTestCase {
std::vector<RelativeEdit> rel_edits;
diff::Edits expected_edits;
};
TEST(MakeDiffEditsTest, Various) {
const MakeDiffEditsTestCase kTestCases[] = {
{{}, {}},
// Single edit operations:
{{
{Operation::EQUALS, 10},
},
{
{Operation::EQUALS, 0, 10},
}},
{{
{Operation::DELETE, 8},
},
{
{Operation::DELETE, 0, 8},
}},
{{
{Operation::INSERT, 7},
},
{
{Operation::INSERT, 0, 7},
}},
// Repeated edit operations:
{{
{Operation::EQUALS, 4},
{Operation::EQUALS, 6},
},
{
{Operation::EQUALS, 0, 10},
}},
{{
{Operation::DELETE, 5},
{Operation::DELETE, 3},
},
{
{Operation::DELETE, 0, 8},
}},
{{
{Operation::INSERT, 2},
{Operation::INSERT, 5},
},
{
{Operation::INSERT, 0, 7},
}},
// Cover each edit transition:
{{
{Operation::EQUALS, 2},
{Operation::DELETE, 3},
},
{
{Operation::EQUALS, 0, 2},
{Operation::DELETE, 2, 5},
}},
{{
{Operation::EQUALS, 4},
{Operation::INSERT, 5},
},
{
{Operation::EQUALS, 0, 4},
{Operation::INSERT, 4, 9},
}},
{{
{Operation::DELETE, 3},
{Operation::EQUALS, 2},
},
{
{Operation::DELETE, 0, 3},
{Operation::EQUALS, 3, 5},
}},
{{
{Operation::DELETE, 3},
{Operation::INSERT, 6},
},
{
{Operation::DELETE, 0, 3},
{Operation::INSERT, 0, 6},
}},
{{
{Operation::INSERT, 7},
{Operation::EQUALS, 4},
},
{
{Operation::INSERT, 0, 7},
{Operation::EQUALS, 0, 4},
}},
{{
{Operation::INSERT, 7},
{Operation::DELETE, 3},
},
{
{Operation::INSERT, 0, 7},
{Operation::DELETE, 0, 3},
}},
{{
// covers one of each transition
{Operation::EQUALS, 2},
{Operation::DELETE, 3},
{Operation::INSERT, 4},
{Operation::EQUALS, 5},
{Operation::INSERT, 6},
{Operation::DELETE, 7},
{Operation::EQUALS, 8},
},
{
{Operation::EQUALS, 0, 2},
{Operation::DELETE, 2, 5},
{Operation::INSERT, 2, 6},
{Operation::EQUALS, 5, 10},
{Operation::INSERT, 11, 17},
{Operation::DELETE, 10, 17},
{Operation::EQUALS, 17, 25},
}},
};
for (const auto& test : kTestCases) {
EXPECT_THAT(MakeDiffEdits(test.rel_edits),
ElementsAreArray(test.expected_edits));
}
}
struct DiffEditsToPatchHunksTestCase {
diff::Edits whole_edits;
int common_context;
std::vector<diff::Edits> expected_hunks;
};
TEST(DiffEditsToPatchHunksTest, Various) {
typedef std::initializer_list<RelativeEdit> RelEdits;
const DiffEditsToPatchHunksTestCase kTestCases[] = {
{
.whole_edits = MakeDiffEdits(RelEdits{{Operation::EQUALS, 2}}),
.common_context = 1,
.expected_hunks = {} // empty because no-change hunk was removed
},
{
.whole_edits = MakeDiffEdits(RelEdits{{Operation::EQUALS, 200}}),
.common_context = 1,
.expected_hunks = {} // empty because no-change hunk was removed
},
{.whole_edits = MakeDiffEdits(RelEdits{{Operation::INSERT, 3}}),
.common_context = 1,
.expected_hunks =
{
MakeDiffEdits(RelEdits{{Operation::INSERT, 3}}),
}},
{.whole_edits = MakeDiffEdits(RelEdits{{Operation::DELETE, 4}}),
.common_context = 1,
.expected_hunks =
{
MakeDiffEdits(RelEdits{{Operation::DELETE, 4}}),
}},
{.whole_edits = MakeDiffEdits(RelEdits{
{Operation::EQUALS, 3},
{Operation::DELETE, 1},
}),
.common_context = 2, // first hunk should start at line[3-2]
.expected_hunks =
{
MakeDiffEdits(
RelEdits{
{Operation::EQUALS, 2},
{Operation::DELETE, 1},
},
1, 1),
}},
{.whole_edits = MakeDiffEdits(RelEdits{
{Operation::DELETE, 1},
{Operation::EQUALS, 3},
}),
.common_context = 2, // last EQUALS edit should be no larger than this
.expected_hunks =
{
MakeDiffEdits(
RelEdits{
{Operation::DELETE, 1},
{Operation::EQUALS, 2},
},
0, 0),
}},
{.whole_edits = MakeDiffEdits(RelEdits{
{Operation::EQUALS, 3},
{Operation::DELETE, 1},
{Operation::EQUALS, 3},
}),
.common_context = 2, // first hunk should start at line[3-2]
.expected_hunks =
{
MakeDiffEdits(
RelEdits{
{Operation::EQUALS, 2},
{Operation::DELETE, 1},
{Operation::EQUALS, 2},
},
1, 1),
}},
{.whole_edits = MakeDiffEdits(RelEdits{
{Operation::EQUALS, 3},
{Operation::INSERT, 1},
}),
.common_context = 2, // first hunk should start at line[3-2]
.expected_hunks =
{
MakeDiffEdits(
RelEdits{
{Operation::EQUALS, 2},
{Operation::INSERT, 1},
},
1, 1),
}},
{.whole_edits = MakeDiffEdits(RelEdits{
{Operation::INSERT, 1},
{Operation::EQUALS, 3},
}),
.common_context = 2, // last EQUALS edit should be no larger than this
.expected_hunks =
{
MakeDiffEdits(
RelEdits{
{Operation::INSERT, 1},
{Operation::EQUALS, 2},
},
0, 0),
}},
{.whole_edits = MakeDiffEdits(RelEdits{
{Operation::EQUALS, 3},
{Operation::INSERT, 1},
{Operation::EQUALS, 3},
}),
.common_context = 2, // first hunk should start at line[3-2]
.expected_hunks =
{
MakeDiffEdits(
RelEdits{
{Operation::EQUALS, 2},
{Operation::INSERT, 1},
{Operation::EQUALS, 2},
},
1, 1),
}},
{.whole_edits = MakeDiffEdits(RelEdits{
{Operation::DELETE, 2},
{Operation::INSERT, 1},
{Operation::EQUALS, 4}, // expect to remain in one piece
{Operation::DELETE, 1},
{Operation::INSERT, 2},
}),
.common_context = 2,
.expected_hunks =
{
MakeDiffEdits(
RelEdits{
{Operation::DELETE, 2},
{Operation::INSERT, 1},
{Operation::EQUALS, 4}, // remain in one piece
{Operation::DELETE, 1},
{Operation::INSERT, 2},
},
0, 0),
}},
{.whole_edits = MakeDiffEdits(RelEdits{
{Operation::DELETE, 2},
{Operation::INSERT, 1},
{Operation::EQUALS, 5}, // expect to split here
{Operation::DELETE, 1},
{Operation::INSERT, 2},
}),
.common_context = 2,
.expected_hunks =
{
// expect two hunks
MakeDiffEdits(
RelEdits{
{Operation::DELETE, 2},
{Operation::INSERT, 1},
{Operation::EQUALS, 2},
},
0, 0),
// one line of EQUALS in the new gap
MakeDiffEdits(
RelEdits{
{Operation::EQUALS, 2},
{Operation::DELETE, 1},
{Operation::INSERT, 2},
},
5, 4),
}},
};
for (const auto& test : kTestCases) {
EXPECT_THAT(DiffEditsToPatchHunks(test.whole_edits, test.common_context),
ElementsAreArray(test.expected_hunks));
}
}
struct LineDiffsToUnifiedDiffTestCase {
absl::string_view before_text;
absl::string_view after_text;
absl::string_view file_a;
absl::string_view file_b;
int common_context;
absl::string_view expected_diff_text;
};
TEST(LineDiffsToUnifiedDiffTest, Various) {
const LineDiffsToUnifiedDiffTestCase kTestCases[] = {
// No changes
{
"a\nb\nc\n",
"a\nb\nc\n",
{},
{},
1,
"",
},
{
"a\nb\nc\n",
"a\nb\nc\n",
"file.txt",
{},
1,
"",
},
{
"a\nb\nc\n",
"a\nb\nc\n",
"old_file.txt",
"new_file.txt",
1,
"",
},
// Single change
{
"a\nb\nc\n",
"a\nb\nC\n",
{},
{},
1,
"@@ -2,2 +2,2 @@\n"
" b\n"
"-c\n"
"+C\n",
},
{
"a\nb\nc\n",
"a\nb\nC\n",
"file.txt",
{},
1,
"--- a/file.txt\n"
"+++ b/file.txt\n"
"@@ -2,2 +2,2 @@\n"
" b\n"
"-c\n"
"+C\n",
},
{
"a\nb\nc\n",
"a\nb\nC\n",
"old_file.txt",
"new_file.txt",
1,
"--- old_file.txt\n"
"+++ new_file.txt\n"
"@@ -2,2 +2,2 @@\n"
" b\n"
"-c\n"
"+C\n",
},
// Multiple chunks
{
"a\nb\nc\nd\ne\nf\nh\n",
"A\nb\nc\nd\ne\nf\ng\nh\n",
{},
{},
1,
"@@ -1,2 +1,2 @@\n"
"-a\n"
"+A\n"
" b\n"
"@@ -6,2 +6,3 @@\n"
" f\n"
"+g\n"
" h\n",
},
{
"a\nb\nc\nd\ne\nf\nh\n",
"A\nb\nc\nd\ne\nf\ng\nh\n",
"file.txt",
{},
1,
"--- a/file.txt\n"
"+++ b/file.txt\n"
"@@ -1,2 +1,2 @@\n"
"-a\n"
"+A\n"
" b\n"
"@@ -6,2 +6,3 @@\n"
" f\n"
"+g\n"
" h\n",
},
{
"a\nb\nc\nd\ne\nf\nh\n",
"A\nb\nc\nd\ne\nf\ng\nh\n",
"old_file.txt",
"new_file.txt",
1,
"--- old_file.txt\n"
"+++ new_file.txt\n"
"@@ -1,2 +1,2 @@\n"
"-a\n"
"+A\n"
" b\n"
"@@ -6,2 +6,3 @@\n"
" f\n"
"+g\n"
" h\n",
},
// Large context
{
"a\nb\nc\nd\ne\nf\nh\n",
"A\nb\nc\nd\ne\nf\ng\nh\n",
"file.txt",
{},
99,
"--- a/file.txt\n"
"+++ b/file.txt\n"
"@@ -1,7 +1,8 @@\n"
"-a\n"
"+A\n"
" b\n"
" c\n"
" d\n"
" e\n"
" f\n"
"+g\n"
" h\n",
},
// No context
{
"a\nb\nc\nd\ne\nf\nh\n",
"A\nb\nc\nd\ne\nf\ng\nh\n",
"file.txt",
{},
0,
"--- a/file.txt\n"
"+++ b/file.txt\n"
"@@ -1 +1 @@\n"
"-a\n"
"+A\n"
"@@ -7 +7 @@\n"
"+g\n",
},
// Multiple inserts and deletions
{
"a\nb\nc\nh\ni\nj\nk\nm\nn\no\np\nq\nx\ny\nz\nr\ns\n",
"a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\n",
"file.txt",
{},
1,
"--- a/file.txt\n"
"+++ b/file.txt\n"
"@@ -3,2 +3,6 @@\n"
" c\n"
"+d\n"
"+e\n"
"+f\n"
"+g\n"
" h\n"
"@@ -7,2 +11,3 @@\n"
" k\n"
"+l\n"
" m\n"
"@@ -12,5 +17,2 @@\n"
" q\n"
"-x\n"
"-y\n"
"-z\n"
" r\n",
},
// Missing \n in the last line of "before" text
{
"a\nb\nc\nd\ne\nf\nh",
"A\nb\nc\nd\ne\nf\ng\nh\n",
"file.txt",
{},
1,
"--- a/file.txt\n"
"+++ b/file.txt\n"
"@@ -1,2 +1,2 @@\n"
"-a\n"
"+A\n"
" b\n"
"@@ -6,2 +6,3 @@\n"
" f\n"
"+g\n"
"-h\n"
"\\ No newline at end of file\n"
"+h\n",
},
// Missing \n in the last line of "after" text
{
"a\nb\nc\nd\ne\nf\nh\n",
"A\nb\nc\nd\ne\nf\ng\nh",
"file.txt",
{},
1,
"--- a/file.txt\n"
"+++ b/file.txt\n"
"@@ -1,2 +1,2 @@\n"
"-a\n"
"+A\n"
" b\n"
"@@ -6,2 +6,3 @@\n"
" f\n"
"+g\n"
"-h\n"
"+h\n"
"\\ No newline at end of file\n",
},
// Missing \n in the last lines of both texts
{
"a\nb\nc\nd\ne\nf\nh",
"A\nb\nc\nd\ne\nf\ng\nh",
"file.txt",
{},
1,
"--- a/file.txt\n"
"+++ b/file.txt\n"
"@@ -1,2 +1,2 @@\n"
"-a\n"
"+A\n"
" b\n"
"@@ -6,2 +6,3 @@\n"
" f\n"
"+g\n"
" h\n"
"\\ No newline at end of file\n",
},
// File created
{
"",
"A\nb\nc\nd\ne\nf\ng\nh\n",
"/dev/null",
"file.txt",
1,
"--- /dev/null\n"
"+++ file.txt\n"
"@@ -1 +1,8 @@\n"
"+A\n"
"+b\n"
"+c\n"
"+d\n"
"+e\n"
"+f\n"
"+g\n"
"+h\n",
},
// File removed
{
"a\nb\nc\nd\ne\nf\nh\n",
"",
"file.txt",
"/dev/null",
1,
"--- file.txt\n"
"+++ /dev/null\n"
"@@ -1,7 +1 @@\n"
"-a\n"
"-b\n"
"-c\n"
"-d\n"
"-e\n"
"-f\n"
"-h\n",
},
};
for (const auto& test : kTestCases) {
LineDiffs linediffs(test.before_text, test.after_text);
std::ostringstream stream;
LineDiffsToUnifiedDiff(stream, linediffs, test.common_context, test.file_a,
test.file_b);
EXPECT_EQ(stream.str(), test.expected_diff_text);
}
}
} // namespace
} // namespace verible