<commit_before>﻿// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.UsePatternMatching;
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.UsePatternMatching
{
    using VerifyCS = CSharpCodeFixVerifier<
        CSharpUseNotPatternDiagnosticAnalyzer,
        CSharpUseNotPatternCodeFixProvider>;

    [Trait(Traits.Feature, Traits.Features.CodeActionsUseNotPattern)]
    public partial class CSharpUseNotPatternTests
    {
        [Fact, WorkItem(50690, "https://github.com/dotnet/roslyn/issues/50690")]
        public async Task BinaryIsExpression()
        {
            await new VerifyCS.Test
            {
                TestCode =
@"class C
{
    void M(object x)
    {
        if (!(x [|is|] string))
        {
        }
    }
}",
                FixedCode =
@"class C
{
    void M(object x)
    {
        if (x is not string)
        {
        }
    }
}",
                LanguageVersion = LanguageVersion.CSharp9,
            }.RunAsync();
        }

        [Fact, WorkItem(50690, "https://github.com/dotnet/roslyn/issues/50690")]
        public async Task ConstantPattern()
        {
            await new VerifyCS.Test
            {
                TestCode =
@"class C
{
    void M(object x)
    {
        if (!(x [|is|] null))
        {
        }
    }
}",
                FixedCode =
@"class C
{
    void M(object x)
    {
        if (x is not null)
        {
        }
    }
}",
                LanguageVersion = LanguageVersion.CSharp9,
            }.RunAsync();
        }

        [Fact, WorkItem(64292, "https://github.com/dotnet/roslyn/issues/64292")]
        public async Task BooleanValueConstantPattern()
        {
            await new VerifyCS.Test
            {
                TestCode =
@"#nullable enable
class C
{
    void M(bool x)
    {
        if (!(x [|is|] true))
        {
        }
    }
}",
                FixedCode =
@"#nullable enable
class C
{
    void M(bool x)
    {
        if (x is false)
        {
        }
    }
}",
                LanguageVersion = LanguageVersion.CSharp9,
            }.RunAsync();
        }

        [Fact, WorkItem(64292, "https://github.com/dotnet/roslyn/issues/64292")]
        public async Task NonBooleanValueConstantPattern()
        {
            await new VerifyCS.Test
            {
                TestCode =
@"#nullable enable
class C
{
    void M(object x)
    {
        if (!(x [|is|] true))
        {
        }
    }
}",
                FixedCode =
@"#nullable enable
class C
{
    void M(object x)
    {
        if (x is not true)
        {
        }
    }
}",
                LanguageVersion = LanguageVersion.CSharp9,
            }.RunAsync();
        }<commit_msg>Avoid unnecessarily enabling nullable reference types in tests<commit_after>﻿// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.UsePatternMatching;
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.UsePatternMatching
{
    using VerifyCS = CSharpCodeFixVerifier<
        CSharpUseNotPatternDiagnosticAnalyzer,
        CSharpUseNotPatternCodeFixProvider>;

    [Trait(Traits.Feature, Traits.Features.CodeActionsUseNotPattern)]
    public partial class CSharpUseNotPatternTests
    {
        [Fact, WorkItem(50690, "https://github.com/dotnet/roslyn/issues/50690")]
        public async Task BinaryIsExpression()
        {
            await new VerifyCS.Test
            {
                TestCode =
@"class C
{
    void M(object x)
    {
        if (!(x [|is|] string))
        {
        }
    }
}",
                FixedCode =
@"class C
{
    void M(object x)
    {
        if (x is not string)
        {
        }
    }
}",
                LanguageVersion = LanguageVersion.CSharp9,
            }.RunAsync();
        }

        [Fact, WorkItem(50690, "https://github.com/dotnet/roslyn/issues/50690")]
        public async Task ConstantPattern()
        {
            await new VerifyCS.Test
            {
                TestCode =
@"class C
{
    void M(object x)
    {
        if (!(x [|is|] null))
        {
        }
    }
}",
                FixedCode =
@"class C
{
    void M(object x)
    {
        if (x is not null)
        {
        }
    }
}",
                LanguageVersion = LanguageVersion.CSharp9,
            }.RunAsync();
        }

        [Fact, WorkItem(64292, "https://github.com/dotnet/roslyn/issues/64292")]
        public async Task BooleanValueConstantPattern()
        {
            await new VerifyCS.Test
            {
                TestCode =
@"class C
{
    void M(bool x)
    {
        if (!(x [|is|] true))
        {
        }
    }
}",
                FixedCode =
@"class C
{
    void M(bool x)
    {
        if (x is false)
        {
        }
    }
}",
                LanguageVersion = LanguageVersion.CSharp9,
            }.RunAsync();
        }

        [Fact, WorkItem(64292, "https://github.com/dotnet/roslyn/issues/64292")]
        public async Task NonBooleanValueConstantPattern()
        {
            await new VerifyCS.Test
            {
                TestCode =
@"class C
{
    void M(object x)
    {
        if (!(x [|is|] true))
        {
        }
    }
}",
                FixedCode =
@"class C
{
    void M(object x)
    {
        if (x is not true)
        {
        }
    }
}",
                LanguageVersion = LanguageVersion.CSharp9,
            }.RunAsync();
        }
{'fraction_non_alphanumeric': 0.10752335682674971, 'fraction_numerical': 0.014423864940173742, 'mean_word_length': 1.6646288209606988, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 8, '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': '2499177', 'n_tokens_mistral': 1886, 'n_tokens_neox': 1774, 'n_words': 407}