Skip to content

Conversation

@davidwengier
Copy link
Member

@davidwengier davidwengier commented Jun 23, 2025

Fixes #11970
(which is really https://developercommunity.visualstudio.com/t/Razor-file-formatting-throws-ran-out-of/10924272)
((which is really https://dev.azure.com/devdiv/DevDiv/_workitems/edit/2508457))

Seems I missed a case in my previous fix, which is where Roslyn is configured for K&R braces, but the Razor file is not.

In order to track this down, I experimented with automatically generating tests to provide cover for the C# syntax formatting options. I referred to that coverage as "exhaustive", but quickly met with this thing called "Math" which said that would be too many tests, so I toned it down. The last two commits are the generator and the tests.

I'm not convinced they're adding any value, now that I've found the issue and created real targeted tests for the same thing, in our normal formatting test class, but I left them anyway. Copilot wrote most of the generator anyway, so its not a big deal to recreate it again, if anyone thinks it shouldn't be there. Let me know.

@davidwengier davidwengier requested review from a team as code owners June 23, 2025 06:34
@davidwengier davidwengier removed the request for review from a team June 23, 2025 06:37
Copy link
Member

@DustinCampbell DustinCampbell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm definitely in favor of the auto-generated tests.

@chsienki
Copy link
Member

Have we considered writing some fuzz tests for the formatter? Essentially start with a well formatted document, apply some set of randomized but controlled changes, and run the formatter to make sure it gets back to the formatted state?

Don't know if that adds value or is even possible, but figured it might be worth looking at.

@davidwengier
Copy link
Member Author

Definitely thought about it a lot, never quite had to time or concreteness of ideas to put fingers on keyboards. I've tried a few different times to get copilot to write some tests, and found the same thing Fred did in his recent attempt, where it mostly just generates tests that have "@* Insert complex Razor code here *@" in them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Razor file formatting throws "ran out of lines" exception

4 participants