Overview
The file src/TestFramework/TestFramework/Assertions/Assert.StringDifference.cs has grown to 733 lines, making it harder to navigate and maintain. This task involves refactoring it into smaller, more focused files.
Current State
- File:
src/TestFramework/TestFramework/Assertions/Assert.StringDifference.cs
- Size: 733 lines
- Language: C#
Structural Analysis
The file is a partial class Assert containing:
- Two entry-point helpers:
FindFirstStringDifference and AddStringComparisonEvidence
- A large rendering pipeline (~15 private static methods):
CreateStringDifferenceDiagnostic, RenderMismatchFragment, CreatePreview, GetPreviewLength, RenderMismatch, CreateTokenWindow, EnumerateStringTokens, AppendEscapedToken, CreateCodePointDiagnostic, FormatCodePoints, and several Unicode helpers
- Six nested private types:
StringDifference (struct), StringDifferenceDiagnostic (class), StringTokenWindow (class), StringToken (struct), StringPreview (struct), ScalarInfo (struct)
The file has two distinct concerns: (1) the tokenizer/diff engine and its supporting data types, and (2) the rendering/formatting of those differences into diagnostic messages.
Refactoring Strategy
Proposed File Splits
Based on the file's structure, split it into the following files (all remain inside the Assert partial class pattern or as nested-type extractions):
-
Assert.StringDifference.cs (trimmed)
- Contents:
FindFirstStringDifference, AddStringComparisonEvidence, CreateStringDifferenceDiagnostic, and the StringDifference / StringDifferenceDiagnostic nested types
- Responsibility: Entry points — bridge between the public Assert API and the diff engine
-
Assert.StringDifference.Tokenizer.cs
- Contents:
EnumerateStringTokens, CreateStringToken, ShouldMergeTextElements, IsCombiningCharacter, IsEmojiModifier, IsEmojiTag, IsVariationSelector, IsRegionalIndicator, GetScalar, GetPreviousScalar, and the StringToken / ScalarInfo nested types
- Responsibility: Unicode-aware string tokenization
-
Assert.StringDifference.Rendering.cs
- Contents:
GetRenderedStringLengthUpToBudget, GetShortPrefixLength, RenderMismatchFragment, CreatePreview, GetPreviewLength, IsBeforeContextOmitted, IsAfterContextOmitted, RenderMismatch, CreateTokenWindow, GetEscapedCharacterLength, AppendEscapedToken, IsUnpairedSurrogate, CreateCodePointDiagnostic, NeedsCodePointDiagnostic, FormatCodePoints, and the StringTokenWindow / StringPreview nested types
- Responsibility: Formatting diff results into human-readable diagnostic strings
Implementation Guidelines
- Preserve Behavior: All existing functionality must work identically after the split
- Maintain Public API: These are all private helpers — no public API changes required
- Keep partial class pattern: Each new file should be
public sealed partial class Assert in the same namespace
- Test After Each Split: Run
./build.sh -test (or .\build.cmd -test on Windows) after each incremental change
- One File at a Time: Split one module at a time to make review easier
Acceptance Criteria
Priority: Medium
Effort: Small
Expected Impact: Improved code navigability, easier code review, reduced merge conflicts when multiple features touch string-diff diagnostics simultaneously
🤖 Automated content by GitHub Copilot. Generated by the Daily File Diet workflow. · sonnet46 32.5 AIC · ⌖ 5.7 AIC · ⊞ 8K · [◷]( · ◷)
Overview
The file
src/TestFramework/TestFramework/Assertions/Assert.StringDifference.cshas grown to 733 lines, making it harder to navigate and maintain. This task involves refactoring it into smaller, more focused files.Current State
src/TestFramework/TestFramework/Assertions/Assert.StringDifference.csStructural Analysis
The file is a
partial class Assertcontaining:FindFirstStringDifferenceandAddStringComparisonEvidenceCreateStringDifferenceDiagnostic,RenderMismatchFragment,CreatePreview,GetPreviewLength,RenderMismatch,CreateTokenWindow,EnumerateStringTokens,AppendEscapedToken,CreateCodePointDiagnostic,FormatCodePoints, and several Unicode helpersStringDifference(struct),StringDifferenceDiagnostic(class),StringTokenWindow(class),StringToken(struct),StringPreview(struct),ScalarInfo(struct)The file has two distinct concerns: (1) the tokenizer/diff engine and its supporting data types, and (2) the rendering/formatting of those differences into diagnostic messages.
Refactoring Strategy
Proposed File Splits
Based on the file's structure, split it into the following files (all remain inside the
Assertpartial class pattern or as nested-type extractions):Assert.StringDifference.cs(trimmed)FindFirstStringDifference,AddStringComparisonEvidence,CreateStringDifferenceDiagnostic, and theStringDifference/StringDifferenceDiagnosticnested typesAssert.StringDifference.Tokenizer.csEnumerateStringTokens,CreateStringToken,ShouldMergeTextElements,IsCombiningCharacter,IsEmojiModifier,IsEmojiTag,IsVariationSelector,IsRegionalIndicator,GetScalar,GetPreviousScalar, and theStringToken/ScalarInfonested typesAssert.StringDifference.Rendering.csGetRenderedStringLengthUpToBudget,GetShortPrefixLength,RenderMismatchFragment,CreatePreview,GetPreviewLength,IsBeforeContextOmitted,IsAfterContextOmitted,RenderMismatch,CreateTokenWindow,GetEscapedCharacterLength,AppendEscapedToken,IsUnpairedSurrogate,CreateCodePointDiagnostic,NeedsCodePointDiagnostic,FormatCodePoints, and theStringTokenWindow/StringPreviewnested typesImplementation Guidelines
public sealed partial class Assertin the same namespace./build.sh -test(or.\build.cmd -teston Windows) after each incremental changeAcceptance Criteria
./build.sh -test)Assert.*.cspartial-class conventionPriority: Medium
Effort: Small
Expected Impact: Improved code navigability, easier code review, reduced merge conflicts when multiple features touch string-diff diagnostics simultaneously