• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

WillemOpperman / csv-diff-dotnet / 8685582570

15 Apr 2024 08:05AM UTC coverage: 77.354% (+1.1%) from 76.233%
8685582570

push

github

web-flow
Merge pull request #57 from robbery/wip-speedup

speedup

345 of 446 relevant lines covered (77.35%)

28.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.0
csv-diff/Diff.cs
1
using System.Collections.Generic;
2
using System.Diagnostics;
3

4
namespace csv_diff
5
{
6
    // Holds the details of a single difference
7

8
    [DebuggerDisplay("{DiffType} {Row}")]
9
    public class Diff
10
    {
11
        public string DiffType { get; set; }
187✔
12
        public Dictionary<string, object> Fields { get; }
×
13
        public int Row { get; }
×
14
        public object SiblingPosition { get; set; }
48✔
15

16
        public Diff(string diffType, Dictionary<string, object> fields, int rowIdx, object posIdx)
45✔
17
        {
18
            DiffType = diffType;
45✔
19
            Fields = fields;
45✔
20
            Row = rowIdx + 1;
45✔
21
            SetSiblingPosition(posIdx);
45✔
22
        }
45✔
23

24
        private void SetSiblingPosition(object posIdx)
25
        {
26
            if (posIdx is List<int> posList)
45✔
27
            {
28
                posList.RemoveAll(item => item == 0);
21✔
29
                if (posList.Count > 1)
7✔
30
                {
31
                    SiblingPosition = posList.ConvertAll(pos => pos + 1);
3✔
32
                }
33
                else
34
                {
35
                    SiblingPosition = posList.Count > 0 ? posList[0] + 1 : -1;
6✔
36
                }
37
            }
38
            else if (posIdx is int pos)
38✔
39
            {
40
                SiblingPosition = pos + 1;
38✔
41
            }
42
        }
38✔
43

44
        // For backwards compatibility and access to fields with differences
45
        public object this[string key]
46
        {
47
            get
48
            {
49
                switch (key)
50
                {
51
                    case "Action":
52
                    case "action":
53
                        string a = DiffType;
142✔
54
                        if (!string.IsNullOrEmpty(a))
142✔
55
                        {
56
                            a = char.ToUpper(a[0]) + a.Substring(1);
142✔
57
                        }
58
                        return a;
142✔
59
                    case "Row":
60
                    case "row":
61
                        return Row;
×
62
                    case "SiblingPosition":
63
                    case "sibling_position":
64
                        return SiblingPosition;
×
65
                    default:
66
                        return Fields.TryGetValue(key, out object value) ? value : null;
×
67
                }
68
            }
69
        }
70
    }
71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc