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

kysect / Configuin / 9148112992

19 May 2024 01:43PM UTC coverage: 84.596% (-0.6%) from 85.178%
9148112992

push

github

FrediKats
Replace .editorconfig with DotnetConfig

324 of 432 branches covered (75.0%)

Branch coverage included in aggregate %.

314 of 347 new or added lines in 28 files covered. (90.49%)

2 existing lines in 1 file now uncovered.

1977 of 2288 relevant lines covered (86.41%)

1201.67 hits per line

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

66.04
/Sources/Kysect.Configuin.DotnetConfig/Diff/DotnetConfigDocumentComparator.cs
1
using Kysect.Configuin.DotnetConfig.Syntax;
2
using Kysect.Configuin.DotnetConfig.Syntax.Nodes;
3

4
namespace Kysect.Configuin.DotnetConfig.Diff;
5

6
public class DotnetConfigDocumentComparator
7
{
8
    public DotnetConfigDocumentDiff Compare(DotnetConfigDocument left, DotnetConfigDocument right)
9
    {
10
        ArgumentNullException.ThrowIfNull(left);
1✔
11
        ArgumentNullException.ThrowIfNull(right);
1✔
12

13
        IReadOnlyCollection<DotnetConfigRuleSeverityDiff> severityDiffs = GetSeverityDiff(
1✔
14
            left.DescendantNodes().OfType<DotnetConfigRuleSeverityNode>().ToList(),
1✔
15
            right.DescendantNodes().OfType<DotnetConfigRuleSeverityNode>().ToList());
1✔
16

17
        IReadOnlyCollection<DotnetConfigRuleOptionDiff> optionDiffs = GetOptionDiff(
1✔
18
            left.DescendantNodes().OfType<DotnetConfigRuleOptionNode>().ToList(),
1✔
19
            right.DescendantNodes().OfType<DotnetConfigRuleOptionNode>().ToList());
1✔
20

21
        return new DotnetConfigDocumentDiff(severityDiffs, optionDiffs);
1✔
22
    }
23

24
    private IReadOnlyCollection<DotnetConfigRuleSeverityDiff> GetSeverityDiff(
25
        IReadOnlyCollection<DotnetConfigRuleSeverityNode> leftRules,
26
        IReadOnlyCollection<DotnetConfigRuleSeverityNode> rightRules)
27
    {
28
        var diff = new List<DotnetConfigRuleSeverityDiff>();
1✔
29

30
        foreach (DotnetConfigRuleSeverityNode leftRule in leftRules)
4✔
31
        {
32
            // TODO: enhance message in case when >1 rule
33
            DotnetConfigRuleSeverityNode? rightRule = rightRules.SingleOrDefault(r => r.RuleId.Equals(leftRule.RuleId));
1✔
34
            if (rightRule == null)
1!
35
            {
36
                diff.Add(new DotnetConfigRuleSeverityDiff(leftRule.RuleId, leftRule.ParseSeverity(), null));
1✔
37
            }
NEW
38
            else if (leftRule.Severity != rightRule.Severity)
×
39
            {
NEW
40
                diff.Add(new DotnetConfigRuleSeverityDiff(leftRule.RuleId, leftRule.ParseSeverity(), rightRule.ParseSeverity()));
×
41
            }
42
        }
43

44
        foreach (DotnetConfigRuleSeverityNode rightRule in rightRules)
2!
45
        {
46
            // TODO: enhance message in case when >1 rule
NEW
47
            DotnetConfigRuleSeverityNode? leftRule = leftRules.SingleOrDefault(r => r.RuleId.Equals(rightRule.RuleId));
×
NEW
48
            if (leftRule is null)
×
49
            {
NEW
50
                diff.Add(new DotnetConfigRuleSeverityDiff(rightRule.RuleId, null, rightRule.ParseSeverity()));
×
51
            }
52
        }
53

54
        return diff;
1✔
55
    }
56

57
    // TODO: reduce copy paste?
58
    private IReadOnlyCollection<DotnetConfigRuleOptionDiff> GetOptionDiff(
59
        IReadOnlyCollection<DotnetConfigRuleOptionNode> leftRules,
60
        IReadOnlyCollection<DotnetConfigRuleOptionNode> rightRules)
61
    {
62
        var diff = new List<DotnetConfigRuleOptionDiff>();
1✔
63

64
        foreach (DotnetConfigRuleOptionNode leftRule in leftRules)
4✔
65
        {
66
            // TODO: enhance message in case when >1 rule
67
            DotnetConfigRuleOptionNode? rightRule = rightRules.SingleOrDefault(r => r.Key.Equals(leftRule.Key));
1✔
68
            if (rightRule == null)
1!
69
            {
70
                diff.Add(new DotnetConfigRuleOptionDiff(leftRule.Key, leftRule.Value, null));
1✔
71
            }
NEW
72
            else if (leftRule.Value != rightRule.Value)
×
73
            {
NEW
74
                diff.Add(new DotnetConfigRuleOptionDiff(leftRule.Key, leftRule.Value, rightRule.Value));
×
75
            }
76
        }
77

78
        foreach (DotnetConfigRuleOptionNode rightRule in rightRules)
2!
79
        {
80
            // TODO: enhance message in case when >1 rule
NEW
81
            DotnetConfigRuleOptionNode? leftRule = leftRules.SingleOrDefault(r => r.Key.Equals(rightRule.Key));
×
NEW
82
            if (leftRule is null)
×
83
            {
NEW
84
                diff.Add(new DotnetConfigRuleOptionDiff(rightRule.Key, null, rightRule.Value));
×
85
            }
86
        }
87

88
        return diff;
1✔
89
    }
90
}
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