Repository navigation
Closed
Labels
Description
Objective
Expand test coverage for type coercion edge cases to ensure robust handling of unusual numeric formats and prevent regressions.
Context
Related to discussion #4307. While the type conversion functions are well-implemented, test coverage for edge cases (negative numbers, overflow, scientific notation, invalid strings) should be expanded.
Approach
- Add comprehensive unit tests for type conversion functions
- Test edge cases and boundary conditions
- Validate error handling for invalid inputs
- Ensure zero-value returns for invalid conversions
Test Categories to Add
1. String-to-Number Edge Cases
Test ConvertToInt() and parseIntValue() with:
- Valid string numbers:
"123","0","-42" - Invalid strings:
"abc","12.5.6","" - Scientific notation:
"1.5e3"(should it work?) - Hexadecimal:
"0xFF"(should it work?) - With signs:
"+123","-456" - Whitespace:
" 123 ","123\n" - Very large numbers causing overflow
2. Float-to-Int Truncation
Test precision loss scenarios:
- Clean conversion:
60.0→60 - Truncation:
60.7→60 - Negative:
-60.3→-60 - Very large floats
- Very small floats (near zero)
- Special values:
math.MaxFloat64,math.Inf(1)
3. Polymorphic Type Handling
Test category and version fields:
- String:
"main","3.11" - Integer:
123,0,-1 - Float:
3.11,20.0 - Invalid types:
nil,true,[]
4. Type Safety Validation
- Ensure zero values returned for invalid inputs
- No panics on unexpected types
- Graceful degradation
Files to Create/Modify
- Create:
pkg/workflow/type_conversion_test.go(comprehensive test suite) - Update:
pkg/workflow/metrics_test.go(if exists, add edge case tests) - Update:
pkg/workflow/map_helpers_test.go(if exists, add edge case tests)
Acceptance Criteria
- Tests added for all ConvertToInt() edge cases
- Tests added for all parseIntValue() edge cases
- Tests verify zero-value returns for invalid inputs
- Tests verify no panics on unexpected types
- Tests cover scientific notation string formats
- Tests cover hexadecimal string formats
- Tests cover overflow scenarios
- Tests cover negative numbers
- Tests cover whitespace handling
- All tests pass with
make test-unit
Example Test Cases
func TestConvertToIntEdgeCases(t *testing.T) {
tests := []struct {
name string
input any
expected int
}{
{"valid string", "123", 123},
{"negative string", "-42", -42},
{"invalid string", "abc", 0},
{"empty string", "", 0},
{"float64 truncation", 60.7, 60},
{"scientific notation", "1.5e3", 0}, // Document expected behavior
{"hex string", "0xFF", 0}, // Document expected behavior
{"nil", nil, 0},
{"bool", true, 0},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := ConvertToInt(tt.input)
if result != tt.expected {
t.Errorf("ConvertToInt(%v) = %d; want %d", tt.input, result, tt.expected)
}
})
}
}Notes
- Focus on test coverage, not changing behavior
- Document any surprising behavior in test comments
- Ensure tests align with schema documentation updates from other issues
AI generated by Plan Command for discussion #4307
Reacted by Copilot
Activity