feat(quando-7m5): implement MustParse convenience function

Add MustParse() as a convenience wrapper around Parse() that panics on error.
Designed for test fixtures and static initialization where input is known valid.

- Implement MustParse() with clear panic behavior and godoc warnings
- Add comprehensive tests for success cases and panic behavior
- Add example tests showing test fixture and static initialization patterns
- Verify panic message includes input string for debugging
- Test coverage: 97.7% (exceeds 95% target)
This commit is contained in:
Oliver Jakoubek 2026-02-11 20:54:32 +01:00
commit 414dfbdbef
4 changed files with 146 additions and 1 deletions

View file

@ -916,3 +916,39 @@ func ExampleDate_Info_leapYear() {
// Is weekend: false
// Is leap year: true
}
// ExampleMustParse demonstrates basic usage in tests and initialization
func ExampleMustParse() {
// Use in test fixtures or static initialization
date := quando.MustParse("2026-02-09")
fmt.Println(date)
// Output: 2026-02-09 00:00:00
}
// ExampleMustParse_testFixture demonstrates using MustParse in test fixtures
func ExampleMustParse_testFixture() {
// Common pattern in tests - no error handling needed
startDate := quando.MustParse("2026-01-01")
endDate := quando.MustParse("2026-12-31")
fmt.Printf("Start: %v\n", startDate.Time().Format("2006-01-02"))
fmt.Printf("End: %v\n", endDate.Time().Format("2006-01-02"))
// Output:
// Start: 2026-01-01
// End: 2026-12-31
}
// ExampleMustParse_staticInit demonstrates static initialization pattern
func ExampleMustParse_staticInit() {
// Pattern for package-level constants
var (
epoch = quando.MustParse("1970-01-01")
y2k = quando.MustParse("2000-01-01")
)
fmt.Printf("Epoch: %v\n", epoch.Time().Year())
fmt.Printf("Y2K: %v\n", y2k.Time().Year())
// Output:
// Epoch: 1970
// Y2K: 2000
}