• 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

88.57
/Sources/Kysect.Configuin.Tests/DotnetConfig/DotnetConfigDocumentFormatterTests.cs
1
using Kysect.Configuin.DotnetConfig.Formatter;
2
using Kysect.Configuin.DotnetConfig.Syntax;
3
using Kysect.Configuin.DotnetConfig.Syntax.Nodes;
4
using Kysect.Configuin.Learn;
5
using Kysect.Configuin.RoslynModels;
6
using Kysect.Configuin.Tests.Tools;
7

8
namespace Kysect.Configuin.Tests.DotnetConfig;
9

10
public class DotnetConfigDocumentFormatterTests
11
{
12
    private readonly DotnetConfigDocumentFormatter _documentFormatter;
13
    private readonly DotnetConfigDocumentParser _parser;
14
    private readonly LearnDocumentationParser _learnDocumentationParser;
15

16
    public DotnetConfigDocumentFormatterTests()
17
    {
18
        _documentFormatter = new DotnetConfigDocumentFormatter();
4✔
19
        _parser = new DotnetConfigDocumentParser();
4✔
20
        _learnDocumentationParser = new LearnDocumentationParser(TestImplementations.GetTextExtractor(), TestLogger.ProviderForTests());
4✔
21
    }
4✔
22

23
    [Fact]
24
    public void Format_OrderedIdeRulesWithoutHeader_HeaderAdded()
25
    {
26
        var input = """
1✔
27
                    first = value
1✔
28
                    dotnet_diagnostic.IDE0081.severity = none
1✔
29
                    dotnet_diagnostic.IDE0080.severity = none
1✔
30
                    dotnet_diagnostic.IDE0082.severity = warning
1✔
31
                    second = value
1✔
32
                    """;
1✔
33

34
        var expected = """
1✔
35
                       first = value
1✔
36
                       second = value
1✔
37
                       # Autogenerated values
1✔
38
                       [*.cs]
1✔
39
                       ### IDE ###
1✔
40
                       dotnet_diagnostic.IDE0080.severity = none
1✔
41
                       dotnet_diagnostic.IDE0081.severity = none
1✔
42
                       dotnet_diagnostic.IDE0082.severity = warning
1✔
43
                       """;
1✔
44

45
        FormatAndCompare(input, expected);
1✔
46
    }
1✔
47

48
    [Fact]
49
    public void Format_QualityAndStyleRulesMashed_ReturnOrderedLinesWithHeader()
50
    {
51
        var input = """
1✔
52
                    first = value
1✔
53
                    dotnet_diagnostic.IDE0081.severity = none
1✔
54
                    dotnet_diagnostic.CA2001.severity = none
1✔
55
                    second = value
1✔
56
                    dotnet_diagnostic.IDE0080.severity = none
1✔
57
                    dotnet_diagnostic.CA2000.severity = warning
1✔
58
                    """;
1✔
59

60
        var expected = """
1✔
61
                       first = value
1✔
62
                       second = value
1✔
63
                       # Autogenerated values
1✔
64
                       [*.cs]
1✔
65
                       ### IDE ###
1✔
66
                       dotnet_diagnostic.IDE0080.severity = none
1✔
67
                       dotnet_diagnostic.IDE0081.severity = none
1✔
68
                       ### CA ###
1✔
69
                       dotnet_diagnostic.CA2000.severity = warning
1✔
70
                       dotnet_diagnostic.CA2001.severity = none
1✔
71
                       """;
1✔
72

73
        FormatAndCompare(input, expected);
1✔
74
    }
1✔
75

76
    [Fact]
77
    public void Format_NamingRule_ReturnOrderedLinesWithHeader()
78
    {
79
        var input = """
1✔
80
                    dotnet_naming_style.camel_case_style.capitalization = camel_case
1✔
81
                    dotnet_diagnostic.IDE0081.severity = none
1✔
82
                    dotnet_naming_style.disallowed_style.capitalization  = pascal_case
1✔
83
                    dotnet_diagnostic.IDE1006.severity = none
1✔
84
                    dotnet_naming_rule.public_protected_static_readonly_fields_must_be_pascal_case_rule.style      = pascal_case_style
1✔
85
                    """;
1✔
86

87
        var expected = """
1✔
88
                       # Autogenerated values
1✔
89
                       [*.cs]
1✔
90
                       ### IDE ###
1✔
91
                       dotnet_diagnostic.IDE0081.severity = none
1✔
92
                       dotnet_diagnostic.IDE1006.severity = none
1✔
93
                       dotnet_naming_style.camel_case_style.capitalization = camel_case
1✔
94
                       dotnet_naming_style.disallowed_style.capitalization  = pascal_case
1✔
95
                       dotnet_naming_rule.public_protected_static_readonly_fields_must_be_pascal_case_rule.style      = pascal_case_style
1✔
96
                       """;
1✔
97

98
        RoslynRules roslynRules = _learnDocumentationParser.Parse(Constants.GetPathToMsDocsRoot());
1✔
99

100
        DotnetConfigDocument dotnetConfigDocument = _parser.Parse(input);
1✔
101
        DotnetConfigDocument formattedDocument = _documentFormatter.FormatAccordingToRuleDefinitions(dotnetConfigDocument, roslynRules, false);
1✔
102

103
        formattedDocument.ToFullString().Should().Be(expected);
1✔
104
    }
1✔
105

106
    [Fact]
107
    public void Format_QualityRuleByCategory_ReturnGroupedByCategory()
108
    {
109
        var input = """
1✔
110
                    dotnet_diagnostic.CA1016.severity = none
1✔
111
                    dotnet_diagnostic.CA1027.severity = none
1✔
112
                    dotnet_diagnostic.CA1501.severity = none
1✔
113
                    dotnet_diagnostic.CA1835.severity = none
1✔
114
                    """;
1✔
115

116
        var expected = """
1✔
117
                       # Autogenerated values
1✔
118
                       [*.cs]
1✔
119
                       ### CA Design ###
1✔
120
                       dotnet_diagnostic.CA1016.severity = none
1✔
121
                       dotnet_diagnostic.CA1027.severity = none
1✔
122
                       ### CA Maintainability ###
1✔
123
                       dotnet_diagnostic.CA1501.severity = none
1✔
124
                       ### CA Performance ###
1✔
125
                       dotnet_diagnostic.CA1835.severity = none
1✔
126
                       """;
1✔
127

128
        RoslynRules roslynRules = _learnDocumentationParser.Parse(Constants.GetPathToMsDocsRoot());
1✔
129

130
        DotnetConfigDocument dotnetConfigDocument = _parser.Parse(input);
1✔
131
        DotnetConfigDocument formattedDocument = _documentFormatter.FormatAccordingToRuleDefinitions(dotnetConfigDocument, roslynRules, true);
1✔
132

133
        formattedDocument.ToFullString().Should().Be(expected);
1✔
134
    }
1✔
135

136
    [Fact(Skip = "Test is not work during CI. Need to rewrite it without reading and comparing huge .ini files")]
137
    public void FormatAccordingToRuleDefinitions_Sample_ReturnExpectedFormatterDocument()
138
    {
139
        string input = File.ReadAllText(Path.Combine("Resources", "Editor-config-sample.ini"));
×
140
        // TODO: Do smth with this =_=
141
        string expected = File.ReadAllText(Path.Combine("Resources", "Editor-config-sample-formatted.ini"))
×
142
            .Replace("\r\n", "\n")
×
143
            .Replace("\n", Environment.NewLine);
×
144

145
        RoslynRules roslynRules = _learnDocumentationParser.Parse(Constants.GetPathToMsDocsRoot());
×
146

NEW
147
        DotnetConfigDocument dotnetConfigDocument = _parser.Parse(input);
×
NEW
148
        DotnetConfigDocument formattedDocument = _documentFormatter.FormatAccordingToRuleDefinitions(dotnetConfigDocument, roslynRules, false);
×
149
        // TODO: Do smth with this =_=
150

151
        formattedDocument.ToFullString()
×
152
            .Replace("\r\n", "\n")
×
153
            .Replace("\n", Environment.NewLine)
×
154
            .Should().Be(expected);
×
155
    }
×
156

157
    private void FormatAndCompare(string input, string expected)
158
    {
159
        DotnetConfigDocument dotnetConfigDocument = _parser.Parse(input);
2✔
160
        DotnetConfigDocument formattedDocument = _documentFormatter.Format(dotnetConfigDocument);
2✔
161
        formattedDocument.ToFullString().Should().Be(expected);
2✔
162
    }
2✔
163
}
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