<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Xunit;
using System.Collections.Immutable;

namespace Microsoft.DotNet.CodeFormatting.Tests
{
    /// <summary>
    /// A test which runs all rules on a given piece of code 
    /// </summary>
    public sealed class CombinationTest : CodeFormattingTestBase
    {
        private static FormattingEngineImplementation s_formattingEngine;

        static CombinationTest()
        {
            s_formattingEngine = (FormattingEngineImplementation)FormattingEngine.Create(ImmutableArray<string>.Empty);
        }

        public CombinationTest()
        {
            s_formattingEngine.CopyrightHeader = ImmutableArray.Create("// header");
            s_formattingEngine.FormatLogger = new EmptyFormatLogger();
            s_formattingEngine.PreprocessorConfigurations = ImmutableArray<string[]>.Empty;
        }

        protected override async Task<Document> RewriteDocumentAsync(Document document)
        {
            var solution = await s_formattingEngine.FormatCoreAsync(
                document.Project.Solution,
                new[] { document.Id },
                CancellationToken.None);
            return solution.GetDocument(document.Id);
        }

        [Fact]
        public void FieldUse()
        {
            var text = @"
class C {
    int field;

    void M() {
        N(this.field);
    }
}";

            var expected = @"// header

internal class C<commit_msg>Fix unit test failure<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Xunit;
using System.Collections.Immutable;

namespace Microsoft.DotNet.CodeFormatting.Tests
{
    /// <summary>
    /// A test which runs all rules on a given piece of code 
    /// </summary>
    public sealed class CombinationTest : CodeFormattingTestBase, IDisposable
    {
        private static FormattingEngineImplementation s_formattingEngine;

        static CombinationTest()
        {
            s_formattingEngine = (FormattingEngineImplementation)FormattingEngine.Create(ImmutableArray<string>.Empty);
        }

        public CombinationTest()
        {
            s_formattingEngine.CopyrightHeader = ImmutableArray.Create("// header");
            s_formattingEngine.AllowTables = true;
            s_formattingEngine.FormatLogger = new EmptyFormatLogger();
            s_formattingEngine.PreprocessorConfigurations = ImmutableArray<string[]>.Empty;
        }

        public void Dispose()
        {
            s_formattingEngine.AllowTables = false;
        }

        protected override async Task<Document> RewriteDocumentAsync(Document document)
        {
            var solution = await s_formattingEngine.FormatCoreAsync(
                document.Project.Solution,
                new[] { document.Id },
                CancellationToken.None);
            return solution.GetDocument(document.Id);
        }

        [Fact]
        public void FieldUse()
        {
            var text = @"
class C {
    int field;

    void M() {
        N(this.field);
    }
}";

            var expected = @"// header

internal class C
{'fraction_non_alphanumeric': 0.0851000298596596, 'fraction_numerical': 0.0, 'mean_word_length': 2.4079348931841302, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3140334', 'n_tokens_mistral': 863, 'n_tokens_neox': 840, 'n_words': 194}