public static async Task WaitForParsingComplete(this EditorConfigDocument document)
 {
     while (document.IsParsing)
     {
         await Task.Delay(2);
     }
 }
        public async Task MultipleValues()
        {
            ITextBuffer buffer = Mef.CreateTextBuffer(Samples.MultipleValuesSection);
            var         doc    = EditorConfigDocument.FromTextBuffer(buffer);

            await doc.WaitForParsingComplete();

            Assert.AreEqual(3, doc.ParseItems.Count);
            Assert.AreEqual("accessors, indexers", doc.ParseItems.Last().Text);
        }
        public async Task Suppressions()
        {
            ITextBuffer buffer = Mef.CreateTextBuffer(Samples.Suppression);
            var         doc    = EditorConfigDocument.FromTextBuffer(buffer);

            await doc.WaitForParsingComplete();

            Assert.AreEqual(3, doc.ParseItems.Count);
            Assert.AreEqual("EC101", doc.ParseItems[1].Text);
            Assert.AreEqual(12, doc.ParseItems[1].Span.Start);
            Assert.AreEqual(5, doc.ParseItems[1].Span.Length);
        }
Beispiel #4
0
        public static FormattingOptions Create(FileInfo file, EditorConfigDocument editorConfigDocument)
        {
            if (editorConfigDocument == null)
            {
                return(new FormattingOptions());
            }

            var editorConfigProperties = editorConfigDocument
                                         .Sections
                                         .Where(section => Glob.Glob.IsMatch(file.Name, section.Name))
                                         .Select(section => section.Properties)
                                         .Aggregate(EditorConfigPropertyCollection.Empty, (acc, properties) => acc.Merge(properties));

            return(new FormattingOptions().WithEditorConfigProperties(editorConfigProperties));
        }
Beispiel #5
0
        public void ParsesDocumentWhenEditorConfigDocumentIsValid()
        {
            const string EditorConfigDocument = @"
# This is the root editorconfig file
root = true

[*]
indent_style = space
indent_size = 2

[*.cs]
indent_size = 4
csharp_prefer_braces = true:none
csharp_style_throw_expression = false
";

            var actual = EditorConfigDocumentParser.Parse(EditorConfigDocument);

            var expected = new EditorConfigDocument(
                new EditorConfigPropertyCollection(new[] { new EditorConfigProperty("root", "true") }),
                new EditorConfigSectionCollection(new[]
            {
                new EditorConfigSection("*",
                                        new EditorConfigPropertyCollection(new []
                {
                    new EditorConfigProperty("indent_style", "space"),
                    new EditorConfigProperty("indent_size", "2")
                })
                                        ),
                new EditorConfigSection("*.cs",
                                        new EditorConfigPropertyCollection(new []
                {
                    new EditorConfigProperty("indent_size", "4"),
                    new EditorConfigProperty("csharp_prefer_braces", "true"),
                    new EditorConfigProperty("csharp_style_throw_expression", "false")
                })
                                        )
            })
                );

            Assert.Equal(JsonConvert.SerializeObject(expected), JsonConvert.SerializeObject(actual));
        }
        public async Task Parse()
        {
            ITextBuffer buffer = Mef.CreateTextBuffer(Samples.OneSectionStandard);
            var         doc    = EditorConfigDocument.FromTextBuffer(buffer);

            await doc.WaitForParsingComplete();

            Assert.AreEqual(12, doc.ParseItems.Count);
            Assert.AreEqual(ItemType.Keyword, doc.ParseItems[0].ItemType);
            Assert.AreEqual(ItemType.Comment, doc.ParseItems[2].ItemType);

            Property root = doc.Properties[0];

            Assert.AreEqual(1, doc.Properties.Count);
            Assert.IsTrue(root.IsValid);
            Assert.AreEqual(SchemaCatalog.Root, root.Keyword.Text);

            Section section = doc.Sections[0];

            Assert.AreEqual("[*.cs]", section.Item.Text);
            Assert.AreEqual(4, section.Properties.Count);
            Assert.IsTrue(section.Properties.All(p => p.IsValid));
        }