Add more tests (and fix some things) for replacecommand
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user