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

kysect / Configuin / 9085969473

14 May 2024 08:45PM UTC coverage: 80.405% (+1.5%) from 78.934%
9085969473

push

github

FrediKats
Replace ini line parsing with .editorconfig node model

192 of 290 branches covered (66.21%)

Branch coverage included in aggregate %.

177 of 183 new or added lines in 10 files covered. (96.72%)

1515 of 1833 relevant lines covered (82.65%)

593.04 hits per line

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

91.3
/Sources/Kysect.Configuin.EditorConfig/DocumentModel/EditorConfigDocumentParser.cs
1
using Kysect.CommonLib.BaseTypes.Extensions;
2
using Kysect.Configuin.EditorConfig.DocumentModel.Nodes;
3

4
namespace Kysect.Configuin.EditorConfig.DocumentModel;
5

6
public class EditorConfigDocumentParser
7
{
8
    public EditorConfigDocument Parse(string content)
9
    {
10
        content.ThrowIfNull();
14✔
11

12
        string[] lines = content.Split(Environment.NewLine);
14✔
13

14
        var context = new EditorConfigDocumentParsingContext();
14✔
15
        //List<string> currentTrivia = new List<string>();
16

17
        foreach (string line in lines)
2,320✔
18
        {
19
            var trimmedLine = line.Trim();
1,146✔
20
            bool isCategory = trimmedLine.StartsWith("[");
1,146✔
21
            if (isCategory)
1,146✔
22
            {
23
                var categoryName = line.Substring(1, line.Length - 2);
8✔
24
                context.AddCategory(categoryName);
8✔
25
                continue;
8✔
26
            }
27

28
            bool isSection = trimmedLine.StartsWith(EditorConfigDocumentSectionNode.NodeIndicator);
1,138✔
29
            if (isSection)
1,138✔
30
            {
31
                int indicatorLength = EditorConfigDocumentSectionNode.NodeIndicator.Length;
2✔
32
                string sectionTitle = line.Substring(indicatorLength, line.Length - (indicatorLength * 2)).Trim();
2✔
33
                context.AddSection(sectionTitle);
2✔
34
                continue;
2✔
35
            }
36

37
            // TODO: add test for commented properties
38
            bool isTrivia = trimmedLine.StartsWith("#") || string.IsNullOrWhiteSpace(line);
1,136✔
39
            if (isTrivia)
1,136✔
40
            {
41
                context.AddTrivia(line);
337✔
42
                continue;
337✔
43
            }
44

45
            bool isProperty = trimmedLine.Contains('=');
799✔
46
            if (isProperty)
799!
47
            {
48
                string[] parts = line.Split('=');
799✔
49
                if (parts.Length != 2)
799!
NEW
50
                    throw new ArgumentException($"Line {line} contains unexpected count of '='");
×
51

52
                string key = parts[0].Trim();
799✔
53
                string value = parts[1].Trim();
799✔
54
                EditorConfigPropertyNode propertyNode = new EditorConfigPropertyNode(key, value);
799✔
55
                context.AddProperty(propertyNode);
799✔
56
                continue;
799✔
57
            }
58

NEW
59
            throw new NotSupportedException($"Not supported line: {line}");
×
60
        }
61

62
        return context.Build();
14✔
63
    }
64
}
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