Housekeeping

This commit is contained in:
2025-03-28 02:11:54 +01:00
parent 513773f641
commit e8f16dda2b
3 changed files with 43 additions and 38 deletions

View File

@@ -250,7 +250,7 @@ func deduplicateGroups(captureGroups []*CaptureGroup) []*CaptureGroup {
}
if overlaps {
// We CAN just continue despite this fuckup
logger.Error("Overlapping capture group: %s", group.Name)
logger.Warning("Overlapping capture group: %s", group.Name)
continue
}
logger.Debug("No overlap detected for capture group: %s. Adding to deduplicated groups.", group.Name)
@@ -268,8 +268,6 @@ func resolveRegexPlaceholders(pattern string) string {
// Handle special pattern modifications
if !strings.HasPrefix(pattern, "(?s)") {
pattern = "(?s)" + pattern
// Use fmt.Printf for test compatibility
fmt.Printf("Pattern modified to include (?s): %s\n", pattern)
}
namedGroupNum := regexp.MustCompile(`(?:(\?<[^>]+>)(!num))`)

View File

@@ -979,29 +979,12 @@ func TestPatternWithoutPrefixGetsModified(t *testing.T) {
// Setup
pattern := "some.*pattern"
// Redirect stdout to capture fmt.Printf output
oldStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
// Execute function
result := resolveRegexPlaceholders(pattern)
// Restore stdout
w.Close()
os.Stdout = oldStdout
// Read captured output
var buf bytes.Buffer
io.Copy(&buf, r)
output := buf.String()
// Verify results
expectedPattern := "(?s)some.*pattern"
assert.Equal(t, expectedPattern, result, "Expected pattern to be %q, got %q", expectedPattern, result)
expectedOutput := fmt.Sprintf("Pattern modified to include (?s): %s\n", expectedPattern)
assert.Equal(t, expectedOutput, output, "Expected output message %q, got %q", expectedOutput, output)
}
// Empty string input returns "(?s)"
@@ -1009,29 +992,12 @@ func TestEmptyStringReturnsWithPrefix(t *testing.T) {
// Setup
pattern := ""
// Redirect stdout to capture fmt.Printf output
oldStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
// Execute function
result := resolveRegexPlaceholders(pattern)
// Restore stdout
w.Close()
os.Stdout = oldStdout
// Read captured output
var buf bytes.Buffer
io.Copy(&buf, r)
output := buf.String()
// Verify results
expectedPattern := "(?s)"
assert.Equal(t, expectedPattern, result, "Expected pattern to be %q, got %q", expectedPattern, result)
expectedOutput := fmt.Sprintf("Pattern modified to include (?s): %s\n", expectedPattern)
assert.Equal(t, expectedOutput, output, "Expected output message %q, got %q", expectedOutput, output)
}
// Named group with "!num" pattern gets replaced with proper regex for numbers