Ensure exhaustive switch statements
PR #162 revealed that missing node type handlers in switch statements cause silent data loss - CDATA content was being dropped because CharDataNode wasn't handled. This PR adds defensive programming to prevent this entire class of bug.
Changes:
- Added exhaustive switch coverage for all xmlquery.NodeType values
- Added exhaustive switch coverage for xml.Token and html.TokenType
- Added exhaustive switch coverage for json.Token and json.Delim
- Added default cases with panic() to all exhaustive switches
- Added explicit documented defaults to intentionally non-exhaustive switches
This follows the Go stdlib pattern (runtime/panic.go, go/types) of using panic("unreachable") for "should be impossible" states. If future xmlquery versions add new node types, or if we overlook a handler, tests will fail immediately rather than silently corrupting output.
All switches now explicitly handle defaults:
- 8 exhaustive switches panic on unknown values
- 7 non-exhaustive switches have documented intentional behavior
Added TestExhaustiveNodeTypeHandling to verify all node types are processed without panicking. All existing tests pass.
This is a non-breaking change - no API modifications, only defensive additions to switch statements.
Related: #162
:warning: Please install the to ensure uploads and comments are reliably processed by Codecov.
Codecov Report
:x: Patch coverage is 52.38095% with 10 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 79.85%. Comparing base (ec5a59a) to head (6ddf893).
| Files with missing lines | Patch % | Lines |
|---|---|---|
| internal/utils/utils.go | 12.50% | 7 Missing :warning: |
| internal/utils/jsonutil.go | 83.33% | 2 Missing :warning: |
| internal/utils/config.go | 0.00% | 1 Missing :warning: |
| :exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality. |
Additional details and impacted files
@@ Coverage Diff @@
## master #164 +/- ##
==========================================
- Coverage 80.57% 79.85% -0.73%
==========================================
Files 5 5
Lines 690 710 +20
==========================================
+ Hits 556 567 +11
- Misses 92 101 +9
Partials 42 42
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.