Add PiExample and PiExampleFluent tests; extract shared test helpers#12
Merged
Conversation
… code Co-authored-by: dex3r <3155725+dex3r@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add tests for similar case as PiExample
Add PiExample and PiExampleFluent tests; extract shared test helpers
Feb 27, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR expands the test suite to cover both attribute-based and fluent API code generation patterns while eliminating test code duplication. The PR mirrors the PiExample and PiExampleFluent examples from the Examples project, creating comprehensive test coverage for switch-based method generation with compile-time and runtime branches.
Changes:
- Extracted shared test helpers (
GeneratedCodeTestHelper,TestSlowMath) to eliminate duplication and provide reusable test infrastructure - Added
PiExampleTestscovering attribute-based[SwitchCase]/[SwitchDefault]pattern with tests for cases 0-2 (compile-time) and 5 (runtime) - Added
PiExampleFluentTestscovering fluent API pattern withInteger.Range()support, testing cases 0-2, 300-303 (compile-time) and 5 (runtime)
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| MattSourceGenHelpers.Tests/GeneratedCodeTestHelper.cs | Centralized helper for locating and reading generated .g.cs files with improved error messages |
| MattSourceGenHelpers.Tests/TestSlowMath.cs | Pi digit calculation utility mirroring Examples/SlowMath.cs for test isolation |
| MattSourceGenHelpers.Tests/PiExampleTests.cs | Test fixture for attribute-based switch generation pattern with runtime and generated-code assertions |
| MattSourceGenHelpers.Tests/PiExampleFluentTests.cs | Test fixture for fluent API switch generation with Integer.Range support and comprehensive case coverage |
| MattSourceGenHelpers.Tests/UnitTest1.cs | Refactored to use GeneratedCodeTestHelper, removing duplicate helper methods |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The test suite only covered the simple
ColorsClasspattern. This adds coverage for the attribute-based switch pattern (SwitchCase/SwitchDefault) and the fluent generator API (Generator.MethodImplementation<TArg, TReturn>().WithSwitchBody()...), while eliminating duplication across test helpers.Changes
GeneratedCodeTestHelper(new) — centralizesFindProjectDirectory()andReadGeneratedCode(fileName)previously duplicated inline inUnitTest1TestSlowMath(new) — Pi-digit lookup shared by both Pi test classes, mirrorsSlowMathfrom ExamplesPiExampleTests(new) —TestPiClassmirrorsPiExampleusing[SwitchCase]/[SwitchDefault]attributes; tests verify both runtime values and exact generatedswitchsourcePiExampleFluentTests(new) —TestPiFluentClassmirrorsPiExampleFluentusing the fluent API withInteger.Range(300, 303); tests cover the expanded case set (0–2, 300–303) and default fallbackUnitTest1(refactored) — drops the now-redundant private helpers in favour ofGeneratedCodeTestHelperEach new test fixture has parameterized runtime-output tests and a generated-code assertion:
Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.