Skip to content

TUNU0001 code fixer corrupts code when #region directive follows a comment #4487

@thomhurst

Description

@thomhurst

Description

The TUNU0001 NUnit migration code fixer corrupts code when a #region directive follows a single-line comment. The comment and #region directive are merged onto the same line, causing CS1028 syntax errors.

Reproduction Steps

  1. Create a test file with this pattern:
using NUnit.Framework;

[TestFixture]
public class MyTests
{
    // Some comment
    #region My Region
    
    [Test]
    public void TestMethod()
    {
    }

    #endregion
}
  1. Run the TUNU0001 code fixer

Expected Behavior

The code should remain valid with proper formatting:

public class MyTests
{
    // Some comment
    #region My Region
    
    [Test]
    public async Task TestMethod()
    {
    }

    #endregion
}

Actual Behavior

The comment and #region are merged into a single line:

public class MyTests
{
    // Some comment			#region My Region
    
    [Test]
    public async Task TestMethod()
    {
    }

    #endregion
}

This causes:

error CS1028: Unexpected preprocessor directive

Environment

  • TUnit version: 1.11.64
  • .NET SDK: 10.0.102

Tests should be added to verify the code fixer correctly handles #region directives near comments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions