chore: bump Go 1.18→1.26, fix typos, clean up tests

- Update go.mod to Go 1.26
- Fix help text typos ('menut' → 'menu', 'most-significant' → 'most-specific')
- Fix error comment typo ('ll' → 'all')
- Remove unnecessary fmt.Sprintf in test names
- Remove unused fmt imports from test files
- Add compile-time interface check for TimeWindow
This commit is contained in:
2026-02-22 21:01:23 +00:00
parent 433d28a87b
commit 8b431b5d2f
7 changed files with 12 additions and 11 deletions

2
go.mod
View File

@@ -1,3 +1,3 @@
module github.com/taigrr/most-specific-period module github.com/taigrr/most-specific-period
go 1.18 go 1.26

View File

@@ -41,7 +41,7 @@ func warnMessage() {
} }
func helpMessage() { func helpMessage() {
fmt.Print("\nmost-significant-period [-h][-d]\n\nGenerates a timeline of periods and will provide a most significant period if available.\n\n-h\tShows this help menut\n-d\tProvide a RFC 3339 time to provide an alternate point for calculating MSP.") fmt.Print("\nmost-specific-period [-h][-d]\n\nGenerates a timeline of periods and will provide a most specific period if available.\n\n-h\tShows this help menu\n-d\tProvide an RFC 3339 time to provide an alternate point for calculating MSP.")
} }
func main() { func main() {

View File

@@ -1,7 +1,6 @@
package msp package msp
import ( import (
"fmt"
"testing" "testing"
"time" "time"
) )
@@ -148,7 +147,7 @@ func TestGetChangeOvers(t *testing.T) {
}, },
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run(fmt.Sprintf("%s", tc.testID), func(t *testing.T) { t.Run(tc.testID, func(t *testing.T) {
changeovers := GetChangeOvers(tc.periods...) changeovers := GetChangeOvers(tc.periods...)
if !slicesEqual(changeovers, tc.result) { if !slicesEqual(changeovers, tc.result) {
t.Errorf("Expected %v but got %v", tc.result, changeovers) t.Errorf("Expected %v but got %v", tc.result, changeovers)
@@ -320,7 +319,7 @@ func TestFlattenPeriods(t *testing.T) {
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run(fmt.Sprintf("%s", tc.testID), func(t *testing.T) { t.Run(tc.testID, func(t *testing.T) {
changeovers := FlattenPeriods(tc.periods...) changeovers := FlattenPeriods(tc.periods...)
if !slicesEqual(changeovers, tc.result) { if !slicesEqual(changeovers, tc.result) {
t.Errorf("Expected %v but got %v", tc.result, changeovers) t.Errorf("Expected %v but got %v", tc.result, changeovers)
@@ -468,7 +467,7 @@ func TestGetNextChangeOver(t *testing.T) {
}, },
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run(fmt.Sprintf("%s", tc.testID), func(t *testing.T) { t.Run(tc.testID, func(t *testing.T) {
ts, err := GetNextChangeOver(now, tc.periods...) ts, err := GetNextChangeOver(now, tc.periods...)
if tc.err != err { if tc.err != err {
t.Errorf("Error %v does not match expected %v", tc.err, err) t.Errorf("Error %v does not match expected %v", tc.err, err)

View File

@@ -5,9 +5,9 @@ import (
) )
var ( var (
// ErrEndAfterStart occurs when a period given has an end time after its start time // ErrEndAfterStart occurs when a period's start time is after its end time
ErrEndAfterStart = errors.New("error: start time is after end time") ErrEndAfterStart = errors.New("error: start time is after end time")
// ErrNoValidPeriods occurs when an empty set of periods is passed or when ll periods are invalid // ErrNoValidPeriods occurs when an empty set of periods is passed or when all periods are invalid
ErrNoValidPeriods = errors.New("error: no valid periods available") ErrNoValidPeriods = errors.New("error: no valid periods available")
// ErrNoNextChangeover occurs when GetNextChangeover is called but there are no changeovers after t // ErrNoNextChangeover occurs when GetNextChangeover is called but there are no changeovers after t
ErrNoNextChangeover = errors.New("error: no valid changeovers available") ErrNoNextChangeover = errors.New("error: no valid changeovers available")

View File

@@ -1,7 +1,6 @@
package msp package msp
import ( import (
"fmt"
"testing" "testing"
"time" "time"
) )
@@ -146,7 +145,7 @@ func TestMostSpecificPeriod(t *testing.T) {
}, },
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run(fmt.Sprintf("%s", tc.testID), func(t *testing.T) { t.Run(tc.testID, func(t *testing.T) {
id, err := MostSpecificPeriod(tc.ts, tc.periods...) id, err := MostSpecificPeriod(tc.ts, tc.periods...)
if id != tc.result { if id != tc.result {
t.Errorf("ID '%s' does not match expected '%s'", id, tc.result) t.Errorf("ID '%s' does not match expected '%s'", id, tc.result)

View File

@@ -263,7 +263,7 @@ func TestGenerateTime(t *testing.T) {
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run(fmt.Sprintf("%s", tc.testID), func(t *testing.T) { t.Run(tc.testID, func(t *testing.T) {
timeline := GenerateTimeline(tc.periods...) timeline := GenerateTimeline(tc.periods...)
if len(timeline) != len(tc.result) { if len(timeline) != len(tc.result) {
t.Fatalf("Time line had %d results, expected %d", len(timeline), len(tc.result)) t.Fatalf("Time line had %d results, expected %d", len(timeline), len(tc.result))

View File

@@ -2,6 +2,9 @@ package msp
import "time" import "time"
// Compile-time interface check.
var _ Period = TimeWindow{}
type Period interface { type Period interface {
GetStartTime() time.Time GetStartTime() time.Time
GetEndTime() time.Time GetEndTime() time.Time