Exemple #1
0
        private static void AssertHunks(List <DiffView.HunkInfo> hunks, LineList previousLines, LineList currentLines, List <string[]> expected)
        {
            foreach (var(i, hunk) in hunks.AsIndexed())
            {
                Console.WriteLine($"Hunk {hunk.Lines.Count} lines Start: {hunk.StartPrevious}, {hunk.StartCurrent}");
                var actual = new List <string>();

                int?previousStart = null;
                int?previousEnd   = null;
                int?currentStart  = null;
                int?currentEnd    = null;


                foreach (var(p, c) in hunk.Lines)
                {
                    if (p != null)
                    {
                        var idx = previousLines.IndexOf(p) + 1;
                        Console.WriteLine($"P{idx:D3} {p}");

                        actual.Add($"P{idx}");

                        previousStart = Min(previousStart, idx);
                        previousEnd   = Max(previousEnd, idx);
                    }

                    if (c != null)
                    {
                        var idx = currentLines.IndexOf(c) + 1;
                        Console.WriteLine($"C{idx:D3} {c}");

                        actual.Add($"C{idx}");

                        currentStart = Min(currentStart, idx);
                        currentEnd   = Max(currentEnd, idx);
                    }

                    if (p != null && c != null)
                    {
                        Assert.That(p.Text, Is.EqualTo(c.Text), "For equal lines texts should be identical");
                    }
                }

                Assert.That(actual, Is.EqualTo(expected[i]));
                if (previousStart.HasValue)
                {
                    Assert.That(hunk.StartPrevious, Is.EqualTo(previousStart), "Previous start");
                }
                if (currentStart.HasValue)
                {
                    Assert.That(hunk.StartCurrent, Is.EqualTo(currentStart), "Current start");
                }
            }

            int?Min(int?a, int b)
            {
                return(Math.Min(a ?? b, b));
            }

            int?Max(int?a, int b)
            {
                return(Math.Max(a ?? b, b));
            }
        }