Add more tests (and fix some things) for replacecommand

This commit is contained in:
2025-03-28 00:23:42 +01:00
parent 294c04a11a
commit 9064a53820
2 changed files with 328 additions and 1 deletions

View File

@@ -36,7 +36,7 @@ func ExecuteModifications(modifications []ReplaceCommand, fileData string) (stri
func (m *ReplaceCommand) Execute(fileDataStr string) (string, error) {
err := m.Validate(len(fileDataStr))
if err != nil {
return "", fmt.Errorf("failed to validate modification: %v", err)
return fileDataStr, fmt.Errorf("failed to validate modification: %v", err)
}
logger.Trace("Replace pos %d-%d with %q", m.From, m.To, m.With)
@@ -50,5 +50,8 @@ func (m *ReplaceCommand) Validate(maxsize int) error {
if m.From > maxsize || m.To > maxsize {
return fmt.Errorf("command from or to is greater than replacement length: %v", m)
}
if m.From < 0 || m.To < 0 {
return fmt.Errorf("command from or to is less than 0: %v", m)
}
return nil
}