Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 28 additions & 34 deletions parser/sectionParser_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package parser

import (
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -31,30 +30,30 @@ 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: "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})

})
}
Expand Down Expand Up @@ -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})
})

}
}

Expand Down
Loading