<commit_before>﻿// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.

using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServices.CSharp.Debugging;
using Roslyn.Test.Utilities;
using Roslyn.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Debugging
{
    [UseExportProvider]
    public class DataTipInfoGetterTests
    {
        private async Task TestAsync(string markup, string expectedText = null)
        {
            await TestSpanGetterAsync(markup, async (document, position, expectedSpan) =>
            {
                var result = await DataTipInfoGetter.GetInfoAsync(document, position, CancellationToken.None);

                Assert.Equal(expectedSpan, result.Span);
                Assert.Equal(expectedText, result.Text);
            });
        }

        private async Task TestNoDataTipAsync(string markup)
        {
            await TestSpanGetterAsync(markup, async (document, position, expectedSpan) =>
            {
                var result = await DataTipInfoGetter.GetInfoAsync(document, position, CancellationToken.None);
                Assert.True(result.IsDefault);
            });
        }

        private async Task TestSpanGetterAsync(string markup, Func<Document, int, TextSpan?, Task> continuation)
        {
            using (var workspace = TestWorkspace.CreateCSharp(markup))
            {
                var testHostDocument = workspace.Documents.Single();
                var position = testHostDocument.CursorPosition.Value;
                var expectedSpan = testHostDocument.SelectedSpans.Any()
                    ? testHostDocument.SelectedSpans.Single()
                    : (TextSpan?)null;

                await continuation(
                    workspace.CurrentSolution.Projects.First().Documents.First(),
                    position,
                    expectedSpan);
            }
        }

        [Fact, Trait(Traits.Feature, Traits.Features.DebuggingDataTips)]
        public async Task TestCSharpLanguageDebugInfoGetDataTipSpanAndText()
        {
            await TestAsync("class [|C$$|] { }");
            await TestAsync("struct [|C$$|] { }");
            await TestAsync("interface [|C$$|] { }");<commit_msg>Use simple using statement<commit_after>﻿// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.

using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServices.CSharp.Debugging;
using Roslyn.Test.Utilities;
using Roslyn.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Debugging
{
    [UseExportProvider]
    public class DataTipInfoGetterTests
    {
        private async Task TestAsync(string markup, string expectedText = null)
        {
            await TestSpanGetterAsync(markup, async (document, position, expectedSpan) =>
            {
                var result = await DataTipInfoGetter.GetInfoAsync(document, position, CancellationToken.None);

                Assert.Equal(expectedSpan, result.Span);
                Assert.Equal(expectedText, result.Text);
            });
        }

        private async Task TestNoDataTipAsync(string markup)
        {
            await TestSpanGetterAsync(markup, async (document, position, expectedSpan) =>
            {
                var result = await DataTipInfoGetter.GetInfoAsync(document, position, CancellationToken.None);
                Assert.True(result.IsDefault);
            });
        }

        private async Task TestSpanGetterAsync(string markup, Func<Document, int, TextSpan?, Task> continuation)
        {
            using var workspace = TestWorkspace.CreateCSharp(markup);
            var testHostDocument = workspace.Documents.Single();
            var position = testHostDocument.CursorPosition.Value;
            var expectedSpan = testHostDocument.SelectedSpans.Any()
                ? testHostDocument.SelectedSpans.Single()
                : (TextSpan?)null;

            await continuation(
                workspace.CurrentSolution.Projects.First().Documents.First(),
                position,
                expectedSpan);
        }

        [Fact, Trait(Traits.Feature, Traits.Features.DebuggingDataTips)]
        public async Task TestCSharpLanguageDebugInfoGetDataTipSpanAndText()
        {
            await TestAsync("class [|C$$|] { }");
            await TestAsync("struct [|C$$|] { }");
            await TestAsync("interface [|C$$|] { }");
{'fraction_non_alphanumeric': 0.09117762898779047, 'fraction_numerical': 0.0007877116975187081, 'mean_word_length': 2.5767605633802817, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '6647020', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1276, 'n_words': 285}