From b6b08e3c596ba6a9c12665636ec65ece0db6f6ec Mon Sep 17 00:00:00 2001 From: Sidd-Pelluru Date: Thu, 29 Oct 2026 14:08:32 -0500 Subject: [PATCH 1/2] Refactor parser tests to use slices with Name field and replaces map-based test cases with slices of structs so test order is deterministic. --- parser/sectionParser_test.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/parser/sectionParser_test.go b/parser/sectionParser_test.go index a920b4d1..2238d7b4 100644 --- a/parser/sectionParser_test.go +++ b/parser/sectionParser_test.go @@ -31,16 +31,16 @@ func TestGetInternalClassAndCourseNum(t *testing.T) { }) } - fails := []map[string]string{ - { - "Class Section:": "ENTP33S", - }, - { - "Class Section:": "", - }, - { - "Class Section:": "Garbage In, Garbage out", - }, + + // fails holds inputs that must cause a panic. + // Uses a slice (not a map) so test order is deterministic. + fails := []struct{ + Name string + ClassSection string + }{ + {Name: "empty_string01", ClassSection: "ENTP33S"}, + {Name: "empty_string02", ClassSection: ""}, + {Name: "garbage_in_garbage_out", ClassSection: "Garbage In, Garbage out"}, } for i, fail := range fails { From 501ab1551eb7d41ea2a64904df80d4d8d5b81daa Mon Sep 17 00:00:00 2001 From: Sidd-Pelluru Date: Thu, 29 Oct 2026 15:41:40 -0500 Subject: [PATCH 2/2] Convert parser test cases from maps to ordered slices and replace map-based fails and TestParseTimeOrPanic cases with slices of structs that have a Name field, so test order is deterministic and changed syntax in the loops after changing from map to slice and removed the fmt package which was used to make names for unnamed test cases and updated code gets the name from the struct instead as go treats unused imports as errors --- parser/sectionParser_test.go | 46 ++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/parser/sectionParser_test.go b/parser/sectionParser_test.go index 2238d7b4..2f66e68e 100644 --- a/parser/sectionParser_test.go +++ b/parser/sectionParser_test.go @@ -1,7 +1,6 @@ package parser import ( - "fmt" "testing" "time" @@ -38,23 +37,23 @@ func TestGetInternalClassAndCourseNum(t *testing.T) { Name string ClassSection string }{ - {Name: "empty_string01", ClassSection: "ENTP33S"}, - {Name: "empty_string02", ClassSection: ""}, + {Name: "missing_section_number", ClassSection: "ENTP33S"}, + {Name: "empty_string", ClassSection: ""}, {Name: "garbage_in_garbage_out", ClassSection: "Garbage In, Garbage out"}, } - for i, fail := range fails { - name := fmt.Sprintf("case_%03d", i+len(testData)) + for _, fail := range fails { + - t.Run(name, func(t *testing.T) { + t.Run(fail.Name, func(t *testing.T) { t.Parallel() defer func() { if r := recover(); r == nil { - t.Errorf("expected panic for input %s but none occurred", fail) + t.Errorf("expected panic for input %q but none occurred", fail.ClassSection) } }() - getInternalClassAndCourseNum(fail) + getInternalClassAndCourseNum(map[string]string{"Class Section:": fail.ClassSection}) }) } @@ -97,33 +96,28 @@ func TestGetSectionNumber(t *testing.T) { }) } - fails := []map[string]string{ - { - "Class Section:": "ENTP33S", - }, - { - "Class Section:": "", - }, - { - "Class Section:": "Garbage In, Garbage out", - }, + // fails holds inputs that must cause a panic. + // Uses a slice (not a map) so test order is deterministic. + fails := []struct{ + Name string + ClassSection string + }{ + {Name: "missing_section_number", ClassSection: "ENTP33S"}, + {Name: "empty_string", ClassSection: ""}, + {Name: "garbage_in_garbage_out", ClassSection: "Garbage In, Garbage out"}, } - for i, fail := range fails { - name := fmt.Sprintf("case_%03d", i+len(testData)) - - t.Run(name, func(t *testing.T) { + for _, fail := range fails { + t.Run(fail.Name, func(t *testing.T) { t.Parallel() defer func() { if r := recover(); r == nil { - t.Errorf("expected panic for input %s but none occurred", fail) + t.Errorf("expected panic for input %q but none occurred", fail.ClassSection) } }() - getSectionNumber(fail) - + getSectionNumber(map[string]string{"Class Section:": fail.ClassSection}) }) - } }