From da5f68703756ac584aad56dbc1f2d3556c3ef4d7 Mon Sep 17 00:00:00 2001 From: Flavore669 Date: Tue, 13 Jan 2026 15:26:35 -0600 Subject: [PATCH] Basic Testing Functionality + Test groupParens --- parser/requisiteParser_test.go | 87 ++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 parser/requisiteParser_test.go diff --git a/parser/requisiteParser_test.go b/parser/requisiteParser_test.go new file mode 100644 index 0000000..dd1b027 --- /dev/null +++ b/parser/requisiteParser_test.go @@ -0,0 +1,87 @@ +package parser + +import "testing" + +func TestInitMatchers(t *testing.T) { + // Test 1: Initialization + Matchers = nil + initMatchers() + + if Matchers == nil { + t.Error("Matchers should not be nil after initialization") + } + + if Matchers == nil { + t.Error("Matchers contain matchers after initialization") + } + + // Test 2: No regex compilation errors + for i, m := range Matchers { + if m.Regex == nil { + t.Errorf("Matcher %d has nil regex", i) + } + } +} + +func TestGroupParens(t *testing.T) { + tests := []struct { + name string + input string + expected string + groups []string + }{ + { + name: "No parentheses", + input: "MATH 2417 and PHYS 2125", + expected: "MATH 2417 and PHYS 2125", + groups: []string{}, + }, + { + name: "Single parentheses", + input: "MATH 2417 and (PHYS 2125 or PHYS 2126)", + expected: "MATH 2417 and @0", + groups: []string{"PHYS 2125 or PHYS 2126"}, + }, + { + name: "Nested parentheses", + input: "((A and B) or (C and D))", + expected: "@0", + groups: []string{"@1 or @2", "A and B", "C and D"}, + }, + { + name: "Multiple parentheses", + input: "(A) and (B) or (C)", + expected: "@0 and @1 or @2", + groups: []string{"A", "B", "C"}, + }, + { + name: "Mismatched closing parentheses", + input: "(A and B)) extra text", + expected: "@0 extra text", + groups: []string{"A and B"}, + }, + { + name: "Complex expression", + input: "MATH 2417 and (PHYS 2125 or (PHYS 2126 and CHEM 1311))", + expected: "MATH 2417 and @0", + groups: []string{"PHYS 2125 or @1", "PHYS 2126 and CHEM 1311"}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result, groups := groupParens(tt.input) + if result != tt.expected { + t.Errorf("groupParens() = %q, want %q", result, tt.expected) + } + if len(groups) != len(tt.groups) { + t.Errorf("group count = %d, want %d", len(groups), len(tt.groups)) + } + for i, group := range groups { + if i < len(tt.groups) && group != tt.groups[i] { + t.Errorf("group[%d] = %q, want %q", i, group, tt.groups[i]) + } + } + }) + } +}