3 Commits

Author SHA1 Message Date
60ba3ad417 Fix some tests that broke for some good reason I'm sure 2025-10-26 17:10:42 +01:00
b74e4724d4 Convert \n to \r?\n because of windows thank you windows :) 2025-10-26 17:04:39 +01:00
30246fd626 Fix logging the regex
It was adding backslashes and shit
2025-10-26 17:04:39 +01:00
2 changed files with 11 additions and 8 deletions

View File

@@ -84,7 +84,7 @@ END`
assert.Len(t, association.Commands, 0, "Expected 0 regular commands") assert.Len(t, association.Commands, 0, "Expected 0 regular commands")
// Run the isolate commands // Run the isolate commands
result, err := RunIsolateCommands(association, "test.txt", testContent) result, err := RunIsolateCommands(association, "test.txt", testContent, false)
if err != nil && err != NothingToDo { if err != nil && err != NothingToDo {
t.Fatalf("Failed to run isolate commands: %v", err) t.Fatalf("Failed to run isolate commands: %v", err)
} }
@@ -162,7 +162,7 @@ END_SECTION2`
} }
// Run the isolate commands // Run the isolate commands
result, err := RunIsolateCommands(associations["test.txt"], "test.txt", testContent) result, err := RunIsolateCommands(associations["test.txt"], "test.txt", testContent, false)
if err != nil && err != NothingToDo { if err != nil && err != NothingToDo {
t.Fatalf("Failed to run isolate commands: %v", err) t.Fatalf("Failed to run isolate commands: %v", err)
} }
@@ -234,7 +234,7 @@ func TestIsolateCommandsWithJSONMode(t *testing.T) {
} }
// Run the isolate commands // Run the isolate commands
result, err := RunIsolateCommands(associations["test.json"], "test.json", testContent) result, err := RunIsolateCommands(associations["test.json"], "test.json", testContent, false)
if err != nil && err != NothingToDo { if err != nil && err != NothingToDo {
t.Fatalf("Failed to run isolate commands: %v", err) t.Fatalf("Failed to run isolate commands: %v", err)
} }
@@ -309,7 +309,7 @@ END_REGULAR`
assert.Len(t, association.Commands, 1, "Expected 1 regular command") assert.Len(t, association.Commands, 1, "Expected 1 regular command")
// First run isolate commands // First run isolate commands
isolateResult, err := RunIsolateCommands(association, "test.txt", testContent) isolateResult, err := RunIsolateCommands(association, "test.txt", testContent, false)
if err != nil && err != NothingToDo { if err != nil && err != NothingToDo {
t.Fatalf("Failed to run isolate commands: %v", err) t.Fatalf("Failed to run isolate commands: %v", err)
} }
@@ -320,7 +320,7 @@ END_REGULAR`
// Then run regular commands // Then run regular commands
commandLoggers := make(map[string]*logger.Logger) commandLoggers := make(map[string]*logger.Logger)
finalResult, err := RunOtherCommands("test.txt", isolateResult, association, commandLoggers) finalResult, err := RunOtherCommands("test.txt", isolateResult, association, commandLoggers, false)
if err != nil && err != NothingToDo { if err != nil && err != NothingToDo {
t.Fatalf("Failed to run regular commands: %v", err) t.Fatalf("Failed to run regular commands: %v", err)
} }
@@ -397,7 +397,7 @@ irons_spellbooks:chain_lightning
assert.Len(t, association.Commands, 0, "Expected 0 regular commands") assert.Len(t, association.Commands, 0, "Expected 0 regular commands")
// Run the isolate commands // Run the isolate commands
result, err := RunIsolateCommands(association, "irons_spellbooks-server.toml", testContent) result, err := RunIsolateCommands(association, "irons_spellbooks-server.toml", testContent, false)
if err != nil && err != NothingToDo { if err != nil && err != NothingToDo {
t.Fatalf("Failed to run isolate commands: %v", err) t.Fatalf("Failed to run isolate commands: %v", err)
} }

View File

@@ -53,7 +53,7 @@ func ProcessRegex(content string, command utils.ModifyCommand, filename string)
processRegexLogger.Error("Error compiling pattern %q: %v", pattern, err) processRegexLogger.Error("Error compiling pattern %q: %v", pattern, err)
return commands, fmt.Errorf("error compiling pattern: %v", err) return commands, fmt.Errorf("error compiling pattern: %v", err)
} }
processRegexLogger.Debug("Compiled pattern successfully in %v", time.Since(patternCompileStart)) processRegexLogger.Debug("Compiled pattern successfully in %v. Pattern: %s", time.Since(patternCompileStart), pattern)
// Same here, it's just string concatenation, it won't kill us // Same here, it's just string concatenation, it won't kill us
// More important is that we don't fuck up the command // More important is that we don't fuck up the command
@@ -77,7 +77,7 @@ func ProcessRegex(content string, command utils.ModifyCommand, filename string)
processRegexLogger.Debug("Pattern complexity estimate: %d", patternComplexity) processRegexLogger.Debug("Pattern complexity estimate: %d", patternComplexity)
if len(indices) == 0 { if len(indices) == 0 {
processRegexLogger.Warning("No matches found for regex: %q", pattern) processRegexLogger.Warning("No matches found for regex: %s", pattern)
processRegexLogger.Debug("Total regex processing time: %v", time.Since(startTime)) processRegexLogger.Debug("Total regex processing time: %v", time.Since(startTime))
return commands, nil return commands, nil
} }
@@ -335,6 +335,9 @@ func resolveRegexPlaceholders(pattern string) string {
pattern = strings.ReplaceAll(pattern, "!any", `.*?`) pattern = strings.ReplaceAll(pattern, "!any", `.*?`)
resolveLogger.Debug("Replaced !any with non-greedy wildcard") resolveLogger.Debug("Replaced !any with non-greedy wildcard")
pattern = strings.ReplaceAll(pattern, "\n", "\r?\n")
resolveLogger.Debug("Added optional carriage return support for Windows line endings")
repPattern := regexp.MustCompile(`!rep\(([^,]+),\s*(\d+)\)`) repPattern := regexp.MustCompile(`!rep\(([^,]+),\s*(\d+)\)`)
// !rep(pattern, count) repeats the pattern n times // !rep(pattern, count) repeats the pattern n times
// Inserting !any between each repetition // Inserting !any between each repetition